Exemplo n.º 1
0
 public ParserStateException(StatementState state, LexedToken curTok, AllowedTransition transitionRecord) :
     base($"Invalid token {curTok.TokenType.ToString()} in {state.ToString()}")
 {
     this.state            = state;
     this.curTok           = curTok;
     this.transitionRecord = transitionRecord;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Moves to the next token , additionally ensures that the token transition is valid
        /// generally looks at the global token tree , but subclasses can provide thier own allowed transitions to provide dynamic , localized validation
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>
        public LexedToken?MoveNext(AllowedTransition tr, bool SkipWhitespace)
        {
            if (CurrentIndex + 1 == Tokens.Count)
            {
                return(null);
            }

            CurrentIndex++;
            var curTok = Tokens[CurrentIndex];

            if (SkipWhitespace)
            {
                while (curTok.TokenType == LexedTokenType.WHITESPACE)
                {
                    if (CurrentIndex + 1 == Tokens.Count)
                    {
                        return(null);
                    }
                    CurrentIndex++;
                    curTok = Tokens[CurrentIndex];
                }
            }

            var TransitionRecord = tr;

            if (tr == null)
            {
                TransitionRecord = ParseStates.StateTransitions[State];
            }
            if (!TransitionRecord.ContainsKey(curTok.TokenType))
            {
                throw new ParserStateException(State, curTok, TransitionRecord);
            }
            CurrentTransition = TransitionRecord;
            return(curTok);
        }