summaryrefslogtreecommitdiff
path: root/src/output.c
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-06-09 09:11:54 +0200
committerAkim Demaille <akim.demaille@gmail.com>2019-07-02 07:38:52 +0200
commit1161649446ddf96eaf400c38a2217759be41e5bc (patch)
treeae73ab94d82bcd12d134e12cda329d3c1f3cd58b /src/output.c
parent13577a809e30e88115fcd6279b8c27cab74bec8f (diff)
downloadbison-1161649446ddf96eaf400c38a2217759be41e5bc.tar.gz
preserve the indentation in the ouput
Preserve the actions' initial indentation. For instance, on | %define api.value.type {int} | %% | exp: exp '/' exp { if ($3) | $$ = $1 + $3; | else | $$ = 0; } we used to generate | { if (yyvsp[0]) | yyval = yyvsp[-2] + yyvsp[0]; | else | yyval = 0; } now we produce | { if (yyvsp[0]) | yyval = yyvsp[-2] + yyvsp[0]; | else | yyval = 0; } See https://lists.gnu.org/archive/html/bison-patches/2019-06/msg00012.html. * data/skeletons/bison.m4 (b4_symbol_action): Output the code in column 0, leave indentation matters to the C code. * src/output.c (user_actions_output): Preserve the incoming indentation in the output. (prepare_symbol_definitions): Likewise for %printer/%destructor. * tests/synclines.at (Output columns): New.
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/output.c b/src/output.c
index 1f519d0c..85528beb 100644
--- a/src/output.c
+++ b/src/output.c
@@ -359,9 +359,9 @@ symbol_numbers_output (FILE *out)
}
-/*---------------------------------.
-| Output the user actions to OUT. |
-`---------------------------------*/
+/*-------------------------------------------.
+| Output the user reduction actions to OUT. |
+`-------------------------------------------*/
static void
user_actions_output (FILE *out)
@@ -370,11 +370,19 @@ user_actions_output (FILE *out)
for (rule_number r = 0; r < nrules; ++r)
if (rules[r].action)
{
- fprintf (out, "%s(%d, [b4_syncline(%d, ",
+ fprintf (out, "%s(%d, [",
rules[r].is_predicate ? "b4_predicate_case" : "b4_case",
- r + 1, rules[r].action_loc.start.line);
- string_output (out, rules[r].action_loc.start.file);
- fprintf (out, ")dnl\n[ %s]])\n\n", rules[r].action);
+ r + 1);
+ if (!no_lines_flag)
+ {
+ fprintf (out, "b4_syncline(%d, ",
+ rules[r].action_loc.start.line);
+ string_output (out, rules[r].action_loc.start.file);
+ fprintf (out, ")dnl\n");
+ }
+ fprintf (out, "[%*s%s]])\n\n",
+ rules[r].action_loc.start.column - 1, "",
+ rules[r].action);
}
fputs ("])\n\n", out);
}
@@ -482,7 +490,9 @@ prepare_symbol_definitions (void)
muscle_location_grow (key, p->location);
SET_KEY (pname);
- MUSCLE_INSERT_STRING_RAW (key, p->code);
+ obstack_printf (&muscle_obstack,
+ "%*s%s", p->location.start.column - 1, "", p->code);
+ muscle_insert (key, obstack_finish0 (&muscle_obstack));
}
}
#undef SET_KEY2