diff options
author | Norbert Preining <norbert@preining.info> | 2023-02-22 03:01:37 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-02-22 03:01:37 +0000 |
commit | 470678475288a244fd8a9af69f9abc9b46b2860f (patch) | |
tree | b39e9f327aaf2a4b10bada3897e374878369fccc /macros/latex/contrib/naive-ebnf | |
parent | b05164a5b679570a7040f2b28bbf156a0479c429 (diff) |
CTAN sync 202302220301
Diffstat (limited to 'macros/latex/contrib/naive-ebnf')
-rw-r--r-- | macros/latex/contrib/naive-ebnf/DEPENDS.txt | 1 | ||||
-rw-r--r-- | macros/latex/contrib/naive-ebnf/naive-ebnf.dtx | 105 | ||||
-rw-r--r-- | macros/latex/contrib/naive-ebnf/naive-ebnf.pdf | bin | 542835 -> 588553 bytes |
3 files changed, 72 insertions, 34 deletions
diff --git a/macros/latex/contrib/naive-ebnf/DEPENDS.txt b/macros/latex/contrib/naive-ebnf/DEPENDS.txt index 489f2ded15..6abbcb3ff6 100644 --- a/macros/latex/contrib/naive-ebnf/DEPENDS.txt +++ b/macros/latex/contrib/naive-ebnf/DEPENDS.txt @@ -1,3 +1,2 @@ hard pgfopts -hard filecontentsdef hard expl3
\ No newline at end of file diff --git a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx index a69bc2f578..bbdbde0339 100644 --- a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx +++ b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx @@ -50,7 +50,7 @@ %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{naive-ebnf} %<*package> -[2023-02-03 0.0.4 EBNF in Plain Text] +[2023-02-21 0.0.5 EBNF in Plain Text] %</package> %<*driver> \documentclass{ltxdoc} @@ -90,9 +90,9 @@ % \usepackage{mathtools} % \begin{document} % \begin{ebnf} -% <$\lambda$-Expr> := <Var> -% | "$\lambda$" <Var> "." <Expr> -% | "$\lparen$" <Expr> <Expr> "$\rparen$" +% <$\lambda$-Expr> := <Var> \\ +% || "$\lambda$" <Var> "." <Expr> \\ +% || "$\lparen$" <Expr> <Expr> "$\rparen$" % \end{ebnf} % \end{document} % \end{docshot} @@ -107,6 +107,7 @@ % \item \texttt{(...\char`\|...)} denotes a series of options to choose from; % \item |[...]| denotes an optional substitution; % \item |{...}| denotes a zero or more times repetition; +% \item \texttt{\char`\|\char`\|} denotes an indented vertical bar at the beginning of the string. % \end{itemize} % \textbf{Attention}: The usage of some symbols is prohibited inside terminals. Instead, the following substitutions are recommended: @@ -118,6 +119,24 @@ % \item |$\vert$| instead of ``\texttt{\char`\|}''. % \end{itemize} +% \DescribeMacro{width} +% There is an optional argument of |ebnf| environment, which sets the width of the left-hand side of each rule +% (the default width is |6em|): +% \docshotOptions{firstline=4,lastline=10} +% \begin{docshot} +% \documentclass{minimal} +% \usepackage{naive-ebnf} +% \begin{document}\noindent +% This EBNF has a larger width of \\ +% the left hand side than usual: \par +% \begin{ebnf}[1.5in] +% <VeryLongVariable> := <X> | <Y> \\ +% <X> := "X" \\ +% <Y> := "Y" +% \end{ebnf} +% \end{document} +% \end{docshot} + % \DescribeMacro{\terminal} % \DescribeMacro{\nonterminal} % Inside the text, terminals and non-terminals may be formatted using two supplementary commands: @@ -166,12 +185,25 @@ %</verb> %\fi +% \DescribeMacro{trail} +% The |ebnf| environment is doing pre-processing of the \TeX{} commands provided and then let \LaTeX{} render them. It may be useful to see the output generated by the pre-processing. The |trail| option (with a file name) asks the package to save the content of the environment after the pre-processing into the file: +%\iffalse +%<*verb> +%\fi +\begin{verbatim} +\usepackage[trail=log.tex]{naive-ebnf} +\end{verbatim} +%\iffalse +%</verb> +%\fi + % \StopEventually{} % \section{Implementation} % \changes{0.0.1}{2023/01/28}{First draft.} % \changes{0.0.2}{2023/01/29}{Proper parsing of grouping.} % \changes{0.0.2}{2023/01/29}{Substitutions suggested for special symbols.} +% \changes{0.0.5}{2023/02/04}{New package option \texttt{trail} added, to enable saving generated \TeX{} content to a file, for debugging purposes.} % First, we process package options: % \begin{macrocode} @@ -179,13 +211,15 @@ \pgfkeys{ /ebnf/.cd, bw/.store in=\ebnf@bw, + trail/.store in=\ebnf@trail, + trail/.default=naive-ebnf.tmp.tex, + trail } \ProcessPgfPackageOptions{/ebnf} % \end{macrocode} % Then, we include a few packages, mostly to deal with \LaTeX{}3 expressions: % \begin{macrocode} -\RequirePackage{filecontentsdef} \RequirePackage{expl3} % \end{macrocode} @@ -254,7 +288,6 @@ {\ebnf@color{gray}{\(\to\)}} \newcommand\ebnf@alternation {\ebnf@color{gray}{\(\vert\)}} -\newcommand\ebnf@eol{\\} \makeatother % \end{macrocode} @@ -264,34 +297,40 @@ % \begin{macrocode} \ExplSyntaxOn \cs_generate_variant:Nn \tl_replace_all:Nnn {Nx} -\NewDocumentEnvironment{ebnf}{}{\filecontentsdefmacro\l__ebnf_tmp_tl}{ - \endfilecontentsdefmacro - \str_set:NV \l__ebnf_tmp_tl \l__ebnf_tmp_tl - \str_set:Nx \l__ebnf_tmp_tl {\str_range:Nnn \l__ebnf_tmp_tl {1} {-2}} - \regex_replace_all:nnN { \{(.+?)\} } - {\c{ebnf@repetition}{\1}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \((.+?)\) } - {\c{ebnf@grouping}{\1}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \[([^\]]+?)\] } - {\c{ebnf@optional}{\1}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { <([^>]+)> } - {\c{ebnf@nonterminal}{\1}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { "([^"]+)" } - {\c{ebnf@terminal}{\1}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \^^M\s*\| } - {\^^M :=} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \| } - {\c{ebnf@alternation}{}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \^^M\s*:= } - {\^^M \c{-}\c{hspace}{3em}\c{ebnf@alternation}{}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { := } - {\c{ebnf@to}{}} \l__ebnf_tmp_tl - \regex_replace_all:nnN { \^^M } - {\c{ebnf@eol}{}} \l__ebnf_tmp_tl - \tl_put_left:Nn \l__ebnf_tmp_tl {} +\makeatletter +\NewDocumentEnvironment{ebnf}{O{4em}+b} + {\tl_set:Nn\l__ebnf_tmp_tl{#2}} + {% + \regex_replace_all:nnN { \{(.+?)\} }% + {\c{ebnf@repetition}{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { \((.+?)\) }% + {\c{ebnf@grouping}{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { \[(.+?)\] }% + {\c{ebnf@optional}{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { (<[^>]+?>\ :=) }% + {\c{makebox}[#1][r]{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { <(.+?)> }% + {\c{ebnf@nonterminal}{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { "(.+?)" }% + {\c{ebnf@terminal}{\1}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { \|(\|) }% + {\c{makebox}[#1][r]{ \1 }} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { \| }% + {\c{ebnf@alternation}{}} \l__ebnf_tmp_tl% + \regex_replace_all:nnN { := }% + {\c{ebnf@to}{}} \l__ebnf_tmp_tl% + \tl_put_left:Nn \l__ebnf_tmp_tl {\noindent} \tl_put_right:Nn \l__ebnf_tmp_tl {} - \l__ebnf_tmp_tl -} + \ifdefined\ebnf@trail% + \newwrite\ebnf@write% + \immediate\openout\ebnf@write\ebnf@trail\relax% + \immediate\write\ebnf@write{\unexpanded\expandafter{\l__ebnf_tmp_tl}}% + \immediate\closeout\ebnf@write% + \message{naive-ebnf:\space pre-processed\space TeX + \space saved\space to\space "\ebnf@trail"^^J}% + \fi% + \l__ebnf_tmp_tl} +\makeatother \ExplSyntaxOff % \end{macrocode} % \end{macro} diff --git a/macros/latex/contrib/naive-ebnf/naive-ebnf.pdf b/macros/latex/contrib/naive-ebnf/naive-ebnf.pdf Binary files differindex cd63e8dc84..5d346ded12 100644 --- a/macros/latex/contrib/naive-ebnf/naive-ebnf.pdf +++ b/macros/latex/contrib/naive-ebnf/naive-ebnf.pdf |