Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/mdwtools
[mdwtools] / syntax.dtx
index 1226067..1b1965f 100644 (file)
 % \begin{listing}
 %\def\<#1>{\synt{#1}}
 % \end{listing}
-% to allow you to type "\\<"<text>">" as an alternative to 
+% to allow you to type "\\<"<text>">" as an alternative to
 % "\\synt{"<text>"}".
 %
 % \DescribeMacro\lit
 % \DescribeMacro{\[[}
 % \DescribeMacro{\]]}
 % You can use syntax diagrams (see below) instead of a straight piece of BNF
-% by enclosing it in a |\[[| \dots |\]]| pair.  Note that you can't mix 
+% by enclosing it in a |\[[| \dots |\]]| pair.  Note that you can't mix
 % syntax diagrams and BNF in a production rule, and you will get something
 % which looks very strange if you try.
 %
 %
 % \DescribeMacro\tok
 % You can also include text using the |\tok| command.  The argument of this
-% command is typeset in \LaTeX's LR~mode and inserted into the diagram. 
+% command is typeset in \LaTeX's LR~mode and inserted into the diagram.
 % Syntax abbreviations are allowed within the argument, so you can, for
 % example, include textual descriptions like
 % \begin{listing}
 %
 % Note that items on the backwards arrow of a \env{rep} construction should
 % be displayed \emph{backwards}.  You must put the individual items in
-% reverse order when building this part of your diagrams.  \syn\ will 
+% reverse order when building this part of your diagrams.  \syn\ will
 % correctly reverse the arrows on \env{rep} structures, but apart from
 % this, you must cope on your own.  You are recommended to keep these parts
 % of your diagrams as simple as possible to avoid confusing readers.
 %
 % You can also alter the appearance of \env{stack}s and \env{rep}s by using
 % their optional positioning arguments.  By default, \env{stack}s descend
-% below the main line of the diagram, and \env{rep}s extend above it.  
+% below the main line of the diagram, and \env{rep}s extend above it.
 % Specifying an optional argument of |[b]| for either environment reverses
 % this, putting \env{stack}s above and \env{rep}s below the line.
 %
 % characters through.  By default, we re-enable |\|, and make `\verb*" "'
 % typeset some space glue, rather than a space character.  A macro
 % `\verb*"\ "' is defined to actually print a space character, which yield
-% `\verb*" "' in the `|\tt|' font. 
+% `\verb*" "' in the `|\tt|' font.
 %
 % Finally, it defines a |\ch| command, which, given a single-character
 % control sequence as its argument, typesets the character.  This is useful,
   \addspecial\|%
   \addspecial\"%
   \catcode`\|\active%
-  \catcode`\<\active% 
+  \catcode`\<\active%
   \catcode`\"\active%
   \catcode`\`\active%
 }
 % commands.  Well, almost \dots
 %
 %    \begin{macrocode}
-\newcommand{\grammarlabel}[2]{%
-  \synt{#1} \hfill#2%
+\newcommand{\grammarlabel}[3][]{%
+  \synt{#2}#1 \hfill#3%
 }
 %    \end{macrocode}
 %
 % strut just makes sure that I know exactly how high the line is.
 %
 %    \begin{macrocode}
-\def\gr@implitem<#1> #2 {%
-  \sbox\z@{\hskip\labelsep\grammarlabel{#1}{#2}}%
+\def\gr@implitem<#1>#2 #3 {%
+  \sbox\z@{\hskip\labelsep\grammarlabel[{#2}]{#1}{#3}}%
   \strut\@@par%
   \vskip-\parskip%
   \vskip-\baselineskip%