public class Lexer extends Scanner implements StringPool
| Modifier and Type | Class and Description |
|---|---|
static class |
Lexer.LexerToken
Helper class for Lexer tokens, e.g XML or RegExp tokens.
|
protected static interface |
Lexer.LineInfoReceiver
interface to receive line information for multi-line literals.
|
static class |
Lexer.RegexToken
Temporary container for regular expressions.
|
static class |
Lexer.XMLToken
Temporary container for XML expression.
|
| Constructor and Description |
|---|
Lexer(Source source,
int start,
int len,
TokenStream stream,
boolean scripting,
int ecmaScriptVersion,
boolean shebang,
boolean isModule,
boolean pauseOnFunctionBody,
boolean allowBigInt)
Constructor
|
Lexer(Source source,
TokenStream stream,
boolean scripting,
int ecmaScriptVersion,
boolean shebang,
boolean isModule,
boolean allowBigInt)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
add(TokenType type,
int start)
Add a new token to the stream.
|
protected void |
add(TokenType type,
int start,
int end)
Add a new token to the stream.
|
boolean |
canStartLiteral(TokenType token)
Return true if the given token can be the beginning of a literal.
|
boolean |
checkIdentForKeyword(long token,
String keyword) |
protected static int |
convertDigit(char ch,
int base)
Convert a digit to a integer.
|
protected void |
error(String message,
TokenType type,
int start,
int length)
Generate a runtime exception
|
protected boolean |
isEOL(char ch)
Test whether a char is valid JavaScript end of line
|
protected boolean |
isEscapeCharacter(char ch)
Is the given character a valid escape char after "\" ?
|
static boolean |
isJSEOL(char ch)
Test whether a char is valid JavaScript end of line
|
static boolean |
isJSWhitespace(char ch)
Test whether a char is valid JavaScript whitespace
|
protected boolean |
isStringDelimiter(char ch)
Test if char is a string delimiter, e.g.
|
static boolean |
isStringLineTerminator(char ch)
Test whether a char is valid JavaScript end of string.
|
protected boolean |
isWhitespace(char ch)
Test whether a char is valid JavaScript whitespace
|
void |
lexify()
Breaks source content down into lex units, adding tokens to the token stream.
|
protected static String |
message(String msgId,
String... args)
Get the correctly localized error message for a given message id format arguments
|
protected boolean |
scanLiteral(long token,
TokenType startTokenType,
Lexer.LineInfoReceiver lir)
Check whether the given token represents the beginning of a literal.
|
protected void |
scanNumber()
Scan a number.
|
protected void |
scanString(boolean add)
Scan over a string literal.
|
protected void |
scanTemplateSpan()
Continue scanning a template literal after an expression.
|
com.oracle.truffle.api.strings.TruffleString |
stringIntern(String candidate) |
com.oracle.truffle.api.strings.TruffleString |
stringIntern(com.oracle.truffle.api.strings.TruffleString candidate) |
Lexer.RegexToken |
valueOfPattern(int start,
int length)
Convert a regex token to a token object.
|
com.oracle.truffle.api.strings.TruffleString |
valueOfRawString(long token)
Get the raw string value of a template literal string part.
|
public Lexer(Source source, TokenStream stream, boolean scripting, int ecmaScriptVersion, boolean shebang, boolean isModule, boolean allowBigInt)
source - the sourcestream - the token stream to lexscripting - are we in scripting modeecmaScriptVersion - ECMAScript language versionshebang - do we support shebangisModule - are we in modulepublic Lexer(Source source, int start, int len, TokenStream stream, boolean scripting, int ecmaScriptVersion, boolean shebang, boolean isModule, boolean pauseOnFunctionBody, boolean allowBigInt)
source - the sourcestart - start position in source from which to start lexinglen - length of source segment to lexstream - token stream to lexscripting - are we in scripting modeecmaScriptVersion - ECMAScript language versionshebang - do we support shebangisModule - are we in modulepauseOnFunctionBody - if true, lexer will return from Lexer.lexify() when it
encounters a function body. This is used with the feature where the parser is
skipping nested function bodies to avoid reading ahead unnecessarily when we skip
the function bodies.protected void add(TokenType type, int start, int end)
type - Token type.start - Start position.end - End position.protected void add(TokenType type, int start)
type - Token type.start - Start position.public static boolean isJSWhitespace(char ch)
ch - a charpublic static boolean isJSEOL(char ch)
ch - a charpublic static boolean isStringLineTerminator(char ch)
ch - a charprotected boolean isStringDelimiter(char ch)
ch - a charprotected boolean isWhitespace(char ch)
ch - a charprotected boolean isEOL(char ch)
ch - a charpublic Lexer.RegexToken valueOfPattern(int start, int length)
start - Position in source content.length - Length of regex token.public boolean canStartLiteral(TokenType token)
token - a tokenprotected boolean scanLiteral(long token,
TokenType startTokenType,
Lexer.LineInfoReceiver lir)
token - the token.startTokenType - the token type.lir - LineInfoReceiver that receives line info for multi-line string literals.protected static int convertDigit(char ch,
int base)
ch - Character to convert.base - Numeric base.public boolean checkIdentForKeyword(long token,
String keyword)
protected void scanString(boolean add)
add - true if we are not just scanning but should actually modify the token streamprotected final void scanTemplateSpan()
protected boolean isEscapeCharacter(char ch)
ch - character to be checkedprotected void scanNumber()
public void lexify()
public com.oracle.truffle.api.strings.TruffleString valueOfRawString(long token)
token - template string tokenpublic com.oracle.truffle.api.strings.TruffleString stringIntern(com.oracle.truffle.api.strings.TruffleString candidate)
stringIntern in interface StringPoolpublic com.oracle.truffle.api.strings.TruffleString stringIntern(String candidate)
protected static String message(String msgId, String... args)
msgId - message idargs - format argumentsprotected void error(String message, TokenType type, int start, int length) throws ParserException
message - error messagetype - token typestart - start position of lexed errorlength - length of lexed errorParserException - unconditionally