texlive[66017] Master/texmf-dist: naive-ebnf (21feb23)

commits+karl at tug.org commits+karl at tug.org
Tue Feb 21 21:46:50 CET 2023


Revision: 66017
          http://tug.org/svn/texlive?view=revision&revision=66017
Author:   karl
Date:     2023-02-21 21:46:50 +0100 (Tue, 21 Feb 2023)
Log Message:
-----------
naive-ebnf (21feb23)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt
    trunk/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf
    trunk/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx
    trunk/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty

Modified: trunk/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt	2023-02-21 20:46:35 UTC (rev 66016)
+++ trunk/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt	2023-02-21 20:46:50 UTC (rev 66017)
@@ -1,3 +1,2 @@
 hard pgfopts
-hard filecontentsdef
 hard expl3
\ No newline at end of file

Modified: trunk/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx	2023-02-21 20:46:35 UTC (rev 66016)
+++ trunk/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx	2023-02-21 20:46:50 UTC (rev 66017)
@@ -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,6 +185,18 @@
 %</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}
@@ -172,6 +203,7 @@
 % \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,6 +211,9 @@
 \pgfkeys{
   /ebnf/.cd,
   bw/.store in=\ebnf at bw,
+  trail/.store in=\ebnf at trail,
+  trail/.default=naive-ebnf.tmp.tex,
+  trail
 }
 \ProcessPgfPackageOptions{/ebnf}
 %    \end{macrocode}
@@ -185,7 +220,6 @@
 
 % 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 at color{gray}{\(\to\)}}
 \newcommand\ebnf at alternation
   {\ebnf at color{gray}{\(\vert\)}}
-\newcommand\ebnf at 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 at repetition}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \((.+?)\) }
-    {\c{ebnf at grouping}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \[([^\]]+?)\] }
-    {\c{ebnf at optional}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { <([^>]+)> }
-    {\c{ebnf at nonterminal}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { "([^"]+)" }
-    {\c{ebnf at terminal}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M\s*\| }
-    {\^^M :=} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \| }
-    {\c{ebnf at alternation}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M\s*:= }
-    {\^^M \c{-}\c{hspace}{3em}\c{ebnf at alternation}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { := }
-    {\c{ebnf at to}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M }
-    {\c{ebnf at 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 at repetition}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { \((.+?)\) }%
+    {\c{ebnf at grouping}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { \[(.+?)\] }%
+    {\c{ebnf at 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 at nonterminal}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { "(.+?)" }%
+    {\c{ebnf at 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 at alternation}{}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { := }%
+    {\c{ebnf at 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 at trail%
+    \newwrite\ebnf at write%
+    \immediate\openout\ebnf at write\ebnf at trail\relax%
+    \immediate\write\ebnf at write{\unexpanded\expandafter{\l__ebnf_tmp_tl}}%
+    \immediate\closeout\ebnf at write%
+    \message{naive-ebnf:\space pre-processed\space TeX
+      \space saved\space to\space "\ebnf at trail"^^J}%
+  \fi%
+  \l__ebnf_tmp_tl}
+\makeatother
 \ExplSyntaxOff
 %    \end{macrocode}
 % \end{macro}

Modified: trunk/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty	2023-02-21 20:46:35 UTC (rev 66016)
+++ trunk/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty	2023-02-21 20:46:50 UTC (rev 66017)
@@ -31,7 +31,7 @@
 
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{naive-ebnf}
-[2023-02-03 0.0.4 EBNF in Plain Text]
+[2023-02-21 0.0.5 EBNF in Plain Text]
 
 
 
@@ -42,14 +42,18 @@
 
 
 
+
+
 \RequirePackage{pgfopts}
 \pgfkeys{
   /ebnf/.cd,
   bw/.store in=\ebnf at bw,
+  trail/.store in=\ebnf at trail,
+  trail/.default=naive-ebnf.tmp.tex,
+  trail
 }
 \ProcessPgfPackageOptions{/ebnf}
 
-\RequirePackage{filecontentsdef}
 \RequirePackage{expl3}
 
 \makeatletter\ifdefined\ebnf at bw\else
@@ -97,39 +101,44 @@
   {\ebnf at color{gray}{\(\to\)}}
 \newcommand\ebnf at alternation
   {\ebnf at color{gray}{\(\vert\)}}
-\newcommand\ebnf at eol{\\}
 \makeatother
 
 \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 at repetition}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \((.+?)\) }
-    {\c{ebnf at grouping}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \[([^\]]+?)\] }
-    {\c{ebnf at optional}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { <([^>]+)> }
-    {\c{ebnf at nonterminal}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { "([^"]+)" }
-    {\c{ebnf at terminal}{\1}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M\s*\| }
-    {\^^M :=} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \| }
-    {\c{ebnf at alternation}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M\s*:= }
-    {\^^M \c{-}\c{hspace}{3em}\c{ebnf at alternation}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { := }
-    {\c{ebnf at to}{}} \l__ebnf_tmp_tl
-  \regex_replace_all:nnN { \^^M }
-    {\c{ebnf at 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 at repetition}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { \((.+?)\) }%
+    {\c{ebnf at grouping}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { \[(.+?)\] }%
+    {\c{ebnf at 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 at nonterminal}{\1}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { "(.+?)" }%
+    {\c{ebnf at 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 at alternation}{}} \l__ebnf_tmp_tl%
+  \regex_replace_all:nnN { := }%
+    {\c{ebnf at 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 at trail%
+    \newwrite\ebnf at write%
+    \immediate\openout\ebnf at write\ebnf at trail\relax%
+    \immediate\write\ebnf at write{\unexpanded\expandafter{\l__ebnf_tmp_tl}}%
+    \immediate\closeout\ebnf at write%
+    \message{naive-ebnf:\space pre-processed\space TeX
+      \space saved\space to\space "\ebnf at trail"^^J}%
+  \fi%
+  \l__ebnf_tmp_tl}
+\makeatother
 \ExplSyntaxOff
 
 \endinput



More information about the tex-live-commits mailing list.