public BackwardTokenSearchItem(OrderedTokenSet tokenSet, bool match = true, GeneroLanguageVersion minLangVersion = GeneroLanguageVersion.None)
     : base(minLangVersion)
 {
     TokenSet    = tokenSet;
     SingleToken = TokenKind.EndOfFile;
     Match       = match;
 }
            private bool AttemptOrderedSetMatch(int index, IReverseTokenizer revTokenizer, OrderedTokenSet tokenSet, bool doMatch = true)
            {
                bool isMatch    = false;
                int  tokenIndex = 1;

                // start reverse parsing
                var enumerator = revTokenizer.GetReversedTokens().Where(x => x.SourceSpan.Start.Index < index).GetEnumerator();

                while (true)
                {
                    if (!enumerator.MoveNext())
                    {
                        isMatch = false;
                        break;
                    }
                    var tokInfo = enumerator.Current;
                    if (tokInfo.Equals(default(TokenInfo)) || tokInfo.Token.Kind == TokenKind.NewLine || tokInfo.Token.Kind == TokenKind.NLToken || tokInfo.Token.Kind == TokenKind.Comment)
                    {
                        continue;   // linebreak
                    }
                    if (doMatch &&
                        (tokenSet.Set[tokenIndex].Token is TokenKind && (TokenKind)tokenSet.Set[tokenIndex].Token == tokInfo.Token.Kind) ||
                        (tokenSet.Set[tokenIndex].Token is TokenCategory && (TokenCategory)tokenSet.Set[tokenIndex].Token == tokInfo.Category))
                    {
                        if (tokenSet.Set[tokenIndex].FailIfMatch)
                        {
                            break;
                        }
                        tokenIndex++;
                        if (tokenSet.Set.Count == tokenIndex)
                        {
                            isMatch = true;
                            break;
                        }
                    }
                    else if (!doMatch &&
                             (tokenSet.Set[tokenIndex].Token is TokenKind && (TokenKind)tokenSet.Set[tokenIndex].Token != tokInfo.Token.Kind) ||
                             (tokenSet.Set[tokenIndex].Token is TokenCategory && (TokenCategory)tokenSet.Set[tokenIndex].Token != tokInfo.Category))
                    {
                        if (tokenSet.Set[tokenIndex].FailIfMatch)
                        {
                            break;
                        }
                        tokenIndex++;
                        if (tokenSet.Set.Count == tokenIndex)
                        {
                            isMatch = true;
                            break;
                        }
                    }
                    else
                    {
                        if (Genero4glAst.ValidStatementKeywords.Contains(tokInfo.Token.Kind) ||
                            tokInfo.Token.Kind == TokenKind.EndOfFile)
                        {
                            isMatch = false;
                            break;
                        }
                    }
                }

                return(isMatch);
            }
Esempio n. 3
0
 public BackwardTokenSearchItem(OrderedTokenSet tokenSet, bool match = true)
 {
     TokenSet    = tokenSet;
     SingleToken = TokenKind.EndOfFile;
     Match       = match;
 }