public class Parser
extends java.lang.Object
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.
TokenStream
Modifier and Type | Class and Description |
---|---|
protected class |
Parser.PerFunctionVariables |
Modifier and Type | Field and Description |
---|---|
static int |
ARGC_LIMIT
Maximum number of allowed function or constructor arguments,
to follow SpiderMonkey.
|
protected boolean |
inUseStrictDirective |
protected int |
nestingOfFunction |
Constructor and Description |
---|
Parser() |
Parser(CompilerEnvirons compilerEnv) |
Parser(CompilerEnvirons compilerEnv,
ErrorReporter errorReporter) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkActivationName(java.lang.String name,
int token) |
protected void |
checkMutableReference(Node n) |
protected Node |
createName(int type,
java.lang.String name,
Node child) |
protected Node |
createName(java.lang.String name) |
protected Node |
createNumber(double number) |
protected Scope |
createScopeNode(int token,
int lineno)
Create a node that can be used to hold lexically scoped variable
definitions (via let declarations).
|
boolean |
eof() |
AstRoot |
parse(java.io.Reader sourceReader,
java.lang.String sourceURI,
int lineno)
Builds a parse tree from the given sourcereader.
|
AstRoot |
parse(java.lang.String sourceString,
java.lang.String sourceURI,
int lineno)
Builds a parse tree from the given source string.
|
protected AstNode |
removeParens(AstNode node) |
protected void |
setIsGenerator() |
protected void |
setRequiresActivation() |
protected Node |
simpleAssignment(Node left,
Node right) |
public static final int ARGC_LIMIT
protected int nestingOfFunction
protected boolean inUseStrictDirective
public Parser()
public Parser(CompilerEnvirons compilerEnv)
public Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter)
public boolean eof()
public AstRoot parse(java.lang.String sourceString, java.lang.String sourceURI, int lineno)
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
.)public AstRoot parse(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno) throws java.io.IOException
java.io.IOException
- if the Reader
encounters an errorparse(String,String,int)
protected void checkActivationName(java.lang.String name, int token)
protected void setRequiresActivation()
protected void setIsGenerator()
protected Node createName(java.lang.String name)
protected Node createNumber(double number)
protected Scope createScopeNode(int token, int lineno)
token
- the token of the node to createlineno
- line number of sourceprotected void checkMutableReference(Node n)