summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-02-21 20:50:47 +0000
committerKarl Berry <karl@freefriends.org>2023-02-21 20:50:47 +0000
commitba471fee0fecefbb27dc4d5629f8205ddc83bc13 (patch)
treed51748483f43e22d532ddd7fbc0c8c12490ea6c2 /Master/texmf-dist
parent8b829058d190d3a9fba7c61886c45743cb866ec5 (diff)
naive-ebnf (21feb23) (branch)
git-svn-id: svn://tug.org/texlive/branches/branch2022.final@66029 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt1
-rw-r--r--Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdfbin542835 -> 588553 bytes
-rw-r--r--Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx105
-rw-r--r--Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty69
4 files changed, 111 insertions, 64 deletions
diff --git a/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt b/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt
index 489f2ded15f..6abbcb3ff6d 100644
--- a/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt
+++ b/Master/texmf-dist/doc/latex/naive-ebnf/DEPENDS.txt
@@ -1,3 +1,2 @@
hard pgfopts
-hard filecontentsdef
hard expl3 \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf b/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf
index cd63e8dc841..5d346ded12a 100644
--- a/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf
+++ b/Master/texmf-dist/doc/latex/naive-ebnf/naive-ebnf.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx b/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx
index a69bc2f578a..bbdbde0339b 100644
--- a/Master/texmf-dist/source/latex/naive-ebnf/naive-ebnf.dtx
+++ b/Master/texmf-dist/source/latex/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/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty b/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty
index 549ea50b16d..48136fd5c0f 100644
--- a/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty
+++ b/Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty
@@ -31,7 +31,9 @@
\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]
+
+
@@ -46,10 +48,12 @@
\pgfkeys{
/ebnf/.cd,
bw/.store in=\ebnf@bw,
+ trail/.store in=\ebnf@trail,
+ trail/.default=naive-ebnf.tmp.tex,
+ trail
}
\ProcessPgfPackageOptions{/ebnf}
-\RequirePackage{filecontentsdef}
\RequirePackage{expl3}
\makeatletter\ifdefined\ebnf@bw\else
@@ -97,39 +101,44 @@
{\ebnf@color{gray}{\(\to\)}}
\newcommand\ebnf@alternation
{\ebnf@color{gray}{\(\vert\)}}
-\newcommand\ebnf@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@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
\endinput