error_type);
}
+ void GetUnexpectedTokenMessage(
+ Token::Value token, MessageTemplate::Template* message, const char** arg,
+ MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken);
+
void ReportUnexpectedToken(Token::Value token);
void ReportUnexpectedTokenAt(
Scanner::Location location, Token::Value token,
}
void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
- classifier->RecordExpressionError(scanner()->peek_location(),
- MessageTemplate::kUnexpectedToken,
- Token::String(peek()));
+ MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
+ const char* arg;
+ GetUnexpectedTokenMessage(peek(), &message, &arg);
+ classifier->RecordExpressionError(scanner()->peek_location(), message, arg);
}
void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
- classifier->RecordBindingPatternError(scanner()->peek_location(),
- MessageTemplate::kUnexpectedToken,
- Token::String(peek()));
+ MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
+ const char* arg;
+ GetUnexpectedTokenMessage(peek(), &message, &arg);
+ classifier->RecordBindingPatternError(scanner()->peek_location(), message,
+ arg);
}
void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
- classifier->RecordArrowFormalParametersError(
- scanner()->peek_location(), MessageTemplate::kUnexpectedToken,
- Token::String(peek()));
+ MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
+ const char* arg;
+ GetUnexpectedTokenMessage(peek(), &message, &arg);
+ classifier->RecordArrowFormalParametersError(scanner()->peek_location(),
+ message, arg);
}
// Recursive descent functions:
}
-template<class Traits>
-void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
- return ReportUnexpectedTokenAt(scanner_->location(), token);
-}
-
-
template <class Traits>
-void ParserBase<Traits>::ReportUnexpectedTokenAt(
- Scanner::Location source_location, Token::Value token,
- MessageTemplate::Template message) {
+void ParserBase<Traits>::GetUnexpectedTokenMessage(
+ Token::Value token, MessageTemplate::Template* message, const char** arg,
+ MessageTemplate::Template default_) {
// Four of the tokens are treated specially
switch (token) {
case Token::EOS:
- return ReportMessageAt(source_location, MessageTemplate::kUnexpectedEOS);
+ *message = MessageTemplate::kUnexpectedEOS;
+ *arg = nullptr;
+ break;
case Token::SMI:
case Token::NUMBER:
- return ReportMessageAt(source_location,
- MessageTemplate::kUnexpectedTokenNumber);
+ *message = MessageTemplate::kUnexpectedTokenNumber;
+ *arg = nullptr;
+ break;
case Token::STRING:
- return ReportMessageAt(source_location,
- MessageTemplate::kUnexpectedTokenString);
+ *message = MessageTemplate::kUnexpectedTokenString;
+ *arg = nullptr;
+ break;
case Token::IDENTIFIER:
- return ReportMessageAt(source_location,
- MessageTemplate::kUnexpectedTokenIdentifier);
+ *message = MessageTemplate::kUnexpectedTokenIdentifier;
+ *arg = nullptr;
+ break;
case Token::FUTURE_RESERVED_WORD:
- return ReportMessageAt(source_location,
- MessageTemplate::kUnexpectedReserved);
+ *message = MessageTemplate::kUnexpectedReserved;
+ *arg = nullptr;
+ break;
case Token::LET:
case Token::STATIC:
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD:
- return ReportMessageAt(source_location,
- is_strict(language_mode())
- ? MessageTemplate::kUnexpectedStrictReserved
- : MessageTemplate::kUnexpectedTokenIdentifier);
+ *message = is_strict(language_mode())
+ ? MessageTemplate::kUnexpectedStrictReserved
+ : MessageTemplate::kUnexpectedTokenIdentifier;
+ *arg = nullptr;
+ break;
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL:
- return Traits::ReportMessageAt(
- source_location, MessageTemplate::kUnexpectedTemplateString);
+ *message = MessageTemplate::kUnexpectedTemplateString;
+ *arg = nullptr;
+ break;
default:
const char* name = Token::String(token);
DCHECK(name != NULL);
- Traits::ReportMessageAt(source_location, message, name);
+ *arg = name;
+ break;
}
}
template <class Traits>
+void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
+ return ReportUnexpectedTokenAt(scanner_->location(), token);
+}
+
+
+template <class Traits>
+void ParserBase<Traits>::ReportUnexpectedTokenAt(
+ Scanner::Location source_location, Token::Value token,
+ MessageTemplate::Template message) {
+ const char* arg;
+ GetUnexpectedTokenMessage(token, &message, &arg);
+ Traits::ReportMessageAt(source_location, message, arg);
+}
+
+
+template <class Traits>
typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) {
ExpressionClassifier classifier;