summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-06-27 00:21:50 +0300
committerOxore <oxore@protonmail.com>2023-06-27 00:21:50 +0300
commit565f95997c5e5b8707bb3a259796cbaf14de2b50 (patch)
treef90f78d2218c88f18ceb052dd40887db45d66158
parent2b230a858d7f4a928e2b43b3501fb18016247b14 (diff)
Rearrange expression parsing routine
-rw-r--r--main.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/main.c b/main.c
index b38594f..98b4061 100644
--- a/main.c
+++ b/main.c
@@ -1672,7 +1672,16 @@ static int pars_parse_expr(
unsigned nesting = 0;
// Otherwise expect open parenthesis, number, or unary operator.
bool expect_close_or_binary = false;
- while (!pars_is_eof_reached(self)) {
+ while (1) {
+ if (pars_is_eof_reached(self)) {
+ if (nesting != 0) {
+ assert(pars_is_eof_reached(self));
+ return pars_yield_error_eof(
+ self,
+ expect_close_or_binary ? E_EXPR_CLOSE : E_EXPR_OPEN);
+ }
+ break;
+ }
const struct token token = pars_peek(self);
if (token.type == TT_LPAREN) {
if (expect_close_or_binary) {
@@ -1730,12 +1739,6 @@ static int pars_parse_expr(
pars_commit(self);
}
assert(first_token_id != self->cur_tok_id);
- if (nesting != 0) {
- assert(pars_is_eof_reached(self));
- return pars_yield_error_eof(
- self,
- expect_close_or_binary ? E_EXPR_CLOSE : E_EXPR_OPEN);
- }
*expr = (struct expr_tokens_span){
.first_token = first_token_id,
.num_tokens = self->cur_tok_id - first_token_id,