wgsl parser: Replace set_error() with add_error()

Have slightly different overloads.

Long term we will want to be able to emit more than one error in a single parse.

Bug: tint:282
Bug: tint:291
Change-Id: Ide61c6ca75d45065e917b8fa16a097048397e31b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31723
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-04 02:23:10 +00:00 committed by Commit Bot service account
parent e862fde45c
commit 88cd156fd9
3 changed files with 206 additions and 186 deletions

File diff suppressed because it is too large Load Diff

View File

@ -125,13 +125,22 @@ class ParserImpl {
/// @param idx the index of the token to return
/// @returns the token |idx| positions ahead without advancing
Token peek(size_t idx);
/// Sets the error from |t|
/// @param t the token to set the error from
void set_error(const Token& t);
/// Sets the error from |t| or |msg| if |t| is not in error
/// @param t the token to set the error from
/// Appends an error at |t| with the message |msg|
/// @param t the token to associate the error with
/// @param msg the error message
void set_error(const Token& t, const std::string& msg);
void add_error(const Token& t, const std::string& msg);
/// Appends an error raised when parsing |use| at |t| with the message |msg|
/// @param t the token to associate the error with
/// @param msg the error message
/// @param use a description of what was being parsed when the error was
/// raised.
void add_error(const Token& t,
const std::string& msg,
const std::string& use);
/// Appends an error at |source| with the message |msg|
/// @param source the source to associate the error with
/// @param msg the error message
void add_error(const Source& source, const std::string& msg);
/// Registers a constructed type into the parser
/// @param name the constructed name

View File

@ -289,7 +289,7 @@ TEST_F(ParserImplErrorTest, FunctionDeclDecoStageInvalid) {
TEST_F(ParserImplErrorTest, FunctionDeclDecoStageTypeInvalid) {
// TODO(bclayton) - BUG(https://crbug.com/tint/291)
EXPECT("[[shader(vertex)]] fn main() -> void {}",
"test.wgsl:1:1 error: invalid token ([[) encountered\n"
"test.wgsl:1:1 error: invalid token\n"
"[[shader(vertex)]] fn main() -> void {}\n"
"^^\n");
}
@ -1178,7 +1178,7 @@ TEST_F(ParserImplErrorTest, UnaryInvalidExpr) {
TEST_F(ParserImplErrorTest, UnexpectedToken) {
EXPECT("unexpected",
"test.wgsl:1:1 error: invalid token (kIdentifier) encountered\n"
"test.wgsl:1:1 error: invalid token\n"
"unexpected\n"
"^^^^^^^^^^\n");
}