%%
%% This is file `formal-grammar.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% formal-grammar.dtx  (with options: `package')
%% This is a generated file.
%% Copyright (C) 2021 by Martin Vassor
%% 
%% This file 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.
%% 

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{formal-grammar}[2022/02/09 v1.2 A package to typeset formal grammars]
\RequirePackage{xparse}
\RequirePackage{newfloat}
\RequirePackage{xcolor}
\RequirePackage{colortbl}
\RequirePackage{array}
\definecolor{LightCyan}{rgb}{0.8,1,1}
%% \begin{abstract}
%%   The \textsf{formal-grammar} package provides commands to typeset formal grammars.
%% \end{abstract}
    \newif\if@formalalignsymbol\@formalalignsymbolfalse
    \DeclareOption{center}{
      \@formalalignsymboltrue
    }
    \ProcessOptions\relax
\DeclareFloatingEnvironment[
name=Grammar,
listname={List of Grammars},
placement=tbhp,
]{floatgrammar}
%% Taken from https://tex.stackexchange.com/a/26364/107341
\newcommand*{\formal@rowstyle}{}

\newcommand*{\rowstyle}[1]{% sets the style of the next row
  \gdef\formal@rowstyle{#1}%
  \formal@rowstyle\ignorespaces%
}
\newcolumntype{\formal@reset}{% resets the row style
  >{\gdef\formal@rowstyle{}}%
}

\newcolumntype{\formal@add}{% adds the current row style to the next column
  >{\formal@rowstyle}%
}
%% End of stackexchange
    \if@formalalignsymbol
      \newcolumntype{\formal@symbol}{c}
    \else
      \newcolumntype{\formal@symbol}{r}
    \fi
\ExplSyntaxOn
%% 1st argument: caption (makes it float)
%% 2nd argument: positionning option (`p` by default)
%% 3rd argument: label
\NewDocumentEnvironment{grammar} {o O{p} o}
{
\IfNoValueF{#1}{
\begin{floatgrammar}[#2]
\centering
}

\begin{tabular}{\formal@reset l \formal@add \formal@symbol \formal@add l \formal@add l}
}{
\end{tabular}

\IfNoValueF{#1}{
\caption{#1}
\IfNoValueF{#3}{
\label{#3}
}
\end{floatgrammar}
}
}
\ExplSyntaxOff

\newcommand{\firstcase}[3]{\(\mathcal{#1}\) & \(\formal@Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}
\newcommand{\firstcasesubtil}[3]{#1 & \(\formal@Coloneqq\) & \(#2\) & {\itshape \color{gray!90!black} #3}\\}

\newcommand{\otherform}[2]{& \(|\) & \(#1\) & {\itshape \color{gray!90!black} #2}\\}

\newcommand{\nonterm}[1]{\mathcal{#1}}

\newcommand{\nontermsubtil}[1]{#1}

\newcommand{\gralt}[0]{\quad |\quad }

\newcommand{\highlight}[0]{\rowcolor{LightCyan}}

\newcommand{\lochighlight}[1]{{\color{red} #1}}

\newcommand{\downplay}[0]{\rowstyle{\color{white!80!black}}}
\AtBeginDocument{%
\ifdefined\Coloneqq
\let\formal@Coloneqq\Coloneqq
\else
\newcommand{\formal@Coloneqq}{::=}
\fi
}
\endinput
%%
%% End of file `formal-grammar.sty'.
