Ejemplo n.º 1
0
        public override bool TryMatchCurrent(LexerBuilder lexer)
        {
            var prev  = lexer.Previous;
            var first = lexer.Current;

            // check for keywords
            if (lexer.IsDelimiter(prev, true) && char.IsLetter(first))
            {
                // can be a keyword...

                var sb = new StringBuilder();
                sb.Append(lexer.Current);
                while (!lexer.EndOfInput && char.IsLetter(lexer.PeekNext()))
                {
                    sb.Append(lexer.Current);
                }

                if (keywords.Contains(sb.ToString()))
                {
                    if (!lexer.EndOfInput)
                    {
                        lexer.RollbackBy(1);
                    }
                    lexer.Commit();
                    return(true);
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public override bool TryMatchCurrent(LexerBuilder lexer)
        {
            // previous character must be delimiter, whitespace, or alphanumeric.
            if (!lexer.IsDelimiter(lexer.Previous, true, true))
            {
                return(false);
            }

            if (IsSymbol(lexer.Current))
            {
                do
                {
                    lexer.Commit();
                    lexer.PeekNext();
                }while (IsSymbol(lexer.Current));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override bool TryMatchCurrent(LexerBuilder lexer)
        {
            // previous character must be whitespace or delimiter
            if (!lexer.IsDelimiter(lexer.Previous, true))
            {
                return(false);
            }

            if (!IsNumeric(lexer.Current))
            {
                return(false);
            }

            while (!lexer.EndOfInput)
            {
                lexer.Commit();
                if (!IsNumeric(lexer.PeekNext()))
                {
                    break;
                }
            }

            return(true);
        }