aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal/parser/AbstractParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jdk/nashorn/internal/parser/AbstractParser.java')
-rw-r--r--src/jdk/nashorn/internal/parser/AbstractParser.java38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/jdk/nashorn/internal/parser/AbstractParser.java b/src/jdk/nashorn/internal/parser/AbstractParser.java
index a3263b81..8f65e0f7 100644
--- a/src/jdk/nashorn/internal/parser/AbstractParser.java
+++ b/src/jdk/nashorn/internal/parser/AbstractParser.java
@@ -37,8 +37,8 @@ import jdk.nashorn.internal.runtime.ECMAErrors;
import jdk.nashorn.internal.runtime.ErrorManager;
import jdk.nashorn.internal.runtime.JSErrorType;
import jdk.nashorn.internal.runtime.ParserException;
-import jdk.nashorn.internal.runtime.regexp.RegExpFactory;
import jdk.nashorn.internal.runtime.Source;
+import jdk.nashorn.internal.runtime.regexp.RegExpFactory;
/**
* Base class for parsers.
@@ -197,9 +197,10 @@ public abstract class AbstractParser {
*
* @param message Error message.
* @param errorToken Offending token.
+ * @return ParserException upon failure. Caller should throw and not ignore
*/
- protected final void error(final String message, final long errorToken) {
- error(JSErrorType.SYNTAX_ERROR, message, errorToken);
+ protected final ParserException error(final String message, final long errorToken) {
+ return error(JSErrorType.SYNTAX_ERROR, message, errorToken);
}
/**
@@ -208,22 +209,24 @@ public abstract class AbstractParser {
* @param errorType The error type
* @param message Error message.
* @param errorToken Offending token.
+ * @return ParserException upon failure. Caller should throw and not ignore
*/
- protected final void error(final JSErrorType errorType, final String message, final long errorToken) {
+ protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) {
final int position = Token.descPosition(errorToken);
final int lineNum = source.getLine(position);
final int columnNum = source.getColumn(position);
final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken);
- throw new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
+ return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
}
/**
* Report an error.
*
* @param message Error message.
+ * @return ParserException upon failure. Caller should throw and not ignore
*/
- protected final void error(final String message) {
- error(JSErrorType.SYNTAX_ERROR, message);
+ protected final ParserException error(final String message) {
+ return error(JSErrorType.SYNTAX_ERROR, message);
}
/**
@@ -231,13 +234,24 @@ public abstract class AbstractParser {
*
* @param errorType The error type
* @param message Error message.
+ * @return ParserException upon failure. Caller should throw and not ignore
*/
- protected final void error(final JSErrorType errorType, final String message) {
+ protected final ParserException error(final JSErrorType errorType, final String message) {
// TODO - column needs to account for tabs.
final int position = Token.descPosition(token);
final int column = position - linePosition;
final String formatted = ErrorManager.format(message, source, line, column, token);
- throw new ParserException(errorType, formatted, source, line, column, token);
+ return new ParserException(errorType, formatted, source, line, column, token);
+ }
+
+ /**
+ * Report a warning to the error manager.
+ *
+ * @param errorType The error type of the warning
+ * @param message Warning message.
+ */
+ protected final void warning(final JSErrorType errorType, final String message, final long errorToken) {
+ errors.warning(error(errorType, message, errorToken));
}
/**
@@ -270,7 +284,7 @@ public abstract class AbstractParser {
*/
protected final void expect(final TokenType expected) throws ParserException {
if (type != expected) {
- error(expectMessage(expected));
+ throw error(expectMessage(expected));
}
next();
@@ -285,7 +299,7 @@ public abstract class AbstractParser {
*/
protected final Object expectValue(final TokenType expected) throws ParserException {
if (type != expected) {
- error(expectMessage(expected));
+ throw error(expectMessage(expected));
}
final Object value = getValue();
@@ -429,7 +443,7 @@ public abstract class AbstractParser {
try {
RegExpFactory.validate(regex.getExpression(), regex.getOptions());
} catch (final ParserException e) {
- error(e.getMessage());
+ throw error(e.getMessage());
}
}
node = LiteralNode.newInstance(source, literalToken, finish, (LexerToken)value);