aboutsummaryrefslogtreecommitdiff
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
parentbac9982d2939c5949238ec4c0ee62751e398e30f (diff)
Support line continuations
-rw-r--r--src/lexer.l1
-rw-r--r--src/parser.y26
2 files changed, 18 insertions, 9 deletions
diff --git a/src/lexer.l b/src/lexer.l
index befd30a..74d301a 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -26,6 +26,7 @@ extern const char *current_file;
\( { return OPAR; }
\) { return CPAR; }
\| { return '|'; }
+\\ { return '\\'; }
\n { return EOL; }
[a-zA-Z] {
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)
{