Skip to content

Commit 8ac95b9

Browse files
committed
[macros, stmt] Introduce macro \bnfindent and change bnftab to simplebnf.
Indentation that was previously achieved with tabbing is now done with \bnfindent. One particularly tricky case of aligned comments required the use of zero-width boxes for alignment.
1 parent 6b9d2e1 commit 8ac95b9

File tree

2 files changed

+49
-73
lines changed

2 files changed

+49
-73
lines changed

source/macros.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
\setlength{\BnfRest}{2\BnfIndent}
429429
\newcommand{\BnfNontermshape}{\small\rmfamily\itshape}
430430
\newcommand{\BnfTermshape}{\small\ttfamily\upshape}
431+
\newcommand{\bnfindent}{\hspace*{\bnfindentfirst}}
431432

432433
\newenvironment{bnfbase}
433434
{

source/statements.tex

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -296,35 +296,27 @@
296296

297297
\pnum
298298
An \tcode{if} statement of the form
299-
300-
\begin{ncbnf}
299+
\begin{ncsimplebnf}
301300
\terminal{if \opt{constexpr} (} init-statement condition \terminal{)} statement
302-
\end{ncbnf}
303-
301+
\end{ncsimplebnf}
304302
is equivalent to
305-
306-
\begin{ncbnftab}
303+
\begin{ncsimplebnf}
307304
\terminal{\{}\br
308-
\>init-statement\br
309-
\>\terminal{if \opt{constexpr} (} condition \terminal{)} statement\br
305+
\bnfindent init-statement\br
306+
\bnfindent \terminal{if \opt{constexpr} (} condition \terminal{)} statement\br
310307
\terminal{\}}
311-
\end{ncbnftab}
312-
308+
\end{ncsimplebnf}
313309
and an \tcode{if} statement of the form
314-
315-
\begin{ncbnf}
310+
\begin{ncsimplebnf}
316311
\terminal{if \opt{constexpr} (} init-statement condition \terminal{)} statement \terminal{else} statement
317-
\end{ncbnf}
318-
312+
\end{ncsimplebnf}
319313
is equivalent to
320-
321-
\begin{ncbnftab}
314+
\begin{ncsimplebnf}
322315
\terminal{\{}\br
323-
\>init-statement\br
324-
\>\terminal{if \opt{constexpr} (} condition \terminal{)} statement \terminal{else} statement\br
316+
\bnfindent init-statement\br
317+
\bnfindent \terminal{if \opt{constexpr} (} condition \terminal{)} statement \terminal{else} statement\br
325318
\terminal{\}}
326-
\end{ncbnftab}
327-
319+
\end{ncsimplebnf}
328320
except that names declared in the \grammarterm{init-statement} are in
329321
the same declarative region as those declared in the
330322
\grammarterm{condition}.
@@ -400,20 +392,16 @@
400392

401393
\pnum
402394
A \tcode{switch} statement of the form
403-
404-
\begin{ncbnf}
395+
\begin{ncsimplebnf}
405396
\terminal{switch (} init-statement condition \terminal{)} statement
406-
\end{ncbnf}
407-
397+
\end{ncsimplebnf}
408398
is equivalent to
409-
410-
\begin{ncbnftab}
399+
\begin{ncsimplebnf}
411400
\terminal{\{}\br
412-
\>init-statement\br
413-
\>\terminal{switch (} condition \terminal{)} statement\br
401+
\bnfindent init-statement\br
402+
\bnfindent \terminal{switch (} condition \terminal{)} statement\br
414403
\terminal{\}}
415-
\end{ncbnftab}
416-
404+
\end{ncsimplebnf}
417405
except that names declared in the \grammarterm{init-statement} are in
418406
the same declarative region as those declared in the
419407
\grammarterm{condition}.%
@@ -513,23 +501,20 @@
513501
\grammarterm{statement}. A \tcode{while} statement whose \grammarterm{condition}
514502
is an initialized declaration of some variable \tcode{t}
515503
is equivalent to
516-
517-
\begin{ncbnftab}
504+
\begin{ncsimplebnf}
518505
\terminal{label:}\br
519-
\terminal{\{}\>\>\>// start of condition scope\br
520-
\>condition \terminal{;}\>\>// declares \terminal{t}\br
521-
\>\terminal{if (t) \{}\br
522-
\>\>statement\br
523-
\>\>\terminal{goto label;}\br
524-
\>\terminal{\}}\br
525-
\terminal{\}}\>\>\>// end of condition scope
526-
\end{ncbnftab}
527-
506+
\makebox[0pt][l]{\terminal{\{}}\bnfindent\bnfindent\bnfindent\bnfindent// start of condition scope\br
507+
\bnfindent\makebox[0pt][l]{condition \terminal{;}}\bnfindent\bnfindent\bnfindent// declares \terminal{t}\br
508+
\bnfindent \terminal{if (t) \{}\br
509+
\bnfindent\bnfindent statement\br
510+
\bnfindent\bnfindent \terminal{goto label;}\br
511+
\bnfindent \terminal{\}}\br
512+
\makebox[0pt][l]{\terminal{\}}}\bnfindent\bnfindent\bnfindent\bnfindent// end of condition scope
513+
\end{ncsimplebnf}
528514
\begin{note}
529515
The variable created in the condition is destroyed and created with each
530516
iteration of the loop.
531517
\begin{example}
532-
533518
\begin{codeblock}
534519
struct A {
535520
int val;
@@ -543,7 +528,6 @@
543528
i = 0;
544529
}
545530
\end{codeblock}
546-
547531
In the while-loop, the constructor and destructor are each called twice,
548532
once for the condition that succeeds and once for the condition that
549533
fails.
@@ -567,23 +551,19 @@
567551

568552
\pnum
569553
The \tcode{for} statement
570-
571-
\begin{ncbnf}
554+
\begin{ncsimplebnf}
572555
\terminal{for (} init-statement \opt{condition} \terminal{;} \opt{expression} \terminal{)} statement
573-
\end{ncbnf}
574-
556+
\end{ncsimplebnf}
575557
is equivalent to
576-
577-
\begin{ncbnftab}
558+
\begin{ncsimplebnf}
578559
\terminal{\{}\br
579-
\>init-statement\br
580-
\>\terminal{while (} condition \terminal{) \{}\br
581-
\>\>statement\br
582-
\>\>expression \terminal{;}\br
583-
\>\terminal{\}}\br
560+
\bnfindent init-statement\br
561+
\bnfindent \terminal{while (} condition \terminal{) \{}\br
562+
\bnfindent\bnfindent statement\br
563+
\bnfindent\bnfindent expression \terminal{;}\br
564+
\bnfindent \terminal{\}}\br
584565
\terminal{\}}
585-
\end{ncbnftab}
586-
566+
\end{ncsimplebnf}
587567
except that names declared in the \grammarterm{init-statement} are in
588568
the same declarative region as those declared in the
589569
\grammarterm{condition}, and except that a
@@ -629,28 +609,23 @@
629609

630610
\pnum
631611
The range-based \tcode{for} statement
632-
633-
\begin{ncbnf}
612+
\begin{ncsimplebnf}
634613
\terminal{for (} \opt{init-statement} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement
635-
\end{ncbnf}
636-
614+
\end{ncsimplebnf}
637615
is equivalent to
638-
639-
\begin{ncbnftab}
616+
\begin{ncsimplebnf}
640617
\terminal{\{}\br
641-
\>\opt{init-statement}\br
642-
\>\terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br
643-
\>\terminal{auto __begin =} begin-expr \terminal{;}\br
644-
\>\terminal{auto __end =} end-expr \terminal{;}\br
645-
\>\terminal{for ( ; __begin != __end; ++__begin ) \{}\br
646-
\>\>for-range-declaration \terminal{= *__begin;}\br
647-
\>\>statement\br
648-
\>\terminal{\}}\br
618+
\bnfindent \opt{init-statement}\br
619+
\bnfindent \terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br
620+
\bnfindent \terminal{auto __begin =} begin-expr \terminal{;}\br
621+
\bnfindent \terminal{auto __end =} end-expr \terminal{;}\br
622+
\bnfindent \terminal{for ( ; __begin != __end; ++__begin ) \{}\br
623+
\bnfindent\bnfindent for-range-declaration \terminal{= *__begin;}\br
624+
\bnfindent\bnfindent statement\br
625+
\bnfindent \terminal{\}}\br
649626
\terminal{\}}
650-
\end{ncbnftab}
651-
627+
\end{ncsimplebnf}
652628
where
653-
654629
\begin{itemize}
655630
\item
656631
if the \grammarterm{for-range-initializer} is an \grammarterm{expression},

0 commit comments

Comments
 (0)