Skip to content

Commit 7ae3805

Browse files
authored
Show line/col for parsing exceptions in gen-s-parser (#2138)
1 parent 5644d15 commit 7ae3805

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

scripts/gen-s-parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def emit(node, idx=0):
528528
emit(trie)
529529
printer.print_line("parse_error:")
530530
with printer.indent():
531-
printer.print_line("throw ParseException(std::string(op));")
531+
printer.print_line("throw ParseException(std::string(op), s.line, s.col);")
532532

533533

534534
def print_header():

src/gen-s-parser.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ switch (op[0]) {
22502250
default: goto parse_error;
22512251
}
22522252
parse_error:
2253-
throw ParseException(std::string(op));
2253+
throw ParseException(std::string(op), s.line, s.col);
22542254
#endif // INSTRUCTION_PARSER
22552255

22562256
// clang-format on

test/unit/test_parsing_error.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from scripts.test.shared import WASM_OPT, run_process
2+
from utils import BinaryenTestCase
3+
import os
4+
5+
6+
class ParsingErrorTest(BinaryenTestCase):
7+
def test_parsing_error_msg(self):
8+
module = '''
9+
(module
10+
(func $foo
11+
(abc)
12+
)
13+
)
14+
'''
15+
p = run_process(WASM_OPT + ['--print', '-o', os.devnull], input=module,
16+
check=False, capture_output=True)
17+
self.assertNotEqual(p.returncode, 0)
18+
self.assertIn("parse exception: abc (at 4:6)", p.stderr)

0 commit comments

Comments
 (0)