primaryExpr
- Throws:
IOException
IRFactory
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.
private static class
private static class
protected class
static final int
(package private) boolean
(package private) static final int
(package private) CompilerEnvirons
private int
private Comment
private LabeledStatement
(package private) Scope
(package private) ScriptNode
private int
private boolean
private int
private IdeErrorReporter
private ErrorReporter
private static final int
private boolean
private boolean
protected boolean
private Map<String,LabeledStatement>
private static final int
protected int
private boolean
private int
private int
private String
private static final int
private static final int
private char[]
private String
private int
(package private) static final int
(package private) static final int
private TokenStream
Parser()
Parser(CompilerEnvirons compilerEnv)
Parser(CompilerEnvirons compilerEnv,
ErrorReporter errorReporter)
(package private) void
(package private) void
(package private) void
(package private) void
(package private) void
private void
addError(String messageId,
String messageArg,
int position,
int length,
int line,
String lineSource,
int lineOffset)
private AstNode
addExpr()
(package private) void
addStrictWarning(String messageId,
String messageArg)
(package private) void
addStrictWarning(String messageId,
String messageArg,
int position,
int length)
private void
addStrictWarning(String messageId,
String messageArg,
int position,
int length,
int line,
String lineSource,
int lineOffset)
(package private) void
addWarning(String messageId,
int position,
int length)
(package private) void
addWarning(String messageId,
String messageArg)
(package private) void
addWarning(String messageId,
String messageArg,
int position,
int length)
private void
addWarning(String messageId,
String messageArg,
int position,
int length,
int line,
String lineSource,
int lineOffset)
private AstNode
andExpr()
private AstNode
arrayComprehension(AstNode result,
int pos)
private ArrayComprehensionLoop
private AstNode
ArrayLiteral
or ArrayComprehension
.private AstNode
arrowFunction(AstNode params)
private void
arrowFunctionParams(FunctionNode fnNode,
AstNode params,
Map<String,Node> destructuring,
Set<String> paramNames)
private AstNode
private AstNode
private void
private AstNode
private AstNode
private AstNode
private AstNode
block()
private BreakStatement
protected void
checkActivationName(String name,
int token)
private void
private void
protected void
private RuntimeException
codeBug()
private AstNode
condExpr()
private Parser.ConditionData
private void
private ContinueStatement
(package private) Node
createDestructuringAssignment(int type,
Node left,
Node right)
protected Node
createName(int type,
String name,
Node child)
protected Node
createName(String name)
private Name
private Name
createNameNode(boolean checkActivation,
int token)
Name
node using the token info from the last scanned name.protected Node
createNumber(double number)
private AstNode
createNumericLiteral(int tt,
boolean isProperty)
protected Scope
createScopeNode(int token,
int lineno)
private StringLiteral
private TemplateCharacters
createTemplateLiteralCharacters(int pos)
private AstNode
(package private) void
defineSymbol(int declType,
String name)
(package private) void
defineSymbol(int declType,
String name,
boolean ignoreNotInBlock)
(package private) boolean
destructuringArray(ArrayLiteral array,
int variableType,
String tempName,
Node parent,
List<String> destructuringNames)
(package private) Node
destructuringAssignmentHelper(int variableType,
Node left,
Node right,
String tempName)
(package private) boolean
destructuringObject(ObjectLiteral node,
int variableType,
String tempName,
Node parent,
List<String> destructuringNames)
private AstNode
private DoLoop
doLoop()
private void
private void
enterSwitch(SwitchStatement node)
boolean
eof()
private AstNode
eqExpr()
private void
exitLoop()
private void
private AstNode
expExpr()
private AstNode
expr()
private Loop
forLoop()
private AstNode
forLoopInit(int tt)
private FunctionNode
function(int type)
private FunctionNode
function(int type,
boolean isGenerator)
private AstNode
generatorExpression(AstNode result,
int pos)
private AstNode
generatorExpression(AstNode result,
int pos,
boolean inFunctionParams)
private GeneratorExpressionLoop
private Comment
private static String
private AstNode
private static int
private IfStatement
(package private) boolean
boolean
private AstNode
let(boolean isStatement,
int pos)
private AstNode
private int
lineBeginningFor(int pos)
(package private) String
lookupMessage(String messageId)
(package private) String
lookupMessage(String messageId,
String messageArg)
private ErrorNode
(package private) void
markDestructuring(AstNode node)
private LabeledStatement
private boolean
matchToken(int toMatch,
boolean ignoreComment)
private AstNode
memberExpr(boolean allowCallSyntax)
Token.NEW
, a primary expression.private AstNode
memberExprTail(boolean allowCallSyntax,
AstNode pn)
private ObjectProperty
methodDefinition(int pos,
AstNode propName,
int entryKind)
private AstNode
mulExpr()
private void
private boolean
mustMatchToken(int toMatch,
String messageId,
boolean ignoreComment)
private boolean
mustMatchToken(int toMatch,
String msgId,
int pos,
int len,
boolean ignoreComment)
private AstNode
name(int ttFlagged,
int tt)
private AstNode
private int
private static int
private static final boolean
nowAllSet(int before,
int after,
int mask)
private ObjectLiteral
private AstNode
private AstNode
orExpr()
private AstNode
private AstRoot
parse()
private AstNode
parseFunctionBody(int type,
FunctionNode fnNode)
private void
parseFunctionParams(FunctionNode fnNode)
private int
private int
private int
private int
peekUntilNonComment(int tt)
private ObjectProperty
plainProperty(AstNode property,
int ptt)
(package private) void
popScope()
private AstNode
private AstNode
propertyAccess(int tt,
AstNode pn)
private AstNode
propertyName(int atPos,
int memberTypeFlags)
(package private) void
private void
recordComment(int lineno,
String comment)
private void
recordLabel(Label label,
LabeledStatement bundle)
private AstNode
relExpr()
protected AstNode
removeParens(AstNode node)
(package private) void
reportError(String messageId)
(package private) void
reportError(String messageId,
int position,
int length)
(package private) void
reportError(String messageId,
String messageArg)
(package private) void
reportError(String messageId,
String messageArg,
int position,
int length)
private void
private AstNode
returnOrYield(int tt,
boolean exprContext)
private void
saveNameTokenData(int pos,
String name,
int lineno)
void
setDefaultUseStrictDirective(boolean useStrict)
protected void
protected void
private AstNode
protected Node
simpleAssignment(Node left,
Node right)
private AstNode
private AstNode
private AstNode
private AstNode
statements(AstNode parent)
private SwitchStatement
private AstNode
private AstNode
templateLiteral(boolean isTaggedLiteral)
private ThrowStatement
private TryStatement
private AstNode
private VariableDeclaration
variables(int declType,
int pos,
boolean isStatement)
private void
warnMissingSemi(int pos,
int end)
private void
warnTrailingComma(int pos,
List<?> elems,
int commaPos)
private WhileLoop
private WithStatement
private XmlElemRef
xmlElemRef(int atPos,
Name namespace,
int colonPos)
private AstNode
IOException
IOException
IOException
IOException
IOException
IOException
IOException
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
.)IOException
- if the Reader
encounters an errorIOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
before
- bits before changeafter
- bits after changemask
- mask for bitstrue
if all the bits in the mask are set in "after" but not in "before"IOException
IOException
IOException
IOException
LabeledStatement
"bundle" and return that.
Otherwise we parse an expression and return it wrapped in an ExpressionStatement
.IOException
declType
- A token value: either VAR, CONST, or LET depending on context.pos
- the position where the node should start. It's sometimes the var/const/let
keyword, and other times the beginning of the first token in the first variable
declaration.IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
Token.NEW
, a primary expression.allowCallSyntax
- passed down to memberExprTail(boolean, org.mozilla.javascript.ast.AstNode)
IOException
pn
- the non-null parent nodeIOException
IOException
pn
- the left-hand side (target) of the operator. Never null.IOException
@attr
, @ns::attr
, @ns::*
, @ns::*
, @*
,
@*::attr
, @*::*
, @ns::[expr]
, @*::[expr]
, @[expr]
Called if we peeked an '@' token.
IOException
atPos
- a natural number if we just read an '@' token, else -1memberTypeFlags
- flags tracking whether we're a '.' or '..' childs
- the name or string that was matched (an identifier, "throw" or "*").IOException
IOException
IOException
Parser.ParserException
IOException
IOException
IOException
ArrayLiteral
or ArrayComprehension
.IOException
result
- the first expression after the opening left-bracketpos
- start of LB token that begins the array comprehensionIOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
IOException
Name
node using the token info from the last scanned name. In some cases we
need to either synthesize a name node, or we lost the name token information by peeking. If
the token
parameter is not Token.NAME
, then we use token info saved in
instance vars.IOException
pos
- an offset into the input source stream. If the offset is negative, it's converted
to 0, and if it's beyond the end of the source buffer, the last source position is used.CompilerEnvirons
is not set to
ide-mode, and parse(java.io.Reader,String,int)
was used.type
- declaration type: Token.VAR or Token.LET or -1left
- array or object literal containing NAME nodes for variables to assignright
- expression to assign fromtoken
- the token of the node to createlineno
- line number of sourceRuntimeException