texlive[68186] Master/texmf-dist: piton (5sep23)
commits+karl at tug.org
commits+karl at tug.org
Tue Sep 5 22:06:40 CEST 2023
Revision: 68186
http://tug.org/svn/texlive?view=revision&revision=68186
Author: karl
Date: 2023-09-05 22:06:40 +0200 (Tue, 05 Sep 2023)
Log Message:
-----------
piton (5sep23)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2023-09-05 20:06:27 UTC (rev 68185)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2023-09-05 20:06:40 UTC (rev 68186)
@@ -91,8 +91,8 @@
\maketitle
\begin{abstract}
-L'extension \pkg{piton} propose des outils pour composer des codes informatiques en Python, OCaml et C avec une
-coloration syntaxique en utilisant la bibliothèque Lua LPEG. L'extension \pkg{piton} nécessite l'emploi de
+L'extension \pkg{piton} propose des outils pour composer des codes informatiques en Python, OCaml, C et SQL avec
+une coloration syntaxique en utilisant la bibliothèque Lua LPEG. L'extension \pkg{piton} nécessite l'emploi de
LuaLaTeX.
\end{abstract}
@@ -102,7 +102,7 @@
L'extension \pkg{piton} utilise la librairie Lua nommée LPEG\footnote{LPEG est une librairie de capture de motifs
(\emph{pattern-matching} en anglais) pour Lua, écrite en C, fondée sur les PEG (\emph{parsing expression
- grammars}): \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} pour «parser» le code Python, OCaml ou C et le
+ grammars}): \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} pour «parser» le code Python, OCaml, C ou SQL et le
composer avec un coloriage syntaxique. Comme elle utilise du code Lua, elle fonctionne uniquement avec |lualatex|
(et ne va pas fonctionner avec les autres moteurs de compilation LaTeX, que ce soit |latex|, |pdflatex| ou
|xelatex|). Elle n'utilise aucun programme extérieur et la compilation ne requiert donc pas |--shell-escape|. La
@@ -148,7 +148,7 @@
\subsection{Choix du langage}
-L'extension \pkg{piton} prend en charge trois langages informatiques : Python, OCaml et C, ou plutôt \CC.
+L'extension \pkg{piton} prend en charge quatre langages informatiques : Python, OCaml, SQL et C, ou plutôt \CC.
\smallskip
Par défaut, le language est Python.
@@ -201,7 +201,12 @@
\item La commande \colorbox{gray!20}{\ttfamily \textbackslash PitonInputFile} doit être utilisée pour insérer et
composer un fichier extérieur.
-Il est possible de n'insérer qu'une partie du fichier : cf. partie~\ref{part-of-a-file}, p.~\pageref{part-of-a-file}.
+Il est possible de n'insérer qu'une partie du fichier : cf. partie~\ref{part-of-a-file},
+p.~\pageref{part-of-a-file}.
+
+\colorbox{yellow!50}{\textbf{Nouveau 2.2}}\enskip La clé |path| de la commande |\PitonOptions| permet de spécifier
+un chemin de recherche pour le fichier à inclure. En fait, on peut spécifier plusieurs chemins, séparés par des
+virgules.
\end{itemize}
@@ -308,8 +313,11 @@
\begin{itemize}
\item La clé \Definition{language} spécifie le langage informatique considéré (la casse n'est pas prise en compte).
-Trois valeurs sont possibles : |Python|, |OCaml| et |C|. La valeur initiale est |Python|.
+Quatre valeurs sont possibles : |Python|, |OCaml|, |C| et |SQL|. La valeur initiale est |Python|.
+\item La clé \Definition{path} indique un chemin où seront cherchés prioritairement les fichiers inclus par
+|\PitonInputFile|. En fait, on peut spécifier plusieurs chemins, séparés par des virgules.
+
\item La clé \Definition{gobble} prend comme valeur un entier positif $n$ : les $n$ premiers caractères de chaque
ligne sont alors retirés (avant formatage du code) dans les environnements |{Piton}|. Ces $n$ caractères ne sont
pas nécessairement des espaces.
@@ -339,7 +347,7 @@
valeur initiale de cette clé est \verb|true|.
\item La clé \Definition{line-numbers/absolute} demande, pour les listings générés par \verb|\PitonInputFile|, que les numéros de
-lignes affichés soient absolus (c'est-à-dire ceux du fichier d'origine). Elle n'a d'intérêt que si on insère qu'une
+lignes affichés soient absolus (c'est-à-dire ceux du fichier d'origine). Elle n'a d'intérêt que si on n'insère qu'une
partie du fichier (cf. part~\ref{part-of-a-file}, p.~\pageref{part-of-a-file}). La clé |/absolute| est sans effet dans les environnements \verb|{Piton}|.
\item La clé \Definition{line-numbers/resume} reprend la numérotation là où elle avait été laissée au dernier listing. En fait,
@@ -415,9 +423,9 @@
Exemple : \piton{my_string = 'Très bonne réponse'}
\endgroup
-\smallskip
-Avec la clé \Definition{show-spaces}, tous les espaces sont matérialisés (et aucune coupure de ligne ne peut plus
-intervenir sur ces espaces matérialisés, même si la clé |break-lines|\footnote{cf. \ref{line-breaks} p.~\pageref{line-breaks}.} est active).
+\item Avec la clé \Definition{show-spaces}, tous les espaces sont matérialisés (et aucune coupure de ligne ne peut
+plus intervenir sur ces espaces matérialisés, même si la clé |break-lines|\footnote{cf. \ref{line-breaks}
+ p.~\pageref{line-breaks}.} est active).
\end{itemize}
\bigskip
@@ -478,6 +486,8 @@
\label{styles}
+\subsubsection{Notion de style}
+
L'extension \pkg{piton} fournit la commande |\SetPitonStyle| pour personnaliser les différents styles utilisés pour
formater les éléments syntaxiques des listings Python. Ces personnalisations ont une portée qui correspond au
groupe TeX courant.\footnote{On rappelle que tout environnement LaTeX est, en particulier, un groupe.}
@@ -513,13 +523,11 @@
\bigskip
-Les différents styles sont décrits dans la table \ref{Semantic}. Les réglages initiaux effectués par \pkg{piton}
-dans |piton.sty| sont inspirés par le style \pkg{manni} de Pygments.\footnote{Voir
- \url{https://pygments.org/styles/}. À remarquer que, par défaut, Pygments propose pour le style \pkg{manni} un
- fond coloré dont la couleur est la couleur HTML |#F0F3F3|. Il est possible d'avoir la même couleur dans |{Piton}|
- avec l'instruction : |\PitonOptions{background-color = [HTML]{F0F3F3}}|}
+L'usage des différents styles suivant le langage informatique considéré est décrit dans la partie \ref{Semantic}, à
+partir de la page \pageref{Semantic}.
+
\bigskip
La commande |\PitonStyle| prend en argument le nom d'un style et permet de récupérer la valeur (en tant que liste
d'instructions LaTeX) de ce style.
@@ -533,15 +541,53 @@
semi-globales et des commandes à argument présentes dans la valeur courante du style \texttt{\textsl{style}}.
+\subsubsection{Styles locaux et globaux}
+
+Un style peut être défini de manière globale avec la commande |\SetPitonStyle|. Cela veut dire qu'il s'appliquera
+par défaut à tous les langages informatiques qui utilisent ce style.
+
+\medskip
+Par exemple, avec la commande
+\begin{Verbatim}
+\SetPitonStyle{Comment = \color{gray}}
+\end{Verbatim}
+tous les commentaires (que ce soit en Python, en C, en OCaml, etc.) seront composés en gris.
+
\bigskip
-Il existe un style spécial nommé |UserFunction|. Ce style s'applique aux noms des fonctions précédemment définies
-par l'utilisateur via une instruction Python \piton{def} dans l'un des listings précédents. La valeur initiale de
-ce style est nulle (=vide), ce qui fait que ces noms de fonctions sont formatés comme du texte courant (en noir).
-Néanmoins, il est possible de changer la valeur de ce style, comme tous les autres styles, avec la commande
-|\SetPitonStyle|.
+\colorbox{yellow!50}{\textbf{Nouveau 2.2}}\enskip Mais il est aussi possible de définir un style localement pour un
+certain langage informatique en passant le nom du langage en argument optionnel (entre crochets) de la commande
+|\SetPitonStyle|.\footnote{On rappelle que, dans \pkg{piton}, les noms des langages informatiques ne sont pas
+ sensibles à la casse.}
+\medskip
+Par exemple, avec la commande
+\begin{Verbatim}
+\SetPitonStyle~emphase#[SQL]@{Keywords = \color[HTML]{006699} \bfseries \MakeUppercase}
+\end{Verbatim}
+les mots-clés dans les listings SQL seront composés en lettres capitales, même s'ils s'apparaissent en minuscules
+dans le fichier source LaTeX (on rappelle que, en SQL, les mot-clés ne sont pas sensibles à la casse et donc forcer
+leur mise en minuscule peut être envisagé).
\medskip
+Comme on s'en doute, si un langage informatique utilise un certain style et que ce style n'est pas défini
+localement pour ce langage, c'est la version globale qui est utilisée. Cette notion de globalité n'a pas de
+rapport à la notion de liaison locale de TeX (notion de groupe TeX).
+
+\medskip
+Les styles fournis par défaut par \pkg{piton} sont tous définis globalement.
+
+\bigskip
+\subsubsection{Le style UserFunction}
+
+\bigskip
+Il existe un style spécial nommé |UserFunction|. Ce style s'applique aux noms des fonctions précédemment définies
+par l'utilisateur (par exemple, avec le langage Python, ces noms de fonctions sont ceux qui apparaissent après le
+mot-clé \piton{def} dans un listing Python précédent). La valeur initiale de ce style est nulle (=vide), ce qui
+fait que ces noms de fonctions sont formatés comme du texte courant (en noir). Néanmoins, il est possible de
+changer la valeur de ce style, comme tous les autres styles, avec la commande |\SetPitonStyle|.
+
+
+\medskip
Dans l'exemple suivant, on prend comme valeur de ce style |UserFunction| la valeur initiale du style
|Name.Function| (qui s'applique au nom des fonctions \emph{au moment de leur définition}).
@@ -571,14 +617,20 @@
Comme on le voit, le nom |transpose| a été mis en évidence comme étant le nom d'une fonction définie précédemment
par l'utilisateur (d'où le nom |UserFunction| pour ce style).
-\PitonClearUserFunctions
+\PitonClearUserFunctions[Python]
\bigskip
+\begin{small}
Bien sûr, la liste des noms de fonctions Python précédemment définies est gardée en mémoire de LuaLaTeX (de manière
globale, c'est-à-dire indépendamment des groupes TeX). L'extension \pkg{piton} fournit une commande qui permet de
-vider cette liste : c'est la commande |\PitonClearUserFunctions|.
+vider cette liste : c'est la commande |\PitonClearUserFunctions|. Quand elle est utilisée sans argument, cette
+commande s'applique à tous les languages informatiques utilisées par l'utilisateur mais on peut spécifier en
+argument optionnel (entre crochets) une liste de languages informatiques auquels elle s'appliquera.\footnote{On
+ rappelle que, dans \pkg{piton}, les noms des langages informatiques ne sont pas sensibles à la casse. }
+\end{small}
+
\subsection{Définition de nouveaux environnements}
\label{NewPitonEnvironment}
@@ -585,7 +637,8 @@
Comme l'environnement |{Piton}| a besoin d'absorber son contenu d'une manière spéciale (à peu près comme du texte
verbatim), il n'est pas possible de définir de nouveaux environnements directement au-dessus de l'environnement
-|{Piton}| avec les commandes classiques |\newenvironment| et |\NewDocumentEnvironment|.
+|{Piton}| avec les commandes classiques |\newenvironment| (de LaTeX standard) et |\NewDocumentEnvironment| (de
+LaTeX3).
C'est pourquoi \pkg{piton} propose une commande |\NewPitonEnvironment|. Cette commande a la même syntaxe que la
commande classique |\NewDocumentEnvironment|.
@@ -850,7 +903,8 @@
\subsection{Mise en évidence d'identificateurs}
On peut demander le changement de formatage de certains identificateurs avec la clé |identifiers| de
-|\PitonOptions|.
+|\PitonOptions|.\footnote{Cette fonctionnalité n'est pas disponible avec le langage SQL car, en SQL, il n'y a pas
+ d'identificateurs (il n'y a que des noms de tables et des noms de champs).}
\smallskip
Cette clé prend en argument une valeur au format suivant :
@@ -1961,8 +2015,17 @@
Le langage par défaut de l'extension \pkg{piton} est Python. Si besoin est, on peut revenir au langage Python avec
|\PitonOptions{language=Python}|.
+\bigskip
+
+Les réglages initiaux effectués par \pkg{piton} dans |piton.sty| sont inspirés par le style \pkg{manni} de Pygments
+tel qu'il est appliqué au language Python par Pygments.\footnote{Voir \url{https://pygments.org/styles/}. À
+ remarquer que, par défaut, Pygments propose pour le style \pkg{manni} un fond coloré dont la couleur est la
+ couleur HTML |#F0F3F3|. Il est possible d'avoir la même couleur dans |{Piton}| avec l'instruction :
+ |\PitonOptions{background-color = [HTML]{F0F3F3}}|}
+
\vspace{1cm}
+
\begin{center}
\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
\toprule
@@ -2023,6 +2086,10 @@
\end{Verbatim}
+\bigskip
+L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=OCaml]{...}|
+
+
\vspace{1cm}
@@ -2080,6 +2147,8 @@
\end{Piton}
\end{Verbatim}
+\bigskip
+L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=C]{...}|
\vspace{1cm}
@@ -2117,8 +2186,61 @@
\end{tabularx}
\end{center}
+
\newpage
+\subsection{Le langage SQL}
+
+On peut basculer vers le langage |SQL| avec |\PitonOptions{language = SQL}|
+
+\bigskip
+On peut aussi choisir le langage |SQL| pour un environnement |{Piton}| individuel :
+%
+\begin{Verbatim}
+\begin{Piton}~emphase#[language=SQL]@
+...
+\end{Piton}
+\end{Verbatim}
+
+\bigskip
+L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=SQL]{...}|
+
+
+\vspace{1cm}
+
+\begin{center}
+\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+\toprule
+\normalfont Style & Usage \\
+\midrule
+Number & les nombres \\
+String.Long & les chaînes de caractères (entre \texttt{'} et non entre \texttt{"} car les éléments entre \texttt{"}
+ sont des noms de champs et formatés avec |Name.Field|) \\
+Operator & les opérateurs suivants :
+\texttt{= != <> >= > < <= * + / } \\
+Name.Table & les noms des tables \\
+Name.Field & les noms des champs des tables \\
+Name.Builtin & les fonctions prédéfinies suivantes (leur nom n'est \emph{pas} sensible à la casse) :
+ |avg|, |count|, |char_lenght|, |concat|, |curdate|, |current_date|,
+ |date_format|, |day|, |lower|, |ltrim|, |max|, |min|, |month|, |now|,
+ |rank|, |round|, |rtrim|, |substring|, |sum|, |upper| et |year|. \\
+Comment & les commentaires (débutant par |--| ou bien entre |/*| et |*/|) \\
+Comment.LaTeX & les commentaires commençant par \texttt{-->} qui sont composés par \pkg{piton} comme du code LaTeX (et
+ appelés simplement «commentaires LaTeX» dans ce document) \\
+Keyword & les mots-clés suivants (leur nom n'est \emph{pas} sensible à la casse) :
+ |add|, |after|, |all|, |alter|, |and|, |as|, |asc|, |between|, |by|,
+ |change|, |column|, |create|, |cross join|, |delete|, |desc|, |distinct|,
+ |drop|, |from|, |group|, |having|, |in|, |inner|, |insert|, |into|, |is|,
+ |join|, |left|, |like|, |limit|, |merge|, |not|, |null|, |on|, |or|,
+ |order|, |over|, |right|, |select|, |set|, |table|, |then|, |truncate|,
+ |union|, |update|, |values|, |when|, |where| et |with|. \\
+\bottomrule
+\end{tabularx}
+\end{center}
+
+
+\newpage
+
\section*{Autre documentation}
Le document |piton.pdf| (fourni avec l'extension \pkg{piton}) contient une traduction anglaise de la
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2023-09-05 20:06:27 UTC (rev 68185)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2023-09-05 20:06:40 UTC (rev 68186)
@@ -43,12 +43,12 @@
%
%<@@=piton>
%<*STY>
-\def\myfileversion{2.1}
-\def\myfiledate{2023/08/26}
+\def\myfileversion{2.2}
+\def\myfiledate{2023/09/05}
%</STY>
%<*driver>
-\def\myfileversion{2.1}
-\def\myfiledate{2023/08/26}
+\def\myfileversion{2.2}
+\def\myfiledate{2023/09/05}
\documentclass{l3doc}
\usepackage{geometry}
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
@@ -96,7 +96,7 @@
%
% \begin{abstract}
% The package \pkg{piton} provides tools to typeset computer listings in Python,
-% OCaml and C with syntactic highlighting by using the Lua library LPEG. It
+% OCaml, C and SQL with syntactic highlighting by using the Lua library LPEG. It
% requires LuaLaTeX.
% \end{abstract}
%
@@ -109,7 +109,7 @@
% pattern-matching library for Lua, written in C, based on \emph{parsing
% expression grammars}:
% \url{http://www.inf.puc-rio.br/~roberto/lpeg/}}
-% for parsing Python OCaml or C listings and typesets them with syntactic
+% for parsing Python, OCaml, C or SQL listings and typesets them with syntactic
% highlighting. Since it uses Lua code, it works with |lualatex| only (and won't
% work with the other engines: |latex|, |pdflatex| and |xelatex|). It does not
% use external program and the compilation does not require |--shell-escape|.
@@ -170,8 +170,8 @@
%
% \subsection{Choice of the computer language}
%
-% In current version, the package \pkg{piton} supports three computer languages:
-% Python, OCaml and C (in fact \CC).
+% In current version, the package \pkg{piton} supports four computer languages:
+% Python, OCaml, SQL and C (in fact \CC).
%
% \smallskip
% By default, the language used is Python.
@@ -210,6 +210,11 @@
%
% It's possible to insert only a part of the file: cf.
% part~\ref{part-of-a-file}, p.~\pageref{part-of-a-file}.
+%
+% \colorbox{yellow!50}{\textbf{New 2.2}}\enskip The key |path| of the command
+% |\PitonOptions| specifies a path where the files included by |\PitonInputFile|
+% will be searched. In fact, it's possible to specify a comma-separated list of
+% paths.
% \end{itemize}
%
% \subsection{The syntax of the command \textbackslash piton}
@@ -317,9 +322,13 @@
%
% \begin{itemize}
% \item The key \Definition{language} speficies which computer language is
-% considered (that key is case-insensitive). Three values are allowed :
-% |Python|, |OCaml| and |C|. the initial value is |Python|.
+% considered (that key is case-insensitive). Four values are allowed :
+% |Python|, |OCaml|, |C| and |SQL|. The initial value is |Python|.
%
+% \item The key |path| specifies a path where the files included by
+% |\PitonInputFile| will be searched. In fact, it's possible to specify a
+% comma-separated list of paths.
+%
% \item The key \Definition{gobble} takes in as value a
% positive integer~$n$: the first $n$ characters are discarded (before the
% process of highlightning of the code) for each line of the environment
@@ -508,6 +517,8 @@
%
% \label{styles}
%
+% \subsubsection{Notion of style}
+%
% The package \pkg{piton} provides the command |\SetPitonStyle| to customize the
% different styles used to format the syntactic elements of the Python listings.
% The customizations done by that command are limited to the current TeX
@@ -547,10 +558,10 @@
% \endgroup
%
% \bigskip
-% The different styles are described in the table \ref{Semantic}. The initial
-% settings done by \pkg{piton} in |piton.sty| are inspired by the style
-% \pkg{manni} de Pygments.\footnote{See:
-% \url{https://pygments.org/styles/}. Remark that, by default, Pygments provides for its style \pkg{manni} a colored background whose color is the HTML color \texttt{\#F0F3F3}. It's possible to have the same color in \texttt{\{Pion\}} with the instruction \texttt{\textbackslash PitonOptions\{background-color = [HTML]\{F0F3F3\}\}}.}
+% The different styles, and their use by \pkg{piton} in the different languages
+% which it supports (Python, OCaml, C and SQL), are described in the part
+% \ref{Semantic}, starting at the page \pageref{Semantic}.
+%
%
% \bigskip
% The command |\PitonStyle| takes in as argument the name of a style and allows
@@ -567,17 +578,59 @@
% \texttt{\textsl{style}}.
%
% \bigskip
+% \subsubsection{Global styles and local styles}
%
+% A style may be defined globally with the command |\SetPitonStyle|. That means
+% that it will apply to all the informatic languages that use that style.
+%
+% \bigskip
+% For example, with the command
+% \begin{Verbatim}
+% \SetPitonStyle{Comment = \color{gray}}
+% \end{Verbatim}
+% all the comments will be composed in gray in all the listings, whatever
+% informatic language they use (Python, C, OCaml, etc.).
+%
+% \bigskip
+% \colorbox{yellow!50}{\textbf{New 2.2}}\enskip But it's also possible to define
+% a style locally for a given informatic langage by providing the name of that
+% language as optional argument (between square brackets) to the command
+% |\SetPitonStyle|.\footnote{We recall, that, in the package \pkg{piton}, the
+% names of the informatic languages are case-insensitive.}
+%
+% \bigskip
+% For example, with the command
+% \begin{Verbatim}
+% \SetPitonStyle~emphase#[SQL]@{Keywords = \color[HTML]{006699} \bfseries \MakeUppercase}
+% \end{Verbatim}
+% the keywords in the SQL listings will be composed in capital letters, even if
+% they appear in lower case in the LaTeX source (we recall that, in SQL, the
+% keywords are case-insensitive).
+%
+% \bigskip
+% As expected, if an informatic language uses a given style and if that style has
+% no local definition for that language, the global version is used. That notion
+% of ``global style'' has no link with the notion of global definition in TeX
+% (the notion of \emph{group} in TeX).
+%
+% \bigskip
+% The package \pkg{piton} itself (that is to say the file |piton.sty|) defines
+% all the styles globally.
+%
+% \bigskip
+%
+% \subsubsection{The style UserFunction}
% The extension \pkg{piton} provides a special style called~|UserFunction|. That
-% style applies to the names of the functions previously defined by the user via
-% an instruction Python \piton{def} in one of the previous listings. The initial
-% value of that style is empty, and, therefore, the names of the functions are
-% formatted as standard text (in black). However, it's possible to change the
-% value of that style, as any other style, with the command |\SetPitonStyle|.
+% style applies to the names of the functions previously defined by the user
+% (for example, in Python, these names are those following the keyword
+% \piton{def} in a previous Python listing). The initial value of that style is
+% empty, and, therefore, the names of the functions are formatted as standard
+% text (in black). However, it's possible to change the value of that style, as
+% any other style, with the command |\SetPitonStyle|.
%
% \medskip
% In the following example, we fix as value for that style |UserFunction| the
-% initial value of the the style |Name.Function| (which applies to the name of
+% initial value of the style |Name.Function| (which applies to the name of
% the functions, \emph{at the moment of their definition}).
%
% \begingroup
@@ -602,17 +655,24 @@
%
% \endgroup
%
-% As one see, the name |transpse| has been highlighted because it's the name of
+% As one see, the name |transpose| has been highlighted because it's the name of
% a Python function previously defined by the user (hence the name
% |UserFunction| for that style).
%
-% \PitonClearUserFunctions
+% \PitonClearUserFunctions[Python]
%
% \bigskip
+% \begin{small}
% Of course, the list of the names of Python functions previously défined is
-% kept in the memory of LuaLaTeX (in a global way, that is to say independtly of
-% the TeX groups). The extension \pkg{piton} provides a command to clear that
-% list : it's the command |\PitonClearUserFunctions|.
+% kept in the memory of LuaLaTeX (in a global way, that is to say independently
+% of the TeX groups). The extension \pkg{piton} provides a command to clear that
+% list : it's the command |\PitonClearUserFunctions|. When it is used without
+% argument, that command is applied to all the informatic languages used by the
+% user but it's also possible to use it with an optional argument (between
+% square brackets) which is a list of informatic languages to which the command
+% will be applied.\footnote{We remind that, in \pkg{piton}, the name of the
+% informatic languages are case-insensitive.}
+% \end{small}
%
% \subsection{Creation of new environments}
%
@@ -621,7 +681,8 @@
% Since the environment |{Piton}| has to catch its body in a special way (more
% or less as verbatim text), it's not possible to construct new environments
% directly over the environment |{Piton}| with the classical commands
-% |\newenvironment| or |\NewDocumentEnvironment|.
+% |\newenvironment| (of standard LaTeX) or |\NewDocumentEnvironment| (of
+% LaTeX3).
%
% That's why \pkg{piton} provides a command |\NewPitonEnvironment|. That
% command takes in three mandatory arguments.
@@ -907,7 +968,9 @@
% \subsection{Highlighting some identifiers}
%
% It's possible to require a changement of formating for some identifiers with
-% the key |identifiers| of |\PitonOptions|.
+% the key |identifiers| of |\PitonOptions|.\footnote{This feature is not
+% available for the language SQL because, in SQL, there is no identifiers :
+% there are only names of fields and names of tables.}
%
% \smallskip
% That key takes in as argument a value of the following format:
@@ -1597,7 +1660,7 @@
% if x < 0:
% return -arctan(-x) #> recursive call
% elif x > 1:
-% return pi/2 - arctan(1/x) #> anoother recursive call
+% return pi/2 - arctan(1/x) #> another recursive call
% else:
% s = 0
% for k in range(n):
@@ -1879,7 +1942,17 @@
% In \pkg{piton}, the default language is Python. If necessary, it's possible to
% come back to the language Python with |\PitonOptions{language=Python}|.
%
+% \bigskip
%
+% The initial settings
+% done by \pkg{piton} in |piton.sty| are inspired by the style \pkg{manni} de
+% Pygments, as applied by Pygments to the language Python.\footnote{See:
+% \url{https://pygments.org/styles/}. Remark that, by default, Pygments provides
+% for its style \pkg{manni} a colored background whose color is the HTML color
+% \texttt{\#F0F3F3}. It's possible to have the same color in \texttt{\{Piton\}}
+% with the instruction \texttt{\textbackslash PitonOptions\{background-color =
+% [HTML]\{F0F3F3\}\}}.}
+%
% \vspace{1cm}
%
% \begin{center}
@@ -1947,6 +2020,8 @@
% \end{Piton}
% \end{Verbatim}
%
+% \bigskip
+% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=OCaml]{...}|
%
% \vspace{1cm}
%
@@ -1969,11 +2044,11 @@
% Name.Module & the name of the modules \\
% Name.Function & the name of the Python functions defined by the user \emph{at their
% point of definition} (with the keyword |let|) \\
-% UserFunction & the name of the Python functions previously defined by the user
+% UserFunction & the name of the OCaml functions previously defined by the user
% (the initial value of that parameter is empty and these
% elements are drawn in the current color, usually black) \\
% Exception & the predefined exceptions (eg : |End_of_File|) \\
-% TypeParameter & the parameters of the type \\
+% TypeParameter & the parameters of the types \\
% Comment & the comments, between |(*| et |*)|; these comments may be nested \\
% Keyword.Constant & |true| et |false| \\
% Keyword & the following keywords:
@@ -2005,6 +2080,8 @@
% \end{Piton}
% \end{Verbatim}
%
+% \bigskip
+% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=C]{...}|
%
% \vspace{1cm}
%
@@ -2045,7 +2122,58 @@
% \end{tabularx}
% \end{center}
%
+% \newpage
%
+% \subsection{The language SQL}
+%
+%
+% It's possible to switch to the language |SQL| with |\PitonOptions{language = SQL}|.
+%
+% \bigskip
+% It's also possible to set the language SQL for an individual environment |{Piton}|.
+% %
+% \begin{Verbatim}
+% \begin{Piton}~emphase#[language=SQL]@
+% ...
+% \end{Piton}
+% \end{Verbatim}
+%
+% \bigskip
+% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=SQL]{...}|
+%
+%
+% \vspace{1cm}
+%
+% \begin{center}
+% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+% \toprule
+% \normalfont Style & Use \\
+% \midrule
+% Number & the numbers \\
+% String.Long & the strings (between \texttt{'} and not \texttt{"} because the
+% elements between \texttt{"} are names of fields and formatted with |Name.Field|) \\
+% Operator & the following operators : \texttt{= != <> >= > < <= * + / } \\
+% Name.Table & the names of the tables \\
+% Name.Field & the names of the fields of the tables \\
+% Name.Builtin & the following built-in functions (their names are \emph{not} case-sensitive):
+% |avg|, |count|, |char_lenght|, |concat|, |curdate|, |current_date|,
+% |date_format|, |day|, |lower|, |ltrim|, |max|, |min|, |month|, |now|,
+% |rank|, |round|, |rtrim|, |substring|, |sum|, |upper| and |year|. \\
+% Comment & the comments (beginning by \texttt{--} or between |/*| and |*/|) \\
+% Comment.LaTeX & the comments beginning by \texttt{-->} which are composed by
+% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
+% Keyword & the following keywords (their names are \emph{not} case-sensitive):
+% |add|, |after|, |all|, |alter|, |and|, |as|, |asc|, |between|, |by|,
+% |change|, |column|, |create|, |cross join|, |delete|, |desc|, |distinct|,
+% |drop|, |from|, |group|, |having|, |in|, |inner|, |insert|, |into|, |is|,
+% |join|, |left|, |like|, |limit|, |merge|, |not|, |null|, |on|, |or|,
+% |order|, |over|, |right|, |select|, |set|, |table|, |then|, |truncate|,
+% |union|, |update|, |values|, |when|, |where| and |with|. \\
+% \bottomrule
+% \end{tabularx}
+% \end{center}
+%
+%
% \newpage
%
% \section{Implementation}
@@ -2434,6 +2562,12 @@
% \end{macrocode}
%
% \medskip
+% \begin{macrocode}
+\tl_new:N \l_@@_path_seq
+% \end{macrocode}
+%
+%
+% \medskip
% In order to have a better control over the keys.
% \begin{macrocode}
\bool_new:N \l_@@_in_PitonOptions_bool
@@ -2514,7 +2648,7 @@
% \medskip
% The argument of |\PitonInputFile|.
% \begin{macrocode}
-\str_new:N \l_@@_file_name_str
+\tl_new:N \l_@@_file_name_tl
% \end{macrocode}
%
% \medskip
@@ -2642,7 +2776,19 @@
% \end{macrocode}
%
% \medskip
+% Be careful. The following sequence |\g_@@_languages_seq| is not the list of
+% the languages supported by \pkg{piton}. It's the list of the languages for
+% which at least a user function has been defined. We need that sequence only
+% for the command |\PitonClearUserFunctions| when it is used without its
+% optional argument: it must clear all the list of languages for which at least
+% a user function has been defined.
% \begin{macrocode}
+\seq_new:N \g_@@_languages_seq
+% \end{macrocode}
+%
+%
+% \medskip
+% \begin{macrocode}
\cs_new_protected:Npn \@@_set_tab_tl:n #1
{
\tl_clear:N \l_@@_tab_tl
@@ -3156,6 +3302,9 @@
language .code:n =
\str_set:Nx \l_@@_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
+ path .code:n =
+ \seq_set_from_clist:Nn \l_@@_path_seq { #1 } ,
+ path .value_required:n = true ,
gobble .int_set:N = \l_@@_gobble_int ,
gobble .value_required:n = true ,
auto-gobble .code:n = \int_set:Nn \l_@@_gobble_int { -1 } ,
@@ -3569,6 +3718,7 @@
{ \box_wd:N \l_tmpa_box + \l_@@_numbers_sep_dim + 0.1 em }
}
}
+\cs_generate_variant:Nn \@@_compute_left_margin:nn { n V }
% \end{macrocode}
%
%
@@ -3764,16 +3914,18 @@
% \begin{macrocode}
\NewDocumentCommand { \PitonInputFile } { d < > O { } m }
{
- \file_if_exist:nTF { #3 }
- { \@@_input_file:nnn { #1 } { #2 } { #3 } }
+ \group_begin:
+ \seq_set_eq:NN \l_file_search_path_seq \l_@@_path_seq
+ \file_get_full_name:nNTF { #3 } \l_@@_file_name_tl
+ { \@@_input_file:nn { #1 } { #2 } }
{ \msg_error:nnn { piton } { Unknown~file } { #3 } }
+ \group_end:
}
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new_protected:Npn \@@_input_file:nnn #1 #2 #3
+\cs_new_protected:Npn \@@_input_file:nn #1 #2
{
- \str_set:Nn \l_@@_file_name_str { #3 }
% \end{macrocode}
% We recall that, if we are in Beamer, the command |\PitonInputFile| is
% ``overlay-aware'' and that's why there is an optional argument between angular
@@ -3839,12 +3991,12 @@
% stored by Lua in |\l_@@_nb_lines_int|. That information will be used to allow
% or disallow page breaks.
% \begin{macrocode}
- \lua_now:e { piton.CountLinesFile('\l_@@_file_name_str') }
+ \lua_now:e { piton.CountLinesFile('\l_@@_file_name_tl') }
% \end{macrocode}
% The first argument of the following function is the name of the Lua function
% that will be applied to the second argument in order to count the number of lines.
% \begin{macrocode}
- \@@_compute_left_margin:nn { CountNonEmptyLinesFile } { #3 }
+ \@@_compute_left_margin:nV { CountNonEmptyLinesFile } \l_@@_file_name_tl
\@@_compute_width:
\ttfamily
\bool_if:NT \g_@@_footnote_bool { \begin { savenotes } }
@@ -3853,7 +4005,7 @@
{
piton.ParseFile(
'\l_@@_language_str' ,
- '\l_@@_file_name_str' ,
+ '\l_@@_file_name_tl' ,
\int_use:N \l_@@_first_line_int ,
\int_use:N \l_@@_last_line_int )
}
@@ -3895,7 +4047,7 @@
\lua_now:e
{
piton.ComputeRange
- ( '\l_tmpa_str' , '\l_tmpb_str' , '\l_@@_file_name_str' )
+ ( '\l_tmpa_str' , '\l_tmpb_str' , '\l_@@_file_name_tl' )
}
}
% \end{macrocode}
@@ -3906,13 +4058,23 @@
% \medskip
% The following command is fundamental: it will be used by the Lua code.
% \begin{macrocode}
-\NewDocumentCommand { \PitonStyle } { m } { \use:c { pitonStyle #1 } }
+\NewDocumentCommand { \PitonStyle } { m }
+ {
+ \cs_if_exist_use:cF { pitonStyle _ \l_@@_language_str _ #1 }
+ { \use:c { pitonStyle _ #1 } }
+ }
% \end{macrocode}
%
% \medskip
-% The following command takes in its argument by curryfication.
% \begin{macrocode}
-\NewDocumentCommand { \SetPitonStyle } { } { \keys_set:nn { piton / Styles } }
+\NewDocumentCommand { \SetPitonStyle } { O { } m }
+ {
+ \str_set:Nx \l_@@_SetPitonStyle_option_str { \str_lowercase:n { #1 } }
+ \str_if_eq:VnT \l_@@_SetPitonStyle_option_str { current-language }
+ { \str_set_eq:NN \l_@@_SetPitonStyle_option_str \l_@@_language_str }
+ \keys_set:nn { piton / Styles } { #2 }
+ \str_clear:N \l_@@_SetPitonStyle_option_str
+ }
% \end{macrocode}
%
% \medskip
@@ -3943,6 +4105,7 @@
Name.Function ,
Name.Module ,
Name.Namespace ,
+ Name.Table ,
Name.Type ,
Number ,
Operator ,
@@ -3957,12 +4120,20 @@
UserFunction
}
-\clist_map_inline:Nn \g_@@_styles_clist
+\clist_map_inline:Nn \g_@@_styles_clist
{
\keys_define:nn { piton / Styles }
{
- #1 .tl_set:c = pitonStyle #1 ,
- #1 .value_required:n = true
+ #1 .value_required:n = true ,
+ #1 .code:n =
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l_@@_SetPitonStyle_option_str
+ { \l_@@_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
}
}
@@ -4022,6 +4193,7 @@
Name.Constructor = \color[HTML]{006000} \bfseries ,
Name.Field = \color[HTML]{AA6600} ,
Name.Module = \color[HTML]{0060A0} \bfseries ,
+ Name.Table = \color[HTML]{309030} ,
Number = \color[HTML]{FF6600} ,
Operator = \color[HTML]{555555} ,
Operator.Word = \bfseries ,
@@ -4035,7 +4207,7 @@
TypeParameter = \color[HTML]{336666} \itshape ,
Preproc = \color[HTML]{AA6600} \slshape ,
Identifier = \@@_identifier:n ,
- UserFunction = ,
+ UserFunction = ,
Prompt = ,
ParseAgain.noCR = \@@_piton_no_cr:n ,
ParseAgain = \@@_piton:n ,
@@ -4103,7 +4275,7 @@
% that name. We define now that style (you define it directly and you short-cut
% the function |\SetPitonStyle|).
% \begin{macrocode}
-\cs_new_protected:cpn { pitonStyle Name.Function.Internal } #1
+\cs_new_protected:cpn { pitonStyle _ Name.Function.Internal } #1
{
% \end{macrocode}
% First, the element is composed in the TeX flow with the style |Name.Function|
@@ -4126,13 +4298,51 @@
\seq_if_exist:cF { g_@@_functions _ \l_@@_language_str _ seq }
{ \seq_new:c { g_@@_functions _ \l_@@_language_str _ seq } }
\seq_gput_right:cn { g_@@_functions _ \l_@@_language_str _ seq } { #1 }
+% \end{macrocode}
+% We update |\g_@@_languages_seq| which is used only by the command
+% |\PitonClearUserFunctions| when it's used without its optional argument.
+% \begin{macrocode}
+ \seq_if_in:NVF \g_@@_languages_seq \l_@@_language_str
+ { \seq_gput_left:NV \g_@@_languages_seq \l_@@_language_str }
}
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
-\NewDocumentCommand \PitonClearUserFunctions { ! O { \l_@@_language_str } }
+\NewDocumentCommand \PitonClearUserFunctions { ! o }
+ {
+ \tl_if_novalue:nTF { #1 }
+% \end{macrocode}
+% If the command is used without its optional argument, we will deleted the
+% user language for all the informatic languages.
+% \begin{macrocode}
+ { \@@_clear_all_functions: }
+ { \@@_clear_list_functions:n { #1 } }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_clear_list_functions:n #1
{
+ \clist_set:Nn \l_tmpa_clist { #1 }
+ \clist_map_function:NN \l_tmpa_clist \@@_clear_functions_i:n
+ \clist_map_inline:nn { #1 }
+ { \seq_gremove_all:Nn \g_@@_languages_seq { ##1 } }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_clear_functions_i:n #1
+ { \exp_args:Nx \@@_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+% \end{macrocode}
+%
+% The following command clears the list of the user-defined functions for the
+% language provided in argument (mandatory in lower case).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_clear_functions_ii:n #1
+ {
\seq_if_exist:cT { g_@@_functions _ #1 _ seq }
{
\seq_map_inline:cn { g_@@_functions _ #1 _ seq }
@@ -4141,13 +4351,33 @@
}
}
% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_clear_functions:n #1
+ {
+ \@@_clear_functions_i:n { #1 }
+ \seq_gremove_all:Nn \g_@@_languages_seq { #1 }
+ }
+% \end{macrocode}
%
% \bigskip
+% The following command clears all the user-defined functions for all the
+% informatic languages.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_clear_all_functions:
+ {
+ \seq_map_function:NN \g_@@_languages_seq \@@_clear_functions_i:n
+ \seq_gclear:N \g_@@_languages_seq
+ }
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{Security}
%
% \begin{macrocode}
\AddToHook { env / piton / begin }
- { \msg_fatal:nn { piton } { No~environment~piton } }
+ { \msg_fatal:nn { piton } { No~environment~piton } }
\msg_new:nnn { piton } { No~environment~piton }
{
@@ -4205,8 +4435,6 @@
}
% \end{macrocode}
%
-%
-%
% \begin{macrocode}
\@@_msg_new:nn { bad~range~specification }
{
@@ -4213,7 +4441,7 @@
Incompatible~keys.\\
You~can't~specify~the~range~of~lines~to~include~by~using~both~
markers~and~explicit~number~of~lines.\\
- Your~whole~file~'\l_@@_file_name_str'~will~be~included.
+ Your~whole~file~'\l_@@_file_name_tl'~will~be~included.
}
% \end{macrocode}
%
@@ -4237,7 +4465,7 @@
Marker~not~found.\\
The~range~'\l_@@_begin_range_str'~provided~to~the~
command~\token_to_str:N \PitonInputFile\ has~not~been~found.~
- The~whole~file~'\l_@@_file_name_str'~will~be~inserted.
+ The~whole~file~'\l_@@_file_name_tl'~will~be~inserted.
}
% \end{macrocode}
%
@@ -4248,7 +4476,7 @@
Marker~not~found.\\
The~marker~of~end~of~the~range~'\l_@@_end_range_str'~
provided~to~the~command~\token_to_str:N \PitonInputFile\
- has~not~been~found.~The~file~'\l_@@_file_name_str'~will~
+ has~not~been~found.~The~file~'\l_@@_file_name_tl'~will~
be~inserted~till~the~end.
}
% \end{macrocode}
@@ -4297,6 +4525,7 @@
left-margin,~
line-numbers/,~
marker/,~
+ path,~
prompt-background-color,~
resume,~
show-spaces,~
@@ -4465,6 +4694,8 @@
%
%
% \bigskip
+% The following function |WithStyle| is similar to the function |K| but should
+% be used for multi-lines elements.
% \begin{macrocode}
local function WithStyle(style,pattern)
return
@@ -4543,7 +4774,7 @@
% On the other hand, the \textsc{lpeg} |Identifier| (with a capital) also returns
% a \emph{capture}.
% \begin{macrocode}
-local Identifier = K ( 'Identifier' , identifier)
+local Identifier = K ( 'Identifier' , identifier )
% \end{macrocode}
%
% \bigskip
@@ -5308,7 +5539,7 @@
+ Word
% \end{macrocode}
%
-% Ici, il ne faut pas mettre |local| !
+% Here, we must not put |local|!
% \begin{macrocode}
MainLoopPython =
( ( space^1 * -1 )
@@ -5860,6 +6091,8 @@
% Some strings of length 2 are explicit because we want the corresponding
% ligatures available in some fonts such as \emph{Fira Code} to be active.
% \begin{macrocode}
+local identifier = letter * alphanum ^ 0
+
local Operator =
K ( 'Operator' ,
P "!=" + P "==" + P "<<" + P ">>" + P "<=" + P ">="
@@ -6020,29 +6253,7 @@
% \bigskip
% \paragraph{EOL}
%
-% \bigskip
-% The following LPEG will detect the Python prompts when the user is typesetting
-% an interactive session of Python (directly or through |{pyconsole}| of
-% \pkg{pyluatex}). We have to detect that prompt twice. The first detection
-% (called \emph{hasty detection}) will be before the |\@@_begin_line:| because
-% you want to trigger a special background color for that row (and, after the
-% |\@@_begin_line:|, it's too late to change de background).
-% \begin{macrocode}
-local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\@@_prompt:' ) ) ^ -1
-% \end{macrocode}
-% We remind that the marker |#| of \textsc{lpeg} specifies that the pattern will be
-% detected but won't consume any character.
%
-% \medskip
-% With the following \textsc{lpeg}, a style will actually be applied to the
-% prompt (for instance, it's possible to decide to discard these prompts).
-% \begin{macrocode}
-local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
-% \end{macrocode}
-%
-%
-%
-% \bigskip
% The following \textsc{lpeg} |EOL| is for the end of lines.
% \begin{macrocode}
local EOL =
@@ -6152,7 +6363,7 @@
+ Word
% \end{macrocode}
%
-% Ici, il ne faut pas mettre |local| !
+% Here, we must not put |local|!
% \begin{macrocode}
MainLoopC =
( ( space^1 * -1 )
@@ -6171,9 +6382,7 @@
Ct (
( ( space - P "\r" ) ^0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * PromptHastyDetection
* Lc '\\@@_begin_line:'
- * Prompt
* SpaceIndentation ^ 0
* MainLoopC
* -1
@@ -6185,8 +6394,356 @@
languages['c'] = languageC
% \end{macrocode}
%
+%
+% \bigskip
+% \subsubsection{The LPEG language SQL}
%
% \bigskip
+% In the identifiers, we will be able to catch those contening spaces, that is
+% to say like |"last name"|.
+% \begin{macrocode}
+local identifier =
+ letter * ( alphanum + P "-" ) ^ 0
+ + P '"' * ( ( alphanum + space - P '"' ) ^ 1 ) * P '"'
+
+
+local Operator =
+ K ( 'Operator' ,
+ P "=" + P "!=" + P "<>" + P ">=" + P ">" + P "<=" + P "<" + S "*+/"
+ )
+% \end{macrocode}
+% In SQL, the keywords are case-insensitive. That's why we have a little
+% complication. We will catch the keywords with the identifiers and, then,
+% distinguish the keywords with a Lua function. However, some keywords will be
+% catched in special LPEG because we want to detect the names of the SQL tables.
+% \begin{macrocode}
+local function Set (list)
+ local set = {}
+ for _, l in ipairs(list) do set[l] = true end
+ return set
+end
+
+local set_keywords = Set
+ {
+ "ADD" , "AFTER" , "ALL" , "ALTER" , "AND" , "AS" , "ASC" , "BETWEEN" , "BY" ,
+ "CHANGE" , "COLUMN" , "CREATE" , "CROSS JOIN" , "DELETE" , "DESC" , "DISTINCT" ,
+ "DROP" , "FROM" , "GROUP" , "HAVING" , "IN" , "INNER" , "INSERT" , "INTO" , "IS" ,
+ "JOIN" , "LEFT" , "LIKE" , "LIMIT" , "MERGE" , "NOT" , "NULL" , "ON" , "OR" ,
+ "ORDER" , "OVER" , "RIGHT" , "SELECT" , "SET" , "TABLE" , "THEN" , "TRUNCATE" ,
+ "UNION" , "UPDATE" , "VALUES" , "WHEN" , "WHERE" , "WITH"
+ }
+
+local set_builtins = Set
+ {
+ "AVG" , "COUNT" , "CHAR_LENGHT" , "CONCAT" , "CURDATE" , "CURRENT_DATE" ,
+ "DATE_FORMAT" , "DAY" , "LOWER" , "LTRIM" , "MAX" , "MIN" , "MONTH" , "NOW" ,
+ "RANK" , "ROUND" , "RTRIM" , "SUBSTRING" , "SUM" , "UPPER" , "YEAR"
+ }
+% \end{macrocode}
+%
+% The \textsc{lpeg} |Identifer| will catch the identifiers of the fields
+% but also the keywords and the built-in functions of SQL. If will \emph{not}
+% catch the names of the SQL tables.
+% \begin{macrocode}
+local Identifier =
+ C ( identifier ) /
+ (
+ function (s)
+ if set_keywords[string.upper(s)] -- the keywords are case-insensitive in SQL
+% \end{macrocode}
+% Remind that, in Lua, it's possible to return \emph{several} values.
+% \begin{macrocode}
+ then return { "{\\PitonStyle{Keyword}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else if set_builtins[string.upper(s)]
+ then return { "{\\PitonStyle{Name.Builtin}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else return { "{\\PitonStyle{Name.Field}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ end
+ end
+ end
+ )
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{The strings of SQL}
+%
+% \begin{macrocode}
+local String =
+ K ( 'String.Long' , P "'" * ( 1 - P "'" ) ^ 1 * P "'" )
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{Beamer}
+%
+% The following \textsc{lpeg} |balanced_braces| will be used for the (mandatory)
+% argument of the commands |\only| and \emph{al.} of Beamer. It's necessary to
+% use a \emph{grammar} because that pattern mainly checks the correct nesting of
+% the delimiters (and it's known in the theory of formal languages that this
+% can't be done with regular expressions \emph{stricto sensu} only).
+% \begin{macrocode}
+local balanced_braces =
+ P { "E" ,
+ E =
+ (
+ P "{" * V "E" * P "}"
+ +
+ String
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
+% \begin{macrocode}
+if piton_beamer
+then
+ Beamer =
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+ +
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopSQL:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopSQL )
+ +
+ L (
+% \end{macrocode}
+% For |\\alt|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
+ ( P "\\alt" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+ +
+ L (
+% \end{macrocode}
+% For |\\temporal|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
+ ( P "\\temporal" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+end
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{EOL}
+%
+% \bigskip
+% The following \textsc{lpeg} |EOL| is for the end of lines.
+% \begin{macrocode}
+local EOL =
+ P "\r"
+ *
+ (
+ ( space^0 * -1 )
+ +
+% \end{macrocode}
+% We recall that each line in the SQL code we have to parse will be sent
+% back to LaTeX between a pair |\@@_begin_line:| --
+% |\@@_end_line:|\footnote{Remember that the \texttt{\textbackslash
+% @@\_end\_line:} must be explicit because it will be used as marker in order to
+% delimit the argument of the command \texttt{\textbackslash @@\_begin\_line:}}.
+% \begin{macrocode}
+ Ct (
+ Cc "EOL"
+ *
+ Ct (
+ Lc "\\@@_end_line:"
+ * BeamerEndEnvironments
+ * BeamerBeginEnvironments
+ * Lc "\\@@_newline: \\@@_begin_line:"
+ )
+ )
+ )
+ *
+ SpaceIndentation ^ 0
+% \end{macrocode}
+%
+%
+%
+% \bigskip
+% \paragraph{The comments in the SQL listings}
+%
+% We define different \textsc{lpeg} dealing with comments in the SQL listings.
+% \begin{macrocode}
+local CommentMath =
+ P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$"
+
+local Comment =
+ WithStyle ( 'Comment' ,
+ Q ( P "--" ) -- syntax of SQL92
+ * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 )
+ * ( EOL + -1 )
+
+local LongComment =
+ WithStyle ( 'Comment' ,
+ Q ( P "/*" )
+ * ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
+ * Q ( P "*/" )
+ ) -- $
+% \end{macrocode}
+%
+%
+% \bigskip
+% The following \textsc{lpeg} |CommentLaTeX| is for what is called in that
+% document the ``LaTeX comments''. Since the elements that will be catched must
+% be sent to LaTeX with standard LaTeX catcodes, we put the capture (done by
+% the function~|C|) in a table (by using~|Ct|, which is an alias for |lpeg.Ct|).
+% \begin{macrocode}
+local CommentLaTeX =
+ P(piton.comment_latex)
+ * Lc "{\\PitonStyle{Comment.LaTeX}{\\ignorespaces"
+ * L ( ( 1 - P "\r" ) ^ 0 )
+ * Lc "}}"
+ * ( EOL + -1 )
+% \end{macrocode}
+%
+%
+%
+%
+% \bigskip
+% \paragraph{The main LPEG for the language SQL}
+%
+%
+% \begin{macrocode}
+local function LuaKeyword ( name )
+return
+ Lc ( "{\\PitonStyle{Keyword}{" )
+ * Q ( Cmt (
+ C ( identifier ) ,
+ function(s,i,a) return string.upper(a) == name end
+ )
+ )
+ * Lc ( "}}" )
+end
+% \end{macrocode}
+%
+% \begin{macrocode}
+local TableField =
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+
+local OneField =
+ (
+ Q ( P "(" * ( 1 - P ")" ) ^ 0 * P ")" )
+ +
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+ +
+ K ( 'Name.Field' , identifier )
+ )
+ * (
+ Space * LuaKeyword ( "AS" ) * Space * K ( 'Name.Field' , identifier )
+ ) ^ -1
+ * ( Space * ( LuaKeyword ( "ASC" ) + LuaKeyword ( "DESC" ) ) ) ^ -1
+
+local OneTable =
+ K ( 'Name.Table' , identifier )
+ * (
+ Space
+ * LuaKeyword ( "AS" )
+ * Space
+ * K ( 'Name.Table' , identifier )
+ ) ^ -1
+
+local WeCatchTableNames =
+ LuaKeyword ( "FROM" )
+ * ( Space + EOL )
+ * OneTable * ( SkipSpace * Q ( P "," ) * SkipSpace * OneTable ) ^ 0
+ + (
+ LuaKeyword ( "JOIN" ) + LuaKeyword ( "INTO" ) + LuaKeyword ( "UPDATE" )
+ + LuaKeyword ( "TABLE" )
+ )
+ * ( Space + EOL ) * OneTable
+% \end{macrocode}
+%
+%
+% First, the main loop :
+% \begin{macrocode}
+local MainSQL =
+ EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + CommentLaTeX
+ + Beamer
+ + Comment + LongComment
+ + Delim
+ + Operator
+ + String
+ + Punct
+ + WeCatchTableNames
+ + ( TableField + Identifier ) * ( Space + Operator + Punct + Delim + EOL + -1 )
+ + Number
+ + Word
+% \end{macrocode}
+%
+% Here, we must not put |local|!
+% \begin{macrocode}
+MainLoopSQL =
+ ( ( space^1 * -1 )
+ + MainSQL
+ ) ^ 0
+% \end{macrocode}
+%
+% \bigskip
+% We recall that each line in the C code to parse will be sent back to
+% LaTeX between a pair |\@@_begin_line:| -- |\@@_end_line:|\footnote{Remember
+% that the \texttt{\textbackslash @@\_end\_line:} must be explicit because it
+% will be used as marker in order to delimit the argument of the command
+% \texttt{\textbackslash @@\_begin\_line:}}.
+% \begin{macrocode}
+languageSQL =
+ Ct (
+ ( ( space - P "\r" ) ^ 0 * P "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * Lc '\\@@_begin_line:'
+ * SpaceIndentation ^ 0
+ * MainLoopSQL
+ * -1
+ * Lc '\\@@_end_line:'
+ )
+% \end{macrocode}
+%
+% \begin{macrocode}
+languages['sql'] = languageSQL
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{The function Parse}
%
%
@@ -6551,6 +7108,15 @@
%
% \verb|https://github.com/fpantigny/piton|
%
+% \subsection*{Changes between versions 2.1 and 2.2}
+%
+% New key |path| for |\PitonOptions|.
+%
+% New language SQL.
+%
+% It's now possible to define styles locally to a given language (with the
+% optional argument of |\SetPitonStyle|).
+%
% \subsection*{Changes between versions 2.0 and 2.1}
%
% The key |line-numbers| has now subkeys |line-numbers/skip-empty-lines|,
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2023-09-05 20:06:27 UTC (rev 68185)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2023-09-05 20:06:40 UTC (rev 68186)
@@ -60,7 +60,7 @@
local alphanum = letter + digit
local identifier = letter * alphanum ^ 0
-local Identifier = K ( 'Identifier' , identifier)
+local Identifier = K ( 'Identifier' , identifier )
local Number =
K ( 'Number' ,
( digit^1 * P "." * digit^0 + digit^0 * P "." * digit^1 + digit^1 )
@@ -830,6 +830,8 @@
* Lc ( '\\__piton_end_line:' )
)
languages['ocaml'] = ocaml
+local identifier = letter * alphanum ^ 0
+
local Operator =
K ( 'Operator' ,
P "!=" + P "==" + P "<<" + P ">>" + P "<=" + P ">="
@@ -941,8 +943,6 @@
* K ( 'ParseAgain.noCR' , balanced_braces )
* L ( P "}" )
end
-local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\__piton_prompt:' ) ) ^ -1
-local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
local EOL =
P "\r"
*
@@ -1016,9 +1016,7 @@
Ct (
( ( space - P "\r" ) ^0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * PromptHastyDetection
* Lc '\\__piton_begin_line:'
- * Prompt
* SpaceIndentation ^ 0
* MainLoopC
* -1
@@ -1025,6 +1023,234 @@
* Lc '\\__piton_end_line:'
)
languages['c'] = languageC
+local identifier =
+ letter * ( alphanum + P "-" ) ^ 0
+ + P '"' * ( ( alphanum + space - P '"' ) ^ 1 ) * P '"'
+
+local Operator =
+ K ( 'Operator' ,
+ P "=" + P "!=" + P "<>" + P ">=" + P ">" + P "<=" + P "<" + S "*+/"
+ )
+local function Set (list)
+ local set = {}
+ for _, l in ipairs(list) do set[l] = true end
+ return set
+end
+
+local set_keywords = Set
+ {
+ "ADD" , "AFTER" , "ALL" , "ALTER" , "AND" , "AS" , "ASC" , "BETWEEN" , "BY" ,
+ "CHANGE" , "COLUMN" , "CREATE" , "CROSS JOIN" , "DELETE" , "DESC" , "DISTINCT" ,
+ "DROP" , "FROM" , "GROUP" , "HAVING" , "IN" , "INNER" , "INSERT" , "INTO" , "IS" ,
+ "JOIN" , "LEFT" , "LIKE" , "LIMIT" , "MERGE" , "NOT" , "NULL" , "ON" , "OR" ,
+ "ORDER" , "OVER" , "RIGHT" , "SELECT" , "SET" , "TABLE" , "THEN" , "TRUNCATE" ,
+ "UNION" , "UPDATE" , "VALUES" , "WHEN" , "WHERE" , "WITH"
+ }
+
+local set_builtins = Set
+ {
+ "AVG" , "COUNT" , "CHAR_LENGHT" , "CONCAT" , "CURDATE" , "CURRENT_DATE" ,
+ "DATE_FORMAT" , "DAY" , "LOWER" , "LTRIM" , "MAX" , "MIN" , "MONTH" , "NOW" ,
+ "RANK" , "ROUND" , "RTRIM" , "SUBSTRING" , "SUM" , "UPPER" , "YEAR"
+ }
+local Identifier =
+ C ( identifier ) /
+ (
+ function (s)
+ if set_keywords[string.upper(s)] -- the keywords are case-insensitive in SQL
+ then return { "{\\PitonStyle{Keyword}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else if set_builtins[string.upper(s)]
+ then return { "{\\PitonStyle{Name.Builtin}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else return { "{\\PitonStyle{Name.Field}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ end
+ end
+ end
+ )
+local String =
+ K ( 'String.Long' , P "'" * ( 1 - P "'" ) ^ 1 * P "'" )
+local balanced_braces =
+ P { "E" ,
+ E =
+ (
+ P "{" * V "E" * P "}"
+ +
+ String
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
+if piton_beamer
+then
+ Beamer =
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+ +
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopSQL:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopSQL )
+ +
+ L (
+ ( P "\\alt" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+ +
+ L (
+ ( P "\\temporal" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+end
+local EOL =
+ P "\r"
+ *
+ (
+ ( space^0 * -1 )
+ +
+ Ct (
+ Cc "EOL"
+ *
+ Ct (
+ Lc "\\__piton_end_line:"
+ * BeamerEndEnvironments
+ * BeamerBeginEnvironments
+ * Lc "\\__piton_newline: \\__piton_begin_line:"
+ )
+ )
+ )
+ *
+ SpaceIndentation ^ 0
+local CommentMath =
+ P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$"
+
+local Comment =
+ WithStyle ( 'Comment' ,
+ Q ( P "--" ) -- syntax of SQL92
+ * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 )
+ * ( EOL + -1 )
+
+local LongComment =
+ WithStyle ( 'Comment' ,
+ Q ( P "/*" )
+ * ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
+ * Q ( P "*/" )
+ ) -- $
+local CommentLaTeX =
+ P(piton.comment_latex)
+ * Lc "{\\PitonStyle{Comment.LaTeX}{\\ignorespaces"
+ * L ( ( 1 - P "\r" ) ^ 0 )
+ * Lc "}}"
+ * ( EOL + -1 )
+local function LuaKeyword ( name )
+return
+ Lc ( "{\\PitonStyle{Keyword}{" )
+ * Q ( Cmt (
+ C ( identifier ) ,
+ function(s,i,a) return string.upper(a) == name end
+ )
+ )
+ * Lc ( "}}" )
+end
+local TableField =
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+
+local OneField =
+ (
+ Q ( P "(" * ( 1 - P ")" ) ^ 0 * P ")" )
+ +
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+ +
+ K ( 'Name.Field' , identifier )
+ )
+ * (
+ Space * LuaKeyword ( "AS" ) * Space * K ( 'Name.Field' , identifier )
+ ) ^ -1
+ * ( Space * ( LuaKeyword ( "ASC" ) + LuaKeyword ( "DESC" ) ) ) ^ -1
+
+local OneTable =
+ K ( 'Name.Table' , identifier )
+ * (
+ Space
+ * LuaKeyword ( "AS" )
+ * Space
+ * K ( 'Name.Table' , identifier )
+ ) ^ -1
+
+local WeCatchTableNames =
+ LuaKeyword ( "FROM" )
+ * ( Space + EOL )
+ * OneTable * ( SkipSpace * Q ( P "," ) * SkipSpace * OneTable ) ^ 0
+ + (
+ LuaKeyword ( "JOIN" ) + LuaKeyword ( "INTO" ) + LuaKeyword ( "UPDATE" )
+ + LuaKeyword ( "TABLE" )
+ )
+ * ( Space + EOL ) * OneTable
+local MainSQL =
+ EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + CommentLaTeX
+ + Beamer
+ + Comment + LongComment
+ + Delim
+ + Operator
+ + String
+ + Punct
+ + WeCatchTableNames
+ + ( TableField + Identifier ) * ( Space + Operator + Punct + Delim + EOL + -1 )
+ + Number
+ + Word
+MainLoopSQL =
+ ( ( space^1 * -1 )
+ + MainSQL
+ ) ^ 0
+languageSQL =
+ Ct (
+ ( ( space - P "\r" ) ^ 0 * P "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * Lc '\\__piton_begin_line:'
+ * SpaceIndentation ^ 0
+ * MainLoopSQL
+ * -1
+ * Lc '\\__piton_end_line:'
+ )
+languages['sql'] = languageSQL
function piton.Parse(language,code)
local t = languages[language] : match ( code )
if t == nil
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2023-09-05 20:06:27 UTC (rev 68185)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2023-09-05 20:06:40 UTC (rev 68186)
@@ -18,8 +18,8 @@
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
-\def\myfileversion{2.1}
-\def\myfiledate{2023/08/26}
+\def\myfileversion{2.2}
+\def\myfiledate{2023/09/05}
\NeedsTeXFormat{LaTeX2e}
@@ -153,6 +153,7 @@
\lua_now:n { piton = piton~or { } }
\str_new:N \l__piton_language_str
\str_set:Nn \l__piton_language_str { python }
+\tl_new:N \l__piton_path_seq
\bool_new:N \l__piton_in_PitonOptions_bool
\bool_new:N \l__piton_in_PitonInputFile_bool
\bool_new:N \g__piton_in_document_bool
@@ -166,7 +167,7 @@
\tl_new:N \l__piton_prompt_bg_color_tl
\str_new:N \l__piton_begin_range_str
\str_new:N \l__piton_end_range_str
-\str_new:N \l__piton_file_name_str
+\tl_new:N \l__piton_file_name_tl
\int_new:N \g__piton_env_int
\bool_new:N \l__piton_show_spaces_bool
\bool_new:N \l__piton_break_lines_in_Piton_bool
@@ -187,6 +188,7 @@
\dim_new:N \l__piton_numbers_sep_dim
\dim_set:Nn \l__piton_numbers_sep_dim { 0.7 em }
\tl_new:N \l__piton_tab_tl
+\seq_new:N \g__piton_languages_seq
\cs_new_protected:Npn \__piton_set_tab_tl:n #1
{
\tl_clear:N \l__piton_tab_tl
@@ -499,6 +501,9 @@
language .code:n =
\str_set:Nx \l__piton_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
+ path .code:n =
+ \seq_set_from_clist:Nn \l__piton_path_seq { #1 } ,
+ path .value_required:n = true ,
gobble .int_set:N = \l__piton_gobble_int ,
gobble .value_required:n = true ,
auto-gobble .code:n = \int_set:Nn \l__piton_gobble_int { -1 } ,
@@ -807,6 +812,7 @@
{ \box_wd:N \l_tmpa_box + \l__piton_numbers_sep_dim + 0.1 em }
}
}
+\cs_generate_variant:Nn \__piton_compute_left_margin:nn { n V }
\cs_new_protected:Npn \__piton_compute_width:
{
\dim_compare:nNnTF \l__piton_line_width_dim = \c_zero_dim
@@ -902,13 +908,15 @@
}
\NewDocumentCommand { \PitonInputFile } { d < > O { } m }
{
- \file_if_exist:nTF { #3 }
- { \__piton_input_file:nnn { #1 } { #2 } { #3 } }
+ \group_begin:
+ \seq_set_eq:NN \l_file_search_path_seq \l__piton_path_seq
+ \file_get_full_name:nNTF { #3 } \l__piton_file_name_tl
+ { \__piton_input_file:nn { #1 } { #2 } }
{ \msg_error:nnn { piton } { Unknown~file } { #3 } }
+ \group_end:
}
-\cs_new_protected:Npn \__piton_input_file:nnn #1 #2 #3
+\cs_new_protected:Npn \__piton_input_file:nn #1 #2
{
- \str_set:Nn \l__piton_file_name_str { #3 }
\tl_if_novalue:nF { #1 }
{
\bool_if:NTF \g__piton_beamer_bool
@@ -960,8 +968,8 @@
\int_compare:nNnT \g__piton_visual_line_int < 0
{ \int_gzero:N \g__piton_visual_line_int }
\mode_if_vertical:TF \mode_leave_vertical: \newline
- \lua_now:e { piton.CountLinesFile('\l__piton_file_name_str') }
- \__piton_compute_left_margin:nn { CountNonEmptyLinesFile } { #3 }
+ \lua_now:e { piton.CountLinesFile('\l__piton_file_name_tl') }
+ \__piton_compute_left_margin:nV { CountNonEmptyLinesFile } \l__piton_file_name_tl
\__piton_compute_width:
\ttfamily
\bool_if:NT \g__piton_footnote_bool { \begin { savenotes } }
@@ -970,7 +978,7 @@
{
piton.ParseFile(
'\l__piton_language_str' ,
- '\l__piton_file_name_str' ,
+ '\l__piton_file_name_tl' ,
\int_use:N \l__piton_first_line_int ,
\int_use:N \l__piton_last_line_int )
}
@@ -991,11 +999,22 @@
\lua_now:e
{
piton.ComputeRange
- ( '\l_tmpa_str' , '\l_tmpb_str' , '\l__piton_file_name_str' )
+ ( '\l_tmpa_str' , '\l_tmpb_str' , '\l__piton_file_name_tl' )
}
}
-\NewDocumentCommand { \PitonStyle } { m } { \use:c { pitonStyle #1 } }
-\NewDocumentCommand { \SetPitonStyle } { } { \keys_set:nn { piton / Styles } }
+\NewDocumentCommand { \PitonStyle } { m }
+ {
+ \cs_if_exist_use:cF { pitonStyle _ \l__piton_language_str _ #1 }
+ { \use:c { pitonStyle _ #1 } }
+ }
+\NewDocumentCommand { \SetPitonStyle } { O { } m }
+ {
+ \str_set:Nx \l__piton_SetPitonStyle_option_str { \str_lowercase:n { #1 } }
+ \str_if_eq:VnT \l__piton_SetPitonStyle_option_str { current-language }
+ { \str_set_eq:NN \l__piton_SetPitonStyle_option_str \l__piton_language_str }
+ \keys_set:nn { piton / Styles } { #2 }
+ \str_clear:N \l__piton_SetPitonStyle_option_str
+ }
\cs_new_protected:Npn \__piton_math_scantokens:n #1
{ \normalfont \scantextokens { $#1$ } }
\clist_new:N \g__piton_style_clist
@@ -1018,6 +1037,7 @@
Name.Function ,
Name.Module ,
Name.Namespace ,
+ Name.Table ,
Name.Type ,
Number ,
Operator ,
@@ -1036,8 +1056,16 @@
{
\keys_define:nn { piton / Styles }
{
- #1 .tl_set:c = pitonStyle #1 ,
- #1 .value_required:n = true
+ #1 .value_required:n = true ,
+ #1 .code:n =
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l__piton_SetPitonStyle_option_str
+ { \l__piton_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
}
}
@@ -1075,6 +1103,7 @@
Name.Constructor = \color[HTML]{006000} \bfseries ,
Name.Field = \color[HTML]{AA6600} ,
Name.Module = \color[HTML]{0060A0} \bfseries ,
+ Name.Table = \color[HTML]{309030} ,
Number = \color[HTML]{FF6600} ,
Operator = \color[HTML]{555555} ,
Operator.Word = \bfseries ,
@@ -1088,7 +1117,7 @@
TypeParameter = \color[HTML]{336666} \itshape ,
Preproc = \color[HTML]{AA6600} \slshape ,
Identifier = \__piton_identifier:n ,
- UserFunction = ,
+ UserFunction = ,
Prompt = ,
ParseAgain.noCR = \__piton_piton_no_cr:n ,
ParseAgain = \__piton_piton:n ,
@@ -1115,7 +1144,7 @@
\l__piton_style_tl
}
}
-\cs_new_protected:cpn { pitonStyle Name.Function.Internal } #1
+\cs_new_protected:cpn { pitonStyle _ Name.Function.Internal } #1
{
{ \PitonStyle { Name.Function } { #1 } }
\cs_gset_protected:cpn { PitonIdentifier _ \l__piton_language_str _ #1 }
@@ -1123,9 +1152,26 @@
\seq_if_exist:cF { g__piton_functions _ \l__piton_language_str _ seq }
{ \seq_new:c { g__piton_functions _ \l__piton_language_str _ seq } }
\seq_gput_right:cn { g__piton_functions _ \l__piton_language_str _ seq } { #1 }
+ \seq_if_in:NVF \g__piton_languages_seq \l__piton_language_str
+ { \seq_gput_left:NV \g__piton_languages_seq \l__piton_language_str }
}
-\NewDocumentCommand \PitonClearUserFunctions { ! O { \l__piton_language_str } }
+\NewDocumentCommand \PitonClearUserFunctions { ! o }
{
+ \tl_if_novalue:nTF { #1 }
+ { \__piton_clear_all_functions: }
+ { \__piton_clear_list_functions:n { #1 } }
+ }
+\cs_new_protected:Npn \__piton_clear_list_functions:n #1
+ {
+ \clist_set:Nn \l_tmpa_clist { #1 }
+ \clist_map_function:NN \l_tmpa_clist \__piton_clear_functions_i:n
+ \clist_map_inline:nn { #1 }
+ { \seq_gremove_all:Nn \g__piton_languages_seq { ##1 } }
+ }
+\cs_new_protected:Npn \__piton_clear_functions_i:n #1
+ { \exp_args:Nx \__piton_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+\cs_new_protected:Npn \__piton_clear_functions_ii:n #1
+ {
\seq_if_exist:cT { g__piton_functions _ #1 _ seq }
{
\seq_map_inline:cn { g__piton_functions _ #1 _ seq }
@@ -1133,8 +1179,18 @@
\seq_gclear:c { g__piton_functions _ #1 _ seq }
}
}
+\cs_new_protected:Npn \__piton_clear_functions:n #1
+ {
+ \__piton_clear_functions_i:n { #1 }
+ \seq_gremove_all:Nn \g__piton_languages_seq { #1 }
+ }
+\cs_new_protected:Npn \__piton_clear_all_functions:
+ {
+ \seq_map_function:NN \g__piton_languages_seq \__piton_clear_functions_i:n
+ \seq_gclear:N \g__piton_languages_seq
+ }
\AddToHook { env / piton / begin }
- { \msg_fatal:nn { piton } { No~environment~piton } }
+ { \msg_fatal:nn { piton } { No~environment~piton } }
\msg_new:nnn { piton } { No~environment~piton }
{
@@ -1179,7 +1235,7 @@
Incompatible~keys.\\
You~can't~specify~the~range~of~lines~to~include~by~using~both~
markers~and~explicit~number~of~lines.\\
- Your~whole~file~'\l__piton_file_name_str'~will~be~included.
+ Your~whole~file~'\l__piton_file_name_tl'~will~be~included.
}
\__piton_msg_new:nn { syntax~error }
{
@@ -1193,7 +1249,7 @@
Marker~not~found.\\
The~range~'\l__piton_begin_range_str'~provided~to~the~
command~\token_to_str:N \PitonInputFile\ has~not~been~found.~
- The~whole~file~'\l__piton_file_name_str'~will~be~inserted.
+ The~whole~file~'\l__piton_file_name_tl'~will~be~inserted.
}
\__piton_msg_new:nn { end~marker~not~found }
{
@@ -1200,7 +1256,7 @@
Marker~not~found.\\
The~marker~of~end~of~the~range~'\l__piton_end_range_str'~
provided~to~the~command~\token_to_str:N \PitonInputFile\
- has~not~been~found.~The~file~'\l__piton_file_name_str'~will~
+ has~not~been~found.~The~file~'\l__piton_file_name_tl'~will~
be~inserted~till~the~end.
}
\NewDocumentCommand \PitonBeginMarkerNotFound { }
@@ -1239,6 +1295,7 @@
left-margin,~
line-numbers/,~
marker/,~
+ path,~
prompt-background-color,~
resume,~
show-spaces,~
More information about the tex-live-commits
mailing list.