diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-05-24 12:44:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-24 12:44:50 -0700 |
commit | 7ae38053cf1e1e5c8f84c34a142efb043f6d4810 (patch) | |
tree | 6206f285e01f637a0698d693ce47a9493c911ed4 | |
parent | 5644d15b87577478659d7cbeb9bb0555cc233631 (diff) | |
download | binaryen-7ae38053cf1e1e5c8f84c34a142efb043f6d4810.tar.gz binaryen-7ae38053cf1e1e5c8f84c34a142efb043f6d4810.tar.bz2 binaryen-7ae38053cf1e1e5c8f84c34a142efb043f6d4810.zip |
Show line/col for parsing exceptions in gen-s-parser (#2138)
-rwxr-xr-x | scripts/gen-s-parser.py | 2 | ||||
-rw-r--r-- | src/gen-s-parser.inc | 2 | ||||
-rw-r--r-- | test/unit/test_parsing_error.py | 18 |
3 files changed, 20 insertions, 2 deletions
diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py index 5e5ec494f..8329ae13b 100755 --- a/scripts/gen-s-parser.py +++ b/scripts/gen-s-parser.py @@ -528,7 +528,7 @@ def instruction_parser(): emit(trie) printer.print_line("parse_error:") with printer.indent(): - printer.print_line("throw ParseException(std::string(op));") + printer.print_line("throw ParseException(std::string(op), s.line, s.col);") def print_header(): diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc index 65a780b8b..2fd554107 100644 --- a/src/gen-s-parser.inc +++ b/src/gen-s-parser.inc @@ -2250,7 +2250,7 @@ switch (op[0]) { default: goto parse_error; } parse_error: - throw ParseException(std::string(op)); + throw ParseException(std::string(op), s.line, s.col); #endif // INSTRUCTION_PARSER // clang-format on diff --git a/test/unit/test_parsing_error.py b/test/unit/test_parsing_error.py new file mode 100644 index 000000000..93aab1d16 --- /dev/null +++ b/test/unit/test_parsing_error.py @@ -0,0 +1,18 @@ +from scripts.test.shared import WASM_OPT, run_process +from utils import BinaryenTestCase +import os + + +class ParsingErrorTest(BinaryenTestCase): + def test_parsing_error_msg(self): + module = ''' + (module + (func $foo + (abc) + ) + ) + ''' + p = run_process(WASM_OPT + ['--print', '-o', os.devnull], input=module, + check=False, capture_output=True) + self.assertNotEqual(p.returncode, 0) + self.assertIn("parse exception: abc (at 4:6)", p.stderr) |