graph: prefer *.gv to *.dot

Reported by Hans Åberg.
https://lists.gnu.org/archive/html/help-bison/2019-02/msg00064.html

* src/files.c (spec_graph_file): Use `*.gv` when 3.4 or better,
otherwise `*.dot`.
* src/parse-gram.y (handle_require): Pretend we are already 3.4.
* doc/bison.texi: Adjust.
* tests/local.at, tests/output.at: Exercise this.
This commit is contained in:
Akim Demaille
2019-02-19 18:16:02 +01:00
parent 98020cedf7
commit bd55d43333
8 changed files with 42 additions and 28 deletions

9
NEWS
View File

@@ -2,6 +2,12 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?] * Noteworthy changes in release ?.? (????-??-??) [?]
** Changes
In conformance with the recommendations of the GraphViz team, if %require
"3.4" (or better) is specified, the option --graph generates a *.gv file
by default, instead of *.dot.
** New features ** New features
*** Disabling output *** Disabling output
@@ -14,6 +20,9 @@ GNU Bison NEWS
A new example in C shows an simple infix calculator with a hand-written A new example in C shows an simple infix calculator with a hand-written
scanner (examples/c/calc). scanner (examples/c/calc).
A new example in C shows a reentrant parser (capable of recursive calls)
built with Flex and Bison (examples/c/reccalc).
* Noteworthy changes in release 3.3.2 (2019-02-03) [stable] * Noteworthy changes in release 3.3.2 (2019-02-03) [stable]
** Bug fixes ** Bug fixes

View File

@@ -4795,10 +4795,16 @@ status 63).
@end example @end example
Some deprecated behaviors are disabled for some required @var{version}: Some deprecated behaviors are disabled for some required @var{version}:
@table @code @table @asis
@item "3.2" @item @code{"3.2"} (or better)
The C++ deprecated files @file{position.hh} and @file{stack.hh} are no The C++ deprecated files @file{position.hh} and @file{stack.hh} are no
longer generated. longer generated.
@item @code{"3.4"} (or better)
To comply with the
@uref{https://marc.info/?l=graphviz-devel&m=129418103126092, recommendations
of the GraphViz team}, use the @code{.gv} extension instead of @code{.dot}
for the name of the generated DOT file. @xref{Graphviz}.
@end table @end table
@@ -6137,12 +6143,12 @@ start: FILE for ERROR;
@end example @end example
@noindent @noindent
generates the definition of the symbols @code{TOK_FILE}, @code{TOK_for}, generates the definition of the symbols @code{TOK_FILE}, @code{TOK_for}, and
and @code{TOK_ERROR} in the generated source files. In particular, the @code{TOK_ERROR} in the generated source files. In particular, the scanner
scanner must use these prefixed token names, while the grammar itself must use these prefixed token names, while the grammar itself may still use
may still use the short names (as in the sample rule given above). The the short names (as in the sample rule given above). The generated
generated informational files (@file{*.output}, @file{*.xml}, informational files (@file{*.output}, @file{*.xml}, @file{*.gv}) are not
@file{*.dot}) are not modified by this prefix. modified by this prefix.
Bison also prefixes the generated member names of the semantic value union. Bison also prefixes the generated member names of the semantic value union.
@xref{Type Generation,, Generating the Semantic Value Type}, for more @xref{Type Generation,, Generating the Semantic Value Type}, for more
@@ -9732,8 +9738,8 @@ to help them understand LR parsers.
This file is generated when the @option{--graph} option is specified This file is generated when the @option{--graph} option is specified
(@pxref{Invocation, , Invoking Bison}). Its name is made by removing (@pxref{Invocation, , Invoking Bison}). Its name is made by removing
@samp{.tab.c} or @samp{.c} from the parser implementation file name, and @samp{.tab.c} or @samp{.c} from the parser implementation file name, and
adding @samp{.dot} instead. If the grammar file is @file{foo.y}, the adding @samp{.gv} instead. If the grammar file is @file{foo.y}, the
Graphviz output file is called @file{foo.dot}. A DOT file may also be Graphviz output file is called @file{foo.gv}. A DOT file may also be
produced via an XML file and XSLT processing (@pxref{Xml,,Visualizing your produced via an XML file and XSLT processing (@pxref{Xml,,Visualizing your
parser in multiple formats}). parser in multiple formats}).
@@ -10767,12 +10773,12 @@ described under the @samp{-v} and @samp{-d} options.
@item -g [@var{file}] @item -g [@var{file}]
@itemx --graph[=@var{file}] @itemx --graph[=@var{file}]
Output a graphical representation of the parser's Output a graphical representation of the parser's automaton computed by
automaton computed by Bison, in @uref{http://www.graphviz.org/, Graphviz} Bison, in @uref{http://www.graphviz.org/, Graphviz}
@uref{http://www.graphviz.org/doc/info/lang.html, DOT} format. @uref{http://www.graphviz.org/doc/info/lang.html, DOT} format.
@code{@var{file}} is optional. @code{@var{file}} is optional. If omitted and the grammar file is
If omitted and the grammar file is @file{foo.y}, the output file will be @file{foo.y}, the output file will be @file{foo.gv} if the @code{%required}
@file{foo.dot}. version is 3.4 or better, @file{foo.dot} otherwise.
@item -x [@var{file}] @item -x [@var{file}]
@itemx --xml[=@var{file}] @itemx --xml[=@var{file}]

View File

@@ -342,7 +342,8 @@ compute_output_file_names (void)
if (graph_flag) if (graph_flag)
{ {
if (! spec_graph_file) if (! spec_graph_file)
spec_graph_file = concat2 (all_but_tab_ext, ".dot"); spec_graph_file = concat2 (all_but_tab_ext,
304 <= required_version ? ".gv" : ".dot");
output_file_name_check (&spec_graph_file, false); output_file_name_check (&spec_graph_file, false);
} }

View File

@@ -3463,10 +3463,9 @@ handle_require (location const *loc, char const *version)
return; return;
} }
required_version = major * 100 + minor; required_version = major * 100 + minor;
/* Pretend to be at least 3.2, even if we are only 3.1-211, as it /* Pretend to be at least 3.4, to check features published in 3.4
allows us to check features published in 3.2 while developping while developping it. */
3.2. */ const char* api_version = "3.4";
const char* api_version = "3.2";
const char* package_version = const char* package_version =
strverscmp (api_version, PACKAGE_VERSION) > 0 strverscmp (api_version, PACKAGE_VERSION) > 0
? api_version : PACKAGE_VERSION; ? api_version : PACKAGE_VERSION;

