Class BaseParser
- Direct Known Subclasses:
JsParser
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseParser(Resource resource, List<Token> tokens, boolean errorRecovery) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected booleanprotected voidprotected booleanprotected voidprotected booleanconsumeSoft(TokenType token) Consume token if present, or record error if in recovery mode.protected voidprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected voidprotected voidprotected voidprotected booleanexit()protected booleanexit(boolean result, boolean mandatory) protected voidexit(BaseParser.Shift shift) protected booleanexitSoft()Exit that tolerates incomplete nodes.protected intbooleanprotected booleanisCallerType(NodeType type) protected TokenTypeprotected Stringprotected Nodeprotected Tokennext()protected booleanIs there no LineTerminator between the token just consumed and the next one?protected TokenTypepeek()protected booleanprotected booleanprotected booleanprotected Tokenprotected booleanSkip tokens until we find a recovery point.toString()
-
Field Details
-
resource
-
tokens
-
errorRecoveryEnabled
protected final boolean errorRecoveryEnabled
-
-
Constructor Details
-
BaseParser
-
-
Method Details
-
markerNode
-
isCallerType
-
toString
-
error
-
error
-
error
-
getErrors
- Returns:
- list of syntax errors collected during parsing
-
hasErrors
public boolean hasErrors()- Returns:
- true if any syntax errors were recorded
-
recoverTo
Skip tokens until we find a recovery point. Includes infinite loop detection - if called from the same position twice, forces skip of at least one token to guarantee progress.- Parameters:
recoveryTokens- tokens that indicate a safe recovery point- Returns:
- true if a recovery token was found, false if EOF reached
-
consumeSoft
Consume token if present, or record error if in recovery mode.- Parameters:
token- the expected token type- Returns:
- true if consumed successfully or in recovery mode
-
exitSoft
protected boolean exitSoft()Exit that tolerates incomplete nodes. Even if the node is incomplete, it is added to the parent. -
enter
-
enter
-
enter
-
enterIf
-
enter
-
enterIf
-
exit
protected boolean exit() -
exit
protected boolean exit(boolean result, boolean mandatory) -
exit
-
peek
-
peekToken
-
consume
-
anyOf
-
anyOf
-
consumeIf
-
peekIf
-
peekAnyOf
-
peekAnyOf
-
lastConsumed
-
lastConsumedText
-
noLineTerminatorBefore
protected boolean noLineTerminatorBefore()Is there no LineTerminator between the token just consumed and the next one?What the ECMAScript grammar's restricted productions need: in a handful of places a LineTerminator is not whitespace, it ends the statement. Without the check,
returnfollowed by a newline and a call swallows the call as its argument — which parses fine and means something else.Which productions actually consult this today:
return,throw, andbreak/continuebefore a label. The grammar also restrictsyieldbefore its operand and a postfix++/--after its operand; neither is enforced here — the postfix case is a separate, unfixed gap. Do not read this javadoc as a claim that they are covered.Reusing it needs one caution. It measures the gap after the last token of the current node, so a caller whose preceding element is an expression rather than a keyword — the postfix case — gets the right token only because
Node.getLastToken()recurses to it. And the scan start is clamped:Token.lengthis ashort, so a token longer than 32767 characters reports a negative length (a limitation this engine already has inToken.getText()). The clamp makes that fail toward terminating the statement, which is the safe direction — the unsafe one is silently swallowing the next expression. -
getPosition
protected int getPosition() -
consumeNext
protected void consumeNext() -
next
-