X-Git-Url: https://git.distorted.org.uk/~mdw/mdwtools/blobdiff_plain/e1069af1e2771b20455999803846ee852d7e42d6..eafdddad07cf0a91ba07cbd9309a0a46e3bd00ac:/syntax.dtx diff --git a/syntax.dtx b/syntax.dtx index 1226067..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 @@ -172,7 +172,7 @@ % \begin{listing} %\def\<#1>{\synt{#1}} % \end{listing} -% to allow you to type "\\<"">" as an alternative to +% to allow you to type "\\<"">" as an alternative to % "\\synt{""}". % % \DescribeMacro\lit @@ -283,14 +283,14 @@ % 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{\]]} % 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. % @@ -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 @@ -445,7 +452,7 @@ % % \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} @@ -473,7 +480,7 @@ % % 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. @@ -604,7 +611,7 @@ % % 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. % @@ -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 @@ -1132,7 +1139,7 @@ % 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, @@ -1298,7 +1305,7 @@ \addspecial\|% \addspecial\"% \catcode`\|\active% - \catcode`\<\active% + \catcode`\<\active% \catcode`\"\active% \catcode`\`\active% } @@ -1358,9 +1365,8 @@ % commands. Well, almost \dots % % \begin{macrocode} -\newcommand{\grammarlabel}[2]{% - \synt{#1} \hfill#2% -} +\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 @@ -1372,8 +1378,13 @@ % 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% + \def\@tempa{#2}% + \ifx\@tempa\@empty\grammarlabel{#1}{#3}% + \else\grammarlabelx{#1}{#2}{#3}\fi% + }% \strut\@@par% \vskip-\parskip% \vskip-\baselineskip%