src/jdk/nashorn/internal/parser/Lexer.java
Print this page
@@ -646,11 +646,11 @@
* @param ch Character to convert.
* @param base Numeric base.
*
* @return The converted digit or -1 if invalid.
*/
- private static int convertDigit(final char ch, final int base) {
+ protected static int convertDigit(final char ch, final int base) {
int digit;
if ('0' <= ch && ch <= '9') {
digit = ch - '0';
} else if ('A' <= ch && ch <= 'Z') {
@@ -906,11 +906,11 @@
}
/**
* Scan over a string literal.
*/
- private void scanString(final boolean add) {
+ protected void scanString(final boolean add) {
// Type of string.
TokenType type = STRING;
// Record starting quote.
final char quote = ch0;
// Skip over quote.
@@ -923,10 +923,13 @@
while (!atEOF() && ch0 != quote && !isEOL(ch0)) {
// Skip over escaped character.
if (ch0 == '\\') {
type = ESCSTRING;
skip(1);
+ if (! isEscapeCharacter(ch0)) {
+ error(Lexer.message("invalid.escape.char"), STRING, position, limit);
+ }
if (isEOL(ch0)) {
// Multiline string literal
skipEOL(false);
continue;
}
@@ -977,10 +980,20 @@
}
}
}
/**
+ * Is the given character a valid escape char after "\" ?
+ *
+ * @param ch character to be checked
+ * @return if the given character is valid after "\"
+ */
+ protected boolean isEscapeCharacter(final char ch) {
+ return true;
+ }
+
+ /**
* Convert string to number.
*
* @param valueString String to convert.
* @param radix Numeric base.
* @return Converted number.
@@ -1022,11 +1035,11 @@
}
/**
* Scan a number.
*/
- private void scanNumber() {
+ protected void scanNumber() {
// Record beginning of number.
final int start = position;
// Assume value is a decimal.
TokenType type = DECIMAL;
@@ -1581,11 +1594,11 @@
}
return null;
}
- private static String message(final String msgId, final String... args) {
+ protected static String message(final String msgId, final String... args) {
return ECMAErrors.getMessage("lexer.error." + msgId, args);
}
/**
* Generate a runtime exception