public void AppendCharacterClass(LsmCharacterClass charClass)
        {
            LsmClassMatchRule constantRule
                = _lastState.MatchRules.GetRuleByClass(charClass);

            if (constantRule == null)
            {
                constantRule = new LsmClassMatchRule(charClass);

                _lastState.MatchRules.Add(constantRule);

                if (_lastState == _rootState)
                    constantRule.Actions.EnsureClearTokenAction();
            }

            constantRule.Actions.EnsureAcceptCharAction();
            constantRule.Actions.EnsureAdvanceAction();

            _lastState = constantRule.Actions.GetTransitionDestination();
            if (_lastState == null)
            {
                _lastState = new LsmState();
                _document.States.Add(_lastState);
                constantRule.Actions.SetTransitionDestination(_lastState);
            }
        }
Exemplo n.º 2
0
        /*
        public int IdentifierTokenTypeID
        {
            get { return identifierTokenTypeID; }
            set { identifierTokenTypeID = value; }
        }*/
        public void ApplyIdentifierPaths(int tokenTypeID)
        {
            //LsmState identifierFirst = new LsmState();
            LsmState identifierRest = new LsmState();

            LsmClassMatchRule alphaNumericRule = new LsmClassMatchRule(LsmCharacterClass.Alphanumeric);
            LsmClassMatchRule letterRule = new LsmClassMatchRule(LsmCharacterClass.Letter);

            letterRule.Actions.Add(new LsmStateTransitionAction(identifierRest));
            letterRule.Actions.Add(new LsmMarkTokenStartAction());

            alphaNumericRule.Actions.Add(new LsmAcceptCharAction());
            alphaNumericRule.Actions.Add(new LsmAdvanceAction());
            alphaNumericRule.Actions.Add(new LsmStateTransitionAction(identifierRest));

            rootState.MatchRules.Add(letterRule);

            identifierRest.MatchRules.Add(alphaNumericRule);
            identifierRest.DefaultActions.Add(new LsmAcceptTokenAction(tokenTypeID));
            identifierRest.DefaultActions.Add(new LsmClearTokenTextAction());
            identifierRest.DefaultActions.Add(new LsmStateTransitionAction(rootState));
            identifierRest.PostStreamActions.Add(new LsmAcceptTokenAction(tokenTypeID));

            foreach (LsmState keywordEndState in keywordEndStates)
                keywordEndState.MatchRules.Add(alphaNumericRule);

            document.States.Add(identifierRest);
        }