X-Git-Url: https://git.distorted.org.uk/~mdw/mdwtools/blobdiff_plain/6d86a5276ba4bac330f33b4e6b56f18e1d7463f0..d93764b338514894110ad0a7f51391da1862d9cc:/syntax.dtx

diff --git a/syntax.dtx b/syntax.dtx
index 1b1965f..ee0f4e3 100644
--- a/syntax.dtx
+++ b/syntax.dtx
@@ -35,7 +35,7 @@
 %<+package>                [2003/08/25 1.08 Syntax typesetting (MDW)]
 % \end{meta-comment}
 %
-% \CheckSum{1616}
+% \CheckSum{1627}
 %% \CharacterTable
 %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
 %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
@@ -283,9 +283,9 @@
 % blank lines.  You can use the normal |\\| command to perform line-breaking
 % of a production rule.  Note that a production rule must begin with a
 % nonterminal name enclosed in angle brackets (|<| \dots |>|), followed by
-% whitespace, then some kind of production operator (usually `::=') and then
-% some more whitespace.  You can control how this text is actually typeset,
-% however.
+% any decorative material, whitespace, some kind of production operator
+% (usually `::=') and then some more whitespace.  You can control how this
+% text is actually typeset, however.
 %
 % \DescribeMacro{\[[}
 % \DescribeMacro{\]]}
@@ -325,13 +325,20 @@
 %
 % \end{description}
 %
-% \DescribeMacro\grammarlabel
+% \DescribeMacro\grammarlabelx
 % You can also control how the `label' is typeset by redefining the
-% |\grammarlabel| command.  The command is given two arguments: the name of
-% the nonterminal (which was enclosed in angle brackets), and the `production
-% operator'.  The command is expected to produce the label.  By default, it
-% typesets the nonterminal name using |\synt| and the operator at opposite
-% ends of the label, separated by an |\hfill|.
+% |\grammarlabelx| command.  The command is given three arguments: the name
+% of the nonterminal (which was enclosed in angle brackets), the following
+% decorative material, and the `production operator'.  The command is
+% expected to produce the label.  By default, it typesets the nonterminal
+% name using |\synt| followed by the decoration, and the operator, at
+% opposite ends of the label, separated by an |\hfill|.
+%
+% \DescribeMacro\grammarlabel
+% For compatibility, if there is no decorative material, the macro
+% |\grammarlabel| is called instead, with just two arguments: the nonterminal
+% name and the operator.  The default implementation of |\grammarlabel| just
+% calls |\grammarlabelx| with empty decoration.
 %
 % \subsection{Syntax diagrams}
 %
@@ -399,17 +406,17 @@
 % ^^A took to get the table below to look right: __6.  Hmm... not as bad
 % ^^A as I expected.  Most of them were fine-tuning things.
 %
-% \medskip					^^A Leave a vertical gap
-% \hbox to\columnwidth{\hfil\vbox{\tabskip=0pt	^^A Centre it horizontally
-% \sdsize \csname sd@setsize\endcsname		^^A Position syntdiag arrows
-% \halign to .5\columnwidth{			^^A Set the table width
+% \medskip                                      ^^A Leave a vertical gap
+% \hbox to\columnwidth{\hfil\vbox{\tabskip=0pt  ^^A Centre it horizontally
+% \sdsize \csname sd@setsize\endcsname          ^^A Position syntdiag arrows
+% \halign to .5\columnwidth{                    ^^A Set the table width
 %   &\ttfamily\ignorespaces#\unskip\hfil\tabskip=0pt ^^A Typeset the name
-%   &\quad\csname sd@arr@#\endcsname\hfil	^^A Typeset the arrow
-%   &\setbox0=\hbox{#}\tabskip=0pt plus 1fil\cr	^^A Stretch between columns
+%   &\quad\csname sd@arr@#\endcsname\hfil       ^^A Typeset the arrow
+%   &\setbox0=\hbox{#}\tabskip=0pt plus 1fil\cr ^^A Stretch between columns
 %   >>-&>>-&   &>-&>-&   &->&->\cr
 %   -><&-><&   &...&...& &-&-\cr
-% }}\hfil}					^^A Close the boxing
-% \medskip					^^A And leave another gap
+% }}\hfil}                                      ^^A Close the boxing
+% \medskip                                      ^^A And leave another gap
 %
 % These declarations should be used only in the optional argument to the
 % \env{syntdiag$*$} command.  The second optional argument to the
@@ -616,11 +623,11 @@
 % |\lit| and |\lit*|) has two style commands associated with it, as shown
 % in the table below.
 %
-% \begin{tab}{lll}						   \hline
-% \bf Syntax item	& \bf Left command & \bf Right command	\\ \hline
-% Nonterminals		& |\syntleft|	   & |\syntright|	\\
-% Quoted terminals	& |\litleft|	   & |\litright|	\\
-% Unquoted terminals	& |\ulitleft|	   & |\ulitright|	\\ \hline
+% \begin{tab}{lll}                                                 \hline
+% \bf Syntax item       & \bf Left command & \bf Right command  \\ \hline
+% Nonterminals          & |\syntleft|      & |\syntright|       \\
+% Quoted terminals      & |\litleft|       & |\litright|        \\
+% Unquoted terminals    & |\ulitleft|      & |\ulitright|       \\ \hline
 % \end{tab}
 %
 % It's not too hard to see how this works.  For example, if you look at
@@ -1358,9 +1365,8 @@
 % commands.  Well, almost \dots
 %
 %    \begin{macrocode}
-\newcommand{\grammarlabel}[3][]{%
-  \synt{#2}#1 \hfill#3%
-}
+\newcommand{\grammarlabel}[2]{\grammarlabelx{#1}{}{#2}}
+\newcommand{\grammarlabelx}[3]{\synt{#1}#2 \hfill#3}
 %    \end{macrocode}
 %
 % Now for a bit of hacking to make the item stuff work properly.  This gets
@@ -1373,7 +1379,12 @@
 %
 %    \begin{macrocode}
 \def\gr@implitem<#1>#2 #3 {%
-  \sbox\z@{\hskip\labelsep\grammarlabel[{#2}]{#1}{#3}}%
+  \sbox\z@{%
+    \hskip\labelsep%
+    \def\@tempa{#2}%
+    \ifx\@tempa\@empty\grammarlabel{#1}{#3}%
+    \else\grammarlabelx{#1}{#2}{#3}\fi%
+  }%
   \strut\@@par%
   \vskip-\parskip%
   \vskip-\baselineskip%
