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 interfacestatic classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum number of allowed function or constructor arguments, to follow SpiderMonkey.protected booleanprotected int -
Constructor Summary
ConstructorsConstructorDescriptionParser()Parser(CompilerEnvirons compilerEnv) Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckActivationName(String name, int token) protected voidprotected NodecreateName(int type, String name, Node child) protected NodecreateName(String name) protected NodecreateNumber(double number) protected ScopecreateScopeNode(int token, int lineno, int column) Create a node that can be used to hold lexically scoped variable definitions (via let declarations).booleaneof()booleanDeprecated.use parse(String, String, int) insteadBuilds a parse tree from the given source string.protected AstNoderemoveParens(AstNode node) voidreportErrorsIfExists(int baseLineno) voidsetDefaultUseStrictDirective(boolean useStrict) protected voidprotected voidprotected NodesimpleAssignment(Node left, Node right) protected NodesimpleAssignment(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
AstRootobject representing the parsed program. If the parse fails,nullwill be returned. (The parse failure will result in a call to theErrorReporterfromCompilerEnvirons.)
-
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 theReaderencounters 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)
-