Class Parser

java.lang.Object
org.mozilla.javascript.Parser

public class Parser extends Object
This class implements the JavaScript parser.

It is based on the SpiderMonkey C source files jsparse.c and jsparse.h in the jsref package.

The parser generates an AstRoot parse tree representing the source code. No tree rewriting is permitted at this stage, so that the parse tree is a faithful representation of the source for frontend processing tools and IDEs.

This parser implementation is not intended to be reused after a parse finishes, and will throw an IllegalStateException() if invoked again.

Author:
Mike McCabe, Brendan Eich
See Also:
  • TokenStream
  • Field Details

    • ARGC_LIMIT

      public static final int ARGC_LIMIT
      Maximum number of allowed function or constructor arguments, to follow SpiderMonkey.
      See Also:
    • nestingOfFunction

      protected int nestingOfFunction
    • inUseStrictDirective

      protected boolean inUseStrictDirective
  • Constructor Details

  • Method Details

    • eof

      public boolean eof()
    • parse

      public AstRoot parse(String sourceString, String sourceURI, int lineno)
      Builds a parse tree from the given source string.
      Returns:
      an AstRoot object representing the parsed program. If the parse fails, null will be returned. (The parse failure will result in a call to the ErrorReporter from CompilerEnvirons.)
    • parse

      @Deprecated public AstRoot parse(Reader sourceReader, String sourceURI, int lineno) throws IOException
      Deprecated.
      use parse(String, String, int) instead
      Builds a parse tree from the given sourcereader.
      Throws:
      IOException - if the Reader encounters an error
      See Also:
    • checkActivationName

      protected void checkActivationName(String name, int token)
    • setRequiresActivation

      protected void setRequiresActivation()
    • setIsGenerator

      protected void setIsGenerator()
    • createName

      protected Node createName(String name)
    • createName

      protected Node createName(int type, String name, Node child)
    • createNumber

      protected Node createNumber(double number)
    • createScopeNode

      protected Scope createScopeNode(int token, int lineno, int column)
      Create a node that can be used to hold lexically scoped variable definitions (via let declarations).
      Parameters:
      token - the token of the node to create
      lineno - line number of source
      Returns:
      the created node
    • simpleAssignment

      protected Node simpleAssignment(Node left, Node right)
    • simpleAssignment

      protected Node simpleAssignment(Node left, Node right, org.mozilla.javascript.Parser.Transformer transformer)
    • checkMutableReference

      protected void checkMutableReference(Node n)
    • removeParens

      protected AstNode removeParens(AstNode node)
    • setDefaultUseStrictDirective

      public void setDefaultUseStrictDirective(boolean useStrict)
    • inUseStrictDirective

      public boolean inUseStrictDirective()
    • reportErrorsIfExists

      public void reportErrorsIfExists(int baseLineno)