aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-05 14:21:05 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-05 14:21:05 +0200
commit8f267b847edefe8b8751d85b9a5abe6d53d3628c (patch)
treead9162668d48fc6c8b024df99563ebc446719d00 /src/parser.y
parentbac9982d2939c5949238ec4c0ee62751e398e30f (diff)
Support line continuations
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/parser.y b/src/parser.y
index 07afbe7..8492821 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -11,6 +11,7 @@
static ast_t mkunop(int, ast_t);
static ast_t mkbinop(int, ast_t, ast_t);
+static asts_t pushast(asts_t, ast_t);
static void yyerror(const char *);
extern const char *current_file;
@@ -42,7 +43,7 @@ extern const char *current_file;
%left AND
%left XOR
%left IMPL EQUIV
-%nonassoc NOT
+%precedence NOT
%%
@@ -66,14 +67,9 @@ exprs:
$$.buf = xmalloc(sizeof(*$$.buf) * $$.cap);
$$.buf[0] = $1;
}
- | exprs '|' expr {
- $$ = $1;
- if ($$.len == $$.cap) {
- $$.cap *= 2;
- $$.buf = xrealloc($$.buf, sizeof(*$$.buf) * $$.cap);
- }
- $$.buf[$$.len++] = $3;
- }
+ | exprs '|' expr { $$ = pushast($1, $3); }
+ | exprs cont '|' expr { $$ = pushast($1, $4); }
+ | exprs '|' cont expr { $$ = pushast($1, $4); }
;
expr:
@@ -92,6 +88,7 @@ expr:
| expr EQUIV expr { $$ = mkbinop(EQUIV, $1, $3); }
;
+cont: EOL '\\';
eol: EOL | YYEOF;
%%
@@ -121,6 +118,17 @@ mkbinop(int 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)
{