diff options
author | Thomas Lively <tlively@google.com> | 2024-02-22 09:37:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 09:37:33 -0800 |
commit | f6bb943490dc87b16481bfc1604a796edf2acea8 (patch) | |
tree | 9e9123c84cfc8f11f5b3e73bfc9ae0c67560d3c8 /src/parser/parsers.h | |
parent | f9a49faa33f3a61bd27da8227eeac20b74f649c3 (diff) | |
download | binaryen-f6bb943490dc87b16481bfc1604a796edf2acea8.tar.gz binaryen-f6bb943490dc87b16481bfc1604a796edf2acea8.tar.bz2 binaryen-f6bb943490dc87b16481bfc1604a796edf2acea8.zip |
[Parser][NFC] Remove `Token` from lexer interface (#6333)
Replace the general `peek` method that returned a `Token` with specific peek
methods that look for (but do not consume) specific kinds of tokens. This change
is a prerequisite for simplifying the lexer implementation by removing `Token`
entirely.
Diffstat (limited to 'src/parser/parsers.h')
-rw-r--r-- | src/parser/parsers.h | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/parser/parsers.h b/src/parser/parsers.h index bd3aef9dc..1069a39bd 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -549,7 +549,7 @@ template<typename Ctx> Result<typename Ctx::FieldT> fieldtype(Ctx& ctx) { template<typename Ctx> Result<typename Ctx::FieldsT> fields(Ctx& ctx) { auto res = ctx.makeFields(); while (true) { - if (auto t = ctx.in.peek(); !t || t->isRParen()) { + if (ctx.in.empty() || ctx.in.peekRParen()) { return res; } if (ctx.in.takeSExprStart("field")) { @@ -754,13 +754,11 @@ template<typename Ctx> MaybeResult<> plaininstr(Ctx& ctx) { // instr ::= plaininstr | blockinstr template<typename Ctx> MaybeResult<> instr(Ctx& ctx) { // Check for valid strings that are not instructions. - if (auto tok = ctx.in.peek()) { - if (auto keyword = tok->getKeyword()) { - if (keyword == "end"sv || keyword == "then"sv || keyword == "else"sv || - keyword == "catch"sv || keyword == "catch_all"sv || - keyword == "delegate"sv || keyword == "ref"sv) { - return {}; - } + if (auto keyword = ctx.in.peekKeyword()) { + if (keyword == "end"sv || keyword == "then"sv || keyword == "else"sv || + keyword == "catch"sv || keyword == "catch_all"sv || + keyword == "delegate"sv || keyword == "ref"sv) { + return {}; } } if (auto inst = blockinstr(ctx)) { @@ -775,7 +773,7 @@ template<typename Ctx> MaybeResult<> instr(Ctx& ctx) { template<typename Ctx> MaybeResult<> foldedinstr(Ctx& ctx) { // We must have an '(' to start a folded instruction. - if (auto tok = ctx.in.peek(); !tok || !tok->isLParen()) { + if (!ctx.in.peekLParen()) { return {}; } @@ -2965,7 +2963,7 @@ template<typename Ctx> MaybeResult<> tag(Ctx& ctx) { // | data // | tag template<typename Ctx> MaybeResult<> modulefield(Ctx& ctx) { - if (auto t = ctx.in.peek(); !t || t->isRParen()) { + if (ctx.in.empty() || ctx.in.peekRParen()) { return {}; } if (auto res = deftype(ctx)) { |