diff options
-rw-r--r-- | include/wabt/wast-parser.h | 1 | ||||
-rw-r--r-- | src/wast-parser.cc | 15 | ||||
-rw-r--r-- | test/parse/empty-file.txt | 3 | ||||
-rw-r--r-- | test/regress/regress-30.txt | 2 |
4 files changed, 15 insertions, 6 deletions
diff --git a/include/wabt/wast-parser.h b/include/wabt/wast-parser.h index 09b4e537..b80a8e5d 100644 --- a/include/wabt/wast-parser.h +++ b/include/wabt/wast-parser.h @@ -252,6 +252,7 @@ class WastParser { Result ParseSimdV128Const(Const*, TokenType, ConstType); void CheckImportOrdering(Module*); + bool HasError() const; WastLexer* lexer_; Index last_module_index_ = kInvalidIndex; diff --git a/src/wast-parser.cc b/src/wast-parser.cc index 11d0d338..29da7b23 100644 --- a/src/wast-parser.cc +++ b/src/wast-parser.cc @@ -1174,13 +1174,15 @@ Result WastParser::ParseModule(std::unique_ptr<Module>* out_module) { } else if (IsModuleField(PeekPair())) { // Parse an inline module (i.e. one with no surrounding (module)). CHECK_RESULT(ParseModuleFieldList(module.get())); + } else if (PeekMatch(TokenType::Eof)) { + errors_->emplace_back(ErrorLevel::Warning, GetLocation(), "empty module"); } else { ConsumeIfLpar(); ErrorExpected({"a module field", "a module"}); } EXPECT(Eof); - if (errors_->size() == 0) { + if (!HasError()) { *out_module = std::move(module); return Result::Ok; } else { @@ -1203,13 +1205,15 @@ Result WastParser::ParseScript(std::unique_ptr<Script>* out_script) { script->commands.emplace_back(std::move(command)); } else if (IsCommand(PeekPair())) { CHECK_RESULT(ParseCommandList(script.get(), &script->commands)); + } else if (PeekMatch(TokenType::Eof)) { + errors_->emplace_back(ErrorLevel::Warning, GetLocation(), "empty script"); } else { ConsumeIfLpar(); ErrorExpected({"a module field", "a command"}); } EXPECT(Eof); - if (errors_->size() == 0) { + if (!HasError()) { *out_script = std::move(script); return Result::Ok; } else { @@ -3343,7 +3347,6 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) { module->name = bsm->name; module->loc = bsm->loc; for (const auto& error : errors) { - assert(error.error_level == ErrorLevel::Error); if (error.loc.offset == kInvalidOffset) { Error(bsm->loc, "error in binary module: %s", error.message.c_str()); } else { @@ -3590,6 +3593,12 @@ void WastParser::CheckImportOrdering(Module* module) { } } +bool WastParser::HasError() const { + return std::any_of(errors_->begin(), errors_->end(), [](const auto& x) { + return x.error_level == ErrorLevel::Error; + }); +} + Result ParseWatModule(WastLexer* lexer, std::unique_ptr<Module>* out_module, Errors* errors, diff --git a/test/parse/empty-file.txt b/test/parse/empty-file.txt index 8fd4f01a..6f5ff7f9 100644 --- a/test/parse/empty-file.txt +++ b/test/parse/empty-file.txt @@ -1,6 +1,5 @@ ;;; TOOL: wat2wasm -;;; ERROR: 1 ;; empty file (;; STDERR ;;; -out/test/parse/empty-file.txt:4:1: error: unexpected token "EOF", expected a module field or a module. +out/test/parse/empty-file.txt:3:1: warning: empty module ;;; STDERR ;;) diff --git a/test/regress/regress-30.txt b/test/regress/regress-30.txt index 5a89f2dd..8d262190 100644 --- a/test/regress/regress-30.txt +++ b/test/regress/regress-30.txt @@ -7,7 +7,7 @@ out/test/regress/regress-30.txt:3: assert_malformed passed: out/test/regress/regress-30/regress-30.0.wat:1:1: error: unexpected char € ^ - out/test/regress/regress-30/regress-30.0.wat:1:2: error: unexpected token "EOF", expected a module field or a module. + out/test/regress/regress-30/regress-30.0.wat:1:2: warning: empty module € ^ 1/1 tests passed. |