View File

@@ -958,10 +958,9 @@ handle_require (location const *loc, char const *version)
return; return;
} }
required_version = major * 100 + minor; required_version = major * 100 + minor;
/* Pretend to be at least 3.2, even if we are only 3.1-211, as it /* Pretend to be at least 3.4, to check features published in 3.4
allows us to check features published in 3.2 while developping while developping it. */
3.2. */ const char* api_version = "3.4";
const char* api_version = "3.2";
const char* package_version = const char* package_version =
strverscmp (api_version, PACKAGE_VERSION) > 0 strverscmp (api_version, PACKAGE_VERSION) > 0
? api_version : PACKAGE_VERSION; ? api_version : PACKAGE_VERSION;

2
tests/.gitignore vendored
View File

@@ -1,8 +1,6 @@
/*.dot
/*.output /*.output
/atconfig /atconfig
/atlocal /atlocal
/autom4te.cache
/bison /bison
/calc /calc
/calc.[chy] /calc.[chy]

View File

@@ -752,7 +752,7 @@ m4_define([AT_BISON_CHECK_XML],
# Don't combine these Bison invocations since we want to be sure that # Don't combine these Bison invocations since we want to be sure that
# --report=all isn't required to get the full XML file. # --report=all isn't required to get the full XML file.
AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \ AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
--graph=xml-tests/test.dot ]]AT_BISON_ARGS, --graph=xml-tests/test.gv ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore]) [[0]], [ignore], [ignore])
AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS, AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore]) [[0]], [ignore], [ignore])
@@ -761,7 +761,7 @@ m4_define([AT_BISON_CHECK_XML],
AT_CHECK([[$XSLTPROC \ AT_CHECK([[$XSLTPROC \
`]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \ `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \
xml-tests/test.xml]], [[0]], [expout]) xml-tests/test.xml]], [[0]], [expout])
[sort xml-tests/test.dot > expout] [sort xml-tests/test.gv > expout]
AT_CHECK([[$XSLTPROC \ AT_CHECK([[$XSLTPROC \
`]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \ `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \
xml-tests/test.xml | sort]], [[0]], [expout]) xml-tests/test.xml | sort]], [[0]], [expout])

View File

@@ -76,6 +76,8 @@ AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -y], AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -y],
[y.dot y.output y.tab.c y.tab.h y.xml]) [y.dot y.output y.tab.c y.tab.h y.xml])
AT_CHECK_OUTPUT([foo.y], [%require "3.4"], [-dv -g --xml -y],
[y.gv y.output y.tab.c y.tab.h y.xml])
# With '-o y.tab.c', we expect 'y.output' etc. (for compatibility with Yacc). # With '-o y.tab.c', we expect 'y.output' etc. (for compatibility with Yacc).
AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c], AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c],
[y.dot y.output y.tab.c y.tab.h y.xml]) [y.dot y.output y.tab.c y.tab.h y.xml])