Package org.mozilla.javascript
Class Parser
java.lang.Object
org.mozilla.javascript.Parser
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
protected class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Maximum number of allowed function or constructor arguments, to follow SpiderMonkey.protected boolean
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionParser()
Parser
(CompilerEnvirons compilerEnv) Parser
(CompilerEnvirons compilerEnv, ErrorReporter errorReporter) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkActivationName
(String name, int token) protected void
protected Node
createName
(int type, String name, Node child) protected Node
createName
(String name) protected Node
createNumber
(double number) 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).boolean
eof()
boolean
Deprecated.use parse(String, String, int) insteadBuilds a parse tree from the given source string.protected AstNode
removeParens
(AstNode node) void
reportErrorsIfExists
(int baseLineno) void
setDefaultUseStrictDirective
(boolean useStrict) protected void
protected void
protected Node
simpleAssignment
(Node left, Node right) protected Node
simpleAssignment
(Node left, Node right, org.mozilla.javascript.Parser.Transformer transformer)
-
Field Details
-
ARGC_LIMIT
public static final int ARGC_LIMITMaximum number of allowed function or constructor arguments, to follow SpiderMonkey.- See Also:
-
nestingOfFunction
protected int nestingOfFunction -
inUseStrictDirective
protected boolean inUseStrictDirective
-
-
Constructor Details
-
Parser
public Parser() -
Parser
-
Parser
-
-
Method Details
-
eof
public boolean eof() -
parse
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 theErrorReporter
fromCompilerEnvirons
.)
-
parse
@Deprecated public AstRoot parse(Reader sourceReader, String sourceURI, int lineno) throws IOException Deprecated.use parse(String, String, int) insteadBuilds a parse tree from the given sourcereader.- Throws:
IOException
- if theReader
encounters an error- See Also:
-
checkActivationName
-
setRequiresActivation
protected void setRequiresActivation() -
setIsGenerator
protected void setIsGenerator() -
createName
-
createName
-
createNumber
-
createScopeNode
Create a node that can be used to hold lexically scoped variable definitions (via let declarations).- Parameters:
token
- the token of the node to createlineno
- line number of source- Returns:
- the created node
-
simpleAssignment
-
simpleAssignment
-
checkMutableReference
-
removeParens
-
setDefaultUseStrictDirective
public void setDefaultUseStrictDirective(boolean useStrict) -
inUseStrictDirective
public boolean inUseStrictDirective() -
reportErrorsIfExists
public void reportErrorsIfExists(int baseLineno)
-