File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,31 @@ GNU Bison NEWS
4343 When given -fsyntax-only, the diagnostics are reported, but no output is
4444 generated.
4545
46+ *** Diagnostics for stylistic issues: -Wstyle
47+
48+ A new warning category is introduced: 'style'. Currently it reports
49+ useless explicit actions. For instance on the following grammar:
50+
51+ %type <int> "number" expr term
52+ %%
53+ expr: expr "+" term { $$ = $1 + $3; }
54+ | term { $$ = $1; }
55+ term: "(" expr ")" { $$ = $2; }
56+ | "number" { $$ = $1; }
57+
58+ bison diagnoses:
59+
60+ $ bison -Wstyle foo.y
61+ foo.y:4.21-32: warning: useless explicit action [-Wstyle]
62+ | term { $$ = $1; }
63+ ^~~~~~~~~~~~
64+ foo.y:6.21-32: warning: useless explicit action [-Wstyle]
65+ | "number" { $$ = $1; }
66+ ^~~~~~~~~~~~
67+ foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
68+
69+ Running 'bison -Wstyle --update foo.y' would remove these actions.
70+
4671*** Include the generated header (yacc.c)
4772
4873 Before, when --defines is used, bison generated a header, and pasted an
Original file line number Diff line number Diff line change @@ -10448,6 +10448,42 @@ One would get the exact same parser with the following directives instead:
1044810448@end group
1044910449@end example
1045010450
10451+ @item style
10452+ Stylistic issues, i.e., valid input that should be written in a different
10453+ way. Useless explicit actions (@samp {@{ $$ = $1; @} }) are reported. For
10454+ instance on the following grammar:
10455+
10456+ @example
10457+ @group
10458+ $ @kbd {cat foo.y }
10459+ %type <int> "number" expr term
10460+ %%
10461+ expr: expr "+" term @{ $$ = $1 + $3; @}
10462+ | term @{ $$ = $1; @}
10463+ term: "(" expr ")" @{ $$ = $2; @}
10464+ | "number" @{ $$ = $1; @}
10465+ @end group
10466+ @end example
10467+
10468+ @noindent
10469+ @command {bison } diagnoses:
10470+
10471+ @example
10472+ $ @kbd {bison -Wstyle foo.y }
10473+ foo.y:4.21-32: warning: useless explicit action [-Wstyle]
10474+ | term @{ $$ = $1; @}
10475+ ^~~~~~~~~~~~
10476+ foo.y:6.21-32: warning: useless explicit action [-Wstyle]
10477+ | "number" @{ $$ = $1; @}
10478+ ^~~~~~~~~~~~
10479+ foo.y: warning: fix-its can be applied. Rerun with option '-- update'. [-Wother]
10480+ @end example
10481+
10482+ Running @kbd {bison -Wstyle --update foo.y } would remove these actions.
10483+
10484+ Actions with named references (e.g., @samp {@{ $expr = $term; @} }) are not
10485+ reported. To disable the warning locally, write @samp {@{ $$ = ($1); @} }.
10486+
1045110487@item yacc
1045210488Incompatibilities with POSIX Yacc.
1045310489
Original file line number Diff line number Diff line change @@ -339,6 +339,7 @@ Warning categories include:\n\
339339 'empty-rule' empty rules without %empty\n\
340340 'midrule-values' unset or unused midrule values\n\
341341 'precedence' useless precedence and associativity\n\
342+ 'style' stylistic issues\n\
342343 'yacc' incompatibilities with POSIX Yacc\n\
343344 'other' all other warnings (enabled by default)\n\
344345 'all' all the warnings except 'yacc'\n\
You can’t perform that action at this time.
0 commit comments