From 8f267b847edefe8b8751d85b9a5abe6d53d3628c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 5 Sep 2024 14:21:05 +0200 Subject: Support line continuations --- src/lexer.l | 1 + src/parser.y | 26 +++++++++++++++++--------- 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) { -- cgit v1.2.3