Package org.mozilla.javascript
Class Parser
- java.lang.Object
-
- org.mozilla.javascript.Parser
-
- Direct Known Subclasses:
IRFactory
public class Parser extends java.lang.ObjectThis 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
AstRootparse 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.
- See Also:
TokenStream
-
-
Field Summary
Fields Modifier and Type Field Description static intARGC_LIMITMaximum number of allowed function or constructor arguments, to follow SpiderMonkey.
-
Constructor Summary
Constructors Constructor Description Parser()Parser(CompilerEnvirons compilerEnv)Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleaneof()AstRootparse(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno)Builds a parse tree from the given sourcereader.AstRootparse(java.lang.String sourceString, java.lang.String sourceURI, int lineno)Builds a parse tree from the given source string.
-
-
-
Field Detail
-
ARGC_LIMIT
public static final int ARGC_LIMIT
Maximum number of allowed function or constructor arguments, to follow SpiderMonkey.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Parser
public Parser()
-
Parser
public Parser(CompilerEnvirons compilerEnv)
-
Parser
public Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter)
-
-
Method Detail
-
eof
public boolean eof()
-
parse
public AstRoot parse(java.lang.String sourceString, java.lang.String sourceURI, int lineno)
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
public AstRoot parse(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno) throws java.io.IOException
Builds a parse tree from the given sourcereader.- Throws:
java.io.IOException- if theReaderencounters an error- See Also:
parse(String,String,int)
-
-