public void AppendCharacter(char character)
        {
            LsmConstantMatchRule constantRule
                = _lastState.MatchRules.GetRuleByConstant(character);

            if (constantRule == null)
            {
                constantRule = new LsmConstantMatchRule(character);

                _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);
            }
        }
Пример #2
0
        public LsmState AppendStringTokenPath(LsmState start, string tokenText, int typeID)
        {
            LsmState currState = start;
            for (int i = 0; i < tokenText.Length; i++)
            {
                char character = tokenText[i];
                LsmState nextState;

                LsmConstantMatchRule constantRule
                    = currState.MatchRules.GetRuleByConstant(character);
                if (constantRule == null)
                {
                    constantRule = new LsmConstantMatchRule(character);

                    nextState = new LsmState();
                    document.States.Add(nextState);

                    if (i == 0)
                        constantRule.Actions.Add(new LsmMarkTokenStartAction());

                    constantRule.Actions.Add(new LsmAcceptCharAction());
                    constantRule.Actions.Add(new LsmAdvanceAction());
                    constantRule.Actions.Add(new LsmStateTransitionAction(nextState));

                    currState.MatchRules.Add(constantRule);
                }
                else
                    nextState = constantRule.Actions.GetTransitionDestination();

                if (i == tokenText.Length - 1)
                {
                    nextState.DefaultActions.Add(new LsmAcceptTokenAction(typeID));
                    nextState.DefaultActions.Add(new LsmClearTokenTextAction());
                    nextState.DefaultActions.Add(new LsmStateTransitionAction(rootState));

                    nextState.PostStreamActions.Add(new LsmAcceptTokenAction(typeID));
                }

                currState.DefaultActions.SetTransitionDestination(rootState);

                currState = nextState;
            }

            return currState;
        }