summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
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/tex
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/tex')
-rw-r--r--Master/texmf-dist/tex/latex/naive-ebnf/naive-ebnf.sty69
1 files changed, 39 insertions, 30 deletions
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