Class Parser
java.lang.Object
com.oracle.js.parser.AbstractParser
com.oracle.js.parser.Parser
Builds the IR.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Lexer.LineInfoReceiverto receive line information from Lexer when scanning multiline literals.Fields inherited from class AbstractParser
errors, finish, isStrictMode, k, last, lexer, line, lineOffset, linePosition, previousToken, source, start, stream, token, type -
Constructor Summary
ConstructorsConstructorDescriptionParser(ScriptEnvironment env, Source source, ErrorManager errors) ConstructorParser(ScriptEnvironment env, Source source, ErrorManager errors, boolean strict) ConstructorParser(ScriptEnvironment env, Source source, ErrorManager errors, boolean strict, int lineOffset) Construct a parser. -
Method Summary
Modifier and TypeMethodDescriptiondecoratorList(boolean yield, boolean await) Parse a decorator list.parse()Execute parse and return the resulting function node.parse(com.oracle.truffle.api.strings.TruffleString scriptName, int startPos, int len, int reparseFlags, Scope parentScope, List<String> argumentNames) Execute parse and return the resulting function node.Parse eval code.Parse and return an expression.voidParse and return the list of function parameter list.parseFunctionBody(boolean generator, boolean async) Execute parse and return the resulting function node.parseModule(String moduleName) parseModule(String moduleName, int startPos, int len) Parse and return the resulting module.parseWithArguments(List<String> argumentNames) Parse code assuming a set of given arguments for the returnedFunctionNode.voidsetReparsedFunction(RecompilableScriptFunctionData reparsedFunction) Sets the @link RecompilableScriptFunctionData representing the function being reparsed (when this parser instance is used to reparse a previously parsed function, as part of its on-demand compilation).toString()Methods inherited from class AbstractParser
createIdentNode, error, error, error, error, expect, expectDontAdvance, expectMessage, expectMessage, getIdent, getIdentifierName, getLiteral, getNumberToStringConverter, getToken, getValue, getValue, getValueNoEscape, getValueNoEscape, isIdentifierName, isIdentifierName, isNonStrictModeIdent, message, message, next, nextOrEOL, T, validateLexerToken, warning
-
Field Details
-
lineInfoReceiver
to receive line information from Lexer when scanning multiline literals.
-
-
Constructor Details
-
Parser
Constructor- Parameters:
env- script environmentsource- source to parseerrors- error manager
-
Parser
Constructor- Parameters:
env- script environmentsource- source to parseerrors- error managerstrict- strict
-
Parser
public Parser(ScriptEnvironment env, Source source, ErrorManager errors, boolean strict, int lineOffset) Construct a parser.- Parameters:
env- script environmentsource- source to parseerrors- error managerstrict- parser created with strict mode enabled.lineOffset- line offset to start counting lines from
-
-
Method Details
-
parse
Execute parse and return the resulting function node. Errors will be thrown and the error manager will contain information if parsing should fail This is the default parse call, which will name the function nodePROGRAM_NAME.- Returns:
- function node resulting from successful parse
-
setReparsedFunction
Sets the @link RecompilableScriptFunctionData representing the function being reparsed (when this parser instance is used to reparse a previously parsed function, as part of its on-demand compilation). This will trigger various special behaviors, such as skipping nested function bodies.- Parameters:
reparsedFunction- the function being reparsed.
-
parse
public FunctionNode parse(com.oracle.truffle.api.strings.TruffleString scriptName, int startPos, int len, int reparseFlags, Scope parentScope, List<String> argumentNames) Execute parse and return the resulting function node. Errors will be thrown and the error manager will contain information if parsing should fail This should be used to create one and only one function node- Parameters:
scriptName- name for the script, given to the parsed FunctionNodestartPos- start position in sourcelen- length of parsereparseFlags- flags provided byRecompilableScriptFunctionDataas context for the code being reparsed. This allows us to recognize special forms of functions such as property getters and setters or instances of ES6 method shorthand in object literals.argumentNames- optional names of arguments assumed by the parsed function node.- Returns:
- function node resulting from successful parse
-
parseModule
Parse and return the resulting module. Errors will be thrown and the error manager will contain information if parsing should fail- Parameters:
moduleName- name for the module, given to the parsed FunctionNodestartPos- start position in sourcelen- length of parse- Returns:
- function node resulting from successful parse
-
parseModule
-
parseEval
Parse eval code.- Parameters:
parentScope- optional caller context scope (direct eval)
-
parseWithArguments
Parse code assuming a set of given arguments for the returnedFunctionNode.- Parameters:
argumentNames- names of arguments assumed by the parsed function node.
-
parseFormalParameterList
public void parseFormalParameterList()Parse and return the list of function parameter list. A comma separated list of function parameter identifiers is expected to be parsed. Errors will be thrown and the error manager will contain information if parsing should fail. This method is used to check if parameter Strings passed to "Function" constructor is a valid or not.- See Also:
-
parseFunctionBody
Execute parse and return the resulting function node. Errors will be thrown and the error manager will contain information if parsing should fail. This method is used to check if code String passed to "Function" constructor is a valid function body or not.- Returns:
- function node resulting from successful parse
- See Also:
-
toString
-
decoratorList
Parse a decorator list.DecoratorList[Yield, Await] : DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await] Decorator[Yield, Await] : @ DecoratorMemberExpression[?Yield, ?Await] @ DecoratorParenthesizedExpression[?Yield, ?Await] @ DecoratorCallExpression[?Yield, ?Await] DecoratorMemberExpression[Yield, Await] : IdentifierReference[?Yield, ?Await] PrivateIdentifier DecoratorMemberExpression[?Yield, ?Await] . IdentifierName DecoratorCallExpression[Yield, Await] : DecoratorMemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await] DecoratorParenthesizedExpression[Yield, Await] : ( Expression[+In, ?Yield, ?Await] ) ClassDeclaration[Yield, Await, Default] : DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await] [+Default] DecoratorList[?Yield, ?Await]opt class ClassTail[?Yield, ?Await] -
parseExpression
Parse and return an expression. Errors will be thrown and the error manager will contain information if parsing should fail.- Returns:
- expression node resulting from successful parse
-