diff options
author | Thomas Lively <tlively@google.com> | 2022-10-12 14:56:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 12:56:56 -0700 |
commit | c47febe1273d8c5d8db9f80d30eb65405ced0b18 (patch) | |
tree | 94e6ba80cbf0ae65ea9336073124bf3b37b4483a /scripts | |
parent | 871bf6d1d76e8af3c51b47f77875dfe695904bbe (diff) | |
download | binaryen-c47febe1273d8c5d8db9f80d30eb65405ced0b18.tar.gz binaryen-c47febe1273d8c5d8db9f80d30eb65405ced0b18.tar.bz2 binaryen-c47febe1273d8c5d8db9f80d30eb65405ced0b18.zip |
[Parser][NFC] Move `ParseInput` into the parser context (#5132)
Rather than passing both a `Ctx` and a `ParseInput` to every parsing function,
pass only a `Ctx` with a `ParseInput` inside of it. This significantly reduces
verbosity in the parser. To handle cases where parsing needs to happen at
specific locations, which used to be handled by constructing a new `ParseInput`
independent from the ctx, introduce a new RAII utility for temporarily changing
the location of the `ParseInput` inside a context.
Also add a utility for generating an error at a particular location to avoid
having to construct new `ParseInput` objects just for that purpose. This
resolves a few TODOs about correcting error locations, but since we don't test
those yet, I still consider this NFC.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gen-s-parser.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py index 3b89820c7..35c0bdae3 100755 --- a/scripts/gen-s-parser.py +++ b/scripts/gen-s-parser.py @@ -721,7 +721,7 @@ def instruction_parser(new_parser=False): def print_leaf(expr, inst): if new_parser: expr = expr.replace("()", "(ctx)") - expr = expr.replace("(s", "(ctx, in") + expr = expr.replace("(s", "(ctx") printer.print_line("if (op == \"{inst}\"sv) {{".format(inst=inst)) with printer.indent(): printer.print_line("auto ret = {expr};".format(expr=expr)) @@ -760,7 +760,7 @@ def instruction_parser(new_parser=False): printer.print_line("parse_error:") with printer.indent(): if new_parser: - printer.print_line("return in.err(\"unrecognized instruction\");") + printer.print_line("return ctx.in.err(\"unrecognized instruction\");") else: printer.print_line("throw ParseException(std::string(op), s.line, s.col);") |