graph: prefer *.gv to *.dot (was: bison info doc - precedence in recursive parsing)

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches,gmane.comp.parsers.bison.general
Message-ID <[email protected]>
> Le 17 févr. 2019 à 16:19, Akim Demaille <[email protected]> a écrit :
> 
> 
>> Le 10 févr. 2019 à 15:20, Hans Åberg <[email protected]> a écrit :
>> 
>>> On 10 Feb 2019, at 11:07, Akim Demaille <[email protected]> wrote:
>>> 
>>> [*.dot vs. *.gv]
>>> But it's too late to change the default behavior.
>> 
>> You might change it, as it is not usable on real life grammars.
> 
> You have a point :)
> 
> But it does not mean it will not break something for someone.
> Maybe bound to %require "3.4", why not.

Here is my proposal.  Maybe at some point we should change the default for grammars without %require from *.dot to *.gv.  Versions with a %require before 3.4 would still produce *.dot.

commit 90067b14bf744d725387a284a42030f028feebbc
Author: Akim Demaille <[email protected]>
Date:   Tue Feb 19 18:16:02 2019 +0100

    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.

diff --git a/NEWS b/NEWS
index fab5148c..5352e043 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/doc/bison.texi b/doc/bison.texi
index 631f27e4..4563caa4 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -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}]
diff --git a/src/files.c b/src/files.c
index 688ea338..d272c222 100644
--- a/src/files.c
+++ b/src/files.c
@@ -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);
     }
 
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 3d0b99bc..b01c4e83 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -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;
diff --git a/tests/.gitignore b/tests/.gitignore
index 70ae9c31..19f357fb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,8 +1,6 @@
-/*.dot
 /*.output
 /atconfig
 /atlocal
-/autom4te.cache
 /bison
 /calc
 /calc.[chy]
diff --git a/tests/local.at b/tests/local.at
index 0bd0ce5c..6f81fdb3 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -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])
diff --git a/tests/output.at b/tests/output.at
index 31b41694..11ef8731 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -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])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.