Class AbstractParser
java.lang.Object
com.oracle.js.parser.AbstractParser
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ErrorManagerError manager to report errors.protected intFinish position of previous token.protected booleanIs this parser running under strict mode?protected intIndex of current token.protected TokenTypeType of last token.protected LexerLexer used to scan source content.protected intCurrent line number.protected final intWhat should line numbers be counted from?protected intPosition of last EOL + 1.protected longPrevious token - accessible to sub classesprotected final SourceSource to parse.protected intStart position of current token.protected TokenStreamStream of lex tokens to parse.protected longDescriptor of current token.protected TokenTypeType of current token. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractParser(Source source, ErrorManager errors, boolean strict, int lineOffset) Construct a parser. -
Method Summary
Modifier and TypeMethodDescriptionprotected IdentNodecreateIdentNode(long identToken, int identFinish, com.oracle.truffle.api.strings.TruffleString name) Creates a newIdentNodeas if invoked with aconstructorbut making sure that thenameis deduplicated within this parse job.protected final ParserExceptionerror(JSErrorType errorType, String message) Report an error.protected final ParserExceptionerror(JSErrorType errorType, String message, long errorToken) Report an error.protected final ParserExceptionReport an error.protected final ParserExceptionReport an error.protected final voidCheck current token and advance to the next token.protected final voidexpectDontAdvance(TokenType expected) Check current token, but don't advance to the next token.protected final StringexpectMessage(TokenType expected) Generate 'expected' message.protected final StringexpectMessage(TokenType expected, long errorToken) protected final IdentNodegetIdent()Get ident.protected final IdentNodeCreate an IdentNode from the current tokenprotected final LiteralNode<?> Create a LiteralNode from the current tokenCustom number-to-string converter used to convert numeric property names to strings.protected final longgetToken(int i) Get the ith token.protected final ObjectgetValue()Get the value of the current token.protected final ObjectgetValue(long valueToken) Get the value of a specific tokenprotected final ObjectGet the value of the current token.protected final booleanCheck if current token is in identifier nameprotected final booleanisIdentifierName(long currentToken) Check if token is an identifier nameprotected final booleanCertain future reserved words can be used as identifiers in non-strict mode.protected static Stringprotected static StringGet the message string for a message ID and argumentsprotected final TokenTypenext()Seek next token that is not an EOL or comment.protected final TokenTypeSeek next token or EOL (skipping comments.)protected final TokenTypeT(int i) Return the tokenType of the ith token.protected voidvalidateLexerToken(Lexer.LexerToken lexerToken) Lexer token validation hook for subclasses.protected final voidwarning(JSErrorType errorType, String message, long errorToken) Report a warning to the error manager.
-
Field Details
-
source
Source to parse. -
errors
Error manager to report errors. -
stream
Stream of lex tokens to parse. -
k
protected int kIndex of current token. -
previousToken
protected long previousTokenPrevious token - accessible to sub classes -
token
protected long tokenDescriptor of current token. -
type
Type of current token. -
last
Type of last token. -
start
protected int startStart position of current token. -
finish
protected int finishFinish position of previous token. -
line
protected int lineCurrent line number. -
linePosition
protected int linePositionPosition of last EOL + 1. -
lexer
Lexer used to scan source content. -
isStrictMode
protected boolean isStrictModeIs this parser running under strict mode? -
lineOffset
protected final int lineOffsetWhat should line numbers be counted from?
-
-
Constructor Details
-
AbstractParser
Construct a parser.- Parameters:
source- Source to parse.errors- Error reporting manager.strict- True if we are in strict modelineOffset- Offset from which lines should be counted
-
-
Method Details
-
getToken
protected final long getToken(int i) Get the ith token.- Parameters:
i- Index of token.- Returns:
- the token
-
T
Return the tokenType of the ith token.- Parameters:
i- Index of token- Returns:
- the token type
-
next
Seek next token that is not an EOL or comment.- Returns:
- tokenType of next token.
-
nextOrEOL
Seek next token or EOL (skipping comments.)- Returns:
- tokenType of next token.
-
message
-
message
-
error
Report an error.- Parameters:
message- Error message.errorToken- Offending token.- Returns:
- ParserException upon failure. Caller should throw and not ignore
-
error
Report an error.- Parameters:
errorType- The error typemessage- Error message.errorToken- Offending token.- Returns:
- ParserException upon failure. Caller should throw and not ignore
-
error
Report an error.- Parameters:
message- Error message.- Returns:
- ParserException upon failure. Caller should throw and not ignore
-
error
Report an error.- Parameters:
errorType- The error typemessage- Error message.- Returns:
- ParserException upon failure. Caller should throw and not ignore
-
warning
Report a warning to the error manager.- Parameters:
errorType- The error type of the warningmessage- Warning message.errorToken- error token
-
expectMessage
-
expectMessage
-
expect
Check current token and advance to the next token.- Parameters:
expected- Expected tokenType.- Throws:
ParserException- on unexpected token type
-
expectDontAdvance
Check current token, but don't advance to the next token.- Parameters:
expected- Expected tokenType.- Throws:
ParserException- on unexpected token type
-
getValueNoEscape
Get the value of the current token. If the current token contains an escape sequence, the method does not attempt to convert it.- Returns:
- JavaScript value of the token.
-
getValue
Get the value of the current token.- Returns:
- JavaScript value of the token.
-
getValue
Get the value of a specific token- Parameters:
valueToken- the token- Returns:
- JavaScript value of the token
-
isNonStrictModeIdent
protected final boolean isNonStrictModeIdent()Certain future reserved words can be used as identifiers in non-strict mode. Check if the current token is one such.- Returns:
- true if non strict mode identifier
-
getIdent
-
createIdentNode
protected IdentNode createIdentNode(long identToken, int identFinish, com.oracle.truffle.api.strings.TruffleString name) Creates a newIdentNodeas if invoked with aconstructorbut making sure that thenameis deduplicated within this parse job.- Parameters:
identToken- the token for the newIdentNodeidentFinish- the finish for the newIdentNodename- the name for the newIdentNode. It will be de-duplicated.- Returns:
- a newly constructed
IdentNodewith the specified token, finish, and name; the name will be deduplicated.
-
isIdentifierName
protected final boolean isIdentifierName()Check if current token is in identifier name- Returns:
- true if current token is an identifier name
-
isIdentifierName
protected final boolean isIdentifierName(long currentToken) Check if token is an identifier name- Returns:
- true if token is an identifier name
-
getIdentifierName
Create an IdentNode from the current token- Returns:
- an IdentNode representing the current token
-
getLiteral
Create a LiteralNode from the current token- Returns:
- LiteralNode representing the current token
- Throws:
ParserException- if any literals fails to parse
-
validateLexerToken
Lexer token validation hook for subclasses.- Parameters:
lexerToken- the lexer token to validate
-
getNumberToStringConverter
-