Commit 2e052332 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Cleanup pattern classification

This changes the split from AssignmentPattern and BindingPattern to Pattern and
BindingPattern. Pattern collects all errors that are invalid in both assignment
and binding pattern contexts. Binding pattern additionally collects errors for
binding pattern contexts (property access isn't a valid target). The
distinction is piggybacked on to distinguish assignment vs binding pattern
errors since binding pattern verification will first throw the binding pattern
error.

Since we don't throw pattern error as binding pattern as well, this can mean
that a later binding pattern syntax error will show up before an early pattern
error. Since that just changes the message to another syntax violation, I think
that's fine.

Change-Id: Ib6a22c8d11c49eacc6667ae8ee5e98bababadd43
Reviewed-on: https://chromium-review.googlesource.com/c/1349273Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57774}
parent f69dd4bf
......@@ -379,6 +379,7 @@ namespace internal {
T(IntrinsicWithSpread, "Intrinsic calls do not support spread arguments") \
T(InvalidRestBindingPattern, \
"`...` must be followed by an identifier in declaration contexts") \
T(InvalidPropertyBindingPattern, "Illegal property in declaration context") \
T(InvalidRestAssignmentPattern, \
"`...` must be followed by an assignable reference in assignment " \
"contexts") \
......
......@@ -20,8 +20,8 @@ class ZoneList;
#define ERROR_CODES(T) \
T(ExpressionProduction, 0) \
T(FormalParameterInitializerProduction, 1) \
T(BindingPatternProduction, 2) \
T(AssignmentPatternProduction, 3) \
T(PatternProduction, 2) \
T(BindingPatternProduction, 3) \
T(StrictModeFormalParametersProduction, 4) \
T(LetPatternProduction, 5) \
T(AsyncArrowFormalParametersProduction, 6)
......@@ -136,12 +136,12 @@ class ExpressionClassifierBase {
return is_valid(FormalParameterInitializerProduction);
}
V8_INLINE bool is_valid_binding_pattern() const {
return is_valid(BindingPatternProduction);
V8_INLINE bool is_valid_pattern() const {
return is_valid(PatternProduction);
}
V8_INLINE bool is_valid_assignment_pattern() const {
return is_valid(AssignmentPatternProduction);
V8_INLINE bool is_valid_binding_pattern() const {
return is_valid(BindingPatternProduction);
}
// Note: callers should also check
......@@ -374,12 +374,12 @@ class ExpressionClassifier
ErrorKind::kFormalParameterInitializerProduction);
}
V8_INLINE const Error& binding_pattern_error() const {
return this->reported_error(ErrorKind::kBindingPatternProduction);
V8_INLINE const Error& pattern_error() const {
return this->reported_error(ErrorKind::kPatternProduction);
}
V8_INLINE const Error& assignment_pattern_error() const {
return this->reported_error(ErrorKind::kAssignmentPatternProduction);
V8_INLINE const Error& binding_pattern_error() const {
return this->reported_error(ErrorKind::kBindingPatternProduction);
}
V8_INLINE const Error& strict_mode_formal_parameter_error() const {
......@@ -413,6 +413,12 @@ class ExpressionClassifier
ErrorKind::kFormalParameterInitializerProduction, arg));
}
void RecordPatternError(const Scanner::Location& loc, MessageTemplate message,
const char* arg = nullptr) {
this->Add(TP::PatternProduction,
Error(loc, message, ErrorKind::kPatternProduction, arg));
}
void RecordBindingPatternError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
......@@ -420,20 +426,6 @@ class ExpressionClassifier
Error(loc, message, ErrorKind::kBindingPatternProduction, arg));
}
void RecordAssignmentPatternError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
this->Add(
TP::AssignmentPatternProduction,
Error(loc, message, ErrorKind::kAssignmentPatternProduction, arg));
}
void RecordPatternError(const Scanner::Location& loc, MessageTemplate message,
const char* arg = nullptr) {
RecordBindingPatternError(loc, message, arg);
RecordAssignmentPatternError(loc, message, arg);
}
void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc,
MessageTemplate message,
const char* arg = nullptr) {
......
This diff is collapsed.
*%(basename)s:5: SyntaxError: `...` must be followed by an assignable reference in assignment contexts
({...{}} = {});
^
^^
SyntaxError: `...` must be followed by an assignable reference in assignment contexts
*%(basename)s:5: SyntaxError: `...` must be followed by an identifier in declaration contexts
let {...{}} = {};
^
^^
SyntaxError: `...` must be followed by an identifier in declaration contexts
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment