Add `global_directive` rule to the WGSL parser.
This CL adds the `global_directive` rule into the WGSL parser and moves `enable_directive` under that rule. This matches the WGSL specification. Bug: tint:1633 Change-Id: I48b809cd1d2f2ffa6ec0d83474c716d4015e1dea Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98041 Auto-Submit: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Ben Clayton <bclayton@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
99fa7b9e7f
commit
ce6246502c
|
@ -310,7 +310,7 @@ bool ParserImpl::Parse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// translation_unit
|
// translation_unit
|
||||||
// : enable_directive* global_decl* EOF
|
// : global_directive* global_decl* EOF
|
||||||
void ParserImpl::translation_unit() {
|
void ParserImpl::translation_unit() {
|
||||||
bool after_global_decl = false;
|
bool after_global_decl = false;
|
||||||
while (continue_parsing()) {
|
while (continue_parsing()) {
|
||||||
|
@ -319,17 +319,9 @@ void ParserImpl::translation_unit() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ed = enable_directive();
|
auto ed = global_directive(after_global_decl);
|
||||||
if (ed.matched) {
|
if (!ed.matched && !ed.errored) {
|
||||||
if (after_global_decl) {
|
|
||||||
add_error(p, "enable directives must come before all global declarations");
|
|
||||||
}
|
|
||||||
} else if (ed.errored) {
|
|
||||||
// Found a invalid enable directive.
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
auto gd = global_decl();
|
auto gd = global_decl();
|
||||||
|
|
||||||
if (gd.matched) {
|
if (gd.matched) {
|
||||||
after_global_decl = true;
|
after_global_decl = true;
|
||||||
}
|
}
|
||||||
|
@ -347,6 +339,17 @@ void ParserImpl::translation_unit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// global_directive
|
||||||
|
// : enable_directive
|
||||||
|
Maybe<bool> ParserImpl::global_directive(bool have_parsed_decl) {
|
||||||
|
auto& p = peek();
|
||||||
|
auto ed = enable_directive();
|
||||||
|
if (ed.matched && have_parsed_decl) {
|
||||||
|
return add_error(p, "enable directives must come before all global declarations");
|
||||||
|
}
|
||||||
|
return ed;
|
||||||
|
}
|
||||||
|
|
||||||
// enable_directive
|
// enable_directive
|
||||||
// : enable name SEMICLON
|
// : enable name SEMICLON
|
||||||
Maybe<bool> ParserImpl::enable_directive() {
|
Maybe<bool> ParserImpl::enable_directive() {
|
||||||
|
|
|
@ -385,6 +385,10 @@ class ParserImpl {
|
||||||
void deprecated(const Source& source, const std::string& msg);
|
void deprecated(const Source& source, const std::string& msg);
|
||||||
/// Parses the `translation_unit` grammar element
|
/// Parses the `translation_unit` grammar element
|
||||||
void translation_unit();
|
void translation_unit();
|
||||||
|
/// Parses the `global_directive` grammar element, erroring on parse failure.
|
||||||
|
/// @param has_parsed_decl flag indicating if the parser has consumed a global declaration.
|
||||||
|
/// @return true on parse success, otherwise an error or no-match.
|
||||||
|
Maybe<bool> global_directive(bool has_parsed_decl);
|
||||||
/// Parses the `enable_directive` grammar element, erroring on parse failure.
|
/// Parses the `enable_directive` grammar element, erroring on parse failure.
|
||||||
/// @return true on parse success, otherwise an error or no-match.
|
/// @return true on parse success, otherwise an error or no-match.
|
||||||
Maybe<bool> enable_directive();
|
Maybe<bool> enable_directive();
|
||||||
|
|
Loading…
Reference in New Issue