Package org.htmlunit.corejs.javascript
Class Parser
- java.lang.Object
-
- org.htmlunit.corejs.javascript.Parser
-
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classParser.ConditionDataprivate static classParser.ParserExceptionprotected classParser.PerFunctionVariables
-
Field Summary
Fields Modifier and Type Field Description static intARGC_LIMITMaximum number of allowed function or constructor arguments, to follow SpiderMonkey.(package private) booleancalledByCompileFunction(package private) static intCLEAR_TI_MASK(package private) CompilerEnvironscompilerEnvprivate intcurrentFlaggedTokenprivate CommentcurrentJsDocCommentprivate LabeledStatementcurrentLabel(package private) ScopecurrentScope(package private) ScriptNodecurrentScriptOrFnprivate intcurrentTokenprivate booleandefaultUseStrictDirectiveprivate intendFlagsprivate IdeErrorReportererrorCollectorprivate ErrorReportererrorReporterprivate static intGET_ENTRYprivate booleaninDestructuringAssignmentprivate booleaninForInitprotected booleaninUseStrictDirectiveprivate java.util.Map<java.lang.String,LabeledStatement>labelSetprivate java.util.List<Jump>loopAndSwitchSetprivate java.util.List<Loop>loopSetprivate static intMETHOD_ENTRYprotected intnestingOfFunctionprivate booleanparseFinishedprivate intprevNameTokenLinenoprivate intprevNameTokenStartprivate java.lang.StringprevNameTokenStringprivate static intPROP_ENTRYprivate java.util.List<Comment>scannedCommentsprivate static intSET_ENTRYprivate char[]sourceCharsprivate java.lang.StringsourceURIprivate intsyntaxErrorCount(package private) static intTI_AFTER_EOL(package private) static intTI_CHECK_LABELprivate TokenStreamts
-
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) voidaddError(java.lang.String messageId)(package private) voidaddError(java.lang.String messageId, int c)(package private) voidaddError(java.lang.String messageId, int position, int length)(package private) voidaddError(java.lang.String messageId, java.lang.String messageArg)(package private) voidaddError(java.lang.String messageId, java.lang.String messageArg, int position, int length)private voidaddError(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)private AstNodeaddExpr()(package private) voidaddStrictWarning(java.lang.String messageId, java.lang.String messageArg)(package private) voidaddStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)private voidaddStrictWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)(package private) voidaddWarning(java.lang.String messageId, int position, int length)(package private) voidaddWarning(java.lang.String messageId, java.lang.String messageArg)(package private) voidaddWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length)private voidaddWarning(java.lang.String messageId, java.lang.String messageArg, int position, int length, int line, java.lang.String lineSource, int lineOffset)private AstNodeandExpr()private java.util.List<AstNode>argumentList()private AstNodearrayComprehension(AstNode result, int pos)Parse a JavaScript 1.7 Array comprehension.private ArrayComprehensionLooparrayComprehensionLoop()private AstNodearrayLiteral()May return anArrayLiteralorArrayComprehension.private AstNodearrowFunction(AstNode params)private voidarrowFunctionParams(FunctionNode fnNode, AstNode params, java.util.Map<java.lang.String,Node> destructuring, java.util.Set<java.lang.String> paramNames)private AstNodeassignExpr()private AstNodeattributeAccess()Xml attribute expression:private voidautoInsertSemicolon(AstNode pn)private AstNodebitAndExpr()private AstNodebitOrExpr()private AstNodebitXorExpr()private AstNodeblock()private BreakStatementbreakStatement()protected voidcheckActivationName(java.lang.String name, int token)private voidcheckBadIncDec(UpdateExpression expr)private voidcheckCallRequiresActivation(AstNode pn)protected voidcheckMutableReference(Node n)private java.lang.RuntimeExceptioncodeBug()private AstNodecondExpr()private Parser.ConditionDatacondition()private voidconsumeToken()private ContinueStatementcontinueStatement()(package private) NodecreateDestructuringAssignment(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 NodecreateName(int type, java.lang.String name, Node child)protected NodecreateName(java.lang.String name)private NamecreateNameNode()private NamecreateNameNode(boolean checkActivation, int token)Create aNamenode using the token info from the last scanned name.protected NodecreateNumber(double number)private AstNodecreateNumericLiteral(int tt, boolean isProperty)(package private) Parser.PerFunctionVariablescreatePerFunctionVariables(FunctionNode fnNode)protected ScopecreateScopeNode(int token, int lineno)Create a node that can be used to hold lexically scoped variable definitions (via let declarations).private StringLiteralcreateStringLiteral()private TemplateCharacterscreateTemplateLiteralCharacters(int pos)private AstNodedefaultXmlNamespace()(package private) voiddefineSymbol(int declType, java.lang.String name)(package private) voiddefineSymbol(int declType, java.lang.String name, boolean ignoreNotInBlock)(package private) booleandestructuringArray(ArrayLiteral array, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)(package private) NodedestructuringAssignmentHelper(int variableType, Node left, Node right, java.lang.String tempName)(package private) booleandestructuringObject(ObjectLiteral node, int variableType, java.lang.String tempName, Node parent, java.util.List<java.lang.String> destructuringNames)private AstNodedestructuringPrimaryExpr()private DoLoopdoLoop()private voidenterLoop(Loop loop)private voidenterSwitch(SwitchStatement node)booleaneof()private AstNodeeqExpr()private voidexitLoop()private voidexitSwitch()private AstNodeexpExpr()private AstNodeexpr(boolean allowTrailingComma)private LoopforLoop()private AstNodeforLoopInit(int tt)private FunctionNodefunction(int type)private FunctionNodefunction(int type, boolean isGenerator)private AstNodegeneratorExpression(AstNode result, int pos)private AstNodegeneratorExpression(AstNode result, int pos, boolean inFunctionParams)private GeneratorExpressionLoopgeneratorExpressionLoop()private CommentgetAndResetJsDoc()private static java.lang.StringgetDirective(AstNode n)private AstNodegetNextStatementAfterInlineComments(AstNode pn)private static intgetNodeEnd(AstNode n)private IfStatementifStatement()(package private) booleaninsideFunction()booleaninUseStrictDirective()private AstNodelet(boolean isStatement, int pos)private AstNodeletStatement()private intlineBeginningFor(int pos)Return the file offset of the beginning of the input source line containing the passed position.(package private) java.lang.StringlookupMessage(java.lang.String messageId)(package private) java.lang.StringlookupMessage(java.lang.String messageId, java.lang.String messageArg)private ErrorNodemakeErrorNode()(package private) voidmarkDestructuring(AstNode node)private LabeledStatementmatchJumpLabelName()private booleanmatchToken(int toMatch, boolean ignoreComment)private AstNodememberExpr(boolean allowCallSyntax)Parse a new-expression, or if next token isn'tToken.NEW, a primary expression.private AstNodememberExprTail(boolean allowCallSyntax, AstNode pn)Parse any number of "(expr)", "[expr]" ".expr", "..expr", or ".(expr)" constructs trailing the passed expression.private ObjectPropertymethodDefinition(int pos, AstNode propName, int entryKind)private AstNodemulExpr()private voidmustHaveXML()private booleanmustMatchToken(int toMatch, java.lang.String messageId, boolean ignoreComment)private booleanmustMatchToken(int toMatch, java.lang.String msgId, int pos, int len, boolean ignoreComment)private AstNodename(int ttFlagged, int tt)private AstNodenameOrLabel()Found a name in a statement context.private intnextToken()private static intnodeEnd(AstNode node)private static booleannowAllSet(int before, int after, int mask)Returns whether or not the bits in the mask have changed to all set.private ObjectLiteralobjectLiteral()private AstNodeobjliteralProperty()private AstNodeorExpr()private AstNodeparenExpr()private AstRootparse()AstRootparse(java.io.Reader sourceReader, java.lang.String sourceURI, int lineno)Deprecated.use parse(String, String, int) insteadAstRootparse(java.lang.String sourceString, java.lang.String sourceURI, int lineno)Builds a parse tree from the given source string.private AstNodeparseFunctionBody(int type, FunctionNode fnNode)private voidparseFunctionParams(FunctionNode fnNode)private intpeekFlaggedToken()private intpeekToken()private intpeekTokenOrEOL()private intpeekUntilNonComment(int tt)private ObjectPropertyplainProperty(AstNode property, int ptt)(package private) voidpopScope()private AstNodeprimaryExpr()private AstNodepropertyAccess(int tt, AstNode pn)Handles any construct following a "." or ".." operator.private AstNodepropertyName(int atPos, int memberTypeFlags)Check if :: follows name in which case it becomes a qualified name.(package private) voidpushScope(Scope scope)private voidrecordComment(int lineno, java.lang.String comment)private voidrecordLabel(Label label, LabeledStatement bundle)private AstNoderelExpr()protected AstNoderemoveParens(AstNode node)(package private) voidreportError(java.lang.String messageId)(package private) voidreportError(java.lang.String messageId, int position, int length)(package private) voidreportError(java.lang.String messageId, java.lang.String messageArg)(package private) voidreportError(java.lang.String messageId, java.lang.String messageArg, int position, int length)private voidrestoreRelativeLoopPosition(Loop loop)private AstNodereturnOrYield(int tt, boolean exprContext)private voidsaveNameTokenData(int pos, java.lang.String name, int lineno)voidsetDefaultUseStrictDirective(boolean useStrict)protected voidsetIsGenerator()protected voidsetRequiresActivation()private AstNodeshiftExpr()protected NodesimpleAssignment(Node left, Node right)private AstNodestatement()private AstNodestatementHelper()private AstNodestatements()private AstNodestatements(AstNode parent)private SwitchStatementswitchStatement()private AstNodetaggedTemplateLiteral(AstNode pn)private AstNodetemplateLiteral(boolean isTaggedLiteral)private ThrowStatementthrowStatement()private TryStatementtryStatement()private AstNodeunaryExpr()private VariableDeclarationvariables(int declType, int pos, boolean isStatement)Parse a 'var' or 'const' statement, or a 'var' init list in a for statement.private voidwarnMissingSemi(int pos, int end)private voidwarnTrailingComma(int pos, java.util.List<?> elems, int commaPos)private WhileLoopwhileLoop()private WithStatementwithStatement()private XmlElemRefxmlElemRef(int atPos, Name namespace, int colonPos)Parse the [expr] portion of an xml element reference, e.g.private AstNodexmlInitializer()
-
-
-
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
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(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 theReaderencounters 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:
trueif 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.IOExceptionParser.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 anArrayLiteralorArrayComprehension.- 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 aNamenode 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 thetokenparameter 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
CompilerEnvironsis 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()
-
-