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 ?.? (????-??-??) [?]
** 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
*** Disabling output
@@ -14,6 +20,9 @@ GNU Bison NEWS
A new example in C shows an simple infix calculator with a hand-written
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]
** Bug fixes

View File

@@ -4795,10 +4795,16 @@ status 63).
@end example
Some deprecated behaviors are disabled for some required @var{version}:
@table @code
@item "3.2"
@table @asis
@item @code{"3.2"} (or better)
The C++ deprecated files @file{position.hh} and @file{stack.hh} are no
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
@@ -6137,12 +6143,12 @@ start: FILE for ERROR;
@end example
@noindent
generates the definition of the symbols @code{TOK_FILE}, @code{TOK_for},
and @code{TOK_ERROR} in the generated source files. In particular, the
scanner must use these prefixed token names, while the grammar itself
may still use the short names (as in the sample rule given above). The
generated informational files (@file{*.output}, @file{*.xml},
@file{*.dot}) are not modified by this prefix.
generates the definition of the symbols @code{TOK_FILE}, @code{TOK_for}, and
@code{TOK_ERROR} in the generated source files. In particular, the scanner
must use these prefixed token names, while the grammar itself may still use
the short names (as in the sample rule given above). The generated
informational files (@file{*.output}, @file{*.xml}, @file{*.gv}) are not
modified by this prefix.
Bison also prefixes the generated member names of the semantic value union.
@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
(@pxref{Invocation, , Invoking Bison}). Its name is made by removing
@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
Graphviz output file is called @file{foo.dot}. A DOT file may also be
adding @samp{.gv} instead. If the grammar file is @file{foo.y}, the
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
parser in multiple formats}).
@@ -10767,12 +10773,12 @@ described under the @samp{-v} and @samp{-d} options.
@item -g [@var{file}]
@itemx --graph[=@var{file}]
Output a graphical representation of the parser's
automaton computed by Bison, in @uref{http://www.graphviz.org/, Graphviz}
Output a graphical representation of the parser's automaton computed by
Bison, in @uref{http://www.graphviz.org/, Graphviz}
@uref{http://www.graphviz.org/doc/info/lang.html, DOT} format.
@code{@var{file}} is optional.
If omitted and the grammar file is @file{foo.y}, the output file will be
@file{foo.dot}.
@code{@var{file}} is optional. If omitted and the grammar file is
@file{foo.y}, the output file will be @file{foo.gv} if the @code{%required}
version is 3.4 or better, @file{foo.dot} otherwise.
@item -x [@var{file}]
@itemx --xml[=@var{file}]

View File

@@ -342,7 +342,8 @@ compute_output_file_names (void)
if (graph_flag)
{
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);
}

View File

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

View File

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

2
tests/.gitignore vendored
View File

@@ -1,8 +1,6 @@
/*.dot
/*.output
/atconfig
/atlocal
/autom4te.cache
/bison
/calc
/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
# --report=all isn't required to get the full XML file.
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])
AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore])
@@ -761,7 +761,7 @@ m4_define([AT_BISON_CHECK_XML],
AT_CHECK([[$XSLTPROC \
`]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \
xml-tests/test.xml]], [[0]], [expout])
[sort xml-tests/test.dot > expout]
[sort xml-tests/test.gv > expout]
AT_CHECK([[$XSLTPROC \
`]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \
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],
[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).
AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c],
[y.dot y.output y.tab.c y.tab.h y.xml])