Exemplo n.º 1
0
        private bool MatchNonGrammarTerminals()
        {
            TerminalList terms;

            if (!Data.NonGrammarTerminalsLookup.TryGetValue(SourceStream.PreviewChar, out terms))
            {
                return(false);
            }
            foreach (var term in terms)
            {
                SourceStream.ResetPreviewPosition();
                Context.CurrentToken = term.TryMatch(Context, SourceStream);
                if (Context.CurrentToken != null)
                {
                    term.InvokeValidateToken(Context);
                }
                if (Context.CurrentToken != null)
                {
                    //check if we need to fire LineStart token before this token;
                    // we do it only if the token is not a comment; comments should be ignored by the outline logic
                    var token = Context.CurrentToken;
                    if (token.Category == TokenCategory.Content && NeedLineStartToken(token.Location))
                    {
                        Context.BufferedTokens.Push(token);                                              //buffer current token; we'll eject LineStart instead
                        SourceStream.Location     = token.Location;                                      //set it back to the start of the token
                        Context.CurrentToken      = SourceStream.CreateToken(Grammar.LineStartTerminal); //generate LineStart
                        Context.PreviousLineStart = SourceStream.Location;                               //update LineStart
                    }
                    return(true);
                } //if
            }     //foreach term
            SourceStream.ResetPreviewPosition();
            return(false);
        }