From eaa9f2c6dd47c7267c4e7f25565f8cf7f390e114 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 20 Oct 2024 23:08:40 +0300 Subject: rename parser states to be less silly --- src/parser.y | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index edf71c1..2cf2a84 100644 --- a/src/parser.y +++ b/src/parser.y @@ -48,8 +48,8 @@ %token BACKSLASH "\\" %token NL "nl" -%nterm arg args rev_args -%nterm cmd cmds rev_cmds +%nterm arg args +%nterm cmd cmds cmd_list %{ @@ -95,8 +95,8 @@ static void yyerror(YYLTYPE *yylloc, void *lexer, %% arg - : "(" cmds ")" {$$ = $2; $$.kind = LYN_APPLY;} - | "{" cmds "}" {$$ = $2; $$.kind = LYN_GROUP;} + : "(" cmd_list ")" {$$ = $2; $$.kind = LYN_APPLY;} + | "{" cmd_list "}" {$$ = $2; $$.kind = LYN_GROUP;} | ID {$$ = gen_id($1);} | STRING {$$ = gen_str($1);} | INT {$$ = gen_int($1);} @@ -105,13 +105,10 @@ arg cont : BACKSLASH NL -rev_args - : rev_args cont arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} - | rev_args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} - | arg {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} - args - : rev_args + : args cont arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} + | args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} + | arg {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} sep : sep ";" @@ -122,19 +119,19 @@ sep cmd : args {$$ = $1; $$.kind = LYN_CMD;} -rev_cmds - : rev_cmds sep cmd {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} +cmds + : cmds sep cmd {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} | cmd {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} -cmds - : rev_cmds - | rev_cmds sep - | sep rev_cmds {$$ = $2;} - | sep rev_cmds sep {$$ = $2;} +cmd_list + : cmds + | cmds sep + | sep cmds {$$ = $2;} + | sep cmds sep {$$ = $2;} | {$$ = gen_list();} input - : cmds {$1.kind = LYN_GROUP; parser->tree = $1;} + : cmd_list {$1.kind = LYN_GROUP; parser->tree = $1;} | error {parser->failed = true;} %% -- cgit v1.2.3