Class Parser


public class Parser extends AbstractParser
Builds the IR.
  • Field Details

    • lineInfoReceiver

      protected final Lexer.LineInfoReceiver lineInfoReceiver
      to receive line information from Lexer when scanning multiline literals.
  • Constructor Details

    • Parser

      public Parser(ScriptEnvironment env, Source source, ErrorManager errors)
      Constructor
      Parameters:
      env - script environment
      source - source to parse
      errors - error manager
    • Parser

      public Parser(ScriptEnvironment env, Source source, ErrorManager errors, boolean strict)
      Constructor
      Parameters:
      env - script environment
      source - source to parse
      errors - error manager
      strict - strict
    • Parser

      public Parser(ScriptEnvironment env, Source source, ErrorManager errors, boolean strict, int lineOffset)
      Construct a parser.
      Parameters:
      env - script environment
      source - source to parse
      errors - error manager
      strict - parser created with strict mode enabled.
      lineOffset - line offset to start counting lines from
  • Method Details

    • parse

      public FunctionNode 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 node PROGRAM_NAME.
      Returns:
      function node resulting from successful parse
    • setReparsedFunction

      public void setReparsedFunction(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). 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 FunctionNode
      startPos - start position in source
      len - length of parse
      reparseFlags - flags provided by RecompilableScriptFunctionData as 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

      public FunctionNode parseModule(String moduleName, int startPos, int len)
      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 FunctionNode
      startPos - start position in source
      len - length of parse
      Returns:
      function node resulting from successful parse
    • parseModule

      public FunctionNode parseModule(String moduleName)
    • parseEval

      public FunctionNode parseEval(boolean functionContext, Scope parentScope)
      Parse eval code.
      Parameters:
      parentScope - optional caller context scope (direct eval)
    • parseWithArguments

      public FunctionNode parseWithArguments(List<String> argumentNames)
      Parse code assuming a set of given arguments for the returned FunctionNode.
      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

      public FunctionNode parseFunctionBody(boolean generator, boolean async)
      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

      public String toString()
      Overrides:
      toString in class Object
    • decoratorList

      public List<Expression> decoratorList(boolean yield, boolean await)
      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

      public Expression 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