diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2018-10-10 21:21:55 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2018-10-10 21:21:55 +0300 |
commit | 6b7db4aa16976837b4c11544e95aaa4ba9b9cc6c (patch) | |
tree | 76d07ee95ba9a36ec03d7190f730bc5d60ff9e8c /awkgram.y | |
parent | d508085853c94f298960606a28691ac36f89e5f7 (diff) | |
download | egawk-6b7db4aa16976837b4c11544e95aaa4ba9b9cc6c.tar.gz egawk-6b7db4aa16976837b4c11544e95aaa4ba9b9cc6c.tar.bz2 egawk-6b7db4aa16976837b4c11544e95aaa4ba9b9cc6c.zip |
Fix comments for && and ||, other small changes.
Diffstat (limited to 'awkgram.y')
-rw-r--r-- | awkgram.y | 93 |
1 files changed, 38 insertions, 55 deletions
@@ -104,6 +104,7 @@ static void check_funcs(void); static ssize_t read_one_line(int fd, void *buffer, size_t count); static int one_line_close(int fd); static void merge_comments(INSTRUCTION *c1, INSTRUCTION *c2); +static INSTRUCTION *make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace); static void add_sign_to_num(NODE *n, char sign); static bool at_seen = false; @@ -415,32 +416,7 @@ pattern action : l_brace statements r_brace opt_semi opt_nls { - INSTRUCTION *ip; - - if ($2 == NULL) - ip = list_create(instruction(Op_no_op)); - else - ip = $2; - - if ($1 != NULL) { - INSTRUCTION *comment2 = $1->comment; - if (comment2 != NULL) { - ip = list_prepend(ip, comment2); - $1->comment = NULL; - } - ip = list_prepend(ip, $1); - } - - /* Tack any comment onto the end. */ - if ($3 != NULL) { - INSTRUCTION *comment2 = $3->comment; - $3->comment = NULL; - if ($3->memory->comment_type == EOL_COMMENT) - $3->memory->comment_type = BLOCK_COMMENT; - ip = list_append(ip, $3); - if (comment2 != NULL) - ip = list_append(ip, comment2); - } + INSTRUCTION *ip = make_braced_statements($1, $2, $3); if ($5 != NULL) ip = list_append(ip, $5); @@ -600,35 +576,7 @@ statement } | l_brace statements r_brace { - /* FIXME: Make this a function and use also for action production */ - INSTRUCTION *ip; - - if ($2 == NULL) - ip = list_create(instruction(Op_no_op)); - else - ip = $2; - - if ($1 != NULL) { - INSTRUCTION *comment2 = $1->comment; - if (comment2 != NULL) { - ip = list_prepend(ip, comment2); - $1->comment = NULL; - } - ip = list_prepend(ip, $1); - } - - /* Tack any comment onto the end. */ - if ($3 != NULL) { - INSTRUCTION *comment2 = $3->comment; - $3->comment = NULL; - if ($3->memory->comment_type == EOL_COMMENT) - $3->memory->comment_type = BLOCK_COMMENT; - ip = list_append(ip, $3); - if (comment2 != NULL) - ip = list_append(ip, comment2); - } - - $$ = ip; + $$ = make_braced_statements($1, $2, $3); } | if_statement { @@ -6400,3 +6348,38 @@ merge_comments(INSTRUCTION *c1, INSTRUCTION *c2) c1->comment = NULL; } } + +/* make_braced_statements --- handle `l_brace statements r_brace' with comments */ + +static INSTRUCTION * +make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace) +{ + INSTRUCTION *ip; + + if (stmts == NULL) + ip = list_create(instruction(Op_no_op)); + else + ip = stmts; + + if (lbrace != NULL) { + INSTRUCTION *comment2 = lbrace->comment; + if (comment2 != NULL) { + ip = list_prepend(ip, comment2); + lbrace->comment = NULL; + } + ip = list_prepend(ip, lbrace); + } + + /* Tack any comment onto the end. */ + if (rbrace != NULL) { + INSTRUCTION *comment2 = rbrace->comment; + rbrace->comment = NULL; + if (rbrace->memory->comment_type == EOL_COMMENT) + rbrace->memory->comment_type = BLOCK_COMMENT; + ip = list_append(ip, rbrace); + if (comment2 != NULL) + ip = list_append(ip, comment2); + } + + return ip; +} |