%%
%% This is file `lwarp-simplebnf.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% lwarp.dtx  (with options: `simplebnf')
%% This is a generated file.
%% Copyright 2016-2020 Brian Dunn
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
\LWR@ProvidesPackagePass{simplebnf}[2020/09/01]
\ExplSyntaxOn

\RenewDocumentEnvironment { bnfgrammar } { +b }
  {
    %% \l__input_seq is a list of term definitions.
    \regex_split:nnN { ;; } { #1 } \l__input_seq
    \begin{center}
    \begin{lateximage}[#1]%     lwarp
      \tl_set:Nn \l__table_tl
        {
          \begin{tabular}{lcll}
        }
    \bool_set_true:N \l_tmp_first_term % Is this the first term in this grammar?
    \seq_map_inline:Nn \l__input_seq
      {
        %% \l__term_seq    - (term, rhses)...
        %% \l__term_tl     - term
        %% \l__keypairs_tl - rhses
        \regex_split:nnN { ::= } { ##1 } \l__term_seq
        \seq_pop_left:NN \l__term_seq \l__term_tl
        \seq_pop_left:NN \l__term_seq \l__keypairs_tl

        \regex_replace_once:nnN { ^\s+ } {} \l__term_tl

        \bool_if:NTF \l_tmp_first_term
          {
            \bool_set_false:N \l_tmp_first_term
          }
          {
            \tl_put_right:Nn \l__table_tl { \\ }
          }
        \tl_put_right:Nx \l__table_tl
          {
            \bnfexpr { \l__term_tl } & \g__simplebnf_defeq_tl &
          }
        %% \l__keypairs_seq - (rhs:annot | rhs)...
        \seq_set_split:NnV \l__keypairs_seq { | } \l__keypairs_tl

        \bool_set_true:N \l__first_rhs
        \seq_map_function:NN \l__keypairs_seq \simplebnf_typeset_rhs:n
      }

    \tl_put_right:Nn \l__table_tl { \end{tabular} }
    \tl_use:N \l__table_tl
    \end{lateximage}%       lwarp
    \end{center}
  }
  { }

\ExplSyntaxOff
\endinput
%%
%% End of file `lwarp-simplebnf.sty'.
