summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/naive-ebnf/naive-ebnf.dtx')
-rw-r--r--macros/latex/contrib/naive-ebnf/naive-ebnf.dtx26
1 files changed, 24 insertions, 2 deletions
diff --git a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
index 6886393d88..54e0955f8d 100644
--- a/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
+++ b/macros/latex/contrib/naive-ebnf/naive-ebnf.dtx
@@ -1,7 +1,7 @@
% \iffalse meta-comment
% (The MIT License)
%
-% Copyright (c) 2023 Yegor Bugayenko
+% Copyright (c) 2023-2024 Yegor Bugayenko
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the 'Software'), to deal
@@ -50,7 +50,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{naive-ebnf}
%<*package>
-[2023-08-11 0.0.15 EBNF in Plain Text]
+[2024/10/25 0.0.17 EBNF in Plain Text]
%</package>
%<*driver>
\documentclass{ltxdoc}
@@ -113,6 +113,7 @@
% \item |[...]| denotes an optional substitution;
% \item |{...}| denotes a zero or more times repetition;
% \item |{...}+| denotes one or more times repetition;
+% \item \texttt{\char`\|\char`\|\char`\|} denotes an indent at the beginning of the string.
% \item \texttt{\char`\|\char`\|} denotes an indented vertical bar at the beginning of the string.
% \end{itemize}
@@ -235,6 +236,22 @@
% \end{document}
% \end{docshot}
+
+% The \texttt{\char`\|\char`\|\char`\|} character allows indenting the text on a new line, allowing breaking long expressions:
+% \docshotOptions{firstline=5,lastline=11}
+% \begin{docshot}
+% \documentclass{minimal}
+% \usepackage[T1]{fontenc}
+% \usepackage{naive-ebnf}
+% \begin{document}
+% \begin{ebnf}
+% <x> := "beginning" \\
+% ||| ( <y> | <z> ) \\
+% ||| "ending" \\
+% \end{ebnf}
+% \end{document}
+% \end{docshot}
+
% \section{Package Options}
% It's possible to configure the behavior of the package with the help of a few package options:
@@ -407,22 +424,27 @@
{ >([^\s]) } {\\textgreater{}\1} \ebnf_tmp%
\regex_replace_all:nnN
{ ([^\s])'([^\s]) } {\1\\textquotesingle{}\2} \ebnf_tmp%
+ \regex_replace_all:nnN { \|\|\| }%
+ {\c{makebox}[#1][r]{ }} \ebnf_tmp%
\regex_replace_all:nnN
{ ([^\s])\|([^\s]) } {\1\\textbar{}\2} \ebnf_tmp%
%
\regex_replace_all:nnN
{ /(.+?)/ }%
{\c{ebnf@regexp}{\1}} \ebnf_tmp%
+ \cs_undefine:N\ebnf_curled%
\cs_new:Npn\ebnf_curled{%
\regex_replace_all:nnNT
{ \{\s(([^\s]*(\s[^\}\{]|\s(\}|\{)[^\s])?)*)\s\}(\+)? }%
{\c{ebnf@repetition}[\5]{\1}} \ebnf_tmp \ebnf_curled}%
\ebnf_curled%
+ \cs_undefine:N\ebnf_brackets%
\cs_new:Npn\ebnf_brackets{%
\regex_replace_all:nnNT
{ \(\s(([^\s]*(\s[^\)\(]|\s(\)|\()[^\s])?)*)\s\) }%
{\c{ebnf@grouping}{\1}} \ebnf_tmp \ebnf_brackets}%
\ebnf_brackets%
+ \cs_undefine:N\ebnf_squares%
\cs_new:Npn\ebnf_squares{%
\regex_replace_all:nnNT
{ \[\s(([^\s]*(\s[^\]\[]|\s(\]|\[)[^\s])?)*)\s\] }%