Jurassic.Compiler.Lexer.NextToken C# (CSharp) Метод

NextToken() публичный Метод

Reads the next token from the reader.
public NextToken ( ) : Jurassic.Compiler.Token
Результат Jurassic.Compiler.Token
        public Token NextToken()
        {
            int c1 = ReadNextChar();

            if (IsPunctuatorStartChar(c1) == true)
            {
                // Punctuator (puntcuation + operators).
                this.lastSignificantToken = ReadPunctuator(c1);
                return this.lastSignificantToken;
            }
            else if (IsWhiteSpace(c1) == true)
            {
                // White space.
                return ReadWhiteSpace();
            }
            else if (IsIdentifierStartChar(c1) == true)
            {
                // Identifier or reserved word.
                this.lastSignificantToken = ReadIdentifier(c1);
                return this.lastSignificantToken;
            }
            else if (IsStringLiteralStartChar(c1) == true)
            {
                // String literal.
                this.lastSignificantToken = ReadStringLiteral(c1);
                return this.lastSignificantToken;
            }
            else if (IsNumericLiteralStartChar(c1) == true)
            {
                // Number literal.
                this.lastSignificantToken = ReadNumericLiteral(c1);
                return this.lastSignificantToken;
            }
            else if (IsLineTerminator(c1) == true)
            {
                // Line Terminator.
                this.lastSignificantToken = ReadLineTerminator(c1);
                return this.lastSignificantToken;
            }
            else if (c1 == '/')
            {
                // Comment or divide or regular expression.
                this.lastSignificantToken = ReadDivideCommentOrRegularExpression();
                return this.lastSignificantToken;
            }
            else if (c1 == -1)
            {
                // End of input.
                this.lastSignificantToken = null;
                return null;
            }
            else
                throw new JavaScriptException(this.engine, ErrorType.SyntaxError, string.Format("Unexpected character '{0}'.", (char)c1), this.lineNumber, this.Source.Path);
        }

Usage Example

Пример #1
0
 /// <summary>
 /// Validates the given string is a valid identifier and returns the identifier name after
 /// escape sequences have been processed.
 /// </summary>
 /// <param name="engine"> The associated script engine. </param>
 /// <param name="str"> The string to resolve into an identifier. </param>
 /// <returns> The identifier name after escape sequences have been processed, or
 /// <c>null</c> if the string is not an identifier. </returns>
 internal static string ResolveIdentifier(ScriptEngine engine, string str)
 {
     var lexer = new Lexer(engine, new StringScriptSource(str));
     var argumentToken = lexer.NextToken();
     if ((argumentToken is IdentifierToken) == false || lexer.NextToken() != null)
         return null;
     return ((Compiler.IdentifierToken)argumentToken).Name;
 }