2005-10-27 Stepan Kasal * awkgram.y (concat_exp, concat_exp_nc, simp_exp_nc): New nonterminals, needed to fix the precedence of concatenation over "|getline". (common_exp): Is now concat_exp | concat_exp_nc. and for test/ChangeLog: 2005-10-27 Stepan Kasal * getline.awk, getline.ok: Add precedence check "echo " "date"|getline diff -ur gawk-3.1.5.a1/awkgram.y gawk-3.1.5.a2/awkgram.y --- gawk-3.1.5.a1/awkgram.y 2005-10-27 09:58:14.000000000 +0200 +++ gawk-3.1.5.a2/awkgram.y 2005-10-27 10:02:12.000000000 +0200 @@ -117,7 +117,7 @@ } %type function_prologue pattern action variable param_list -%type exp common_exp +%type exp common_exp concat_exp concat_exp_nc simp_exp_nc %type simp_exp non_post_simp_exp %type expression_list opt_expression_list print_expression_list %type statements statement if_statement switch_body case_statements case_statement case_value opt_param_list @@ -840,9 +840,14 @@ ; common_exp + : concat_exp + | concat_exp_nc + ; + +concat_exp : simp_exp { $$ = $1; } - | common_exp simp_exp %prec CONCAT_OP + | concat_exp simp_exp %prec CONCAT_OP { $$ = node($1, Node_concat, $2); } ; @@ -867,11 +872,6 @@ lintwarn(_("non-redirected `getline' undefined inside END action")); $$ = node($2, Node_K_getline, $3); } - | simp_exp IO_IN LEX_GETLINE opt_variable - { - $$ = node($4, Node_K_getline, - node($1, $2, (NODE *) NULL)); - } | variable INCREMENT { $$ = node($1, Node_postincrement, (NODE *) NULL); } | variable DECREMENT @@ -880,6 +880,37 @@ { $$ = node(variable($5, CAN_FREE, Node_var_array), Node_in_array, $2); } ; +/* Expressions containing "| getline" loose the ability to be on the + right-hand side of a concatenation. + This is implemented by the "_nc" shadows of simp_exp and concat_exp. */ + +concat_exp_nc + : simp_exp_nc + { $$ = $1; } + | concat_exp_nc simp_exp %prec CONCAT_OP + { $$ = node($1, Node_concat, $2); } + ; + +simp_exp_nc + : concat_exp IO_IN LEX_GETLINE opt_variable + { + $$ = node($4, Node_K_getline, + node($1, $2, (NODE *) NULL)); + } + | simp_exp_nc '^' simp_exp + { $$ = node($1, Node_exp, $3); } + | simp_exp_nc '*' simp_exp + { $$ = node($1, Node_times, $3); } + | simp_exp_nc '/' simp_exp + { $$ = node($1, Node_quotient, $3); } + | simp_exp_nc '%' simp_exp + { $$ = node($1, Node_mod, $3); } + | simp_exp_nc '+' simp_exp + { $$ = node($1, Node_plus, $3); } + | simp_exp_nc '-' simp_exp + { $$ = node($1, Node_minus, $3); } + ; + non_post_simp_exp : regexp { $$ = $1; } diff -ur gawk-3.1.5.a1/test/getline.awk gawk-3.1.5.a2/test/getline.awk --- gawk-3.1.5.a1/test/getline.awk 2005-05-11 17:28:18.000000000 +0200 +++ gawk-3.1.5.a2/test/getline.awk 2005-10-27 10:10:55.000000000 +0200 @@ -26,4 +26,8 @@ a = cmd | getline x close(cmd) print a, x + + # Concatenation has higher precedence than IO. + "echo " "date" | getline + print } diff -ur gawk-3.1.5.a1/test/getline.ok gawk-3.1.5.a2/test/getline.ok --- gawk-3.1.5.a1/test/getline.ok 2005-05-11 17:28:18.000000000 +0200 +++ gawk-3.1.5.a2/test/getline.ok 2005-10-27 10:11:02.000000000 +0200 @@ -5,3 +5,4 @@ 2 B -1 C 1 D +date