Package org.htmlunit.corejs.javascript
Class Parser
- java.lang.Object
-
- org.htmlunit.corejs.javascript.Parser
-
public class Parser extends java.lang.Object
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.
- See Also:
TokenStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Parser.ConditionData
private static class
Parser.ParserException
protected class
Parser.PerFunctionVariables
-
Field Summary
Fields Modifier and Type Field Description static int
ARGC_LIMIT
Maximum number of allowed function or constructor arguments, to follow SpiderMonkey.(package private) boolean
calledByCompileFunction
(package private) static int
CLEAR_TI_MASK
(package private) CompilerEnvirons
compilerEnv
private int
currentFlaggedToken
private Comment
currentJsDocComment
private LabeledStatement
currentLabel
(package private) Scope
currentScope
(package private) ScriptNode
currentScriptOrFn
private int
currentToken
private boolean
defaultUseStrictDirective
private int
endFlags
private IdeErrorReporter
errorCollector
private ErrorReporter
errorReporter
private static int
GET_ENTRY
private boolean
inDestructuringAssignment
private boolean
inForInit
protected boolean
inUseStrictDirective
private java.util.Map<java.lang.String,LabeledStatement>
labelSet
private java.util.List<Jump>
loopAndSwitchSet
private java.util.List<Loop>
loopSet
private static int
METHOD_ENTRY
protected int
nestingOfFunction
private boolean
parseFinished
private int
prevNameTokenLineno
private int
prevNameTokenStart
private java.lang.String
prevNameTokenString
private static int
PROP_ENTRY
private java.util.List<Comment>
scannedComments
private static int
SET_ENTRY
private char[]
sourceChars
private java.lang.String
sourceURI
private int
syntaxErrorCount
(package private) static int
TI_AFTER_EOL
(package private) static int
TI_CHECK_LABEL
private TokenStream
ts
-
Constructor Summary
Constructors Constructor Description Parser()
Parser(CompilerEnvirons compilerEnv)
Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) void
addError(java.lang.String messageId)
(package private) void
addError(java.lang.String messageId, int c)
(package private) void
addError(java.lang.String messageId, int position, int length)
(package private) void
addError(java.lang.String messageId, java.lang.String messageArg)
(package private) void
addError(java.lang.String messageId, java.lang.String messageArg, int position, int length)
private void
addError(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
private AstNode
addExpr()
(package private) void
addStrictWarning(java.lang.String messageId, java.lang.String messageArg)
(package private) void
addStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)
private void
addStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
(package private) void
addWarning(java.lang.String messageId, int position, int length)
(package private) void
addWarning(java.lang.String messageId, java.lang.String messageArg)
(package private) void
addWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)
private void
addWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
private AstNode
andExpr()
private java.util.List<AstNode>
argumentList()
private AstNode
arrayComprehension(AstNode result, int pos)
Parse a JavaScript 1.7 Array comprehension.private ArrayComprehensionLoop
arrayComprehensionLoop()
private AstNode
arrayLiteral()
May return anArrayLiteral
orArrayComprehension
.private AstNode
arrowFunction(AstNode params)
private void
arrowFunctionParams(FunctionNode fnNode, AstNode params, java.util.Map<java.lang.String,Node> destructuring, java.util.Set<java.lang.String> paramNames)
private AstNode
assignExpr()
private AstNode
attributeAccess()
Xml attribute expression:private void
autoInsertSemicolon(AstNode pn)
private AstNode
bitAndExpr()
private AstNode
bitOrExpr()
private AstNode
bitXorExpr()
private AstNode
block()
private BreakStatement
breakStatement()
protected void
checkActivationName(java.lang.String name, int token)
private void
checkBadIncDec(UpdateExpression expr)
private void
checkCallRequiresActivation(AstNode pn)
protected void
checkMutableReference(Node n)
private java.lang.RuntimeException
codeBug()
private AstNode
condExpr()
private Parser.ConditionData
condition()
private void
consumeToken()
private ContinueStatement
continueStatement()
(package private) Node
createDestructuringAssignment(int type, Node left, Node right)
Given a destructuring assignment with a left hand side parsed as an array or object literal and a right hand side expression, rewrite as a series of assignments to the variables defined in left from property accesses to the expression on the right.protected Node
createName(int type, java.lang.String name, Node child)
protected Node
createName(java.lang.String name)
private Name
createNameNode()
private Name
createNameNode(boolean checkActivation, int token)
Create aName
node using the token info from the last scanned name.protected Node
createNumber(double number)
private AstNode
createNumericLiteral(int tt, boolean isProperty)
(package private) Parser.PerFunctionVariables
createPerFunctionVariables(FunctionNode fnNode)
protected Scope
createScopeNode(int token, int lineno)
Create a node that can be used to hold lexically scoped variable definitions (via let declarations).private StringLiteral
createStringLiteral()
private TemplateCharacters
createTemplateLiteralCharacters(int pos)
private AstNode
defaultXmlNamespace()
(package private) void
defineSymbol(int declType, java.lang.String name)
(package private) void
defineSymbol(int declType, java.lang.String name, boolean ignoreNotInBlock)
(package private) boolean
destructuringArray(ArrayLiteral array, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)
(package private) Node
destructuringAssignmentHelper(int variableType, Node left, Node right, java.lang.String tempName)
(package private) boolean
destructuringObject(ObjectLiteral node, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)
private AstNode
destructuringPrimaryExpr()
private DoLoop
doLoop()
private void
enterLoop(Loop loop)
private void
enterSwitch(SwitchStatement node)
boolean
eof()
private AstNode
eqExpr()
private void
exitLoop()
private void
exitSwitch()
private AstNode
expExpr()
private AstNode
expr(boolean allowTrailingComma)
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
generatorExpressionLoop()
private Comment
getAndResetJsDoc()
private static java.lang.String
getDirective(AstNode n)
private AstNode
getNextStatementAfterInlineComments(AstNode pn)
private static int
getNodeEnd(AstNode n)
private IfStatement
ifStatement()
(package private) boolean
insideFunction()
boolean
inUseStrictDirective()
private AstNode
let(boolean isStatement, int pos)
private AstNode
letStatement()
private int
lineBeginningFor(int pos)
Return the file offset of the beginning of the input source line containing the passed position.(package private) java.lang.String
lookupMessage(java.lang.String messageId)
(package private) java.lang.String
lookupMessage(java.lang.String messageId, java.lang.String messageArg)
private ErrorNode
makeErrorNode()
(package private) void
markDestructuring(AstNode node)
private LabeledStatement
matchJumpLabelName()
private boolean
matchToken(int toMatch, boolean ignoreComment)
private AstNode
memberExpr(boolean allowCallSyntax)
Parse a new-expression, or if next token isn'tToken.NEW
, a primary expression.private AstNode
memberExprTail(boolean allowCallSyntax, AstNode pn)
Parse any number of "(expr)", "[expr]" ".expr", "..expr", or ".(expr)" constructs trailing the passed expression.private ObjectProperty
methodDefinition(int pos, AstNode propName, int entryKind)
private AstNode
mulExpr()
private void
mustHaveXML()
private boolean
mustMatchToken(int toMatch, java.lang.String messageId, boolean ignoreComment)
private boolean
mustMatchToken(int toMatch, java.lang.String msgId, int pos, int len, boolean ignoreComment)
private AstNode
name(int ttFlagged, int tt)
private AstNode
nameOrLabel()
Found a name in a statement context.private int
nextToken()
private static int
nodeEnd(AstNode node)
private static boolean
nowAllSet(int before, int after, int mask)
Returns whether or not the bits in the mask have changed to all set.private ObjectLiteral
objectLiteral()
private AstNode
objliteralProperty()
private AstNode
orExpr()
private AstNode
parenExpr()
private AstRoot
parse()
AstRoot
parse(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno)
Deprecated.use parse(String, String, int) insteadAstRoot
parse(java.lang.String sourceString, java.lang.String sourceURI, int lineno)
Builds a parse tree from the given source string.private AstNode
parseFunctionBody(int type, FunctionNode fnNode)
private void
parseFunctionParams(FunctionNode fnNode)
private int
peekFlaggedToken()
private int
peekToken()
private int
peekTokenOrEOL()
private int
peekUntilNonComment(int tt)
private ObjectProperty
plainProperty(AstNode property, int ptt)
(package private) void
popScope()
private AstNode
primaryExpr()
private AstNode
propertyAccess(int tt, AstNode pn)
Handles any construct following a "." or ".." operator.private AstNode
propertyName(int atPos, int memberTypeFlags)
Check if :: follows name in which case it becomes a qualified name.(package private) void
pushScope(Scope scope)
private void
recordComment(int lineno, java.lang.String comment)
private void
recordLabel(Label label, LabeledStatement bundle)
private AstNode
relExpr()
protected AstNode
removeParens(AstNode node)
(package private) void
reportError(java.lang.String messageId)
(package private) void
reportError(java.lang.String messageId, int position, int length)
(package private) void
reportError(java.lang.String messageId, java.lang.String messageArg)
(package private) void
reportError(java.lang.String messageId, java.lang.String messageArg, int position, int length)
private void
restoreRelativeLoopPosition(Loop loop)
private AstNode
returnOrYield(int tt, boolean exprContext)
private void
saveNameTokenData(int pos, java.lang.String name, int lineno)
void
setDefaultUseStrictDirective(boolean useStrict)
protected void
setIsGenerator()
protected void
setRequiresActivation()
private AstNode
shiftExpr()
protected Node
simpleAssignment(Node left, Node right)
private AstNode
statement()
private AstNode
statementHelper()
private AstNode
statements()
private AstNode
statements(AstNode parent)
private SwitchStatement
switchStatement()
private AstNode
taggedTemplateLiteral(AstNode pn)
private AstNode
templateLiteral(boolean isTaggedLiteral)
private ThrowStatement
throwStatement()
private TryStatement
tryStatement()
private AstNode
unaryExpr()
private VariableDeclaration
variables(int declType, int pos, boolean isStatement)
Parse a 'var' or 'const' statement, or a 'var' init list in a for statement.private void
warnMissingSemi(int pos, int end)
private void
warnTrailingComma(int pos, java.util.List<?> elems, int commaPos)
private WhileLoop
whileLoop()
private WithStatement
withStatement()
private XmlElemRef
xmlElemRef(int atPos, Name namespace, int colonPos)
Parse the [expr] portion of an xml element reference, e.g.private AstNode
xmlInitializer()
-
-
-
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
-
CLEAR_TI_MASK
static final int CLEAR_TI_MASK
- See Also:
- Constant Field Values
-
TI_AFTER_EOL
static final int TI_AFTER_EOL
- See Also:
- Constant Field Values
-
TI_CHECK_LABEL
static final int TI_CHECK_LABEL
- See Also:
- Constant Field Values
-
compilerEnv
CompilerEnvirons compilerEnv
-
errorReporter
private ErrorReporter errorReporter
-
errorCollector
private IdeErrorReporter errorCollector
-
sourceURI
private java.lang.String sourceURI
-
sourceChars
private char[] sourceChars
-
calledByCompileFunction
boolean calledByCompileFunction
-
parseFinished
private boolean parseFinished
-
ts
private TokenStream ts
-
currentFlaggedToken
private int currentFlaggedToken
-
currentToken
private int currentToken
-
syntaxErrorCount
private int syntaxErrorCount
-
scannedComments
private java.util.List<Comment> scannedComments
-
currentJsDocComment
private Comment currentJsDocComment
-
nestingOfFunction
protected int nestingOfFunction
-
currentLabel
private LabeledStatement currentLabel
-
inDestructuringAssignment
private boolean inDestructuringAssignment
-
inUseStrictDirective
protected boolean inUseStrictDirective
-
currentScriptOrFn
ScriptNode currentScriptOrFn
-
currentScope
Scope currentScope
-
endFlags
private int endFlags
-
inForInit
private boolean inForInit
-
labelSet
private java.util.Map<java.lang.String,LabeledStatement> labelSet
-
loopSet
private java.util.List<Loop> loopSet
-
loopAndSwitchSet
private java.util.List<Jump> loopAndSwitchSet
-
prevNameTokenStart
private int prevNameTokenStart
-
prevNameTokenString
private java.lang.String prevNameTokenString
-
prevNameTokenLineno
private int prevNameTokenLineno
-
defaultUseStrictDirective
private boolean defaultUseStrictDirective
-
PROP_ENTRY
private static final int PROP_ENTRY
- See Also:
- Constant Field Values
-
GET_ENTRY
private static final int GET_ENTRY
- See Also:
- Constant Field Values
-
SET_ENTRY
private static final int SET_ENTRY
- See Also:
- Constant Field Values
-
METHOD_ENTRY
private static final int METHOD_ENTRY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Parser
public Parser()
-
Parser
public Parser(CompilerEnvirons compilerEnv)
-
Parser
public Parser(CompilerEnvirons compilerEnv, ErrorReporter errorReporter)
-
-
Method Detail
-
addStrictWarning
void addStrictWarning(java.lang.String messageId, java.lang.String messageArg)
-
addStrictWarning
void addStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)
-
addWarning
void addWarning(java.lang.String messageId, java.lang.String messageArg)
-
addWarning
void addWarning(java.lang.String messageId, int position, int length)
-
addWarning
void addWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)
-
addError
void addError(java.lang.String messageId)
-
addError
void addError(java.lang.String messageId, int position, int length)
-
addError
void addError(java.lang.String messageId, java.lang.String messageArg)
-
addError
void addError(java.lang.String messageId, int c)
-
addError
void addError(java.lang.String messageId, java.lang.String messageArg, int position, int length)
-
addStrictWarning
private void addStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
-
addWarning
private void addWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
-
addError
private void addError(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)
-
lookupMessage
java.lang.String lookupMessage(java.lang.String messageId)
-
lookupMessage
java.lang.String lookupMessage(java.lang.String messageId, java.lang.String messageArg)
-
reportError
void reportError(java.lang.String messageId)
-
reportError
void reportError(java.lang.String messageId, java.lang.String messageArg)
-
reportError
void reportError(java.lang.String messageId, int position, int length)
-
reportError
void reportError(java.lang.String messageId, java.lang.String messageArg, int position, int length)
-
getNodeEnd
private static int getNodeEnd(AstNode n)
-
recordComment
private void recordComment(int lineno, java.lang.String comment)
-
getAndResetJsDoc
private Comment getAndResetJsDoc()
-
peekToken
private int peekToken() throws java.io.IOException
- Throws:
java.io.IOException
-
peekFlaggedToken
private int peekFlaggedToken() throws java.io.IOException
- Throws:
java.io.IOException
-
consumeToken
private void consumeToken()
-
nextToken
private int nextToken() throws java.io.IOException
- Throws:
java.io.IOException
-
matchToken
private boolean matchToken(int toMatch, boolean ignoreComment) throws java.io.IOException
- Throws:
java.io.IOException
-
peekTokenOrEOL
private int peekTokenOrEOL() throws java.io.IOException
- Throws:
java.io.IOException
-
mustMatchToken
private boolean mustMatchToken(int toMatch, java.lang.String messageId, boolean ignoreComment) throws java.io.IOException
- Throws:
java.io.IOException
-
mustMatchToken
private boolean mustMatchToken(int toMatch, java.lang.String msgId, int pos, int len, boolean ignoreComment) throws java.io.IOException
- Throws:
java.io.IOException
-
mustHaveXML
private void mustHaveXML()
-
eof
public boolean eof()
-
insideFunction
boolean insideFunction()
-
pushScope
void pushScope(Scope scope)
-
popScope
void popScope()
-
enterLoop
private void enterLoop(Loop loop)
-
exitLoop
private void exitLoop()
-
restoreRelativeLoopPosition
private void restoreRelativeLoopPosition(Loop loop)
-
enterSwitch
private void enterSwitch(SwitchStatement node)
-
exitSwitch
private void exitSwitch()
-
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
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(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno) throws java.io.IOException
Deprecated.use parse(String, String, int) insteadBuilds a parse tree from the given sourcereader.- Throws:
java.io.IOException
- if theReader
encounters an error- See Also:
parse(String,String,int)
-
parse
private AstRoot parse() throws java.io.IOException
- Throws:
java.io.IOException
-
parseFunctionBody
private AstNode parseFunctionBody(int type, FunctionNode fnNode) throws java.io.IOException
- Throws:
java.io.IOException
-
getDirective
private static java.lang.String getDirective(AstNode n)
-
parseFunctionParams
private void parseFunctionParams(FunctionNode fnNode) throws java.io.IOException
- Throws:
java.io.IOException
-
function
private FunctionNode function(int type) throws java.io.IOException
- Throws:
java.io.IOException
-
function
private FunctionNode function(int type, boolean isGenerator) throws java.io.IOException
- Throws:
java.io.IOException
-
arrowFunction
private AstNode arrowFunction(AstNode params) throws java.io.IOException
- Throws:
java.io.IOException
-
arrowFunctionParams
private void arrowFunctionParams(FunctionNode fnNode, AstNode params, java.util.Map<java.lang.String,Node> destructuring, java.util.Set<java.lang.String> paramNames)
-
statements
private AstNode statements(AstNode parent) throws java.io.IOException
- Throws:
java.io.IOException
-
statements
private AstNode statements() throws java.io.IOException
- Throws:
java.io.IOException
-
condition
private Parser.ConditionData condition() throws java.io.IOException
- Throws:
java.io.IOException
-
statement
private AstNode statement() throws java.io.IOException
- Throws:
java.io.IOException
-
statementHelper
private AstNode statementHelper() throws java.io.IOException
- Throws:
java.io.IOException
-
autoInsertSemicolon
private void autoInsertSemicolon(AstNode pn) throws java.io.IOException
- Throws:
java.io.IOException
-
ifStatement
private IfStatement ifStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
switchStatement
private SwitchStatement switchStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
whileLoop
private WhileLoop whileLoop() throws java.io.IOException
- Throws:
java.io.IOException
-
doLoop
private DoLoop doLoop() throws java.io.IOException
- Throws:
java.io.IOException
-
peekUntilNonComment
private int peekUntilNonComment(int tt) throws java.io.IOException
- Throws:
java.io.IOException
-
getNextStatementAfterInlineComments
private AstNode getNextStatementAfterInlineComments(AstNode pn) throws java.io.IOException
- Throws:
java.io.IOException
-
forLoop
private Loop forLoop() throws java.io.IOException
- Throws:
java.io.IOException
-
forLoopInit
private AstNode forLoopInit(int tt) throws java.io.IOException
- Throws:
java.io.IOException
-
tryStatement
private TryStatement tryStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
throwStatement
private ThrowStatement throwStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
matchJumpLabelName
private LabeledStatement matchJumpLabelName() throws java.io.IOException
- Throws:
java.io.IOException
-
breakStatement
private BreakStatement breakStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
continueStatement
private ContinueStatement continueStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
withStatement
private WithStatement withStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
letStatement
private AstNode letStatement() throws java.io.IOException
- Throws:
java.io.IOException
-
nowAllSet
private static final boolean nowAllSet(int before, int after, int mask)
Returns whether or not the bits in the mask have changed to all set.- Parameters:
before
- bits before changeafter
- bits after changemask
- mask for bits- Returns:
true
if all the bits in the mask are set in "after" but not in "before"
-
returnOrYield
private AstNode returnOrYield(int tt, boolean exprContext) throws java.io.IOException
- Throws:
java.io.IOException
-
block
private AstNode block() throws java.io.IOException
- Throws:
java.io.IOException
-
defaultXmlNamespace
private AstNode defaultXmlNamespace() throws java.io.IOException
- Throws:
java.io.IOException
-
recordLabel
private void recordLabel(Label label, LabeledStatement bundle) throws java.io.IOException
- Throws:
java.io.IOException
-
nameOrLabel
private AstNode nameOrLabel() throws java.io.IOException
Found a name in a statement context. If it's a label, we gather up any following labels and the next non-label statement into aLabeledStatement
"bundle" and return that. Otherwise we parse an expression and return it wrapped in anExpressionStatement
.- Throws:
java.io.IOException
-
variables
private VariableDeclaration variables(int declType, int pos, boolean isStatement) throws java.io.IOException
Parse a 'var' or 'const' statement, or a 'var' init list in a for statement.- Parameters:
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.- Returns:
- the parsed variable list
- Throws:
java.io.IOException
-
let
private AstNode let(boolean isStatement, int pos) throws java.io.IOException
- Throws:
java.io.IOException
-
defineSymbol
void defineSymbol(int declType, java.lang.String name)
-
defineSymbol
void defineSymbol(int declType, java.lang.String name, boolean ignoreNotInBlock)
-
expr
private AstNode expr(boolean allowTrailingComma) throws java.io.IOException
- Throws:
java.io.IOException
-
assignExpr
private AstNode assignExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
condExpr
private AstNode condExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
orExpr
private AstNode orExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
andExpr
private AstNode andExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
bitOrExpr
private AstNode bitOrExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
bitXorExpr
private AstNode bitXorExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
bitAndExpr
private AstNode bitAndExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
eqExpr
private AstNode eqExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
relExpr
private AstNode relExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
shiftExpr
private AstNode shiftExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
addExpr
private AstNode addExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
mulExpr
private AstNode mulExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
expExpr
private AstNode expExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
unaryExpr
private AstNode unaryExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
xmlInitializer
private AstNode xmlInitializer() throws java.io.IOException
- Throws:
java.io.IOException
-
argumentList
private java.util.List<AstNode> argumentList() throws java.io.IOException
- Throws:
java.io.IOException
-
memberExpr
private AstNode memberExpr(boolean allowCallSyntax) throws java.io.IOException
Parse a new-expression, or if next token isn'tToken.NEW
, a primary expression.- Parameters:
allowCallSyntax
- passed down tomemberExprTail(boolean, org.htmlunit.corejs.javascript.ast.AstNode)
- Throws:
java.io.IOException
-
memberExprTail
private AstNode memberExprTail(boolean allowCallSyntax, AstNode pn) throws java.io.IOException
Parse any number of "(expr)", "[expr]" ".expr", "..expr", or ".(expr)" constructs trailing the passed expression.- Parameters:
pn
- the non-null parent node- Returns:
- the outermost (lexically last occurring) expression, which will have the passed parent node as a descendant
- Throws:
java.io.IOException
-
taggedTemplateLiteral
private AstNode taggedTemplateLiteral(AstNode pn) throws java.io.IOException
- Throws:
java.io.IOException
-
propertyAccess
private AstNode propertyAccess(int tt, AstNode pn) throws java.io.IOException
Handles any construct following a "." or ".." operator.- Parameters:
pn
- the left-hand side (target) of the operator. Never null.- Returns:
- a PropertyGet, XmlMemberGet, or ErrorNode
- Throws:
java.io.IOException
-
attributeAccess
private AstNode attributeAccess() throws java.io.IOException
Xml attribute expression:@attr
,@ns::attr
,@ns::*
,@ns::*
,@*
,@*::attr
,@*::*
,@ns::[expr]
,@*::[expr]
,@[expr]
Called if we peeked an '@' token.
- Throws:
java.io.IOException
-
propertyName
private AstNode propertyName(int atPos, int memberTypeFlags) throws java.io.IOException
Check if :: follows name in which case it becomes a qualified name.- Parameters:
atPos
- a natural number if we just read an '@' token, else -1s
- the name or string that was matched (an identifier, "throw" or "*").memberTypeFlags
- flags tracking whether we're a '.' or '..' child- Returns:
- an XmlRef node if it's an attribute access, a child of a '..' operator, or the name is followed by ::. For a plain name, returns a Name node. Returns an ErrorNode for malformed XML expressions. (For now - might change to return a partial XmlRef.)
- Throws:
java.io.IOException
-
xmlElemRef
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos) throws java.io.IOException
Parse the [expr] portion of an xml element reference, e.g. @[expr], @*::[expr], or ns::[expr].- Throws:
java.io.IOException
-
destructuringPrimaryExpr
private AstNode destructuringPrimaryExpr() throws java.io.IOException, Parser.ParserException
- Throws:
java.io.IOException
Parser.ParserException
-
primaryExpr
private AstNode primaryExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
parenExpr
private AstNode parenExpr() throws java.io.IOException
- Throws:
java.io.IOException
-
name
private AstNode name(int ttFlagged, int tt) throws java.io.IOException
- Throws:
java.io.IOException
-
arrayLiteral
private AstNode arrayLiteral() throws java.io.IOException
May return anArrayLiteral
orArrayComprehension
.- Throws:
java.io.IOException
-
arrayComprehension
private AstNode arrayComprehension(AstNode result, int pos) throws java.io.IOException
Parse a JavaScript 1.7 Array comprehension.- Parameters:
result
- the first expression after the opening left-bracketpos
- start of LB token that begins the array comprehension- Returns:
- the array comprehension or an error node
- Throws:
java.io.IOException
-
arrayComprehensionLoop
private ArrayComprehensionLoop arrayComprehensionLoop() throws java.io.IOException
- Throws:
java.io.IOException
-
generatorExpression
private AstNode generatorExpression(AstNode result, int pos) throws java.io.IOException
- Throws:
java.io.IOException
-
generatorExpression
private AstNode generatorExpression(AstNode result, int pos, boolean inFunctionParams) throws java.io.IOException
- Throws:
java.io.IOException
-
generatorExpressionLoop
private GeneratorExpressionLoop generatorExpressionLoop() throws java.io.IOException
- Throws:
java.io.IOException
-
objectLiteral
private ObjectLiteral objectLiteral() throws java.io.IOException
- Throws:
java.io.IOException
-
objliteralProperty
private AstNode objliteralProperty() throws java.io.IOException
- Throws:
java.io.IOException
-
plainProperty
private ObjectProperty plainProperty(AstNode property, int ptt) throws java.io.IOException
- Throws:
java.io.IOException
-
methodDefinition
private ObjectProperty methodDefinition(int pos, AstNode propName, int entryKind) throws java.io.IOException
- Throws:
java.io.IOException
-
createNameNode
private Name createNameNode()
-
createNameNode
private Name createNameNode(boolean checkActivation, int token)
Create aName
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 thetoken
parameter is notToken.NAME
, then we use token info saved in instance vars.
-
createStringLiteral
private StringLiteral createStringLiteral()
-
templateLiteral
private AstNode templateLiteral(boolean isTaggedLiteral) throws java.io.IOException
- Throws:
java.io.IOException
-
createTemplateLiteralCharacters
private TemplateCharacters createTemplateLiteralCharacters(int pos)
-
createNumericLiteral
private AstNode createNumericLiteral(int tt, boolean isProperty)
-
checkActivationName
protected void checkActivationName(java.lang.String name, int token)
-
setRequiresActivation
protected void setRequiresActivation()
-
checkCallRequiresActivation
private void checkCallRequiresActivation(AstNode pn)
-
setIsGenerator
protected void setIsGenerator()
-
checkBadIncDec
private void checkBadIncDec(UpdateExpression expr)
-
makeErrorNode
private ErrorNode makeErrorNode()
-
nodeEnd
private static int nodeEnd(AstNode node)
-
saveNameTokenData
private void saveNameTokenData(int pos, java.lang.String name, int lineno)
-
lineBeginningFor
private int lineBeginningFor(int pos)
Return the file offset of the beginning of the input source line containing the passed position.- Parameters:
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.- Returns:
- the offset of the beginning of the line containing pos (i.e. 1+ the offset of the
first preceding newline). Returns -1 if the
CompilerEnvirons
is not set to ide-mode, andparse(java.io.Reader,String,int)
was used.
-
warnMissingSemi
private void warnMissingSemi(int pos, int end)
-
warnTrailingComma
private void warnTrailingComma(int pos, java.util.List<?> elems, int commaPos)
-
createPerFunctionVariables
Parser.PerFunctionVariables createPerFunctionVariables(FunctionNode fnNode)
-
createDestructuringAssignment
Node createDestructuringAssignment(int type, Node left, Node right)
Given a destructuring assignment with a left hand side parsed as an array or object literal and a right hand side expression, rewrite as a series of assignments to the variables defined in left from property accesses to the expression on the right.- Parameters:
type
- declaration type: Token.VAR or Token.LET or -1left
- array or object literal containing NAME nodes for variables to assignright
- expression to assign from- Returns:
- expression that performs a series of assignments to the variables defined in left
-
destructuringAssignmentHelper
Node destructuringAssignmentHelper(int variableType, Node left, Node right, java.lang.String tempName)
-
destructuringArray
boolean destructuringArray(ArrayLiteral array, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)
-
destructuringObject
boolean destructuringObject(ObjectLiteral node, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)
-
createName
protected Node createName(java.lang.String name)
-
createNumber
protected Node createNumber(double number)
-
createScopeNode
protected Scope createScopeNode(int token, int lineno)
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
-
checkMutableReference
protected void checkMutableReference(Node n)
-
markDestructuring
void markDestructuring(AstNode node)
-
codeBug
private java.lang.RuntimeException codeBug() throws java.lang.RuntimeException
- Throws:
java.lang.RuntimeException
-
setDefaultUseStrictDirective
public void setDefaultUseStrictDirective(boolean useStrict)
-
inUseStrictDirective
public boolean inUseStrictDirective()
-
-