コード例 #1
0
        public override bool IsImplicitMatch(CSharpLexer lexer)
        {
            if (!char.IsWhiteSpace(lexer.Previous) &&
                !lexer.IsSpecialSymbol(lexer.Previous, DelimiterType.End))
            {
                return(false);
            }

            bool matchedNumber = false;

            while (!lexer.EndOfStream)
            {
                if (IsNumberOrDecimalPoint(lexer.ReadNext()))
                {
                    matchedNumber = true;
                    lexer.Commit();
                }
                else
                {
                    lexer.Rollback();
                    break;
                }
            }

            return(matchedNumber);
        }
コード例 #2
0
        private bool IsMatch(CSharpLexer lexer, string commentType)
        {
            if (!string.IsNullOrEmpty(commentType))
            {
                lexer.Rollback();

                bool match = true;
                for (int i = 0; i < commentType.Length; i++)
                {
                    if (commentType[i] != lexer.ReadNext())
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    // Read until end of line or file
                    while (!IsEndLineOrEndFile(lexer, lexer.ReadNext()))
                    {
                    }

                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        public bool IsMatch(CSharpLexer lexer)
        {
            if (IsImplicitMatch(lexer))
            {
                lexer.Commit();
                return(true);
            }

            lexer.Rollback();
            return(false);
        }
コード例 #4
0
ファイル: KeywordMatch.cs プロジェクト: js6pak/UnityExplorer
        public override bool IsImplicitMatch(CSharpLexer lexer)
        {
            if (!char.IsWhiteSpace(lexer.Previous) &&
                !lexer.IsSpecialSymbol(lexer.Previous, DelimiterType.End))
            {
                return(false);
            }

            shortlist.Clear();

            int  currentIndex = 0;
            char currentChar  = lexer.ReadNext();

            for (int i = 0; i < Keywords.Length; i++)
            {
                if (Keywords[i][0] == currentChar)
                {
                    shortlist.Add(Keywords[i]);
                }
            }

            if (shortlist.Count == 0)
            {
                return(false);
            }

            do
            {
                if (lexer.EndOfStream)
                {
                    RemoveLongStrings(currentIndex + 1);
                    break;
                }

                currentChar = lexer.ReadNext();
                currentIndex++;

                if (char.IsWhiteSpace(currentChar) ||
                    lexer.IsSpecialSymbol(currentChar, DelimiterType.Start))
                {
                    RemoveLongStrings(currentIndex);
                    lexer.Rollback(1);
                    break;
                }

                foreach (string keyword in shortlist)
                {
                    if (currentIndex >= keyword.Length || keyword[currentIndex] != currentChar)
                    {
                        removeList.Push(keyword);
                    }
                }

                while (removeList.Count > 0)
                {
                    shortlist.Remove(removeList.Pop());
                }
            }while (shortlist.Count > 0);

            return(shortlist.Count > 0);
        }
コード例 #5
0
        public override bool IsImplicitMatch(CSharpLexer lexer)
        {
            if (lexer == null)
            {
                return(false);
            }

            if (!char.IsWhiteSpace(lexer.Previous) &&
                !char.IsLetter(lexer.Previous) &&
                !char.IsDigit(lexer.Previous) &&
                !lexer.IsSpecialSymbol(lexer.Previous, DelimiterType.End))
            {
                return(false);
            }

            shortlist.Clear();

            int  currentIndex = 0;
            char currentChar  = lexer.ReadNext();

            for (int i = symbols.Length - 1; i >= 0; i--)
            {
                if (symbols[i][0] == currentChar)
                {
                    shortlist.Add(symbols[i]);
                }
            }

            if (shortlist.Count == 0)
            {
                return(false);
            }

            do
            {
                if (lexer.EndOfStream)
                {
                    RemoveLongStrings(currentIndex + 1);
                    break;
                }

                currentChar = lexer.ReadNext();
                currentIndex++;

                if (char.IsWhiteSpace(currentChar) ||
                    char.IsLetter(currentChar) ||
                    char.IsDigit(currentChar) ||
                    lexer.IsSpecialSymbol(currentChar, DelimiterType.Start))
                {
                    RemoveLongStrings(currentIndex);
                    lexer.Rollback(1);
                    break;
                }

                foreach (string symbol in shortlist)
                {
                    if (currentIndex >= symbol.Length || symbol[currentIndex] != currentChar)
                    {
                        removeList.Push(symbol);
                    }
                }

                while (removeList.Count > 0)
                {
                    shortlist.Remove(removeList.Pop());
                }
            }while (shortlist.Count > 0);

            return(shortlist.Count > 0);
        }