C# Class Jurassic.Compiler.Parser

Converts a series of tokens into an abstract syntax tree.
显示文件 Open project: paulbartrum/jurassic Class Usage Examples

Public Methods

Method Description
Parse ( ) : Statement

Parses javascript source code.

Parser ( ScriptEngine engine, Lexer lexer, Scope initialScope, Jurassic.Compiler.CompilerOptions options, CodeContext context, Jurassic.Compiler.MethodOptimizationHints methodOptimizationHints = null ) : System

Creates a Parser instance with the given lexer supplying the tokens.

Private Methods

Method Description
AtValidEndOfStatement ( ) : bool

Returns a value that indicates whether the current position is a valid position to end a statement.

CheckASTValidity ( Jurassic.Compiler.Expression root ) : void

Checks the given AST is valid.

Consume ( ParserExpressionState expressionState = ParserExpressionState.Literal ) : void

Discards the current token and reads the next one.

CreateFunctionBodyParser ( Parser parser, Scope scope, Jurassic.Compiler.MethodOptimizationHints optimizationHints ) : Parser

Creates a parser that can read the body of a function.

CreateScopeContext ( Scope letScope, Scope varScope = null ) : ScopeContext

Sets the current scope and returns an object which can be disposed to restore the previous scope.

Expect ( Jurassic.Compiler.Token token ) : void

Indicates that the next token is identical to the given one. Throws an exception if this is not the case. Consumes the token.

ExpectEndOfStatement ( ) : void

Indicates that the next token should end the current statement. This implies that the next token is a semicolon, right brace or a line terminator.

ExpectIdentifier ( ) : string

Indicates that the next token should be an identifier. Throws an exception if this is not the case. Consumes the token.

InitializeOperatorLookup ( ) : Operator>.Dictionary

Initializes the token -> operator mapping dictionary.

OperatorFromToken ( Jurassic.Compiler.Token token, bool postfixOrInfix ) : Jurassic.Compiler.Operator

Finds a operator given a token and an indication whether the prefix or infix/postfix version is desired.

ParseArrayLiteral ( ) : LiteralExpression

Parses an array literal (e.g. "[1, 2]").

ParseBlock ( ) : Jurassic.Compiler.BlockStatement

Parses a block of statements.

The value of a block statement is the value of the last statement in the block, or undefined if there are no statements in the block.

ParseBreak ( ) : Jurassic.Compiler.BreakStatement

Parses a break statement.

ParseContinue ( ) : Jurassic.Compiler.ContinueStatement

Parses a continue statement.

ParseDebugger ( ) : Jurassic.Compiler.DebuggerStatement

Parses a debugger statement.

ParseDo ( ) : Jurassic.Compiler.DoWhileStatement

Parses a do statement.

ParseEmpty ( ) : Statement

Parses an empty statement.

ParseExpression ( ) : Jurassic.Compiler.Expression

Parses a javascript expression.

ParseFor ( ) : Statement

Parses a for statement, for-in statement, or a for-of statement.

ParseFunction ( FunctionDeclarationType functionType, Scope parentScope, string functionName ) : Jurassic.Compiler.FunctionExpression

Parses a function declaration or a function expression.

ParseFunctionArguments ( Jurassic.Compiler.Token endToken ) : List

Parses a comma-separated list of function arguments.

ParseFunctionDeclaration ( ) : Statement

Parses a function declaration.

ParseFunctionExpression ( ) : Jurassic.Compiler.FunctionExpression

Parses a function expression.

ParseIf ( ) : Jurassic.Compiler.IfStatement

Parses an if statement.

ParseLabelOrExpressionStatement ( ) : Statement

Parses a statement consisting of an expression or starting with a label. These two cases are disambiguated here.

ParseObjectLiteral ( ) : LiteralExpression

Parses an object literal (e.g. "{a: 5}").

ParseReturn ( ) : Jurassic.Compiler.ReturnStatement

Parses a return statement.

ParseStatement ( ) : Statement

Parses any statement other than a function declaration.

ParseStatementNoNewContext ( ) : Statement

Parses any statement other than a function declaration, without beginning a new statement context.

ParseSwitch ( ) : Jurassic.Compiler.SwitchStatement

Parses a switch statement.

ParseTemplateLiteral ( ) : Jurassic.Compiler.Expression

Parses a template literal (e.g. `Bought ${count} items`).

ParseThrow ( ) : Jurassic.Compiler.ThrowStatement

Parses a throw statement.

ParseTry ( ) : Jurassic.Compiler.TryCatchFinallyStatement

Parses a try statement.

ParseVarLetOrConst ( KeywordToken keyword ) : Jurassic.Compiler.VarStatement

Parses a var, let or const statement.

ParseWhile ( ) : Jurassic.Compiler.WhileStatement

Parses a while statement.

ParseWith ( ) : Jurassic.Compiler.WithStatement

Parses a with statement.

ReadPropertyNameExpression ( PropertyNameType &nameType ) : Jurassic.Compiler.Expression

Reads a property name, used in object literals.

SetInitialScope ( Scope initialScope ) : void

Sets the initial scope.

ValidateVariableName ( string name ) : void

Throws an exception if the variable name is invalid.

Method Details

Parse() public method

Parses javascript source code.
public Parse ( ) : Statement
return Statement

Parser() public method

Creates a Parser instance with the given lexer supplying the tokens.
public Parser ( ScriptEngine engine, Lexer lexer, Scope initialScope, Jurassic.Compiler.CompilerOptions options, CodeContext context, Jurassic.Compiler.MethodOptimizationHints methodOptimizationHints = null ) : System
engine ScriptEngine The associated script engine.
lexer Lexer The lexical analyser that provides the tokens.
initialScope Scope The initial variable scope.
options Jurassic.Compiler.CompilerOptions Options that influence the compiler.
context CodeContext The context of the code (global, function or eval).
methodOptimizationHints Jurassic.Compiler.MethodOptimizationHints Hints about whether optimization is possible.
return System