Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: src/parsing/parser-base.h

Issue 1793913002: [parser] implement error reporting for Scanner errors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: shape change a few more lines Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/messages.h ('k') | src/parsing/scanner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index ef492e0c01ad1df71767b8bbf06334d7f9ee2900..610e917ea875c2534e790a5e5d63d37c54982d97 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -582,7 +582,8 @@ class ParserBase : public Traits {
}
void GetUnexpectedTokenMessage(
- Token::Value token, MessageTemplate::Template* message, const char** arg,
+ Token::Value token, MessageTemplate::Template* message,
+ Scanner::Location* location, const char** arg,
MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken);
void ReportUnexpectedToken(Token::Value token);
@@ -683,33 +684,34 @@ class ParserBase : public Traits {
void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
- GetUnexpectedTokenMessage(peek(), &message, &arg);
- classifier->RecordExpressionError(scanner()->peek_location(), message, arg);
+ Scanner::Location location = scanner()->peek_location();
+ GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
+ classifier->RecordExpressionError(location, message, arg);
}
void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
- GetUnexpectedTokenMessage(peek(), &message, &arg);
- classifier->RecordBindingPatternError(scanner()->peek_location(), message,
- arg);
+ Scanner::Location location = scanner()->peek_location();
+ GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
+ classifier->RecordBindingPatternError(location, message, arg);
}
void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
- GetUnexpectedTokenMessage(peek(), &message, &arg);
- classifier->RecordArrowFormalParametersError(scanner()->peek_location(),
- message, arg);
+ Scanner::Location location = scanner()->peek_location();
+ GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
+ classifier->RecordArrowFormalParametersError(location, message, arg);
}
void FormalParameterInitializerUnexpectedToken(
ExpressionClassifier* classifier) {
MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
const char* arg;
- GetUnexpectedTokenMessage(peek(), &message, &arg);
- classifier->RecordFormalParameterInitializerError(
- scanner()->peek_location(), message, arg);
+ Scanner::Location location = scanner()->peek_location();
+ GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
+ classifier->RecordFormalParameterInitializerError(location, message, arg);
}
// Recursive descent functions:
@@ -957,10 +959,10 @@ ParserBase<Traits>::FunctionState::~FunctionState() {
*function_state_stack_ = outer_function_state_;
}
-
template <class Traits>
void ParserBase<Traits>::GetUnexpectedTokenMessage(
- Token::Value token, MessageTemplate::Template* message, const char** arg,
+ Token::Value token, MessageTemplate::Template* message,
+ Scanner::Location* location, const char** arg,
MessageTemplate::Template default_) {
*arg = nullptr;
switch (token) {
@@ -997,7 +999,12 @@ void ParserBase<Traits>::GetUnexpectedTokenMessage(
*message = MessageTemplate::kInvalidEscapedReservedWord;
break;
case Token::ILLEGAL:
- *message = MessageTemplate::kInvalidOrUnexpectedToken;
+ if (scanner()->has_error()) {
+ *message = scanner()->error();
+ *location = scanner()->error_location();
+ } else {
+ *message = MessageTemplate::kInvalidOrUnexpectedToken;
+ }
break;
default:
const char* name = Token::String(token);
@@ -1019,7 +1026,7 @@ void ParserBase<Traits>::ReportUnexpectedTokenAt(
Scanner::Location source_location, Token::Value token,
MessageTemplate::Template message) {
const char* arg;
- GetUnexpectedTokenMessage(token, &message, &arg);
+ GetUnexpectedTokenMessage(token, &message, &source_location, &arg);
Traits::ReportMessageAt(source_location, message, arg);
}
« no previous file with comments | « src/messages.h ('k') | src/parsing/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698