aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-05 15:32:26 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-05 15:32:26 +0200
commit899e79466bb46b6600e55c335b1bf5b3c6c072ff (patch)
tree0efd652b7add8bb02db7636996caa009da78c516 /src/parser.y
parent4377cb485b0d03d189979766bf64676b4db9dad6 (diff)
Allow line continuation anywhere
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/parser.y b/src/parser.y
index 072fef7..827005d 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -11,7 +11,6 @@
static ast_t mkunop(int, ast_t);
static ast_t mkbinop(yytoken_kind_t, ast_t, ast_t);
-static asts_t pushast(asts_t, ast_t);
static void yyerror(const char *);
extern const char *current_file;
@@ -67,9 +66,14 @@ exprs:
$$.buf = xmalloc(sizeof(*$$.buf) * $$.cap);
$$.buf[0] = $1;
}
- | exprs '|' expr { $$ = pushast($1, $3); }
- | exprs cont '|' expr { $$ = pushast($1, $4); }
- | exprs '|' cont expr { $$ = pushast($1, $4); }
+ | exprs '|' expr {
+ $$ = $1;
+ if ($$.len == $$.cap) {
+ $$.cap *= 2;
+ $$.buf = xrealloc($$.buf, sizeof(*$$.buf) * $$.cap);
+ }
+ $$.buf[$$.len++] = $3;
+ }
;
expr:
@@ -79,8 +83,8 @@ expr:
$$.eqn->ch = $1;
$$.vars = UINT64_C(1) << (islower($1) ? $1-'a'+26 : $1-'A');
}
- | NOT expr { $$ = mkunop(NOT, $2); }
- | OPAR expr CPAR { $$ = mkunop(OPAR, $2); }
+ | NOT expr { $$ = mkunop(NOT, $2); }
+ | OPAR expr CPAR { $$ = mkunop(OPAR, $2); }
| expr AND expr { $$ = mkbinop(AND, $1, $3); }
| expr OR expr { $$ = mkbinop(OR, $1, $3); }
| expr XOR expr { $$ = mkbinop(XOR, $1, $3); }
@@ -88,7 +92,6 @@ expr:
| expr EQUIV expr { $$ = mkbinop(EQUIV, $1, $3); }
;
-cont: EOL '\\';
eol: EOL | YYEOF;
%%
@@ -118,17 +121,6 @@ mkbinop(yytoken_kind_t op, ast_t lhs, ast_t rhs)
return a;
}
-asts_t
-pushast(asts_t as, ast_t a)
-{
- if (as.len == as.cap) {
- as.cap *= 2;
- as.buf = xrealloc(as.buf, sizeof(*as.buf) * as.cap);
- }
- as.buf[as.len++] = a;
- return as;
-}
-
void
yyerror(const char *s)
{