texlive[72587] Master/texmf-dist: piton (18oct24)
commits+karl at tug.org
commits+karl at tug.org
Fri Oct 18 23:20:09 CEST 2024
Revision: 72587
https://tug.org/svn/texlive?view=revision&revision=72587
Author: karl
Date: 2024-10-18 23:20:09 +0200 (Fri, 18 Oct 2024)
Log Message:
-----------
piton (18oct24)
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 2024-10-18 21:20:00 UTC (rev 72586)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2024-10-18 21:20:09 UTC (rev 72587)
@@ -114,7 +114,7 @@
\bigskip
-{\color{red} Dans la version 4.0, la syntaxe des chemins absolus et relatifs utilisés dans
+{\color{red} Depuis la version 4.0, la syntaxe des chemins absolus et relatifs utilisés dans
|\PitonInputFile| a été changée : cf.~partie~\ref{PitonInputFile}, p.~\pageref{PitonInputFile}.}
\section{Présentation}
@@ -188,8 +188,9 @@
Les langages informatiques pris en charge par \pkg{piton} se classent en deux catégories :
\begin{itemize}
\item les langages reconnus nativement par \pkg{piton} qui sont au nombre de cinq :
-Python, OCaml, SQL, C (ou plutôt \CC) et un langage nommé |minimal|\footnote{Le langage
- |minimal| peut servir pour formater du pseudo-code : cf.~p.~\pageref{minimal}.} ;
+Python, OCaml, SQL, C (ou plutôt \CC) et deux langages minimalistes nommés |minimal|\footnote{Le langage
+ |minimal| peut servir pour formater du pseudo-code : cf.~p.~\pageref{minimal}.} et
+|verbatim|;
\item les langages définis par l'utilisateur avec la commande |\NewPitonLanguage| décrite
p.~\pageref{NewPitonLanguage} (les parseurs de ces langages ne pourront jamais être aussi
précis que ceux proposés nativement par \pkg{piton)}.
@@ -371,9 +372,10 @@
\begin{itemize}
\item La clé \Definition{language} spécifie le langage informatique considéré (la casse
-n'est pas prise en compte). On peut choisir l'un des cinq langages prédéfinis (|Python|,
-|OCaml|, |C|, |SQL| et |minimal|) ou bien le nom d'un langage défini par l'utilisateur
-avec |\NewPitonLanguage| (voir partie~\ref{NewPitonLanguage}, p.~\pageref{NewPitonLanguage}).
+n'est pas prise en compte). On peut choisir l'un des six langages prédéfinis (|Python|,
+|OCaml|, |C|, |SQL|, |minimal| et |verbatim|) ou bien le nom d'un langage défini par
+l'utilisateur avec |\NewPitonLanguage| (voir partie~\ref{NewPitonLanguage},
+p.~\pageref{NewPitonLanguage}).
La valeur initiale est |Python|.
@@ -382,7 +384,8 @@
La clé \Definition{font-command} contient des instructions de fonte qui seront
insérées au début de chaque élément formaté par \pkg{piton}, que ce soit avec la commande
-|\piton|, l'environnement |{Piton}| ou bien la commande |\PitonInputFile|.
+|\piton|, l'environnement |{Piton}| ou bien la commande |\PitonInputFile| (il n'y a que
+les «commentaires LaTeX» pour lesquels ces instructions de fonte ne sont pas utilisées).
La valeur initiale de ce paramètre |font-command| est |\ttfamily|, ce qui fait, que, par
défaut, \pkg{piton} utilise la fonte mono-chasse courante.
@@ -471,7 +474,7 @@
skip-empty-lines = false ,
label-empty-lines = false ,
sep = 1 em ,
- line-format = \footnotesize \color{blue}
+ format = \footnotesize \color{blue}
}
}
\end{Verbatim}
@@ -528,9 +531,9 @@
courtes, c'est-à-dire celles délimitées par~\verb|'| ou~\verb|"|. En OCaml, cela ne
s'applique pas pour les \emph{quoted strings}.} sont matérialisés par le caractère ␣
(U+2423 : \textsc{open box}). Bien sûr, le caractère U+2423 doit être présent dans la
-fonte mono-chasse utilisée.\footnote{L'extension \pkg{piton} utilise simplement la fonte
- mono-chasse courante. Pour la changer, le mieux est d'utiliser |\setmonofont| de
- \pkg{fontspec}.}\par\nobreak
+fonte mono-chasse utilisée.\footnote{La valeur initial de |font-command| est |\ttfamily|
+ ce qui fait que, par défaut, l'extension \pkg{piton} utilise simplement la fonte
+ mono-chasse courante.}\par\nobreak
%
\begingroup
\PitonOptions{show-spaces-in-strings}
@@ -608,9 +611,10 @@
\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.}
+différents styles utilisés pour formater les éléments syntaxiques des listings
+informatiques. Ces personnalisations ont une portée qui correspond au groupe TeX
+courant.\footnote{On rappelle que tout environnement LaTeX est, en particulier, un
+ groupe.}
\bigskip
\indexcommand{SetPitonStyle} La commande |\SetPitonStyle| prend en argument une liste de
@@ -715,11 +719,14 @@
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|.
+listing Python précédent). La valeur initiale de ce style est |\PitonStyle{Identifier}|,
+ce qui fait que ces noms de fonctions sont formatés comme les autres identificateurs
+(c'est-à-dire, par défaut, sans formatage particulier, si ce n'est celui donné par
+|font-command|).
+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 règle les styles |Name.Function| et |UserFunction| de manière à
ce que, quand on clique sur le nom d'une fonction Python précédemment définie par
@@ -858,8 +865,8 @@
\medskip
Précisons tout de suite que l'extension \pkg{piton} n'utilise \emph{pas} cette commande
-pour définir les langages qu'elle propose nativement (Python, C, OCaml, SQL et
-|minimal|), ce qui permet de proposer des parseurs plus puissants.
+pour définir les langages qu'elle propose nativement (Python, C, OCaml, SQL, |minimal| et
+|verbatim|), ce qui permet de proposer des parseurs plus puissants.
\medskip
Par exemple, dans le fichier |lstlang1.sty|, qui est un des fichiers de definition des
@@ -1186,7 +1193,8 @@
Par défaut, les éléments produits par \pkg{piton} ne peuvent pas être coupés par une fin
de ligne. Il existe néanmoins des clés pour autoriser de telles coupures (les points de
-coupure possibles sont les espaces, y compris les espaces dans les chaînes Python).
+coupure possibles sont les espaces, y compris les espaces qui sont dans les chaînes de
+caractères des langages informatiques).
\begin{itemize}
\item \index{break-lines!break-lines-in-piton} Avec la clé
\Definition{break-lines-in-piton}, les coupures de ligne sont autorisées dans la commande
@@ -1253,7 +1261,14 @@
\end{center}
+\bigskip
+\colorbox{yellow!50}{\bfseries{Nouveau 4.1}}\par\nobreak
+\smallskip
+Avec la clé \Definition{break-strings-anywhere}, les chaînes de caractères pourront être
+coupées n'importe où (et pas seulement sur les espaces).
+
+
\subsubsection{Coupure des pages}
\label{coupure-de-pages}
@@ -1655,13 +1670,13 @@
\index{end-escape}
\label{escape}
-Il est aussi possible de surcharger les listings Python pour y insérer du code LaTeX à peu
-près n'importe où (mais entre deux lexèmes, bien entendu). Cette fonctionnalité n'est pas
-activée par défaut par \pkg{piton}. Pour l'utiliser, il faut spécifier les deux
-délimiteurs marquant l'échappement (le premier le commençant et le deuxième le terminant)
-en utilisant les clés \Definition{begin-escape} et \Definition{end-escape} (\emph{qui ne
- sont accessibles que dans le préambule du document}). Les deux délimiteurs peuvent être
-identiques.
+Il est aussi possible de surcharger les listings informatiques pour y insérer du code
+LaTeX à peu près n'importe où (mais entre deux lexèmes, bien entendu). Cette
+fonctionnalité n'est pas activée par défaut par \pkg{piton}. Pour l'utiliser, il faut
+spécifier les deux délimiteurs marquant l'échappement (le premier le commençant et le
+deuxième le terminant) en utilisant les clés \Definition{begin-escape} et
+\Definition{end-escape} (\emph{qui ne sont accessibles que dans le préambule du
+ document}). Les deux délimiteurs peuvent être identiques.
\medskip
On reprend l'exemple précédent de la factorielle et on souhaite surligner en rose
@@ -1668,7 +1683,7 @@
l'instruction qui contient l'appel récursif. La commande |\highLight| de \pkg{lua-ul}
permet de le faire avec la syntaxe |\highLight[LightPink]{...}|. Du fait de la présence de
l'argument optionnel entre crochets, on ne peut pas utiliser la clé |detected-commands|
-comme précédemment mais on peut utiliser le mécanisme «escape».
+comme précédemment mais on peut utiliser le mécanisme «escape» qui est plus général.
\smallskip
On suppose que le préambule du document contient l'instruction :
@@ -1699,10 +1714,10 @@
\bigskip
-\emph{Attention} : L'échappement vers LaTeX permis par les clés |begin-escape| et
-|end-escape| n'est pas actif dans les chaînes de caractères ni dans les commentaires (pour
-avoir un commentaire entièrement en échappement vers LaTeX, c'est-à-dire ce qui est appelé
-dans ce document «commentaire LaTeX», il suffit de le faire débuter par |#>|).
+\emph{Attention} : Le mécanisme «escape» n'est pas actif dans les chaînes de caractères ni
+dans les commentaires (pour avoir un commentaire entièrement en échappement vers LaTeX,
+c'est-à-dire ce qui est appelé dans ce document «commentaire LaTeX», il suffit de le faire
+débuter par |#>|).
\subsubsection{Le mécanisme «escape-math»}
@@ -1711,7 +1726,7 @@
\index{begin-escape-math}
\index{end-escape-math}
-Le mécanisme «|escape-math|» est très similaire au mécanisme «|escape|» puisque la seule
+Le mécanisme «escape-math» est très similaire au mécanisme «escape» puisque la seule
différence est que les éléments en échappement LaTeX y sont composés en mode mathématique.
On active ce mécanisme avec les clés \Definition{begin-escape-math} et
@@ -1719,15 +1734,14 @@
document}).
\medskip
-Malgré la proximité technique, les usages du mécanisme «|escape-math|» sont en fait assez
-différents de ceux du mécanisme «|escape|». En effet, comme le contenu en échappement est
-composé en mode mathématique, il est en particulier composé dans un groupe TeX et ne
+Malgré la proximité technique, les usages du mécanisme «escape-math» sont en fait assez
+différents de ceux du mécanisme «escape». En effet, comme le contenu en échappement est
+composé en mode mathématique, il est, en particulier, composé dans un groupe TeX et ne
pourra donc pas servir à changer le formatage d'autres unités lexicales.
\medskip
-Dans les langages où le caractère
-|$| ne joue pas un rôle syntaxique important, on peut assez naturellement vouloir activer
-le mécanisme «|escape-math|» avec le caractère |$|:
+Dans les langages où le caractère |$| ne joue pas un rôle syntaxique important, on peut
+assez naturellement vouloir activer le mécanisme «escape-math» avec le caractère |$|:
\begin{Verbatim}
\PitonOptions{~emphase#begin-escape-math=$,end-escape-math=$@}
\end{Verbatim}
@@ -1734,7 +1748,8 @@
Remarquer que le caractère |$| ne doit \emph{pas} être protégé par une contre-oblique. % $
\bigskip
-Néanmoins, il est sans doute plus prudent d'utiliser |\(| et |\)|.
+Néanmoins, il est sans doute plus prudent d'utiliser |\(| et |\)|, qui sont des
+délimiteurs du mode mathématique proposés par LaTeX.
\begin{Verbatim}
\PitonOptions{~emphase#begin-escape-math=\(,end-escape-math=\)@}
\end{Verbatim}
@@ -2019,7 +2034,7 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
\begin{Piton}
def arctan(x,n=10):
if x < 0:
@@ -2033,7 +2048,7 @@
\endgroup
\begingroup
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
\begin{Piton}
def arctan(x,n=10):
if x < 0:
@@ -2056,7 +2071,7 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
\emphase\begin{minipage}{\linewidth}
\begin{Piton}
def arctan(x,n=10):
@@ -2072,7 +2087,7 @@
\endgroup
\begingroup
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
\begin{minipage}{\linewidth}
\begin{Piton}
def arctan(x,n=10):
@@ -2143,8 +2158,8 @@
\end{itemize}
\medskip
-Pour un exemple d'utilisation, voir la partie concernant l'utilisation (standard) de \pkg{pyluatex},
-partie~\ref{pyluatex}, p.~\pageref{pyluatex}.
+Pour un exemple d'utilisation, voir la partie concernant l'utilisation (standard) de
+\pkg{pyluatex}, partie~\ref{pyluatex}, p.~\pageref{pyluatex}.
\section{Exemples}
@@ -2167,7 +2182,7 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-~emphase&\PitonOptions{background-color=gray!10, left-margin = auto, line-numbers}@
+~emphase&\PitonOptions{background-color=gray!15, left-margin = auto, line-numbers}@
\begin{Piton}
def arctan(x,n=10):
if x < 0:
@@ -2183,7 +2198,7 @@
\begingroup
-\PitonOptions{background-color=gray!10,left-margin = auto, line-numbers}
+\PitonOptions{background-color=gray!15,left-margin = auto, line-numbers}
\begin{Piton}
def arctan(x,n=10):
if x < 0:
@@ -2209,7 +2224,7 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
~emphase&\SetPitonStyle{Comment.LaTeX = \hfill \normalfont\color{gray}}@
\begin{Piton}
def arctan(x,n=10):
@@ -2224,7 +2239,7 @@
\endgroup
\begingroup
-\PitonOptions{background-color=gray!10}
+\PitonOptions{background-color=gray!15}
\SetPitonStyle{Comment.LaTeX = \hfill \normalfont\color{gray}}
\begin{Piton}
def arctan(x,n=10):
@@ -2247,7 +2262,7 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-\PitonOptions{width=min, background-color=gray!10}
+\PitonOptions{width=min, background-color=gray!15}
~emphase&\NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}@
~emphase&\SetPitonStyle{Comment.LaTeX = \MyLaTeXCommand}@
\begin{Piton}
@@ -2268,7 +2283,7 @@
\begingroup
-\PitonOptions{width = min, background-color=gray!10}
+\PitonOptions{width = min, background-color=gray!15}
\NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}
\SetPitonStyle{Comment.LaTeX = \MyLaTeXCommand}
\begin{Piton}
@@ -2465,7 +2480,7 @@
\PitonOptions
{
background-color=white,
- ~emphase#prompt-background-color = gray!10@,
+ ~emphase#prompt-background-color = gray!15@,
~#1
}
\PyLTVerbatimEnv
@@ -2492,7 +2507,7 @@
\begin{Verbatim}
~emphase#\begin{PitonREPL}@
def valeur_absolue(x):
- "Renvoie la valeur absolue de x"
+ """Renvoie la valeur absolue de x"""
if x > 0:
return x
else:
@@ -2509,7 +2524,7 @@
\ExplSyntaxOn
\NewDocumentEnvironment { PitonREPL } { }
{
- \PitonOptions{background-color=white,prompt-background-color = gray!10}
+ \PitonOptions{background-color=white,prompt-background-color = gray!15}
\PyLTVerbatimEnv
\begin{pythonrepl}
}
@@ -2528,7 +2543,7 @@
\begin{PitonREPL}
def valeur_absolue(x):
- "Renvoie la valeur absolue de x"
+ """Renvoie la valeur absolue de x"""
if x > 0:
return x
else:
@@ -2571,7 +2586,7 @@
\begin{Verbatim}
~emphase#\begin{PitonREPL}@
def valeur_absolue(x):
- "Renvoie la valeur absolue de x"
+ """Renvoie la valeur absolue de x"""
if x > 0:
return x
else:
@@ -2587,7 +2602,7 @@
\begin{PitonREPL}
def valeur_absolue(x):
- "Renvoie la valeur absolue de x"
+ """Renvoie la valeur absolue de x"""
if x > 0:
return x
else:
@@ -2624,54 +2639,55 @@
\begin{center}
\begin{tabularx}{\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
- \toprule
- \normalfont Style & Usage \\
- \midrule
- Number & les nombres \\
- String.Short & les chaînes de caractères courtes (entre \texttt{'} ou \texttt{"}) \\
- String.Long & les chaînes de caractères longues (entre \texttt{'''} ou \texttt{"""})
- sauf les chaînes de documentation (qui sont gérées par |String.Doc|)\\
- String & cette clé fixe à la fois |String.Short| et |String.Long| \\
- String.Doc & les chaînes de documentation (seulement entre |"""| suivant PEP~257) \\
- String.Interpol & les éléments syntaxiques des champs des f-strings (c'est-à-dire les
- caractères \texttt{\{} et \texttt{\}}) ; ce style hérite des styles
- |String.Short| et |String.Long| (suivant la chaîne où apparaît
- l'interpolation)\\
- Interpol.Inside & le contenu des interpolations dans les f-strings (c'est-à-dire les
- éléments qui se trouvent entre \texttt{\{} et~\texttt{\}} ; si
- l'utilisateur n'a pas fixé ce style, ces éléments sont analysés et
- formatés par \pkg{piton} au même titre que le reste du code. \\
- Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .}
- \verb+|+ |@| \\
- Operator.Word & les opérateurs suivants : |in|, |is|, |and|, |or| et |not| \\
- Name.Builtin & la plupart des fonctions prédéfinies par Python \\
- Name.Decorator & les décorateurs (instructions débutant par \verb|@|) \\
- Name.Namespace & le nom des modules (= bibliothèques extérieures) \\
- Name.Class & le nom des classes au moment de leur définition, c'est-à-dire après le
- mot-clé \verb|class| \\
- Name.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur
- définition} (après le mot-clé |def|) \\
- UserFunction & le nom des fonctions précédemment définies par l'utilisateur (la valeur
- initiale de ce paramètre est vide et ces éléments sont affichés en noir
- --- ou plutôt dans la couleur courante) \\
- Exception & les exceptions prédéfinies (ex.: \texttt{SyntaxError}) \\
- InitialValues & les valeurs initiales (et le symbole |=| qui précède) des arguments
- optionnels dans les définitions de fonctions ; si l'utilisateur n'a pas
- fixé ce style, ces éléments sont analysés et formatés par \pkg{piton}
- au même titre que le reste du code.\\
- Comment & les commentaires commençant par \texttt{\#} \\
- 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.Constant & |True|, |False| et |None| \\
- Keyword & les mots-clés suivants :
- \ttfamily assert, break, case, continue, del,
- elif, else, except, exec, finally, for, from,
- global, if, import, in, lambda, non local,
- pass, raise, return, try, while,
- with, yield et yield from.\\
- Identifier & les identificateurs. \\
- \bottomrule
+\toprule
+\normalfont Style & Usage \\
+\midrule
+Number & les nombres \\
+String.Short & les chaînes de caractères courtes (entre \texttt{'} ou \texttt{"}) \\
+String.Long & les chaînes de caractères longues (entre \texttt{'''} ou \texttt{"""})
+ sauf les chaînes de documentation (qui sont gérées par |String.Doc|)\\
+String & cette clé fixe à la fois |String.Short| et |String.Long| \\
+String.Doc & les chaînes de documentation (seulement entre |"""| suivant PEP~257) \\
+String.Interpol & les éléments syntaxiques des champs des f-strings (c'est-à-dire les
+ caractères \texttt{\{} et \texttt{\}}) ; ce style hérite des styles
+ |String.Short| et |String.Long| (suivant la chaîne où apparaît
+ l'interpolation)\\
+Interpol.Inside & le contenu des interpolations dans les f-strings (c'est-à-dire les
+ éléments qui se trouvent entre \texttt{\{} et~\texttt{\}}) ; si
+ l'utilisateur n'a pas fixé ce style, ces éléments sont analysés et
+ formatés par \pkg{piton} au même titre que le reste du code. \\
+Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .}
+ \verb+|+ |@| \\
+Operator.Word & les opérateurs suivants : |in|, |is|, |and|, |or| et |not| \\
+Name.Builtin & la plupart des fonctions prédéfinies par Python \\
+Name.Decorator & les décorateurs (instructions débutant par \verb|@|) \\
+Name.Namespace & le nom des modules (= bibliothèques extérieures) \\
+Name.Class & le nom des classes au moment de leur définition, c'est-à-dire après le
+ mot-clé \verb|class| \\
+Name.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur
+ définition} (après le mot-clé |def|) \\
+UserFunction & le nom des fonctions précédemment définies par l'utilisateur (la valeur
+ initiale de ce paramètre est {\ttfamily \textbackslash
+ PitonStyle\{Identifier\}}, ce qui fait que ces noms de fonctions sont
+ affichés comme les identifiants) \\
+Exception & les exceptions prédéfinies (ex.: \texttt{SyntaxError}) \\
+InitialValues & les valeurs initiales (et le symbole |=| qui précède) des arguments
+ optionnels dans les définitions de fonctions ; si l'utilisateur n'a pas
+ fixé ce style, ces éléments sont analysés et formatés par \pkg{piton}
+ au même titre que le reste du code.\\
+Comment & les commentaires commençant par \texttt{\#} \\
+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.Constant & |True|, |False| et |None| \\
+Keyword & les mots-clés suivants :
+ \ttfamily assert, break, case, continue, del,
+ elif, else, except, exec, finally, for, from,
+ global, if, import, in, lambda, non local,
+ pass, raise, return, try, while,
+ with, yield et yield from.\\
+Identifier & les identificateurs. \\
+\bottomrule
\end{tabularx}
\end{center}
@@ -2680,25 +2696,12 @@
\subsection{Le langage OCaml}
-On peut basculer vers le langage |OCaml| avec |\PitonOptions{language = OCaml}|
+On peut basculer vers le langage |OCaml| avec la clé |language| : |language = OCaml|
-\bigskip
-On peut aussi choisir le langage |OCaml| pour un environnement |{Piton}| individuel :
-%
-\begin{Verbatim}
-\begin{Piton}~emphase#[language=OCaml]@
-...
-\end{Piton}
-\end{Verbatim}
-
\bigskip
-L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=OCaml]{...}|
-\vspace{1cm}
-
-
\begin{center}
\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
\toprule
@@ -2719,8 +2722,9 @@
Name.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur
définition} (après le mot-clé |let|) \\
UserFunction & le nom des fonctions précédemment définies par l'utilisateur (la valeur
- initiale de ce paramètre est vide et ces éléments sont affichés en noir
- --- ou plutôt dans la couleur courante) \\
+ initiale de ce paramètre est {\ttfamily \textbackslash
+ PitonStyle\{Identifier\}}, ce qui fait que ces noms de fonctions sont
+ affichés comme les identifiants) \\
Exception & les exceptions prédéfinies (ex. : |End_of_File|) \\
TypeParameter & les paramétreurs de type \\
Comment & les commentaires, entre |(*| et |*)| ; ces commentaires peuvent être imbriqués \\
@@ -2743,22 +2747,11 @@
\subsection[Le langage C (et C++)]{Le langage C (et \CC)}
-On peut basculer vers le langage |C| avec |\PitonOptions{language = C}|
+On peut basculer vers le langage |C| avec la clé |language| : |language = C|
-\bigskip
-On peut aussi choisir le langage |C| pour un environnement |{Piton}| individuel :
-%
-\begin{Verbatim}
-\begin{Piton}~emphase#[language=C]@
-...
-\end{Piton}
-\end{Verbatim}
\bigskip
-L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=C]{...}|
-\vspace{1cm}
-
\begin{center}
\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
\toprule
@@ -2775,12 +2768,14 @@
|short|, |signed|, |unsigned|, |void| et |wchar_t| \\
Name.Builtin & les fonctions prédéfinies suivantes : |printf|, |scanf|, |malloc|, |sizeof|
et |alignof| \\
- Name.Class & le nom des classes au moment de leur définition, c'est-à-dire après le
+Name.Class & le nom des classes au moment de leur définition, c'est-à-dire après le
mot-clé |class| \\
-Name.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur définition} \\
+Name.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur
+ définition} \\
UserFunction & le nom des fonctions précédemment définies par l'utilisateur (la valeur
- initiale de ce paramètre est vide et ces éléments sont affichés en noir ---
- ou plutôt dans la couleur courante) \\
+ initiale de ce paramètre est {\ttfamily \textbackslash
+ PitonStyle\{Identifier\}}, ce qui fait que ces noms de fonctions sont
+ affichés comme les identifiants) \\
Preproc & les instructions du préprocesseur (commençant par |#|) \\
Comment & les commentaires (commençant par \texttt{//} ou entre |/*| et |*/|) \\
Comment.LaTeX & les commentaires commençant par \texttt{//>} qui sont composés par
@@ -2804,23 +2799,11 @@
\subsection{Le langage SQL}
-On peut basculer vers le langage |SQL| avec |\PitonOptions{language = SQL}|
+On peut basculer vers le langage |SQL| avec la clé |language| : |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
@@ -2859,8 +2842,44 @@
\SetPitonStyle~emphase#[SQL]@{Keywords = \bfseries \MakeUppercase}
\end{Verbatim}
+\newpage
+\subsection{Les langages définis par la commande \textbackslash NewPitonLanguage}
+\indexcommand{NewPitonLanguage}
+
+\vspace{1cm}
+La commande |\NewPitonLanguage|, qui permet de définir de nouveaux langages en utilisant
+la syntaxe de l'extension \pkg{listings}, a été présentée p.~\pageref{NewPitonLanguage}.
+
+Tous les langages définis avec la commande |\NewPitonLanguage| partagent les mêmes styles.
+
+\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 définies dans |\NewPitonLanguage| par la clé
+ |morestring| \\
+Comment & les commentaires définis dans |\NewPitonLanguage| par la clé |morecomment| \\
+Comment.LaTeX & les commentaires 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, définis dans |\NewPitonLanguage| par les clés |morekeywords| et
+ |moretexcs| (et également la clé |sensitive| qui indique si les mots-clés sont
+ sensibles à la casse) \\
+Directive & les directives définies dans |\NewPitonLanguage| par la clé |moredirectives| \\
+Tag & les «tags» définis par la clé |tag| (les lexèmes détectés à l'intérieur d'un tag
+ seront aussi composés avec leur propre style) \\
+Identifier & les identificateurs. \\
+\bottomrule
+\end{tabularx}
+\end{center}
+
+
+
\newpage
\subsection{Le langage «minimal»}
@@ -2869,23 +2888,11 @@
\label{minimal}
\index{minimal (langage «minimal»)}
-On peut basculer vers le langage «|minimal|» avec |\PitonOptions{language = minimal}|
+On peut basculer vers le langage «|minimal|» avec la clé |language| : |language = minimal|
-\bigskip
-On peut aussi choisir le langage «|minimal|» pour un environnement |{Piton}| individuel :
-%
-\begin{Verbatim}
-\begin{Piton}~emphase#[language=minimal]@
-...
-\end{Piton}
-\end{Verbatim}
\bigskip
-L'option est aussi disponible pour |\PitonInputFile| : |\PitonInputFile[language=minimal]{...}|
-
-\vspace{1cm}
-
\begin{center}
\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
\toprule
@@ -2908,45 +2915,44 @@
\ref{SetPitonIdentifier}, p.~\pageref{SetPitonIdentifier}) et créer par exemple un langage
pour pseudo-code.
+\vspace{2cm}
-\newpage
+\subsection{Le langage «verbatim»}
-\subsection{Les langages définis par la commande \textbackslash NewPitonLanguage}
-\indexcommand{NewPitonLanguage}
+\label{verbatim}
+\index{verbatim (langage «verbatim»)}
-\vspace{1cm}
-La commande |\NewPitonLanguage|, qui permet de définir de nouveaux langages en utilisant
-la syntaxe de l'extension \pkg{listings}, a été présentée p.~\pageref{NewPitonLanguage}.
-Tous les langages définis avec la commande |\NewPitonLanguage| partagent les mêmes styles.
+\colorbox{yellow!50}{\textbf{Nouveau 4.1}}
-\vspace{1cm}
+\bigskip
+
+On peut basculer vers le langage «|verbatim|» avec la clé |language| : |language = verbatim|
+
+\bigskip
+
\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 définies dans |\NewPitonLanguage| par la clé
- |morestring| \\
-Comment & les commentaires définis dans |\NewPitonLanguage| par la clé |morecomment| \\
-Comment.LaTeX & les commentaires 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, définis dans |\NewPitonLanguage| par les clés |morekeywords| et
- |moretexcs| (et également la clé |sensitive| qui indique si les mots-clés sont
- sensibles à la casse) \\
-Directive & les directives définies dans |\NewPitonLanguage| par la clé |moredirectives| \\
-Tag & les «tags» définis par la clé |tag| (les lexèmes détectés à l'intérieur d'un tag
- seront aussi composés avec leur propre style) \\
-Identifier & les identificateurs. \\
+\emph{rien...} & \\
\bottomrule
\end{tabularx}
\end{center}
+\bigskip
+Le language «|verbatim|» ne propose aucun style et ne fait donc aucun formatage
+syntaxique. On peut néanmoins y utiliser le mécanisme |detected-commands| (cf. partie
+\ref{detected-commands}, p.~\pageref{detected-commands}) ainsi que le
+mécanisme de détection des commandes et des environnements de Beamer.
+
+
+
\newpage
\phantomsection
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 2024-10-18 21:20:00 UTC (rev 72586)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2024-10-18 21:20:09 UTC (rev 72587)
@@ -79,12 +79,12 @@
% \iffalse
%<*STY>
% \fi
-\def\PitonFileVersion{4.0}
-\def\PitonFileDate{2024/09/22}
+\def\PitonFileVersion{4.1}
+\def\PitonFileDate{2024/10/18}
% \iffalse
%</STY>
%<*LUA>
-piton_version = "4.0" -- 2024/09/22
+piton_version = "4.1" -- 2024/10/18
%</LUA>
%\fi
%
@@ -102,7 +102,7 @@
% \end{abstract}
%
% \bigskip
-% {\color{red} In the version 4.0, the syntax of the absolute and relative
+% {\color{red} Since the version 4.0, the syntax of the absolute and relative
% paths used in |\PitonInputFile| has been changed:
% cf.~part~\ref{PitonInputFile}, p.~\pageref{PitonInputFile}.}
%
@@ -275,7 +275,8 @@
% {\color{cyan} but the commands |\{| and |\}| are also provided for individual braces};
%
% \item the LaTeX commands\footnote{That concerns the commands beginning with a
-% backslash but also the active characters (with catcode equal to 13). } are fully expanded and not executed,
+% backslash but also the active characters (with catcode equal to 13). } are
+% fully expanded and not executed,
%
% {\color{cyan} so it's possible to use |\\| to insert a backslash}.
% \end{itemize}
@@ -337,14 +338,10 @@
%
% \section{Customization}
%
-% With regard to the font used by \pkg{piton} in its listings, it's only the
-% current monospaced font. The package \pkg{piton} merely uses internally the
-% standard LaTeX command |\texttt|.
%
% \subsection{The keys of the command \textbackslash PitonOptions}
+
%
-%
-%
% \indexcommand{PitonOptions}
%
% The command |\PitonOptions| takes in as argument a comma-separated list of
@@ -358,9 +355,10 @@
% \begin{itemize}
% \item The key \Definition{language} specifies which computer language is
% considered (that key is case-insensitive). It's possible to use the name of
-% the five built-in languages (|Python|, |OCaml|, |C|, |SQL| and |minimal|) or
-% the name of the language defined by the user with |\NewPitonLanguage|
-% (cf.~part~\ref{NewPitonLanguage}, p.~\pageref{NewPitonLanguage}.
+% the six built-in languages (|Python|, |OCaml|, |C|, |SQL|, |minimal| and
+% |verbatim|) or the name of a language defined by the user with
+% |\NewPitonLanguage| (cf.~part~\ref{NewPitonLanguage},
+% p.~\pageref{NewPitonLanguage}).
%
% The initial value is |Python|.
%
@@ -368,7 +366,8 @@
% \colorbox{yellow!50}{\textbf{New 4.0}}\par\nobreak
%
% The key \Definition{font-command} contains instructions of font which will be
-% inserted at the beginning of all the elements composed by \pkg{piton}.
+% inserted at the beginning of all the elements composed by \pkg{piton} (without
+% surprise, these instructions are not used for the so-called ``LaTeX comments'').
%
% The initial value is |\ttfamily| and, thus, \pkg{piton} uses by default the
% current monospaced font.
@@ -458,7 +457,7 @@
% skip-empty-lines = false ,
% label-empty-lines = false ,
% sep = 1 em ,
-% line-format = \footnotesize \color{blue}
+% format = \footnotesize \color{blue}
% }
% }
% \end{Verbatim}
@@ -484,7 +483,7 @@
% this case, the successive rows are colored by using the colors of the list in
% a cyclic way.
%
-% \emph{Example} : |\PitonOptions{background-color = {gray!5,white}}|
+% \emph{Example} : |\PitonOptions{background-color = {gray!15,white}}|
%
% The key |background-color| accepts a color defined «on the fly». For example,
% it's possible to write |background-color = [cmyk]{0.1,0.05,0,0}|.
@@ -520,10 +519,10 @@
% only to the short strings (delimited by~\verb|'| or~\verb|"|). In OCaml, that
% feature does not apply to the \emph{quoted strings}.} are replaced by the
% character~␣ (U+2423 : \textsc{open box}). Of course, that character~U+2423
-% must be present in the monospaced font which is used.\footnote{The package
-% \pkg{piton} simply uses the current monospaced font. The best way to change
-% that font is to use the command \texttt{\textbackslash setmonofont} of the
-% package \pkg{fontspec}.}\par\nobreak \begingroup
+% must be present in the monospaced font which is used.\footnote{The initial
+% value of |font-command| is |\ttfamily| and, thus, by default, \pkg{piton}
+% merely uses the current monospaced font.}\par\nobreak
+% \begingroup
% \PitonOptions{show-spaces-in-strings} Example :
% \piton|my_string = 'Very good answer'| \endgroup
%
@@ -596,7 +595,7 @@
%
% The package \pkg{piton} provides the command
% \DefinitionCommand{SetPitonStyle} to customize the different styles used to
-% format the syntactic elements of the Python listings. The customizations done
+% format the syntactic elements of the informatic listings. The customizations done
% by that command are limited to the current TeX group.\footnote{We remind that
% a LaTeX environment is, in particular, a TeX group.}
%
@@ -636,8 +635,9 @@
%
% \bigskip
% The different styles, and their use by \pkg{piton} in the different languages
-% which it supports (Python, OCaml, C, SQL and ``|minimal|''), are described in
-% the part \ref{Semantic}, starting at the page \pageref{Semantic}.
+% which it supports (Python, OCaml, C, SQL, ``|minimal|'' and ``|verbatim|''),
+% are described in the part \ref{Semantic}, starting at the page
+% \pageref{Semantic}.
%
%
% \bigskip
@@ -707,10 +707,12 @@
% The extension \pkg{piton} provides a special style called~|UserFunction|. That
% 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|.
+% \piton{def} in a previous Python listing). The initial value of that style
+% |\PitonStyle{Identifier}| and, therefore, the names of the functions are
+% formatted like the other identifiers (that is to say, by default, with no
+% special formatting except the features provided in |font-command|). 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 tune the styles |Name.Function| and |UserFunction|
@@ -854,8 +856,8 @@
% syntax of~|\lstdefinelanguage|.
%
% Let's precise that \pkg{piton} does \emph{not} use that command to define the
-% languages provided natively (Python, OCaml, C, SQL and |minimal|), which
-% allows more powerful parsers.
+% languages provided natively (Python, OCaml, C, SQL, |minimal| and |verbatim|),
+% which allows more powerful parsers.
%
% \medskip
% For example, in the file |lstlang1.sty|, which is one of the definition files
@@ -1014,7 +1016,7 @@
% deleted in a future version of \pkg{piton}!).
%
% \smallskip
-% Now, the syntax if the following one:
+% Now, the syntax is the following one:
% \begin{itemize}
% \item The paths beginning by |/| are absolute.
%
@@ -1188,7 +1190,8 @@
%
% By default, the elements produced by \pkg{piton} can't be broken by an end on
% line. However, there are keys to allow such breaks (the possible breaking
-% points are the spaces, even the spaces in the Python strings).
+% points are the spaces, even the spaces which appear in the strings of the
+% informatic languages).
% \begin{itemize}
% \item \index{break-lines!break-lines-in-piton} With the key
% \Definition{break-lines-in-piton}, the line breaks are allowed in the command
@@ -1254,6 +1257,13 @@
% \end{Piton}
% \end{center}
%
+% \bigskip
+% \colorbox{yellow!50}{\bfseries{New 4.1}}\par\nobreak
+%
+% \smallskip
+% With the key \Definition{break-strings-anywhere}, the strings may be broken
+% anywhere (and not only on the spaces).
+%
% \subsubsection{Page breaks}
% \label{page breaks}
% \index{splittable}
@@ -1635,7 +1645,7 @@
%
% \label{escape}
%
-% It's also possible to overwrite the Python listings to insert LaTeX code
+% It's also possible to overwrite the informatic listings to insert LaTeX code
% almost everywhere (but between lexical units, of course). By default,
% \pkg{piton} does not fix any delimiters for that kind of escape.
%
@@ -1653,8 +1663,8 @@
% possible to achieve our goal with the more general mechanism ``escape''.
%
% \medskip
-% We assume that the preamble of the document contains
-% the following instruction:
+% We assume that the preamble of the document contains the following
+% instruction:
%
% \begin{Verbatim}
% \PitonOptions{~emphase#begin-escape=!,end-escape=!@}
@@ -1683,16 +1693,15 @@
%
%
% \bigskip
-% \emph{Caution} : The escape to LaTeX allowed by the |begin-escape| and
-% |end-escape| is not active in the strings nor in the Python comments (however,
-% it's possible to have a whole Python comment composed in LaTeX by beginning it
-% with |#>|; such comments are merely called ``LaTeX comments'' in this
-% document).
+% \emph{Caution} : The mechanism ``escape'' is not active in the strings nor in
+% the Python comments (however, it's possible to have a whole Python comment
+% composed in LaTeX by beginning it with |#>|; such comments are merely called
+% ``LaTeX comments'' in this document).
%
%
% \subsubsection{The mechanism ``escape-math''}
%
-% The mechanism ``|escape-math|'' is very similar to the mechanism ``|escape|''
+% The mechanism ``escape-math'' is very similar to the mechanism ``escape''
% since the only difference is that the elements sent to LaTeX are composed in
% the math mode of LaTeX.
%
@@ -1701,13 +1710,13 @@
% document}).
%
% Despite the technical similarity, the use of the the mechanism
-% ``|escape-math|'' is in fact rather different from that of the mechanism
-% ``|escape|''. Indeed, since the elements are composed in a mathématical mode
-% of LaTeX, they are, in particular, composed within a TeX group and therefore,
+% ``escape-math'' is in fact rather different from that of the mechanism
+% ``escape''. Indeed, since the elements are composed in a mathematical mode
+% of LaTeX, they are, in particular, composed within a TeX group and, therefore,
% they can't be used to change the formatting of other lexical units.
%
% In the languages where the character \verb|$| does not play a important role,
-% it's possible to activate that mechanism ``|escape-math|'' with the character
+% it's possible to activate that mechanism ``escape-math'' with the character
% \verb|$|:
% \begin{Verbatim}
% \PitonOptions{~emphase#begin-escape-math=$,end-escape-math=$@}
@@ -1715,7 +1724,8 @@
% Remark that the character \verb|$| must \emph{not} be protected by a backslash.
%
% \bigskip
-% However, it's probably more prudent to use |\(| et |\)|.
+% However, it's probably more prudent to use |\(| et |\)|, which are delimiters
+% of the mathematical mode provided by LaTeX.
% \begin{Verbatim}
% \PitonOptions{~emphase#begin-escape-math=\(,end-escape-math=\)@}
% \end{Verbatim}
@@ -1997,7 +2007,7 @@
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% \begin{Piton}
% def arctan(x,n=10):
% if x < 0:
@@ -2011,7 +2021,7 @@
% \endgroup
%
% \begingroup
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% \begin{Piton}
% def arctan(x,n=10):
% if x < 0:
@@ -2034,7 +2044,7 @@
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% \emphase\begin{minipage}{\linewidth}
% \begin{Piton}
% def arctan(x,n=10):
@@ -2050,7 +2060,7 @@
% \endgroup
%
% \begingroup
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% \begin{minipage}{\linewidth}
% \begin{Piton}
% def arctan(x,n=10):
@@ -2134,7 +2144,7 @@
% \index{numbers of the lines de code|emph}
%
% We remind that it's possible to have an automatic numbering of the lines in
-% the Python listings by using the key |line-numbers| (used without value).
+% the informatic listings by using the key |line-numbers| (used without value).
%
% By default, the numbers of the lines are composed by \pkg{piton} in an
% overlapping position on the left (by using internally the command |\llap| of LaTeX).
@@ -2147,7 +2157,7 @@
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% ~emphase&\PitonOptions{background-color=gray!10, left-margin = auto, line-numbers}@
+% ~emphase&\PitonOptions{background-color=gray!15, left-margin = auto, line-numbers}@
% \begin{Piton}
% def arctan(x,n=10):
% if x < 0:
@@ -2163,7 +2173,7 @@
%
%
% \begingroup
-% \PitonOptions{background-color=gray!10,left-margin = auto, line-numbers}
+% \PitonOptions{background-color=gray!15,left-margin = auto, line-numbers}
% \begin{Piton}
% def arctan(x,n=10):
% if x < 0:
@@ -2190,7 +2200,7 @@
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% ~emphase&\SetPitonStyle{Comment.LaTeX = \hfill \normalfont\color{gray}}@
% \begin{Piton}
% def arctan(x,n=10):
@@ -2205,7 +2215,7 @@
% \endgroup
%
% \begingroup
-% \PitonOptions{background-color=gray!10}
+% \PitonOptions{background-color=gray!15}
% \SetPitonStyle{Comment.LaTeX = \hfill \normalfont\color{gray}}
% \begin{Piton}
% def arctan(x,n=10):
@@ -2228,7 +2238,7 @@
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10, width=min}
+% \PitonOptions{background-color=gray!15, width=min}
% ~emphase&\NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}@
% ~emphase&\SetPitonStyle{Comment.LaTeX = \MyLaTeXCommand}@
% \begin{Piton}
@@ -2249,7 +2259,7 @@
%
%
% \begingroup
-% \PitonOptions{background-color=gray!10, width=min}
+% \PitonOptions{background-color=gray!15, width=min}
% \NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}
% \SetPitonStyle{Comment.LaTeX = \MyLaTeXCommand}
% \begin{Piton}
@@ -2415,51 +2425,55 @@
%
% \begin{center}
% \begin{tabularx}{\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
-% \toprule
-% \normalfont Style & Use \\
-% \midrule
-% Number & the numbers \\
-% String.Short & the short strings (entre \texttt{'} ou \texttt{"}) \\
-% String.Long & the long strings (entre \texttt{'''} ou \texttt{"""}) excepted
-% the doc-strings (governed by |String.Doc|)\\
-% String & that key fixes both |String.Short| et |String.Long| \\
-% String.Doc & the doc-strings (only with |"""| following PEP~257) \\
-% String.Interpol & the syntactic elements of the fields of the f-strings
-% (that is to say the characters \texttt{\{} et \texttt{\}}); that style
-% inherits for the styles |String.Short| and |String.Long| (according the kind
-% of string where the interpolation appears) \\
-% Interpol.Inside & the content of the interpolations in the f-strings (that
-% is to say the elements between \texttt{\{} and~\texttt{\}}); if the final
-% user has not set that key, those elements will be formatted by \pkg{piton}
-% as done for any Python code. \\
-% Operator & the following operators: \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \verb|@| \\
-% Operator.Word & the following operators: |in|, |is|, |and|, |or| et |not| \\
-% Name.Builtin & almost all the functions predefined by Python \\
-% Name.Decorator & the decorators (instructions beginning by \verb|@|) \\
-% Name.Namespace & the name of the modules \\
-% Name.Class & the name of the Python classes defined by the user \emph{at their point of definition} (with the keyword |class|) \\
-% Name.Function & the name of the Python functions defined by the user \emph{at their
-% point of definition} (with the keyword |def|) \\
-% UserFunction & the name of the Python functions previously defined by the user
-% (the initial value of that parameter is empty and, hence, these
-% elements are drawn, by default, in the current color, usually black) \\
-% Exception & les exceptions prédéfinies (ex.: \texttt{SyntaxError}) \\
-% InitialValues & the initial values (and the preceding symbol |=|) of the
-% optional arguments in the definitions of functions; if the final
-% user has not set that key, those elements will be formatted by \pkg{piton}
-% as done for any Python code. \\
-% Comment & the comments beginning with \texttt{\#} \\
-% Comment.LaTeX & the comments beginning with \texttt{\#>}, which are composed by
-% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
-% Keyword.Constant & |True|, |False| et |None| \\
-% Keyword & the following keywords:
-% \ttfamily assert, break, case, continue, del,
-% elif, else, except, exec, finally, for, from,
-% global, if, import, in, lambda, non local,
-% pass, raise, return, try, while,
-% with, yield et yield from.\\
-% Identifier & the identifiers. \\
-% \bottomrule
+% \toprule
+% \normalfont Style & Use \\
+% \midrule
+% Number & the numbers \\
+% String.Short & the short strings (entre \texttt{'} ou \texttt{"}) \\
+% String.Long & the long strings (entre \texttt{'''} ou \texttt{"""}) excepted
+% the doc-strings (governed by |String.Doc|)\\
+% String & that key fixes both |String.Short| et |String.Long| \\
+% String.Doc & the doc-strings (only with |"""| following PEP~257) \\
+% String.Interpol & the syntactic elements of the fields of the f-strings
+% (that is to say the characters \texttt{\{} et \texttt{\}}); that style
+% inherits for the styles |String.Short| and |String.Long| (according the kind
+% of string where the interpolation appears) \\
+% Interpol.Inside & the content of the interpolations in the f-strings (that
+% is to say the elements between \texttt{\{} and~\texttt{\}}); if the final
+% user has not set that key, those elements will be formatted by \pkg{piton}
+% as done for any Python code. \\
+% Operator & the following operators: \texttt{!= == << >> - \~{} + / * \% = < >
+% \& .} \verb+|+ \verb|@| \\
+% Operator.Word & the following operators: |in|, |is|, |and|, |or| et |not| \\
+% Name.Builtin & almost all the functions predefined by Python \\
+% Name.Decorator & the decorators (instructions beginning by \verb|@|) \\
+% Name.Namespace & the name of the modules \\
+% Name.Class & the name of the Python classes defined by the user \emph{at their
+% point of definition} (with the keyword |class|) \\
+% Name.Function & the name of the Python functions defined by the user \emph{at their
+% point of definition} (with the keyword |def|) \\
+% UserFunction & the name of the Python functions previously defined by the user
+% (the initial value of that parameter is
+% {\ttfamily \textbackslash PitonStyle\{Identifier\}} and,
+% therefore, the names of that functions are formatted like the
+% identifiers). \\
+% Exception & les exceptions prédéfinies (ex.: \texttt{SyntaxError}) \\
+% InitialValues & the initial values (and the preceding symbol |=|) of the
+% optional arguments in the definitions of functions; if the final
+% user has not set that key, those elements will be formatted by \pkg{piton}
+% as done for any Python code. \\
+% Comment & the comments beginning with \texttt{\#} \\
+% Comment.LaTeX & the comments beginning with \texttt{\#>}, which are composed by
+% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
+% Keyword.Constant & |True|, |False| et |None| \\
+% Keyword & the following keywords:
+% \ttfamily assert, break, case, continue, del,
+% elif, else, except, exec, finally, for, from,
+% global, if, import, in, lambda, non local,
+% pass, raise, return, try, while,
+% with, yield et yield from.\\
+% Identifier & the identifiers. \\
+% \bottomrule
% \end{tabularx}
% \end{center}
%
@@ -2468,23 +2482,13 @@
%
% \subsection{The language OCaml}
%
-% It's possible to switch to the language |OCaml| with |\PitonOptions{language = OCaml}|.
+% It's possible to switch to the language |OCaml| with the key |language|:
+% |language = OCaml|.
%
+%
% \bigskip
-% It's also possible to set the language OCaml for an individual environment |{Piton}|.
-% %
-% \begin{Verbatim}
-% \begin{Piton}~emphase#[language=OCaml]@
-% ...
-% \end{Piton}
-% \end{Verbatim}
%
-% \bigskip
-% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=OCaml]{...}|
%
-% \vspace{1cm}
-%
-%
% \begin{center}
% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
% \toprule
@@ -2503,9 +2507,10 @@
% 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 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) \\
+% UserFunction & the name of the Python functions previously defined by the user
+% (the initial value of that parameter is
+% {\ttfamily \textbackslash PitonStyle\{Identifier\}} and,
+% therefore, the names of that functions are formatted like the identifiers). \\
% Exception & the predefined exceptions (eg : |End_of_File|) \\
% TypeParameter & the parameters of the types \\
% Comment & the comments, between |(*| et |*)|; these comments may be nested \\
@@ -2528,22 +2533,10 @@
% \subsection[The language C (and C++)]{The language C (and \CC)}
%
%
-% It's possible to switch to the language |C| with |\PitonOptions{language = C}|.
+% It's possible to switch to the language |C| with the key |language|: |language = C|.
%
% \bigskip
-% It's also possible to set the language C for an individual environment |{Piton}|.
-% %
-% \begin{Verbatim}
-% \begin{Piton}~emphase#[language=C]@
-% ...
-% \end{Piton}
-% \end{Verbatim}
-%
-% \bigskip
-% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=C]{...}|
-%
-% \vspace{1cm}
-%
+%
% \begin{center}
% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
% \toprule
@@ -2553,18 +2546,23 @@
% String.Long & the strings (between \texttt{"}) \\
% String.Interpol & the elements \texttt{\%d}, \texttt{\%i}, \texttt{\%f},
% \texttt{\%c}, etc. in the strings; that style inherits from the style |String.Long| \\
-% Operator & the following operators : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \verb|@| \\
+% Operator & the following operators :
+% \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \verb|@| \\
% Name.Type & the following predefined types:
-% |bool|, |char|, |char16_t|, |char32_t|, |double|, |float|, |int|, |int8_t|, |int16_t|, |int32_t|,
-% |int64_t|, |long|, |short|, |signed|, |unsigned|, |void| et |wchar_t| \\
-% Name.Builtin & the following predefined functions: |printf|, |scanf|, |malloc|, |sizeof| and |alignof| \\
-% Name.Class & le nom des classes au moment de leur définition, c'est-à-dire
+% |bool|, |char|, |char16_t|, |char32_t|, |double|, |float|, |int|, |int8_t|,
+% |int16_t|, |int32_t|, |int64_t|, |long|, |short|, |signed|, |unsigned|,
+% |void| et |wchar_t| \\
+% Name.Builtin & the following predefined functions: |printf|, |scanf|,
+% |malloc|, |sizeof| and |alignof| \\
+% Name.Class & le nom des classes au moment de leur définition, c'est-à-dire
% après le mot-clé \verb|class| \\
-% Name.Function & the name of the Python functions defined by the user \emph{at their
+% 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
-% (the initial value of that parameter is empty and these
-% elements are drawn in the current color, usually black) \\
+% UserFunction & the name of the Python functions previously defined by the user
+% (the initial value of that parameter is
+% {\ttfamily \textbackslash PitonStyle\{Identifier\}} and,
+% therefore, the names of that functions are formatted like the
+% identifiers). \\
% Preproc & the instructions of the preprocessor (beginning par |#|) \\
% Comment & the comments (beginning by \texttt{//} or between |/*| and |*/|) \\
% Comment.LaTeX & the comments beginning by \texttt{//>} which are composed by
@@ -2573,10 +2571,10 @@
% Keyword & the following keywords:
% |alignas|, |asm|, |auto|, |break|, |case|, |catch|, |class|,
% |constexpr|, |const|, |continue|, |decltype|, |do|, |else|, |enum|,
-% |extern|, |for|, |goto|, |if|, |nexcept|, |private|, |public|, |register|, |restricted|, |try|,
-% |return|, |static|, |static_assert|, |struct|, |switch|, |thread_local|, |throw|,
-% |typedef|, |union|, |using|, |virtual|, |volatile| and |while|
-% \\
+% |extern|, |for|, |goto|, |if|, |nexcept|, |private|, |public|, |register|,
+% |restricted|, |try|, |return|, |static|, |static_assert|, |struct|, |switch|,
+% |thread_local|, |throw|, |typedef|, |union|, |using|, |virtual|, |volatile|
+% and |while| \\
% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
@@ -2587,23 +2585,10 @@
% \subsection{The language SQL}
%
%
-% It's possible to switch to the language |SQL| with |\PitonOptions{language = SQL}|.
+% It's possible to switch to the language |SQL| with the key |language|: |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
@@ -2642,28 +2627,48 @@
% \end{Verbatim}
%
% \newpage
+% \subsection{The languages defined by \textbackslash NewPitonLanguage}
%
-% \subsection{The language ``minimal''}
+% \vspace{1cm}
+% The command |\NewPitonLanguage|, which defines new informatic languages with the
+% syntax of the extension \pkg{listings}, has been described p.~\pageref{NewPitonLanguage}.
%
-% It's possible to switch to the language ``|minimal|'' with |\PitonOptions{language = minimal}|.
+% All the languages defined by the command |\NewPitonLanguage| use the same styles.
+% \vspace{1cm}
%
-% \bigskip
-% It's also possible to set the language ``|minimal|'' for an individual environment |{Piton}|.
-% %
-% \begin{Verbatim}
-% \begin{Piton}~emphase#[language=minimal]@
-% ...
-% \end{Piton}
-% \end{Verbatim}
+% \begin{center}
+% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+% \toprule
+% \normalfont Style & Use \\
+% \midrule
+% Number & the numbers \\
+% String.Long & the strings defined in |\NewPitonLanguage| by the key |morestring| \\
+% Comment & the comments defined in |\NewPitonLanguage| by the key |morecomment| \\
+% Comment.LaTeX & the comments which are composed by \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
+% Keyword & the keywords defined in |\NewPitonLanguage| by the keys |morekeywords|
+% and |moretexcs| (and also the key |sensitive| which specifies whether
+% the keywords are case-sensitive or not) \\
+% Directive & the directives defined in |\NewPitonLanguage| by the key
+% |moredirectives| \\
+% Tag & the ``tags'' defines by the key |tag| (the lexical units detected within
+% the tag will also be formatted with their own style) \\
+% Identifier & the identifiers. \\
+% \bottomrule
+% \end{tabularx}
+% \end{center}
%
-% \bigskip
-% The option exists also for |\PitonInputFile| : |\PitonInputFile[language=minimal]{...}|
%
%
+%
+% \subsection{The language ``minimal''}
+%
% \label{minimal}
%
-% \vspace{1cm}
+% It's possible to switch to the language ``|minimal|'' with the key |language|:
+% |language = minimal|.
%
+% \bigskip
+%
% \begin{center}
% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
% \toprule
@@ -2686,37 +2691,34 @@
% p.~\pageref{SetPitonIdentifier}) in order to create, for example, a language
% for pseudo-code.
%
-% \newpage
-% \subsection{The languages defined by \textbackslash NewPitonLanguage}
-%
% \vspace{1cm}
-% The command |\NewPitonLanguage|, which defines new informatic languages with the
-% syntax of the extension \pkg{listings}, has been described p.~\pageref{NewPitonLanguage}.
+%
+% \subsection{The language ``verbatim''}
%
-% All the languages defined by the command |\NewPitonLanguage| use the same styles.
-% \vspace{1cm}
+% \label{verbatim}
%
+% \colorbox{yellow!50}{\textbf{New 4.1}}
+%
+% It's possible to switch to the language ``|verbatim|'' with the key |language|:
+% |language = verbatim|.
+%
+% \bigskip
+%
% \begin{center}
% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
% \toprule
-% \normalfont Style & Use \\
+% \normalfont Style & Usage \\
% \midrule
-% Number & the numbers \\
-% String.Long & the strings defined in |\NewPitonLanguage| by the key |morestring| \\
-% Comment & the comments defined in |\NewPitonLanguage| by the key |morecomment| \\
-% Comment.LaTeX & the comments which are composed by \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
-% Keyword & the keywords defined in |\NewPitonLanguage| by the keys |morekeywords|
-% and |moretexcs| (and also the key |sensitive| which specifies whether
-% the keywords are case-sensitive or not) \\
-% Directive & the directives defined in |\NewPitonLanguage| by the key
-% |moredirectives| \\
-% Tag & the ``tags'' defines by the key |tag| (the lexical units detected within
-% the tag will also be formatted with their own style) \\
-% Identifier & the identifiers. \\
+% None... & \\
% \bottomrule
% \end{tabularx}
% \end{center}
%
+% The language |verbatim| doen't provide any style and, thus, does not do any
+% syntactic formating. However, it's possible to use the mechanism
+% |detected-commands| (cf. part~\ref{detected-commands},
+% p.~\pageref{detected-commands}) and the detection of the commands and
+% environments of Beamer.
%
%
% \newpage
@@ -2940,6 +2942,7 @@
\sys_if_engine_luatex:F { \msg_critical:nn { piton } { LuaLaTeX~mandatory } }
% \end{macrocode}
%
+%
% \bigskip
% \begin{macrocode}
\RequirePackage { luatexbase }
@@ -2963,12 +2966,10 @@
%
% \bigskip
% \begin{macrocode}
-\file_if_exist:nF { piton.lua }
- { \msg_fatal:nn { piton } { piton.lua~not~found } }
+\file_if_exist:nF { piton.lua } { \@@_fatal:n { piton.lua~not~found } }
% \end{macrocode}
%
%
-%
% \bigskip
% The boolean |\g_@@_footnotehyper_bool| will indicate if the option
% |footnotehyper| is used.
@@ -3139,7 +3140,7 @@
% \begin{macrocode}
\lua_now:n
{
- piton.BeamerCommands = lpeg.P ( [[\uncover]] )
+ piton.BeamerCommands = lpeg.P [[\uncover]]
+ [[\only]] + [[\visible]] + [[\invisible]] + [[\alert]] + [[\action]]
piton.beamer_environments = { "uncoverenv" , "onlyenv" , "visibleenv" ,
"invisibleenv" , "alertenv" , "actionenv" }
@@ -3345,7 +3346,13 @@
% \begin{macrocode}
\bool_new:N \l_@@_break_lines_in_piton_bool
% \end{macrocode}
+% However, the key |break-lines_in_piton| raises that boolean but also executes the
+% following instruction:
%
+% \quad |\tl_set_eq:NN \l_@@_space_in_string_tl \space|
+
+% The initial value of |\l_@@_space_in_string_tl| is |\nobreakspace|.
+%
% \bigskip
% The following dimension will be the width of the listing constructed by
% |{Piton}| or |\PitonInputFile|.
@@ -3460,9 +3467,11 @@
% \medskip
% The following token list will be used only for the spaces in the strings.
% \begin{macrocode}
-\tl_new:N \l_@@_space_tl
-\tl_set_eq:NN \l_@@_space_tl \nobreakspace
+\tl_set_eq:NN \l_@@_space_in_string_tl \nobreakspace
% \end{macrocode}
+% When the key |break-lines-in-piton| is set, that parameter will be replaced by
+% |\space| (in |\piton| with the standard syntax) and when the key
+% |show-spaces-in-strings| is set, it will be replaced by ␣ (U+2423).
%
%
% \medskip
@@ -3552,19 +3561,20 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_trailing_space: { }
% \end{macrocode}
-% When we have to rescan some pieces of code with |\@@_piton:n|, we will set
-% |\@@_trailing_space:| equal to |\space|.
+% When we have to rescan some pieces of code, we will use |\@@_piton:n|, which
+% we will set |\@@_trailing_space:| equal to |\space|.
%
% \bigskip
% \subsubsection{Treatment of a line of code}
%
% \begin{macrocode}
+\cs_generate_variant:Nn \@@_replace_spaces:n { o }
\cs_new_protected:Npn \@@_replace_spaces:n #1
{
\tl_set:Nn \l_tmpa_tl { #1 }
\bool_if:NTF \l_@@_show_spaces_bool
{
- \tl_set:Nn \l_@@_space_tl { ␣ } % U+2423
+ \tl_set:Nn \l_@@_space_in_string_tl { ␣ } % U+2423
\regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl
}
{
@@ -3582,7 +3592,7 @@
{ \c { @@_breakable_space: } }
\l_tmpa_tl
\regex_replace_all:nnN
- { \c { l_@@_space_tl } }
+ { \c { l_@@_space_in_string_tl } }
{ \c { @@_breakable_space: } }
\l_tmpa_tl
}
@@ -3651,6 +3661,11 @@
tex.sprint
(
luatexbase.catcodetables.expl ,
+% \end{macrocode}
+% Since the argument of |tostring| will be a integer of Lua (\emph{integer} is a
+% sub-type of \emph{number} introduced in Lua 5.3), the output will be of the
+% form |"3"| (and not |"3.0"|) which is what we want for |\int_set:Nn|.
+% \begin{macrocode}
tostring
( piton.empty_lines
[ \int_eval:n { \g_@@_line_int + 1 } ]
@@ -3662,12 +3677,9 @@
{ \int_compare_p:nNn \l_tmpa_int = \c_one_int }
{ ! \l_@@_skip_empty_lines_bool }
{ \int_gincr:N \g_@@_visual_line_int }
- \bool_if:nT
- {
- \int_compare_p:nNn \l_tmpa_int = \c_one_int
- ||
- ( ! \l_@@_skip_empty_lines_bool && \l_@@_label_empty_lines_bool )
- }
+ \bool_lazy_or:nnT
+ { \int_compare_p:nNn \l_tmpa_int = \c_one_int }
+ { ! \l_@@_skip_empty_lines_bool && \l_@@_label_empty_lines_bool }
\@@_print_number:
}
% \end{macrocode}
@@ -3717,8 +3729,8 @@
% or (if used) it is not used with the special value~|min|.
% In that case, the content of a line of code is composed in a vertical coffin
% with a width equal to |\l_@@_line_width_dim|. That coffin may,
-% eventually, contains several lines when the key |broken-lines-in-Piton| (or
-% |broken-lines|) is used.
+% eventually, contains several lines when the key |break-lines-in-Piton| (or
+% |break-lines|) is used.
%
% That commands takes in its argument by curryfication.
% \begin{macrocode}
@@ -3776,7 +3788,7 @@
% drawn with zero width and, thus, it will be a mere strut (and we need that strut).
% \begin{macrocode}
{ \dim_zero:N \l_@@_width_dim }
- { \exp_args:No \@@_color_i:n \l_tmpa_tl }
+ { \@@_color_i:o \l_tmpa_tl }
}
% \end{macrocode}
%
@@ -3783,6 +3795,7 @@
% The following command |\@@_color:n| will accept both the instruction
% |\@@_color:n { red!15 }| and the instruction |\@@_color:n { [rgb]{0.9,0.9,0} }|.
% \begin{macrocode}
+\cs_generate_variant:Nn \@@_color_i:n { o }
\cs_set_protected:Npn \@@_color_i:n #1
{
\tl_if_head_eq_meaning:nNTF { #1 } [
@@ -3989,6 +4002,8 @@
% \begin{macrocode}
\keys_define:nn { PitonOptions }
{
+ break-strings-anywhere .code:n =
+ \cs_set_eq:NN \@@_break_anywhere:n \@@_actually_break_anywhere:n ,
% \end{macrocode}
% First, we put keys that should be available only in the preamble.
% \begin{macrocode}
@@ -4042,10 +4057,10 @@
% \bigskip
% Now, general keys.
% \begin{macrocode}
- language .code:n =
+ language .code:n =
\str_set:Ne \l_piton_language_str { \str_lowercase:n { #1 } } ,
- language .value_required:n = true ,
- path .code:n =
+ language .value_required:n = true ,
+ path .code:n =
\seq_clear:N \l_@@_path_seq
\clist_map_inline:nn { #1 }
{
@@ -4075,7 +4090,7 @@
splittable-on-empty-lines .default:n = true ,
split-on-empty-lines .bool_set:N = \l_@@_split_on_empty_lines_bool ,
- split-on-empty-lines .default:n = true ,
+ split-on-empty-lines .default:n = true ,
split-separation .tl_set:N = \l_@@_split_separation_tl ,
split-separation .value_required:n = true ,
@@ -4130,7 +4145,8 @@
tab-size .value_required:n = true ,
show-spaces .bool_set:N = \l_@@_show_spaces_bool ,
show-spaces .value_forbidden:n = true ,
- show-spaces-in-strings .code:n = \tl_set:Nn \l_@@_space_tl { ␣ } , % U+2423
+ show-spaces-in-strings .code:n =
+ \tl_set:Nn \l_@@_space_in_string_tl { ␣ } , % U+2423
show-spaces-in-strings .value_forbidden:n = true ,
break-lines-in-Piton .bool_set:N = \l_@@_break_lines_in_Piton_bool ,
break-lines-in-Piton .default:n = true ,
@@ -4171,7 +4187,7 @@
range .value_required:n = true ,
env-used-by-split .code:n =
- \lua_now:n { piton.env_used_by_split = '#1'} ,
+ \lua_now:n { piton.env_used_by_split = '#1' } ,
env-used-by-split .initial:n = Piton ,
resume .meta:n = line-numbers/resume ,
@@ -4182,7 +4198,7 @@
all-line-numbers .code:n =
\bool_set_true:N \l_@@_line_numbers_bool
\bool_set_false:N \l_@@_skip_empty_lines_bool ,
- all-line-numbers .value_forbidden:n = true ,
+ all-line-numbers .value_forbidden:n = true
}
% \end{macrocode}
%
@@ -4380,11 +4396,12 @@
% |\AtBeginDocument|. Hence, we will put also in a |\AtBeginDocument| the
% utilisation of the Lua function |piton.new_language| (which does the main job).
% \begin{macrocode}
- \exp_args:No \@@_NewPitonLanguage:nn \l_tmpa_tl { #3 }
+ \@@_NewPitonLanguage:on \l_tmpa_tl { #3 }
}
% \end{macrocode}
%
% \begin{macrocode}
+\cs_generate_variant:Nn \@@_NewPitonLanguage:nn { o }
\cs_new_protected:Npn \@@_NewPitonLanguage:nn #1 #2
{
\hook_gput_code:nnn { begindocument } { . }
@@ -4404,8 +4421,8 @@
% \begin{macrocode}
\tl_set:Ne \l_tmpa_tl
{
- \tl_if_blank:nF { #3 } { [ \str_lowercase:n { #3 } ] }
- \str_lowercase:n { #4 }
+ \tl_if_blank:nF { #3 } { [ \str_lowercase:n { #3 } ] }
+ \str_lowercase:n { #4 }
}
% \end{macrocode}
% We retrieve in |\l_tmpb_tl| the definition (as provided by the final user) of
@@ -4424,6 +4441,7 @@
%
% \bigskip
% \begin{macrocode}
+\cs_generate_variant:Nn \@@_NewPitonLanguage:nnnn { n n n o }
\cs_new_protected:Npn \@@_NewPitonLanguage:nnnn #1 #2 #3 #4
% \end{macrocode}
% In the following line, we write |#4,#3| and not |#3,#4| because we want that the
@@ -4431,7 +4449,6 @@
% in the language we define.
% \begin{macrocode}
{ \@@_NewPitonLanguage:nnn { #1 } { #2 } { #4 , #3 } }
-\cs_generate_variant:Nn \@@_NewPitonLanguage:nnnn { n n n o }
% \end{macrocode}
%
% \bigskip
@@ -4444,8 +4461,10 @@
\NewDocumentCommand { \@@_piton_standard } { m }
{
\group_begin:
+ \bool_if:NT \l_@@_break_lines_in_piton_bool
+ { \tl_set_eq:NN \l_@@_space_in_string_tl \space }
% \end{macrocode}
-% The following tuning of LuaTeX in order to avoid all break of lines on the
+% The following tuning of LuaTeX in order to avoid all breaks of lines on the
% hyphens.
% \begin{macrocode}
\automatichyphenmode = 1
@@ -4523,11 +4542,11 @@
% \bigskip
%
%
-% \bigskip
-% The following command is not a user command. It will be used when we will
-% have to ``rescan'' some chunks of informatic code. For example, it will be the
-% initial value of the Piton style |InitialValues| (the default values of the
-% arguments of a Python function).
+% \bigskip
+% The following command does \emph{not} correspond to a user command. It will
+% be used when we will have to ``rescan'' some chunks of informatic code. For
+% example, it will be the initial value of the Piton style |InitialValues| (the
+% default values of the arguments of a Python function).
% \begin{macrocode}
\cs_new_protected:Npn \@@_piton:n #1
{ \tl_if_blank:nF { #1 } { \@@_piton_i:n { #1 } } }
@@ -4547,7 +4566,7 @@
}
\bool_if:NT \l_@@_show_spaces_bool
{ \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \exp_args:No \@@_replace_spaces:n \l_tmpa_tl
+ \@@_replace_spaces:o \l_tmpa_tl
\group_end:
}
% \end{macrocode}
@@ -4589,6 +4608,7 @@
% 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}
+\cs_generate_variant:Nn \@@_compute_left_margin:nn { n o }
\cs_new_protected:Npn \@@_compute_left_margin:nn #1 #2
{
\bool_lazy_and:nnT \l_@@_left_margin_auto_bool \l_@@_line_numbers_bool
@@ -4613,7 +4633,6 @@
{ \box_wd:N \l_tmpa_box + \l_@@_numbers_sep_dim + 0.1 em }
}
}
-\cs_generate_variant:Nn \@@_compute_left_margin:nn { n o }
% \end{macrocode}
%
%
@@ -5046,8 +5065,8 @@
% unlikely, suffixes) added to the markers by the functions
% |\@@_marker_beginning:n| and |\@@_marker_end:n|
% \begin{macrocode}
- \exp_args:Nno \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpa_str
- \exp_args:Nno \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpb_str
+ \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpa_str
+ \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpb_str
\lua_now:e
{
piton.ComputeRange
@@ -5151,14 +5170,14 @@
{
#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 }
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l_@@_SetPitonStyle_option_str
+ { \l_@@_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
}
}
@@ -5166,8 +5185,6 @@
{
String .meta:n = { String.Long = #1 , String.Short = #1 } ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
- ParseAgain .value_required:n = true ,
unknown .code:n =
\@@_error:n { Unknown~key~for~SetPitonStyle }
}
@@ -5178,7 +5195,8 @@
\SetPitonStyle[OCaml]
{
TypeExpression =
- \SetPitonStyle { Identifier = \PitonStyle { Name.Type } } \@@_piton:n ,
+ \SetPitonStyle { Identifier = \PitonStyle { Name.Type } }
+ \@@_piton:n ,
}
% \end{macrocode}
%
@@ -5201,8 +5219,19 @@
}
% \end{macrocode}
%
-%
% \bigskip
+% \begin{macrocode}
+\cs_set_eq:NN \@@_break_anywhere:n \prg_do_nothing:
+\cs_new_protected:Npn \@@_actually_break_anywhere:n #1
+ {
+ \seq_clear:N \l_tmpa_seq
+ \tl_map_inline:nn { #1 }
+ { \seq_put_right:Nn \l_tmpa_seq { ##1 } }
+ \seq_use:Nn \l_tmpa_seq { \- }
+ }
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{The initial styles}
%
% The initial styles are inspired by the style ``manni'' of Pygments.
@@ -5228,13 +5257,13 @@
Number = \color[HTML]{FF6600} ,
Operator = \color[HTML]{555555} ,
Operator.Word = \bfseries ,
- String = \color[HTML]{CC3300} ,
+ String = \color[HTML]{CC3300} \@@_break_anywhere:n ,
String.Doc = \color[HTML]{CC3300} \itshape ,
String.Interpol = \color[HTML]{AA0000} ,
Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
Name.Type = \color[HTML]{336666} ,
InitialValues = \@@_piton:n ,
- Interpol.Inside = \color{black}\@@_piton:n ,
+ Interpol.Inside = \l_@@_font_command_tl \@@_piton:n ,
TypeParameter = \color[HTML]{336666} \itshape ,
Preproc = \color[HTML]{AA6600} \slshape ,
% \end{macrocode}
@@ -5246,15 +5275,11 @@
Identifier = ,
Directive = \color[HTML]{AA6600} ,
Tag = \colorbox{gray!10},
- UserFunction = ,
+ UserFunction = \PitonStyle{Identifier} ,
Prompt = ,
- ParseAgain = \@@_piton_no_cr:n ,
Discard = \use_none:n
}
% \end{macrocode}
-% The styles |ParseAgain.noCR| should be considered as
-% ``internal style'' (not available for the final user). However, maybe we will
-% change that and document that style for the final user.
%
% \medskip
% If the key |math-comments| has been used in the preamble of the LaTeX
@@ -5301,7 +5326,7 @@
\cs_if_exist_use:cF { PitonIdentifier _ \l_piton_language_str _ #1 }
{
\cs_if_exist_use:cF { PitonIdentifier _ #1 }
- { \PitonStyle { Identifier } }
+ { \PitonStyle { Identifier } }
}
{ #1 }
}
@@ -5375,12 +5400,13 @@
% \bigskip
% \begin{macrocode}
\cs_new_protected:Npn \@@_clear_functions_i:n #1
- { \exp_args:Ne \@@_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+ { \@@_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_generate_variant:Nn \@@_clear_functions_ii:n { e }
\cs_new_protected:Npn \@@_clear_functions_ii:n #1
{
\seq_if_exist:cT { g_@@_functions _ #1 _ seq }
@@ -5417,7 +5443,7 @@
%
% \begin{macrocode}
\AddToHook { env / piton / begin }
- { \msg_fatal:nn { piton } { No~environment~piton } }
+ { \@@_fatal:n { No~environment~piton } }
\msg_new:nnn { piton } { No~environment~piton }
{
@@ -5587,6 +5613,7 @@
break-lines,~
break-lines-in-piton,~
break-lines-in-Piton,~
+ break-strings-anywhere,~
continuation-symbol,~
continuation-symbol-on-indentation,~
detected-beamer-commands,~
@@ -5651,7 +5678,7 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_test_version:n #1
{
- \str_if_eq:VnF \PitonFileVersion { #1 }
+ \str_if_eq:onF \PitonFileVersion { #1 }
{ \@@_error:n { bad~version~of~piton.lua } }
}
% \end{macrocode}
@@ -5679,11 +5706,12 @@
lpeg.locale(lpeg)
local P , alpha , C , space , S , V
= lpeg.P , lpeg.alpha , lpeg.C , lpeg.space , lpeg.S , lpeg.V
- local function add(...)
- local s = P ( false )
- for _ , x in ipairs({...}) do s = s + x end
- return s
- end
+ local add
+ function add(...)
+ local s = P ( false )
+ for _ , x in ipairs({...}) do s = s + x end
+ return s
+ end
local my_lpeg =
P { "E" ,
E = ( V "F" * ( "," * V "F" ) ^ 0 ) / add ,
@@ -5694,7 +5722,7 @@
% \begin{macrocode}
F = space ^ 0 * ( ( alpha ^ 1 ) / "\\%0" ) * space ^ 0
}
- function piton.addDetectedCommands( key_value )
+ function piton.addDetectedCommands ( key_value )
piton.DetectedCommands = piton.DetectedCommands + my_lpeg : match ( key_value )
end
function piton.addBeamerCommands( key_value )
@@ -5704,11 +5732,12 @@
% \end{macrocode}
%
% \begin{macrocode}
- local function insert(...)
- local s = piton.beamer_environments
- for _ , x in ipairs({...}) do table.insert(s,x) end
- return s
- end
+ local insert
+ function insert(...)
+ local s = piton.beamer_environments
+ for _ , x in ipairs({...}) do table.insert(s,x) end
+ return s
+ end
local my_lpeg_bis =
P { "E" ,
E = ( V "F" * ( "," * V "F" ) ^ 0 ) / insert ,
@@ -5734,14 +5763,15 @@
%
% \begin{macrocode}
%<*LUA>
-if piton.comment_latex == nil then piton.comment_latex = ">" end
+piton.comment_latex = piton.comment_latex or ">"
piton.comment_latex = "#" .. piton.comment_latex
% \end{macrocode}
%
%
% \begin{macrocode}
-local function sprintL3 ( s )
- tex.sprint ( luatexbase.catcodetables.expl , s )
+local sprintL3
+function sprintL3 ( s )
+ tex.sprint ( luatexbase.catcodetables.expl , s )
end
% \end{macrocode}
%
@@ -5763,10 +5793,11 @@
% The function |Q| takes in as argument a pattern and returns a \textsc{lpeg}
% \emph{which does a capture} of the pattern. That capture will be sent to LaTeX
% with the catcode ``other'' for all the characters: it's suitable for elements
-% of the Python listings that \pkg{piton} will typeset verbatim (thanks to the
+% of the informatic listings that \pkg{piton} will typeset verbatim (thanks to the
% catcode ``other'').
% \begin{macrocode}
-local function Q ( pattern )
+local Q
+function Q ( pattern )
return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
end
% \end{macrocode}
@@ -5780,8 +5811,9 @@
% comments'' in the environments |{Piton}| and the elements between
% |begin-escape| and |end-escape|. That function won't be much used.
% \begin{macrocode}
-local function L ( pattern )
- return Ct ( C ( pattern ) )
+local L
+function L ( pattern ) return
+ Ct ( C ( pattern ) )
end
% \end{macrocode}
%
@@ -5793,8 +5825,9 @@
% in order to do the syntactic highlighting (that's the main job of
% \pkg{piton}). That function, unlike the previous one, will be widely used.
% \begin{macrocode}
-local function Lc ( string )
- return Cc ( { luatexbase.catcodetables.expl , string } )
+local Lc
+function Lc ( string ) return
+ Cc ( { luatexbase.catcodetables.expl , string } )
end
% \end{macrocode}
%
@@ -5806,11 +5839,11 @@
% a \pkg{piton} style and the second element is a pattern (that is to say a
% \textsc{lpeg} without capture)
% \begin{macrocode}e
-local function K ( style , pattern )
- return
- Lc ( "{\\PitonStyle{" .. style .. "}{" )
- * Q ( pattern )
- * Lc "}}"
+local K
+function K ( style , pattern ) return
+ Lc ( [[ {\PitonStyle{ ]] .. style .. "}{" )
+ * Q ( pattern )
+ * Lc "}}"
end
% \end{macrocode}
% The formatting commands in a given \pkg{piton} style (eg. the style |Keyword|)
@@ -5824,11 +5857,11 @@
% 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
- Ct ( Cc "Open" * Cc ( "{\\PitonStyle{" .. style .. "}{" ) * Cc "}}" )
- * pattern
- * Ct ( Cc "Close" )
+local WithStyle
+function WithStyle ( style , pattern ) return
+ Ct ( Cc "Open" * Cc ( [[{\PitonStyle{]] .. style .. "}{" ) * Cc "}}" )
+ * pattern
+ * Ct ( Cc "Close" )
end
% \end{macrocode}
%
@@ -5838,8 +5871,7 @@
% \begin{macrocode}
Escape = P ( false )
EscapeClean = P ( false )
-if piton.begin_escape ~= nil
-then
+if piton.begin_escape then
Escape =
P ( piton.begin_escape )
* L ( ( 1 - P ( piton.end_escape ) ) ^ 1 )
@@ -5857,13 +5889,12 @@
%
% \begin{macrocode}
EscapeMath = P ( false )
-if piton.begin_escape_math ~= nil
-then
+if piton.begin_escape_math then
EscapeMath =
P ( piton.begin_escape_math )
* Lc "\\ensuremath{"
* L ( ( 1 - P(piton.end_escape_math) ) ^ 1 )
- * Lc ( "}" )
+ * Lc "}"
* P ( piton.end_escape_math )
end
% \end{macrocode}
@@ -5933,27 +5964,23 @@
% \end{macrocode}
%
% \bigskip
+% We will now define the LPEG |Word|.
+%
+% We have a problem in the following LPEG because, obviously, we should adjust
+% the list of symbols with the delimiters of the current language (no?).
+% \begin{macrocode}
+local lpeg_central = 1 - S " '\"\r[({})]" - digit
+% \end{macrocode}
% We recall that |piton.begin_escape| and |piton_end_escape| are Lua strings
% corresponding to the keys |begin-escape| and |end-escape|.
% \begin{macrocode}
-local Word
if piton.begin_escape then
- if piton.begin_escape_math then
- Word = Q ( ( 1 - space - piton.begin_escape - piton.end_escape
- - piton.begin_escape_math - piton.end_escape_math
- - S "'\"\r[({})]" - digit ) ^ 1 )
- else
- Word = Q ( ( 1 - space - piton.begin_escape - piton.end_escape
- - S "'\"\r[({})]" - digit ) ^ 1 )
- end
-else
- if piton.begin_escape_math then
- Word = Q ( ( 1 - space - piton.begin_escape_math - piton.end_escape_math
- - S "'\"\r[({})]" - digit ) ^ 1 )
- else
- Word = Q ( ( 1 - space - S "'\"\r[({})]" - digit ) ^ 1 )
- end
+ lpeg_central = lpeg_central - piton.begin_escape
end
+if piton.begin_escape_math then
+ lpeg_central = lpeg_central - piton.begin_escape_math
+end
+local Word = Q ( lpeg_central ^ 1 )
% \end{macrocode}
%
% \bigskip
@@ -5964,14 +5991,14 @@
local Punct = Q ( S ".,:;!" )
-local Tab = "\t" * Lc [[\@@_tab:]]
+local Tab = "\t" * Lc [[ \@@_tab: ]]
% \end{macrocode}
%
% \bigskip
% Remember that |\@@_leading_space:| does \emph{not} create a space, only an
-% incrementation of the coutnter |\g_@@_indentation_int|.
+% incrementation of the counter |\g_@@_indentation_int|.
% \begin{macrocode}
-local SpaceIndentation = Lc [[\@@_leading_space:]] * Q " "
+local SpaceIndentation = Lc [[ \@@_leading_space: ]] * Q " "
% \end{macrocode}
%
% \bigskip
@@ -5979,28 +6006,18 @@
local Delim = Q ( S "[({})]" )
% \end{macrocode}
%
-% \bigskip
+% \bigskip
% The following \textsc{lpeg} catches a space (U+0020) and replace it by
-% |\l_@@_space_tl|. It will be used in the strings. Usually,
-% |\l_@@_space_tl| will contain a space and therefore there won't be difference.
-% However, when the key |show-spaces-in-strings| is in force, |\\l_@@_space_tl| will
-% contain ␣ (U+2423) in order to visualize the spaces.
+% |\l_@@_space_in_string_tl|. It will be used in the strings. Usually,
+% |\l_@@_space_in_string_tl| will contain a space and therefore there won't be
+% difference. However, when the key |show-spaces-in-strings| is in force,
+% |\\l_@@_space_in_string_tl| will contain ␣ (U+2423) in order to visualize the
+% spaces.
% \begin{macrocode}
-local VisualSpace = space * Lc [[\l_@@_space_tl]]
+local SpaceInString = space * Lc [[ \l_@@_space_in_string_tl ]]
% \end{macrocode}
%
% \bigskip
-% Of course, the \textsc{lpeg} |strict_braces| is for balanced braces (without the
-% question of strings of an informatic language).
-% \begin{macrocode}
- local strict_braces =
- P { "E" ,
- E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
- F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
- }
-% \end{macrocode}
-%
-% \bigskip
% \paragraph{Several tools for the construction of the main LPEG}
%
% \begin{macrocode}
@@ -6019,17 +6036,18 @@
% the language (at least the shorts strings). The argument of |Compute_braces|
% must be a pattern \emph{which does no catching}.
% \begin{macrocode}
-local function Compute_braces ( lpeg_string ) return
- P { "E" ,
- E =
- (
- "{" * V "E" * "}"
- +
- lpeg_string
- +
- ( 1 - S "{}" )
- ) ^ 0
- }
+local Compute_braces
+function Compute_braces ( lpeg_string ) return
+ P { "E" ,
+ E =
+ (
+ "{" * V "E" * "}"
+ +
+ lpeg_string
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
end
% \end{macrocode}
%
@@ -6039,13 +6057,20 @@
% The following Lua function will compute the \text{lpeg} |DetectedCommands|
% which is a \textsc{lpeg} with captures.
% \begin{macrocode}
-local function Compute_DetectedCommands ( lang , braces ) return
- Ct ( Cc "Open"
+local Compute_DetectedCommands
+function Compute_DetectedCommands ( lang , braces ) return
+ Ct (
+ Cc "Open"
* C ( piton.DetectedCommands * space ^ 0 * P "{" )
* Cc "}"
)
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return
+ LPEG1[lang] : match ( s )
+ end
+ end )
+ )
* P "}"
* Ct ( Cc "Close" )
end
@@ -6053,11 +6078,16 @@
%
% \bigskip
% \begin{macrocode}
-local function Compute_LPEG_cleaner ( lang , braces ) return
+local Compute_LPEG_cleaner
+function Compute_LPEG_cleaner ( lang , braces ) return
Ct ( ( piton.DetectedCommands * "{"
* ( braces
/ ( function ( s )
- if s ~= '' then return LPEG_cleaner[lang] : match ( s ) end end ) )
+ if s ~= '' then return
+ LPEG_cleaner[lang] : match ( s )
+ end
+ end )
+ )
* "}"
+ EscapeClean
+ C ( P ( 1 ) )
@@ -6065,7 +6095,30 @@
end
% \end{macrocode}
%
+% \bigskip
+% The following function |ParseAgain| will be used in the definitions of the
+% LPEG of the different informatic languages when we will need to
+% \emph{parse again} a small chunk of code. It's a way to avoid the use of a actual
+% \emph{grammar} of LPEG (in a sens, a recursive regular expression).
%
+% Remark that there is no \pkg{piton} style associated to a chunk of code which
+% is analyzed by |ParseAgain|. If we wish a \pkg{piton} style available to the
+% final user (if he wish to format that element with a uniform font instead of
+% an analyze by |ParseAgain|), we have to use |\@@_piton:n|.
+% \begin{macrocode}
+local ParseAgain
+function ParseAgain ( code )
+ if code ~= '' then return
+% \end{macrocode}
+% The variable |piton.language| is set in the function |piton.Parse|.
+% \begin{macrocode}
+ LPEG1[piton.language] : match ( code )
+ end
+end
+% \end{macrocode}
+%
+%
+%
% \bigskip
% \paragraph{Constructions for Beamer}
%
@@ -6091,7 +6144,7 @@
( space ^ 0 *
L
(
- P "\\begin{" * piton.BeamerEnvironments * "}"
+ P [[\begin{]] * piton.BeamerEnvironments * "}"
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
)
* "\r"
@@ -6102,7 +6155,7 @@
% \begin{macrocode}
BeamerEndEnvironments =
( space ^ 0 *
- L ( P "\\end{" * piton.BeamerEnvironments * "}" )
+ L ( P [[\end{]] * piton.BeamerEnvironments * "}" )
* "\r"
) ^ 0
% \end{macrocode}
@@ -6113,7 +6166,8 @@
% The following Lua function will be used to compute the \textsc{lpeg} |Beamer|
% for each informatic language.
% \begin{macrocode}
-local function Compute_Beamer ( lang , braces )
+local Compute_Beamer
+function Compute_Beamer ( lang , braces )
% \end{macrocode}
%
% \smallskip
@@ -6136,11 +6190,11 @@
%
%
% \bigskip
-% For the command |\\alt|, the specification of the overlays (between angular
+% For the command |\alt|, the specification of the overlays (between angular
% brackets) is mandatory.
% \begin{macrocode}
lpeg = lpeg +
- L ( P [[\alt]] * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
+ L ( P [[\alt]] * "<" * ( 1 - P ">" ) ^ 0 * ">{" )
* ( braces /
( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
@@ -6150,11 +6204,11 @@
% \end{macrocode}
%
% \bigskip
-% For |\\temporal|, the specification of the overlays (between angular brackets)
+% For |\temporal|, the specification of the overlays (between angular brackets)
% is mandatory.
% \begin{macrocode}
lpeg = lpeg +
- L ( ( P [[\temporal]] ) * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
+ L ( P [[\temporal]] * "<" * ( 1 - P ">" ) ^ 0 * ">{" )
* ( braces
/ ( function ( s )
if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
@@ -6173,24 +6227,24 @@
% Now, the environments of Beamer.
% \begin{macrocode}
for _ , x in ipairs ( piton.beamer_environments ) do
- lpeg = lpeg +
- Ct ( Cc "Open"
- * C (
- P ( "\\begin{" .. x .. "}" )
- * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
- )
- * Cc ( "\\end{" .. x .. "}" )
- )
- * (
- ( ( 1 - P ( "\\end{" .. x .. "}" ) ) ^ 0 )
- / ( function ( s )
- if s ~= ''
- then return LPEG1[lang] : match ( s )
- end
- end )
- )
- * P ( "\\end{" .. x .. "}" )
- * Ct ( Cc "Close" )
+ lpeg = lpeg +
+ Ct ( Cc "Open"
+ * C (
+ P ( [[\begin{]] .. x .. "}" )
+ * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
+ )
+ * Cc ( [[\end{]] .. x .. "}" )
+ )
+ * (
+ ( ( 1 - P ( [[\end{]] .. x .. "}" ) ) ^ 0 )
+ / ( function ( s )
+ if s ~= '' then return
+ LPEG1[lang] : match ( s )
+ end
+ end )
+ )
+ * P ( [[\end{]] .. x .. "}" )
+ * Ct ( Cc "Close" )
end
% \end{macrocode}
%
@@ -6223,7 +6277,7 @@
% |\@@_begin_line:|, it's too late to change de background).
% \begin{macrocode}
local PromptHastyDetection =
- ( # ( P ">>>" + "..." ) * Lc [[\@@_prompt:]] ) ^ -1
+ ( # ( 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.
@@ -6256,7 +6310,7 @@
Ct (
Cc "EOL"
*
- Ct ( Lc [[\@@_end_line:]]
+ Ct ( Lc [[ \@@_end_line: ]]
* BeamerEndEnvironments
*
(
@@ -6271,7 +6325,7 @@
+
BeamerBeginEnvironments
* PromptHastyDetection
- * Lc [[\@@_newline:\@@_begin_line:]]
+ * Lc [[ \@@_newline:\@@_begin_line: ]]
* Prompt
)
)
@@ -6291,11 +6345,10 @@
P ( piton.comment_latex )
* Lc [[{\PitonStyle{Comment.LaTeX}{\ignorespaces]]
* L ( ( 1 - P "\r" ) ^ 0 )
- * Lc [[}}]]
+ * Lc "}}"
* ( EOL + -1 )
% \end{macrocode}
%
-%
%
% \bigskip
% \subsubsection{The language Python}
@@ -6513,7 +6566,7 @@
* Q ( P ":" * ( 1 - S "}:'" ) ^ 0 ) ^ -1
* K ( 'String.Interpol' , "}" )
+
- VisualSpace
+ SpaceInString
+
Q ( ( P "\\'" + "\\\\" + "{{" + "}}" + 1 - S " {}'" ) ^ 1 )
) ^ 0
@@ -6524,7 +6577,7 @@
% \begin{macrocode}
Q ( P "'" + "r'" + "R'" )
* ( Q ( ( P "\\'" + "\\\\" + 1 - S " '\r%" ) ^ 1 )
- + VisualSpace
+ + SpaceInString
+ PercentInterpol
+ Q "%"
) ^ 0
@@ -6541,7 +6594,7 @@
* ( K ( 'String.Interpol' , ":" ) * Q ( (1 - S "}:\"") ^ 0 ) ) ^ -1
* K ( 'String.Interpol' , "}" )
+
- VisualSpace
+ SpaceInString
+
Q ( ( P "\\\"" + "\\\\" + "{{" + "}}" + 1 - S " {}\"" ) ^ 1 )
) ^ 0
@@ -6549,7 +6602,7 @@
+
Q ( P "\"" + "r\"" + "R\"" )
* ( Q ( ( P "\\\"" + "\\\\" + 1 - S " \"\r%" ) ^ 1 )
- + VisualSpace
+ + SpaceInString
+ PercentInterpol
+ Q "%"
) ^ 0
@@ -6589,7 +6642,7 @@
% \paragraph{LPEG_cleaner}
%
% \begin{macrocode}
- LPEG_cleaner['python'] = Compute_LPEG_cleaner ( 'python' , braces )
+ LPEG_cleaner.python = Compute_LPEG_cleaner ( 'python' , braces )
% \end{macrocode}
%
% \bigskip
@@ -6751,12 +6804,9 @@
* SkipSpace
* ( Q "->" * SkipSpace * K ( 'Name.Type' , identifier ) ) ^ -1
% \end{macrocode}
-% Here, we need a \pkg{piton} style |ParseAgain.noCR| which will be linked to
-% |\@@_piton_no_cr:n| (that means that the capture will be parsed once again by
-% \pkg{piton}). We could avoid that kind of trick by using a non-terminal of a
-% grammar but we have probably here a better legibility.
+%
% \begin{macrocode}
- * K ( 'ParseAgain.noCR' , ( 1 - S ":\r" ) ^ 0 )
+ * ( C ( ( 1 - S ":\r" ) ^ 0 ) / ParseAgain )
* Q ":"
* ( SkipSpace
* ( EOL + CommentLaTeX + Comment ) -- in all cases, that contains an EOL
@@ -6786,7 +6836,9 @@
% \paragraph{The main LPEG for the language Python}
%
% \begin{macrocode}
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
% \end{macrocode}
%
% First, the main loop :
@@ -6821,9 +6873,9 @@
% \end{macrocode}
%
% \bigskip
-% Here, we must not put |local|!
+% Here, we must not put |local|, of course.
% \begin{macrocode}
- LPEG1['python'] = Main ^ 0
+ LPEG1.python = Main ^ 0
% \end{macrocode}
%
% \bigskip
@@ -6833,17 +6885,17 @@
% will be used as marker in order to delimit the argument of the command
% \texttt{\textbackslash @@\_begin\_line:}}.
% \begin{macrocode}
- LPEG2['python'] =
+ LPEG2.python =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* Prompt
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
@@ -6879,30 +6931,30 @@
Beamer = Compute_Beamer ( 'ocaml' , braces )
end
DetectedCommands = Compute_DetectedCommands ( 'ocaml' , braces )
- local function Q ( pattern )
- return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther )
- * C ( pattern ) )
- + Beamer + DetectedCommands + EscapeMath + Escape
+ local Q
+ function Q ( pattern ) return
+ Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
+ + Beamer + DetectedCommands + EscapeMath + Escape
end
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
- local function K ( style , pattern )
- return
- Lc ( "{\\PitonStyle{" .. style .. "}{" )
- * Q ( pattern )
- * Lc "}}"
+ local K
+ function K ( style , pattern ) return
+ Lc ( [[ {\PitonStyle{ ]] .. style .. "}{" )
+ * Q ( pattern )
+ * Lc "}}"
end
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
- local function WithStyle ( style , pattern )
- return
- Ct ( Cc "Open" * Cc ( "{\\PitonStyle{" .. style .. "}{" ) * Cc "}}" )
- * ( pattern + Beamer + DetectedCommands + EscapeMath + Escape )
- * Ct ( Cc "Close" )
+ local WithStyle
+ function WithStyle ( style , pattern ) return
+ Ct ( Cc "Open" * Cc ( [[{\PitonStyle{]] .. style .. "}{" ) * Cc "}}" )
+ * ( pattern + Beamer + DetectedCommands + EscapeMath + Escape )
+ * Ct ( Cc "Close" )
end
% \end{macrocode}
%
@@ -6919,7 +6971,7 @@
local ocaml_string =
Q "\""
* (
- VisualSpace
+ SpaceInString
+
Q ( ( 1 - S " \"\r" ) ^ 1 )
+
@@ -7065,7 +7117,8 @@
% \bigskip
% \begin{macrocode}
local EndKeyword
- = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape
+ + EscapeMath + -1
% \end{macrocode}
%
% \bigskip
@@ -7157,9 +7210,7 @@
local OneField =
K ( 'Name.Field' , identifier ) * SkipSpace
* Q "=" * SkipSpace
- * ( expression_for_fields_value
- / ( function ( s ) return LPEG1['ocaml'] : match ( s ) end )
- )
+ * ( expression_for_fields_value / ParseAgain )
* SkipSpace
% \end{macrocode}
%
@@ -7228,7 +7279,7 @@
%
% \bigskip
% \begin{macrocode}
- LPEG_cleaner['ocaml'] = Compute_LPEG_cleaner ( 'ocaml' , braces )
+ LPEG_cleaner.ocaml = Compute_LPEG_cleaner ( 'ocaml' , braces )
% \end{macrocode}
%
% \bigskip
@@ -7364,7 +7415,7 @@
% \end{macrocode}
% For the labels (maybe we will write in the future a dedicated LPEG pour those tokens).
% \begin{macrocode}
- + Q ( "~" ) * Identifier * ( Q ":" ) ^ -1
+ + Q "~" * Identifier * ( Q ":" ) ^ -1
+ Q ":" * # (1 - P ":") * SkipSpace
* K ( 'TypeExpression' , balanced_parens ) * SkipSpace * Q ")"
+ Exception
@@ -7385,14 +7436,14 @@
% \end{macrocode}
%
% \bigskip
-% % Here, we must not put |local|!
+% % Here, we must not put |local|, of course.
% \begin{macrocode}
- LPEG1['ocaml'] = Main ^ 0
+ LPEG1.ocaml = Main ^ 0
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
- LPEG2['ocaml'] =
+ LPEG2.ocaml =
Ct (
% \end{macrocode}
% The following lines are in order to allow, in |\piton| (and not in |{Piton}|),
@@ -7406,14 +7457,14 @@
+
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
- * ( ( space * Lc [[\@@_trailing_space:]] ) ^ 1 * -1
+ * ( ( space * Lc [[ \@@_trailing_space: ]] ) ^ 1 * -1
+ space ^ 0 * EOL
+ Main
) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
@@ -7508,7 +7559,7 @@
String =
WithStyle ( 'String.Long' ,
Q "\""
- * ( VisualSpace
+ * ( SpaceInString
+ K ( 'String.Interpol' ,
"%" * ( S "difcspxXou" + "ld" + "li" + "hd" + "hi" )
)
@@ -7534,7 +7585,7 @@
% \end{macrocode}
%
% \begin{macrocode}
- LPEG_cleaner['c'] = Compute_LPEG_cleaner ( 'c' , braces )
+ LPEG_cleaner.c = Compute_LPEG_cleaner ( 'c' , braces )
% \end{macrocode}
%
% \bigskip
@@ -7570,7 +7621,9 @@
% \paragraph{The main LPEG for the language C}
%
% \begin{macrocode}
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
% \end{macrocode}
%
% First, the main loop :
@@ -7600,9 +7653,9 @@
% \end{macrocode}
%
% \bigskip
-% Here, we must not put |local|!
+% Here, we must not put |local|, of course.
% \begin{macrocode}
- LPEG1['c'] = Main ^ 0
+ LPEG1.c = Main ^ 0
% \end{macrocode}
%
% \bigskip
@@ -7612,15 +7665,15 @@
% will be used as marker in order to delimit the argument of the command
% \texttt{\textbackslash @@\_begin\_line:}}.
% \begin{macrocode}
- LPEG2['c'] =
+ LPEG2.c =
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
@@ -7641,15 +7694,15 @@
%
% \bigskip
% \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 "}}"
+ local LuaKeyword
+ function LuaKeyword ( name ) return
+ Lc [[ {\PitonStyle{Keyword}{ ]]
+ * Q ( Cmt (
+ C ( letter * alphanum ^ 0 ) ,
+ function ( s , i , a ) return string.upper ( a ) == name end
+ )
+ )
+ * Lc "}}"
end
% \end{macrocode}
%
@@ -7671,24 +7724,34 @@
% complication. We will catch the keywords with the identifiers and, then,
% distinguish the keywords with a Lua function. However, some keywords will be
% caught in special LPEG because we want to detect the names of the SQL tables.
+%
+% \bigskip
+% The following function converts a comma-separated list in a ``set'', that is
+% to say a Lua table with a fast way to test whether a string belongs to that
+% set (eventually, the indexation of the components of the table is no longer
+% done by integers but by the strings themselves).
% \begin{macrocode}
- local function Set ( list )
+ local Set
+ function Set ( list )
local set = { }
- for _, l in ipairs ( list ) do set[l] = true end
+ for _ , l in ipairs ( list ) do set[l] = true end
return set
end
% \end{macrocode}
%
% \bigskip
+% We now use the previsou function |Set| to creates the ``sets'' |set_keywords|
+% and |set_builtin|.
% \begin{macrocode}
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"
+ "DROP" , "EXCEPT" , "FROM" , "GROUP" , "HAVING" , "IN" , "INNER" ,
+ "INSERT" , "INTERSECT" , "INTO" , "IS" , "JOIN" , "LEFT" , "LIKE" , "LIMIT" ,
+ "MERGE" , "NOT" , "NULL" , "OFFSET" , "ON" , "OR" , "ORDER" , "OVER" ,
+ "RIGHT" , "SELECT" , "SET" , "TABLE" , "THEN" , "TRUNCATE" , "UNION" ,
+ "UPDATE" , "VALUES" , "WHEN" , "WHERE" , "WITH"
}
% \end{macrocode}
%
@@ -7708,22 +7771,24 @@
local Identifier =
C ( identifier ) /
(
- function (s)
- if set_keywords[string.upper(s)] -- the keywords are case-insensitive in SQL
+ function ( s )
+ if set_keywords[string.upper(s)] then return
% \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
+ { [[{\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
)
@@ -7753,7 +7818,7 @@
% \end{macrocode}
%
% \begin{macrocode}
- LPEG_cleaner['sql'] = Compute_LPEG_cleaner ( 'sql' , braces )
+ LPEG_cleaner.sql = Compute_LPEG_cleaner ( 'sql' , braces )
% \end{macrocode}
%
%
@@ -7783,7 +7848,9 @@
% \paragraph{The main LPEG for the language SQL}
%
% \begin{macrocode}
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
% \end{macrocode}
%
% \begin{macrocode}
@@ -7828,7 +7895,9 @@
% \end{macrocode}
%
% \begin{macrocode}
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer
+ + DetectedCommands + Escape + EscapeMath + -1
% \end{macrocode}
%
%
@@ -7854,9 +7923,9 @@
% \end{macrocode}
%
% \bigskip
-% Here, we must not put |local|!
+% Here, we must not put |local|, of course.
% \begin{macrocode}
- LPEG1['sql'] = Main ^ 0
+ LPEG1.sql = Main ^ 0
% \end{macrocode}
%
% \bigskip
@@ -7866,15 +7935,15 @@
% will be used as marker in order to delimit the argument of the command
% \texttt{\textbackslash @@\_begin\_line:}}.
% \begin{macrocode}
- LPEG2['sql'] =
+ LPEG2.sql =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
@@ -7886,7 +7955,7 @@
%
% \subsubsection{The language ``Minimal''}
%
-% We open a Lua local scope for the language ``|minimal|'' (of course, there
+% We open a Lua local scope for the language ``Minimal'' (of course, there
% will be also global definitions).
% \begin{macrocode}
do
@@ -7905,7 +7974,7 @@
local String =
WithStyle ( 'String.Short' ,
Q "\""
- * ( VisualSpace
+ * ( SpaceInString
+ Q ( ( P "\\\"" + 1 - S " \"" ) ^ 1 )
) ^ 0
* Q "\""
@@ -7922,7 +7991,7 @@
DetectedCommands = Compute_DetectedCommands ( 'minimal' , braces )
- LPEG_cleaner['minimal'] = Compute_LPEG_cleaner ( 'minimal' , braces )
+ LPEG_cleaner.minimal = Compute_LPEG_cleaner ( 'minimal' , braces )
local identifier = letter * alphanum ^ 0
@@ -7948,30 +8017,101 @@
% \end{macrocode}
%
% \bigskip
-% Here, we must not put |local|!
+% Here, we must not put |local|, of course.
% \begin{macrocode}
- LPEG1['minimal'] = Main ^ 0
+ LPEG1.minimal = Main ^ 0
- LPEG2['minimal'] =
+ LPEG2.minimal =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
%
% \bigskip
-% End of the Lua scope for the language ``|minimal|''.
+% End of the Lua scope for the language ``Minimal''.
% \begin{macrocode}
end
% \end{macrocode}
%
+% \subsubsection{The language ``Verbatim''}
+%
+% We open a Lua local scope for the language ``Verbatim'' (of course, there
+% will be also global definitions).
+% \begin{macrocode}
+do
+% \end{macrocode}
+
% \bigskip
+% Here, we don't use |braces| as done with the other languages because we don't
+% have have to take into account the strings (there is no string in the langage
+% ``Verbatim'').
+% \begin{macrocode}
+ local braces =
+ P { "E" ,
+ E = ( "{" * V "E" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+
+ if piton.beamer then Beamer = Compute_Beamer ( 'verbatim' , braces ) end
+
+ DetectedCommands = Compute_DetectedCommands ( 'verbatim' , braces )
+
+ LPEG_cleaner.verbatim = Compute_LPEG_cleaner ( 'verbatim' , braces )
+% \end{macrocode}
+%
+% Now, you will construct the LPEG Word.
+% \begin{macrocode}
+ local lpeg_central = 1 - S " \\\r"
+ if piton.begin_escape then
+ lpeg_central = lpeg_central - piton.begin_escape
+ end
+ if piton.begin_escape_math then
+ lpeg_central = lpeg_central - piton.begin_escape_math
+ end
+ local Word = Q ( lpeg_central ^ 1 )
+
+ local Main =
+ space ^ 0 * EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + Beamer
+ + DetectedCommands
+ + Q [[\]]
+ + Word
+% \end{macrocode}
+%
+% \bigskip
+% Here, we must not put |local|, of course.
+% \begin{macrocode}
+ LPEG1.verbatim = Main ^ 0
+
+ LPEG2.verbatim =
+ Ct (
+ ( space ^ 0 * "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * Lc [[ \@@_begin_line: ]]
+ * SpaceIndentation ^ 0
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * -1
+ * Lc [[ \@@_end_line: ]]
+ )
+% \end{macrocode}
+%
+%
+% \bigskip
+% End of the Lua scope for the language ``|verbatim|''.
+% \begin{macrocode}
+end
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{The function Parse}
%
% \medskip
@@ -7984,9 +8124,12 @@
% \bigskip
% \begin{macrocode}
function piton.Parse ( language , code )
+% \end{macrocode}
+% The variable |piton.language| will be used by the function |ParseAgain|.
+% \begin{macrocode}
+ piton.language = language
local t = LPEG2[language] : match ( code )
- if t == nil
- then
+ if t == nil then
sprintL3 [[ \@@_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
end
@@ -8035,6 +8178,7 @@
end
% \end{macrocode}
%
+
%
%
% \bigskip
@@ -8046,6 +8190,11 @@
( lang , name , first_line , last_line , splittable , split )
local s = ''
local i = 0
+% \end{macrocode}
+% At the date of septembre 2024, LuaLaTeX uses Lua 5.3 and not 5.4. In the
+% version 5.4, |io.lines| returns four values (and not just one) but the
+% following code should be correct.
+% \begin{macrocode}
for line in io.lines ( name ) do
i = i + 1
if i >= first_line then
@@ -8172,13 +8321,14 @@
% \end{macrocode}
%
% \begin{macrocode}
-local function remove_before_cr ( input_string )
- local match_result = ( P "\r" ) : match ( input_string )
- if match_result then
- return string.sub ( input_string , match_result )
- else
- return input_string
- end
+local remove_before_cr
+function remove_before_cr ( input_string )
+ local match_result = ( P "\r" ) : match ( input_string )
+ if match_result then return
+ string.sub ( input_string , match_result )
+ else return
+ input_string
+ end
end
% \end{macrocode}
%
@@ -8186,10 +8336,11 @@
% The function |gobble| gobbles $n$ characters on the left of the code. The
% negative values of $n$ have special significations.
% \begin{macrocode}
-local function gobble ( n , code )
+local gobble
+function gobble ( n , code )
code = remove_before_cr ( code )
- if n == 0 then
- return code
+ if n == 0 then return
+ code
else
if n == -1 then
n = AutoGobbleLPEG : match ( code )
@@ -8207,14 +8358,13 @@
% |auto-gobble| is in force, it's possible that, in fact, there is no space to
% gobble...
% \begin{macrocode}
- if n == 0 then
- return code
- else
+ if n == 0 then return
+ code
+ else return
% \end{macrocode}
% We will now use a \textsc{lpeg} that we have to compute dynamically because it
% depends on the value of~$n$.
% \begin{macrocode}
- return
( Ct (
( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
* ( C "\r" * ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
@@ -8264,8 +8414,8 @@
if piton.write and piton.write ~= '' then
local file = io.open ( piton.write , piton.write_mode )
if file then
- file:write ( piton.get_last_code ( ) )
- file:close ( )
+ file : write ( piton.get_last_code ( ) )
+ file : close ( )
else
sprintL3 [[ \@@_error_or_warning:n { FileError } ]]
end
@@ -8293,16 +8443,16 @@
) ^ 0
)
) : match ( gobble ( n , code ) )
- sprintL3 ( [[ \begingroup ]] )
+ sprintL3 [[ \begingroup ]]
sprintL3
(
- [[ \PitonOptions { split-on-empty-lines=false, gobble = 0, ]]
+ [[ \PitonOptions { split-on-empty-lines = false, gobble = 0, ]]
.. "language = " .. lang .. ","
.. "splittable = " .. splittable .. "}"
)
for k , v in pairs ( chunks ) do
if k > 1 then
- sprintL3 ( [[\l_@@_split_separation_tl ]] )
+ sprintL3 [[ \l_@@_split_separation_tl ]]
end
tex.sprint
(
@@ -8311,7 +8461,7 @@
.. [[\end{]] .. piton.env_used_by_split .. "}"
)
end
- sprintL3 ( [[ \endgroup ]] )
+ sprintL3 [[ \endgroup ]]
end
% \end{macrocode}
%
@@ -8399,10 +8549,10 @@
% \begin{macrocode}
function piton.CountNonEmptyLinesFile ( name )
local count = 0
- for line in io.lines ( name )
- do if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
+ for line in io.lines ( name ) do
+ if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
count = count + 1
- end
+ end
end
sprintL3
( string.format ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { % i } ]] , count ) )
@@ -8421,23 +8571,25 @@
local first_line = -1
local count = 0
local last_found = false
- for line in io.lines ( file_name )
- do if first_line == -1
- then if string.sub ( line , 1 , #s ) == s
- then first_line = count
- end
- else if string.sub ( line , 1 , #t ) == t
- then last_found = true
- break
- end
- end
- count = count + 1
+ for line in io.lines ( file_name ) do
+ if first_line == -1 then
+ if string.sub ( line , 1 , #s ) == s then
+ first_line = count
+ end
+ else
+ if string.sub ( line , 1 , #t ) == t then
+ last_found = true
+ break
+ end
+ end
+ count = count + 1
end
- if first_line == -1
- then sprintL3 [[ \@@_error_or_warning:n { begin~marker~not~found } ]]
- else if last_found == false
- then sprintL3 [[ \@@_error_or_warning:n { end~marker~not~found } ]]
- end
+ if first_line == -1 then
+ sprintL3 [[ \@@_error_or_warning:n { begin~marker~not~found } ]]
+ else
+ if last_found == false then
+ sprintL3 [[ \@@_error_or_warning:n { end~marker~not~found } ]]
+ end
end
sprintL3 (
[[ \int_set:Nn \l_@@_first_line_int { ]] .. first_line .. ' + 2 }'
@@ -8479,11 +8631,11 @@
if piton.beamer then
lpeg_line_beamer =
space ^ 0
- * P "\\begin{" * piton.BeamerEnvironments * "}"
+ * P [[\begin{]] * piton.BeamerEnvironments * "}"
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
+
space ^ 0
- * P "\\end{" * piton.BeamerEnvironments * "}"
+ * P [[\end{]] * piton.BeamerEnvironments * "}"
else
lpeg_line_beamer = P ( false )
end
@@ -8495,7 +8647,7 @@
+
P " " ^ 0 * "\r" * Cc ( 0 )
+
- ( 1 - P "\r" ) ^ 0 * "\r" * Cc ( 1 )
+ ( 1 - P "\r" ) ^ 0 * "\r" * Cc ( 1 )
) ^ 0
*
( lpeg_line_beamer + ( 1 - P "\r" ) ^ 1 * Cc ( 1 ) ) ^ -1
@@ -8507,7 +8659,7 @@
Ct (
( lpeg_line_beamer * "\r"
+
- ( 1 - P "\r" ) ^ 0 * "\r" * Cc ( 1 )
+ ( 1 - P "\r" ) ^ 0 * "\r" * Cc ( 1 )
) ^ 0
*
( lpeg_line_beamer + ( 1 - P "\r" ) ^ 1 * Cc ( 1 ) ) ^ -1
@@ -8547,7 +8699,7 @@
lines_status[i+j] = 2
end
for j = 1 , s - 1 do
- if i - j - 1 == 0 then break end
+ if i - j == 1 then break end
if lines_status[i-j-1] == 0 then break end
lines_status[i-j-1] = 2
end
@@ -8604,7 +8756,7 @@
% a key |alsoother|.
% \begin{macrocode}
function add_to_letter ( c )
- if c ~= " " then table.insert ( extra_letters , c ) end
+ if c ~= " " then table.insert ( extra_letters , c ) end
end
% \end{macrocode}
%
@@ -8611,7 +8763,7 @@
% For the digits, it's straitforward.
% \begin{macrocode}
function add_to_digit ( c )
- if c ~= " " then digit = digit + c end
+ if c ~= " " then digit = digit + c end
end
% \end{macrocode}
%
@@ -8631,19 +8783,19 @@
%
% \begin{macrocode}
function add_to_other ( c )
- if c ~= " " then
+ if c ~= " " then
% \end{macrocode}
% We will use |extra_others| to retrieve further these characters from the list
% of the letters.
% \begin{macrocode}
- extra_others[c] = true
+ extra_others[c] = true
% \end{macrocode}
% The \textsc{lpeg} pattern |other| will be used in conjunction with the key
% |tag| (mainly for the language \textsc{html}) for the character |/| in the
% closing tags |</....>|).
% \begin{macrocode}
- other = other + P ( c )
- end
+ other = other + P ( c )
+ end
end
% \end{macrocode}
%
@@ -8652,13 +8804,23 @@
% Now, the first transformation of the definition of the language, as provided
% by the final user in the argument |definition| of |piton.new_language|.
% \begin{macrocode}
- local cut_definition =
- P { "E" ,
- E = Ct ( V "F" * ( "," * V "F" ) ^ 0 ) ,
- F = Ct ( space ^ 0 * C ( alpha ^ 1 ) * space ^ 0
- * ( "=" * space ^ 0 * C ( strict_braces ) ) ^ -1 )
- }
- local def_table = cut_definition : match ( definition )
+ local def_table
+ if ( S ", " ^ 0 * -1 ) : match ( definition ) then
+ def_table = {}
+ else
+ local strict_braces =
+ P { "E" ,
+ E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
+ F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+ local cut_definition =
+ P { "E" ,
+ E = Ct ( V "F" * ( "," * V "F" ) ^ 0 ) ,
+ F = Ct ( space ^ 0 * C ( alpha ^ 1 ) * space ^ 0
+ * ( "=" * space ^ 0 * C ( strict_braces ) ) ^ -1 )
+ }
+ def_table = cut_definition : match ( definition )
+ end
% \end{macrocode}
% The definition of the language, provided by the final user of \pkg{piton} is
% now in the Lua table |def_table|. We will use it \emph{several times}.
@@ -8785,11 +8947,13 @@
% \end{macrocode}
% The following function will be used if the keywords are not case-sensitive.
% \begin{macrocode}
- local function keyword_to_lpeg ( name )
- return
+ local keyword_to_lpeg
+ function keyword_to_lpeg ( name ) return
Q ( Cmt (
C ( identifier ) ,
- function(s,i,a) return string.upper(a) == string.upper(name) end
+ function ( s , i , a ) return
+ string.upper ( a ) == string.upper ( name )
+ end
)
)
end
@@ -8808,7 +8972,7 @@
% \end{macrocode}
% \begin{macrocode}
local style = [[\PitonStyle{Keyword}]]
- if x[1] == "moredirectives" then style = [[ \PitonStyle{Directive} ]] end
+ if x[1] == "moredirectives" then style = [[\PitonStyle{Directive}]] end
style = tex_option_arg : match ( x[2] ) or style
local n = tonumber ( style )
if n then
@@ -8840,7 +9004,8 @@
% languages TeX, LaTeX, et \emph{al}. In that case, there is two kinds of
% keywords (= control sequences).
% \begin{itemize}
-% \item those beginning with |\| and a sequence of characters of catcode ``|letter|'';
+% \item those beginning with |\| and a sequence of characters of catcode
+% ``|letter|'';
% \item those beginning by |\| followed by one character of catcode ``|other|''.
% \end{itemize}
% The following code addresses both cases. Of course, the \textsc{lpeg} pattern
@@ -8903,7 +9068,7 @@
local pattern =
prefix
* Q ( arg3 )
- * ( VisualSpace + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
+ * ( SpaceInString + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
* Q ( arg4 )
% \end{macrocode}
% We will need |Long_string| in the nested comments.
@@ -8948,7 +9113,7 @@
CommentDelim = CommentDelim +
Ct ( Cc "Open"
* Cc ( "{" .. arg2 .. "{" ) * Cc "}}" )
- * Q ( arg3 )
+ * Q ( arg3 )
* ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 -- $
* Ct ( Cc "Close" )
* ( EOL + -1 )
@@ -8996,7 +9161,11 @@
= args_for_moredelims : match ( x[2] )
local MyFun = Q
if arg1 == "*" or arg1 == "**" then
- MyFun = function ( x ) return K ( 'ParseAgain.noCR' , x ) end
+ function MyFun ( x )
+ if x ~= '' then return
+ LPEG1[lang] : match ( x )
+ end
+ end
end
local left_delim
if arg2 : match "i" then
@@ -9061,7 +9230,7 @@
% The \textsc{lpeg} |LPEG1[lang]| is used to reformat small elements, for
% example the arguments of the ``detected commands''.
%
-% Of course, here, we must not put |local|!
+% Of course, here, we must not put |local|, of course.
% \begin{macrocode}
LPEG1[lang] = Main ^ 0
% \end{macrocode}
@@ -9073,15 +9242,16 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
% \end{macrocode}
%
-% If the key |tag| has been used. Of course, this feature is designed for the \textsc{html}.
+% If the key |tag| has been used. Of course, this feature is designed for the
+% \textsc{html}.
% \begin{macrocode}
if left_tag then
local Tag = Ct ( Cc "Open" * Cc ( "{" .. style_tag .. "{" ) * Cc "}}" )
@@ -9126,7 +9296,7 @@
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
- * Lc [[\@@_end_line:]]
+ * Lc [[ \@@_end_line: ]]
)
end
end
@@ -9153,6 +9323,12 @@
%
% \verb|https://github.com/fpantigny/piton|
%
+% \subsection*{Changes between versions 4.0 and 4.1}
+%
+% New language |verbatim|.
+%
+% New key |break-strings-anywhere|.
+%
% \subsection*{Changes between versions 3.1 and 4.0}
%
% This version introduces an incompatibility: the syntax for the relative and
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-10-18 21:20:00 UTC (rev 72586)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-10-18 21:20:09 UTC (rev 72587)
@@ -20,44 +20,48 @@
-- -------------------------------------------
--
-- This file is part of the LuaLaTeX package 'piton'.
-piton_version = "4.0" -- 2024/09/22
+piton_version = "4.1" -- 2024/10/18
-if piton.comment_latex == nil then piton.comment_latex = ">" end
+
+piton.comment_latex = piton.comment_latex or ">"
piton.comment_latex = "#" .. piton.comment_latex
-local function sprintL3 ( s )
- tex.sprint ( luatexbase.catcodetables.expl , s )
+local sprintL3
+function sprintL3 ( s )
+ tex.sprint ( luatexbase.catcodetables.expl , s )
end
local P, S, V, C, Ct, Cc = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cc
local Cs , Cg , Cmt , Cb = lpeg.Cs, lpeg.Cg , lpeg.Cmt , lpeg.Cb
local B , R = lpeg.B , lpeg.R
-local function Q ( pattern )
+local Q
+function Q ( pattern )
return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
end
-local function L ( pattern )
- return Ct ( C ( pattern ) )
+local L
+function L ( pattern ) return
+ Ct ( C ( pattern ) )
end
-local function Lc ( string )
- return Cc ( { luatexbase.catcodetables.expl , string } )
+local Lc
+function Lc ( string ) return
+ Cc ( { luatexbase.catcodetables.expl , string } )
end
-local function K ( style , pattern )
- return
- Lc ( "{\\PitonStyle{" .. style .. "}{" )
- * Q ( pattern )
- * Lc "}}"
+local K
+function K ( style , pattern ) return
+ Lc ( [[ {\PitonStyle{ ]] .. style .. "}{" )
+ * Q ( pattern )
+ * Lc "}}"
end
-local function WithStyle ( style , pattern )
- return
- Ct ( Cc "Open" * Cc ( "{\\PitonStyle{" .. style .. "}{" ) * Cc "}}" )
- * pattern
- * Ct ( Cc "Close" )
+local WithStyle
+function WithStyle ( style , pattern ) return
+ Ct ( Cc "Open" * Cc ( [[{\PitonStyle{]] .. style .. "}{" ) * Cc "}}" )
+ * pattern
+ * Ct ( Cc "Close" )
end
Escape = P ( false )
EscapeClean = P ( false )
-if piton.begin_escape ~= nil
-then
+if piton.begin_escape then
Escape =
P ( piton.begin_escape )
* L ( ( 1 - P ( piton.end_escape ) ) ^ 1 )
@@ -68,13 +72,12 @@
* P ( piton.end_escape )
end
EscapeMath = P ( false )
-if piton.begin_escape_math ~= nil
-then
+if piton.begin_escape_math then
EscapeMath =
P ( piton.begin_escape_math )
* Lc "\\ensuremath{"
* L ( ( 1 - P(piton.end_escape_math) ) ^ 1 )
- * Lc ( "}" )
+ * Lc "}"
* P ( piton.end_escape_math )
end
lpeg.locale(lpeg)
@@ -95,24 +98,14 @@
* ( S "eE" * S "+-" ^ -1 * digit ^ 1 ) ^ -1
+ digit ^ 1
)
-local Word
+local lpeg_central = 1 - S " '\"\r[({})]" - digit
if piton.begin_escape then
- if piton.begin_escape_math then
- Word = Q ( ( 1 - space - piton.begin_escape - piton.end_escape
- - piton.begin_escape_math - piton.end_escape_math
- - S "'\"\r[({})]" - digit ) ^ 1 )
- else
- Word = Q ( ( 1 - space - piton.begin_escape - piton.end_escape
- - S "'\"\r[({})]" - digit ) ^ 1 )
- end
-else
- if piton.begin_escape_math then
- Word = Q ( ( 1 - space - piton.begin_escape_math - piton.end_escape_math
- - S "'\"\r[({})]" - digit ) ^ 1 )
- else
- Word = Q ( ( 1 - space - S "'\"\r[({})]" - digit ) ^ 1 )
- end
+ lpeg_central = lpeg_central - piton.begin_escape
end
+if piton.begin_escape_math then
+ lpeg_central = lpeg_central - piton.begin_escape_math
+end
+local Word = Q ( lpeg_central ^ 1 )
local Space = Q " " ^ 1
local SkipSpace = Q " " ^ 0
@@ -119,51 +112,65 @@
local Punct = Q ( S ".,:;!" )
-local Tab = "\t" * Lc [[\__piton_tab:]]
-local SpaceIndentation = Lc [[\__piton_leading_space:]] * Q " "
+local Tab = "\t" * Lc [[ \__piton_tab: ]]
+local SpaceIndentation = Lc [[ \__piton_leading_space: ]] * Q " "
local Delim = Q ( S "[({})]" )
-local VisualSpace = space * Lc [[\l__piton_space_tl]]
- local strict_braces =
- P { "E" ,
- E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
- F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
- }
+local SpaceInString = space * Lc [[ \l__piton_space_in_string_tl ]]
local LPEG0 = { }
local LPEG1 = { }
local LPEG2 = { }
local LPEG_cleaner = { }
-local function Compute_braces ( lpeg_string ) return
- P { "E" ,
- E =
- (
- "{" * V "E" * "}"
- +
- lpeg_string
- +
- ( 1 - S "{}" )
- ) ^ 0
- }
+local Compute_braces
+function Compute_braces ( lpeg_string ) return
+ P { "E" ,
+ E =
+ (
+ "{" * V "E" * "}"
+ +
+ lpeg_string
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
end
-local function Compute_DetectedCommands ( lang , braces ) return
- Ct ( Cc "Open"
+local Compute_DetectedCommands
+function Compute_DetectedCommands ( lang , braces ) return
+ Ct (
+ Cc "Open"
* C ( piton.DetectedCommands * space ^ 0 * P "{" )
* Cc "}"
)
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return
+ LPEG1[lang] : match ( s )
+ end
+ end )
+ )
* P "}"
* Ct ( Cc "Close" )
end
-local function Compute_LPEG_cleaner ( lang , braces ) return
+local Compute_LPEG_cleaner
+function Compute_LPEG_cleaner ( lang , braces ) return
Ct ( ( piton.DetectedCommands * "{"
* ( braces
/ ( function ( s )
- if s ~= '' then return LPEG_cleaner[lang] : match ( s ) end end ) )
+ if s ~= '' then return
+ LPEG_cleaner[lang] : match ( s )
+ end
+ end )
+ )
* "}"
+ EscapeClean
+ C ( P ( 1 ) )
) ^ 0 ) / table.concat
end
+local ParseAgain
+function ParseAgain ( code )
+ if code ~= '' then return
+ LPEG1[piton.language] : match ( code )
+ end
+end
local Beamer = P ( false )
local BeamerBeginEnvironments = P ( true )
local BeamerEndEnvironments = P ( true )
@@ -175,7 +182,7 @@
( space ^ 0 *
L
(
- P "\\begin{" * piton.BeamerEnvironments * "}"
+ P [[\begin{]] * piton.BeamerEnvironments * "}"
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
)
* "\r"
@@ -182,10 +189,11 @@
) ^ 0
BeamerEndEnvironments =
( space ^ 0 *
- L ( P "\\end{" * piton.BeamerEnvironments * "}" )
+ L ( P [[\end{]] * piton.BeamerEnvironments * "}" )
* "\r"
) ^ 0
-local function Compute_Beamer ( lang , braces )
+local Compute_Beamer
+function Compute_Beamer ( lang , braces )
local lpeg = L ( P [[\pause]] * ( "[" * ( 1 - P "]" ) ^ 0 * "]" ) ^ -1 )
lpeg = lpeg +
Ct ( Cc "Open"
@@ -200,7 +208,7 @@
* "}"
* Ct ( Cc "Close" )
lpeg = lpeg +
- L ( P [[\alt]] * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
+ L ( P [[\alt]] * "<" * ( 1 - P ">" ) ^ 0 * ">{" )
* ( braces /
( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
@@ -208,7 +216,7 @@
( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
lpeg = lpeg +
- L ( ( P [[\temporal]] ) * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
+ L ( P [[\temporal]] * "<" * ( 1 - P ">" ) ^ 0 * ">{" )
* ( braces
/ ( function ( s )
if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
@@ -222,24 +230,24 @@
if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
for _ , x in ipairs ( piton.beamer_environments ) do
- lpeg = lpeg +
- Ct ( Cc "Open"
- * C (
- P ( "\\begin{" .. x .. "}" )
- * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
- )
- * Cc ( "\\end{" .. x .. "}" )
+ lpeg = lpeg +
+ Ct ( Cc "Open"
+ * C (
+ P ( [[\begin{]] .. x .. "}" )
+ * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
+ )
+ * Cc ( [[\end{]] .. x .. "}" )
+ )
+ * (
+ ( ( 1 - P ( [[\end{]] .. x .. "}" ) ) ^ 0 )
+ / ( function ( s )
+ if s ~= '' then return
+ LPEG1[lang] : match ( s )
+ end
+ end )
)
- * (
- ( ( 1 - P ( "\\end{" .. x .. "}" ) ) ^ 0 )
- / ( function ( s )
- if s ~= ''
- then return LPEG1[lang] : match ( s )
- end
- end )
- )
- * P ( "\\end{" .. x .. "}" )
- * Ct ( Cc "Close" )
+ * P ( [[\end{]] .. x .. "}" )
+ * Ct ( Cc "Close" )
end
return lpeg
end
@@ -246,7 +254,7 @@
local CommentMath =
P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$" -- $
local PromptHastyDetection =
- ( # ( P ">>>" + "..." ) * Lc [[\__piton_prompt:]] ) ^ -1
+ ( # ( P ">>>" + "..." ) * Lc [[ \__piton_prompt: ]] ) ^ -1
local Prompt = K ( 'Prompt' , ( ( P ">>>" + "..." ) * P " " ^ -1 ) ^ -1 )
local EOL =
P "\r"
@@ -257,7 +265,7 @@
Ct (
Cc "EOL"
*
- Ct ( Lc [[\__piton_end_line:]]
+ Ct ( Lc [[ \__piton_end_line: ]]
* BeamerEndEnvironments
*
(
@@ -265,7 +273,7 @@
+
BeamerBeginEnvironments
* PromptHastyDetection
- * Lc [[\__piton_newline:\__piton_begin_line:]]
+ * Lc [[ \__piton_newline:\__piton_begin_line: ]]
* Prompt
)
)
@@ -276,7 +284,7 @@
P ( piton.comment_latex )
* Lc [[{\PitonStyle{Comment.LaTeX}{\ignorespaces]]
* L ( ( 1 - P "\r" ) ^ 0 )
- * Lc [[}}]]
+ * Lc "}}"
* ( EOL + -1 )
do
local Operator =
@@ -374,7 +382,7 @@
* Q ( P ":" * ( 1 - S "}:'" ) ^ 0 ) ^ -1
* K ( 'String.Interpol' , "}" )
+
- VisualSpace
+ SpaceInString
+
Q ( ( P "\\'" + "\\\\" + "{{" + "}}" + 1 - S " {}'" ) ^ 1 )
) ^ 0
@@ -382,7 +390,7 @@
+
Q ( P "'" + "r'" + "R'" )
* ( Q ( ( P "\\'" + "\\\\" + 1 - S " '\r%" ) ^ 1 )
- + VisualSpace
+ + SpaceInString
+ PercentInterpol
+ Q "%"
) ^ 0
@@ -396,7 +404,7 @@
* ( K ( 'String.Interpol' , ":" ) * Q ( (1 - S "}:\"") ^ 0 ) ) ^ -1
* K ( 'String.Interpol' , "}" )
+
- VisualSpace
+ SpaceInString
+
Q ( ( P "\\\"" + "\\\\" + "{{" + "}}" + 1 - S " {}\"" ) ^ 1 )
) ^ 0
@@ -404,7 +412,7 @@
+
Q ( P "\"" + "r\"" + "R\"" )
* ( Q ( ( P "\\\"" + "\\\\" + 1 - S " \"\r%" ) ^ 1 )
- + VisualSpace
+ + SpaceInString
+ PercentInterpol
+ Q "%"
) ^ 0
@@ -422,7 +430,7 @@
)
if piton.beamer then Beamer = Compute_Beamer ( 'python' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'python' , braces )
- LPEG_cleaner['python'] = Compute_LPEG_cleaner ( 'python' , braces )
+ LPEG_cleaner.python = Compute_LPEG_cleaner ( 'python' , braces )
local SingleLongString =
WithStyle ( 'String.Long' ,
( Q ( S "fF" * P "'''" )
@@ -520,7 +528,7 @@
* Q "(" * Params * Q ")"
* SkipSpace
* ( Q "->" * SkipSpace * K ( 'Name.Type' , identifier ) ) ^ -1
- * K ( 'ParseAgain.noCR' , ( 1 - S ":\r" ) ^ 0 )
+ * ( C ( ( 1 - S ":\r" ) ^ 0 ) / ParseAgain )
* Q ":"
* ( SkipSpace
* ( EOL + CommentLaTeX + Comment ) -- in all cases, that contains an EOL
@@ -529,7 +537,9 @@
* StringDoc ^ 0 -- there may be additional docstrings
) ^ -1
local ExceptionInConsole = Exception * Q ( ( 1 - P "\r" ) ^ 0 ) * EOL
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
local Main =
space ^ 0 * EOL -- faut-il le mettre en commentaire ?
+ Space
@@ -557,18 +567,18 @@
+ Identifier
+ Number
+ Word
- LPEG1['python'] = Main ^ 0
- LPEG2['python'] =
+ LPEG1.python = Main ^ 0
+ LPEG2.python =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* Prompt
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
do
@@ -579,22 +589,22 @@
Beamer = Compute_Beamer ( 'ocaml' , braces )
end
DetectedCommands = Compute_DetectedCommands ( 'ocaml' , braces )
- local function Q ( pattern )
- return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther )
- * C ( pattern ) )
- + Beamer + DetectedCommands + EscapeMath + Escape
+ local Q
+ function Q ( pattern ) return
+ Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
+ + Beamer + DetectedCommands + EscapeMath + Escape
end
- local function K ( style , pattern )
- return
- Lc ( "{\\PitonStyle{" .. style .. "}{" )
- * Q ( pattern )
- * Lc "}}"
+ local K
+ function K ( style , pattern ) return
+ Lc ( [[ {\PitonStyle{ ]] .. style .. "}{" )
+ * Q ( pattern )
+ * Lc "}}"
end
- local function WithStyle ( style , pattern )
- return
- Ct ( Cc "Open" * Cc ( "{\\PitonStyle{" .. style .. "}{" ) * Cc "}}" )
- * ( pattern + Beamer + DetectedCommands + EscapeMath + Escape )
- * Ct ( Cc "Close" )
+ local WithStyle
+ function WithStyle ( style , pattern ) return
+ Ct ( Cc "Open" * Cc ( [[{\PitonStyle{]] .. style .. "}{" ) * Cc "}}" )
+ * ( pattern + Beamer + DetectedCommands + EscapeMath + Escape )
+ * Ct ( Cc "Close" )
end
local balanced_parens =
P { "E" , E = ( "(" * V "E" * ")" + ( 1 - S "()" ) ) ^ 0 }
@@ -601,7 +611,7 @@
local ocaml_string =
Q "\""
* (
- VisualSpace
+ SpaceInString
+
Q ( ( 1 - S " \"\r" ) ^ 1 )
+
@@ -665,7 +675,8 @@
+ K ( 'Keyword.Constant' , P "true" + "false" )
+ K ( 'Keyword.Governing', governing_keyword )
local EndKeyword
- = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape
+ + EscapeMath + -1
local identifier = ( R "az" + "_" ) * ( R "az" + R "AZ" + S "_'" + digit ) ^ 0
- ( OperatorWord + Keyword ) * EndKeyword
local Identifier = K ( 'Identifier.Internal' , identifier )
@@ -717,9 +728,7 @@
local OneField =
K ( 'Name.Field' , identifier ) * SkipSpace
* Q "=" * SkipSpace
- * ( expression_for_fields_value
- / ( function ( s ) return LPEG1['ocaml'] : match ( s ) end )
- )
+ * ( expression_for_fields_value / ParseAgain )
* SkipSpace
local Record =
Q "{" * SkipSpace
@@ -759,7 +768,7 @@
P "Division_by_zero" + "End_of_File" + "Failure" + "Invalid_argument" +
"Match_failure" + "Not_found" + "Out_of_memory" + "Stack_overflow" +
"Sys_blocked_io" + "Sys_error" + "Undefined_recursive_module" )
- LPEG_cleaner['ocaml'] = Compute_LPEG_cleaner ( 'ocaml' , braces )
+ LPEG_cleaner.ocaml = Compute_LPEG_cleaner ( 'ocaml' , braces )
local Argument =
( Q "~" * Identifier * Q ":" * SkipSpace ) ^ -1
*
@@ -862,7 +871,7 @@
+ String + QuotedString + Char
+ Comment
+ Operator
- + Q ( "~" ) * Identifier * ( Q ":" ) ^ -1
+ + Q "~" * Identifier * ( Q ":" ) ^ -1
+ Q ":" * # (1 - P ":") * SkipSpace
* K ( 'TypeExpression' , balanced_parens ) * SkipSpace * Q ")"
+ Exception
@@ -880,8 +889,8 @@
+ Delim
+ Number
+ Word
- LPEG1['ocaml'] = Main ^ 0
- LPEG2['ocaml'] =
+ LPEG1.ocaml = Main ^ 0
+ LPEG2.ocaml =
Ct (
( P ":" + Identifier * SkipSpace * Q ":" )
* SkipSpace
@@ -889,14 +898,14 @@
+
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
- * ( ( space * Lc [[\__piton_trailing_space:]] ) ^ 1 * -1
+ * ( ( space * Lc [[ \__piton_trailing_space: ]] ) ^ 1 * -1
+ space ^ 0 * EOL
+ Main
) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
do
@@ -942,7 +951,7 @@
String =
WithStyle ( 'String.Long' ,
Q "\""
- * ( VisualSpace
+ * ( SpaceInString
+ K ( 'String.Interpol' ,
"%" * ( S "difcspxXou" + "ld" + "li" + "hd" + "hi" )
)
@@ -953,7 +962,7 @@
local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then Beamer = Compute_Beamer ( 'c' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'c' , braces )
- LPEG_cleaner['c'] = Compute_LPEG_cleaner ( 'c' , braces )
+ LPEG_cleaner.c = Compute_LPEG_cleaner ( 'c' , braces )
local Preproc = K ( 'Preproc' , "#" * ( 1 - P "\r" ) ^ 0 ) * ( EOL + -1 )
local Comment =
WithStyle ( 'Comment' ,
@@ -966,7 +975,9 @@
* ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
* Q "*/"
) -- $
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
local Main =
space ^ 0 * EOL
+ Space
@@ -989,28 +1000,28 @@
+ Identifier
+ Number
+ Word
- LPEG1['c'] = Main ^ 0
- LPEG2['c'] =
+ LPEG1.c = Main ^ 0
+ LPEG2.c =
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
do
- local function LuaKeyword ( name )
- return
- Lc [[{\PitonStyle{Keyword}{]]
- * Q ( Cmt (
- C ( identifier ) ,
- function ( s , i , a ) return string.upper ( a ) == name end
- )
- )
- * Lc "}}"
+ local LuaKeyword
+ function LuaKeyword ( name ) return
+ Lc [[ {\PitonStyle{Keyword}{ ]]
+ * Q ( Cmt (
+ C ( letter * alphanum ^ 0 ) ,
+ function ( s , i , a ) return string.upper ( a ) == name end
+ )
+ )
+ * Lc "}}"
end
local identifier =
letter * ( alphanum + "-" ) ^ 0
@@ -1017,9 +1028,10 @@
+ P '"' * ( ( 1 - P '"' ) ^ 1 ) * '"'
local Operator =
K ( 'Operator' , P "=" + "!=" + "<>" + ">=" + ">" + "<=" + "<" + S "*+/" )
- local function Set ( list )
+ local Set
+ function Set ( list )
local set = { }
- for _, l in ipairs ( list ) do set[l] = true end
+ for _ , l in ipairs ( list ) do set[l] = true end
return set
end
local set_keywords = Set
@@ -1026,10 +1038,11 @@
{
"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"
+ "DROP" , "EXCEPT" , "FROM" , "GROUP" , "HAVING" , "IN" , "INNER" ,
+ "INSERT" , "INTERSECT" , "INTO" , "IS" , "JOIN" , "LEFT" , "LIKE" , "LIMIT" ,
+ "MERGE" , "NOT" , "NULL" , "OFFSET" , "ON" , "OR" , "ORDER" , "OVER" ,
+ "RIGHT" , "SELECT" , "SET" , "TABLE" , "THEN" , "TRUNCATE" , "UNION" ,
+ "UPDATE" , "VALUES" , "WHEN" , "WHERE" , "WITH"
}
local set_builtins = Set
{
@@ -1040,19 +1053,21 @@
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
+ function ( s )
+ if set_keywords[string.upper(s)] 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
)
@@ -1060,7 +1075,7 @@
local braces = Compute_braces ( "'" * ( 1 - P "'" ) ^ 1 * "'" )
if piton.beamer then Beamer = Compute_Beamer ( 'sql' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'sql' , braces )
- LPEG_cleaner['sql'] = Compute_LPEG_cleaner ( 'sql' , braces )
+ LPEG_cleaner.sql = Compute_LPEG_cleaner ( 'sql' , braces )
local Comment =
WithStyle ( 'Comment' ,
Q "--" -- syntax of SQL92
@@ -1073,7 +1088,9 @@
* ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
* Q "*/"
) -- $
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer + DetectedCommands + Escape +
+ EscapeMath + -1
local TableField =
K ( 'Name.Table' , identifier )
* Q "."
@@ -1112,7 +1129,9 @@
+ LuaKeyword "TABLE"
)
* ( Space + EOL ) * OneTable
- local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
+ local EndKeyword
+ = Space + Punct + Delim + EOL + Beamer
+ + DetectedCommands + Escape + EscapeMath + -1
local Main =
space ^ 0 * EOL
+ Space
@@ -1130,16 +1149,16 @@
+ ( TableField + Identifier ) * ( Space + Operator + Punct + Delim + EOL + -1 )
+ Number
+ Word
- LPEG1['sql'] = Main ^ 0
- LPEG2['sql'] =
+ LPEG1.sql = Main ^ 0
+ LPEG2.sql =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
do
@@ -1155,7 +1174,7 @@
local String =
WithStyle ( 'String.Short' ,
Q "\""
- * ( VisualSpace
+ * ( SpaceInString
+ Q ( ( P "\\\"" + 1 - S " \"" ) ^ 1 )
) ^ 0
* Q "\""
@@ -1166,7 +1185,7 @@
DetectedCommands = Compute_DetectedCommands ( 'minimal' , braces )
- LPEG_cleaner['minimal'] = Compute_LPEG_cleaner ( 'minimal' , braces )
+ LPEG_cleaner.minimal = Compute_LPEG_cleaner ( 'minimal' , braces )
local identifier = letter * alphanum ^ 0
@@ -1189,23 +1208,66 @@
+ Identifier
+ Number
+ Word
- LPEG1['minimal'] = Main ^ 0
+ LPEG1.minimal = Main ^ 0
- LPEG2['minimal'] =
+ LPEG2.minimal =
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
+do
+
+ local braces =
+ P { "E" ,
+ E = ( "{" * V "E" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+
+ if piton.beamer then Beamer = Compute_Beamer ( 'verbatim' , braces ) end
+
+ DetectedCommands = Compute_DetectedCommands ( 'verbatim' , braces )
+
+ LPEG_cleaner.verbatim = Compute_LPEG_cleaner ( 'verbatim' , braces )
+ local lpeg_central = 1 - S " \\\r"
+ if piton.begin_escape then
+ lpeg_central = lpeg_central - piton.begin_escape
+ end
+ if piton.begin_escape_math then
+ lpeg_central = lpeg_central - piton.begin_escape_math
+ end
+ local Word = Q ( lpeg_central ^ 1 )
+
+ local Main =
+ space ^ 0 * EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + Beamer
+ + DetectedCommands
+ + Q [[\]]
+ + Word
+ LPEG1.verbatim = Main ^ 0
+
+ LPEG2.verbatim =
+ Ct (
+ ( space ^ 0 * "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * Lc [[ \__piton_begin_line: ]]
+ * SpaceIndentation ^ 0
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * -1
+ * Lc [[ \__piton_end_line: ]]
+ )
+end
function piton.Parse ( language , code )
+ piton.language = language
local t = LPEG2[language] : match ( code )
- if t == nil
- then
+ if t == nil then
sprintL3 [[ \__piton_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
end
@@ -1239,6 +1301,7 @@
end
end
end
+
function piton.ParseFile
( lang , name , first_line , last_line , splittable , split )
local s = ''
@@ -1306,18 +1369,20 @@
local EnvGobbleLPEG =
( ( 1 - P "\r" ) ^ 0 * "\r" ) ^ 0
* Ct ( C " " ^ 0 * -1 ) / table.getn
-local function remove_before_cr ( input_string )
- local match_result = ( P "\r" ) : match ( input_string )
- if match_result then
- return string.sub ( input_string , match_result )
- else
- return input_string
- end
+local remove_before_cr
+function remove_before_cr ( input_string )
+ local match_result = ( P "\r" ) : match ( input_string )
+ if match_result then return
+ string.sub ( input_string , match_result )
+ else return
+ input_string
+ end
end
-local function gobble ( n , code )
+local gobble
+function gobble ( n , code )
code = remove_before_cr ( code )
- if n == 0 then
- return code
+ if n == 0 then return
+ code
else
if n == -1 then
n = AutoGobbleLPEG : match ( code )
@@ -1330,10 +1395,9 @@
end
end
end
- if n == 0 then
- return code
- else
- return
+ if n == 0 then return
+ code
+ else return
( Ct (
( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
* ( C "\r" * ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
@@ -1356,8 +1420,8 @@
if piton.write and piton.write ~= '' then
local file = io.open ( piton.write , piton.write_mode )
if file then
- file:write ( piton.get_last_code ( ) )
- file:close ( )
+ file : write ( piton.get_last_code ( ) )
+ file : close ( )
else
sprintL3 [[ \__piton_error_or_warning:n { FileError } ]]
end
@@ -1375,16 +1439,16 @@
) ^ 0
)
) : match ( gobble ( n , code ) )
- sprintL3 ( [[ \begingroup ]] )
+ sprintL3 [[ \begingroup ]]
sprintL3
(
- [[ \PitonOptions { split-on-empty-lines=false, gobble = 0, ]]
+ [[ \PitonOptions { split-on-empty-lines = false, gobble = 0, ]]
.. "language = " .. lang .. ","
.. "splittable = " .. splittable .. "}"
)
for k , v in pairs ( chunks ) do
if k > 1 then
- sprintL3 ( [[\l__piton_split_separation_tl ]] )
+ sprintL3 [[ \l__piton_split_separation_tl ]]
end
tex.sprint
(
@@ -1393,7 +1457,7 @@
.. [[\end{]] .. piton.env_used_by_split .. "}"
)
end
- sprintL3 ( [[ \endgroup ]] )
+ sprintL3 [[ \endgroup ]]
end
function piton.RetrieveGobbleSplitParse ( lang , n , splittable , code )
local s
@@ -1436,10 +1500,10 @@
end
function piton.CountNonEmptyLinesFile ( name )
local count = 0
- for line in io.lines ( name )
- do if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
+ for line in io.lines ( name ) do
+ if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
count = count + 1
- end
+ end
end
sprintL3
( string.format ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { % i } ]] , count ) )
@@ -1450,23 +1514,25 @@
local first_line = -1
local count = 0
local last_found = false
- for line in io.lines ( file_name )
- do if first_line == -1
- then if string.sub ( line , 1 , #s ) == s
- then first_line = count
- end
- else if string.sub ( line , 1 , #t ) == t
- then last_found = true
- break
- end
- end
- count = count + 1
+ for line in io.lines ( file_name ) do
+ if first_line == -1 then
+ if string.sub ( line , 1 , #s ) == s then
+ first_line = count
+ end
+ else
+ if string.sub ( line , 1 , #t ) == t then
+ last_found = true
+ break
+ end
+ end
+ count = count + 1
end
- if first_line == -1
- then sprintL3 [[ \__piton_error_or_warning:n { begin~marker~not~found } ]]
- else if last_found == false
- then sprintL3 [[ \__piton_error_or_warning:n { end~marker~not~found } ]]
- end
+ if first_line == -1 then
+ sprintL3 [[ \__piton_error_or_warning:n { begin~marker~not~found } ]]
+ else
+ if last_found == false then
+ sprintL3 [[ \__piton_error_or_warning:n { end~marker~not~found } ]]
+ end
end
sprintL3 (
[[ \int_set:Nn \l__piton_first_line_int { ]] .. first_line .. ' + 2 }'
@@ -1477,11 +1543,11 @@
if piton.beamer then
lpeg_line_beamer =
space ^ 0
- * P "\\begin{" * piton.BeamerEnvironments * "}"
+ * P [[\begin{]] * piton.BeamerEnvironments * "}"
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
+
space ^ 0
- * P "\\end{" * piton.BeamerEnvironments * "}"
+ * P [[\end{]] * piton.BeamerEnvironments * "}"
else
lpeg_line_beamer = P ( false )
end
@@ -1523,7 +1589,7 @@
lines_status[i+j] = 2
end
for j = 1 , s - 1 do
- if i - j - 1 == 0 then break end
+ if i - j == 1 then break end
if lines_status[i-j-1] == 0 then break end
lines_status[i-j-1] = 2
end
@@ -1547,26 +1613,36 @@
local alpha , digit = lpeg.alpha , lpeg.digit
local extra_letters = { "@" , "_" , "$" } -- $
function add_to_letter ( c )
- if c ~= " " then table.insert ( extra_letters , c ) end
+ if c ~= " " then table.insert ( extra_letters , c ) end
end
function add_to_digit ( c )
- if c ~= " " then digit = digit + c end
+ if c ~= " " then digit = digit + c end
end
local other = S ":_ at +-*/<>!?;.()[]~^=#&\"\'\\$" -- $
local extra_others = { }
function add_to_other ( c )
- if c ~= " " then
- extra_others[c] = true
- other = other + P ( c )
- end
+ if c ~= " " then
+ extra_others[c] = true
+ other = other + P ( c )
+ end
end
- local cut_definition =
- P { "E" ,
- E = Ct ( V "F" * ( "," * V "F" ) ^ 0 ) ,
- F = Ct ( space ^ 0 * C ( alpha ^ 1 ) * space ^ 0
- * ( "=" * space ^ 0 * C ( strict_braces ) ) ^ -1 )
- }
- local def_table = cut_definition : match ( definition )
+ local def_table
+ if ( S ", " ^ 0 * -1 ) : match ( definition ) then
+ def_table = {}
+ else
+ local strict_braces =
+ P { "E" ,
+ E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
+ F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+ local cut_definition =
+ P { "E" ,
+ E = Ct ( V "F" * ( "," * V "F" ) ^ 0 ) ,
+ F = Ct ( space ^ 0 * C ( alpha ^ 1 ) * space ^ 0
+ * ( "=" * space ^ 0 * C ( strict_braces ) ) ^ -1 )
+ }
+ def_table = cut_definition : match ( definition )
+ end
local tex_braced_arg = "{" * C ( ( 1 - P "}" ) ^ 0 ) * "}"
local tex_arg = tex_braced_arg + C ( 1 )
local tex_option_arg = "[" * C ( ( 1 - P "]" ) ^ 0 ) * "]" + Cc ( nil )
@@ -1640,11 +1716,13 @@
* ( P "}" ) ^ 1 * space ^ 0 ,
F = space ^ 0 * C ( letter * alphanum ^ 0 + other ^ 1 ) * space ^ 0
}
- local function keyword_to_lpeg ( name )
- return
+ local keyword_to_lpeg
+ function keyword_to_lpeg ( name ) return
Q ( Cmt (
C ( identifier ) ,
- function(s,i,a) return string.upper(a) == string.upper(name) end
+ function ( s , i , a ) return
+ string.upper ( a ) == string.upper ( name )
+ end
)
)
end
@@ -1658,7 +1736,7 @@
then
local keywords = P ( false )
local style = [[\PitonStyle{Keyword}]]
- if x[1] == "moredirectives" then style = [[ \PitonStyle{Directive} ]] end
+ if x[1] == "moredirectives" then style = [[\PitonStyle{Directive}]] end
style = tex_option_arg : match ( x[2] ) or style
local n = tonumber ( style )
if n then
@@ -1713,7 +1791,7 @@
local pattern =
prefix
* Q ( arg3 )
- * ( VisualSpace + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
+ * ( SpaceInString + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
* Q ( arg4 )
Long_string = Long_string + pattern
LongString = LongString +
@@ -1742,7 +1820,7 @@
CommentDelim = CommentDelim +
Ct ( Cc "Open"
* Cc ( "{" .. arg2 .. "{" ) * Cc "}}" )
- * Q ( arg3 )
+ * Q ( arg3 )
* ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 -- $
* Ct ( Cc "Close" )
* ( EOL + -1 )
@@ -1786,7 +1864,11 @@
= args_for_moredelims : match ( x[2] )
local MyFun = Q
if arg1 == "*" or arg1 == "**" then
- MyFun = function ( x ) return K ( 'ParseAgain.noCR' , x ) end
+ function MyFun ( x )
+ if x ~= '' then return
+ LPEG1[lang] : match ( x )
+ end
+ end
end
local left_delim
if arg2 : match "i" then
@@ -1843,11 +1925,11 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
if left_tag then
local Tag = Ct ( Cc "Open" * Cc ( "{" .. style_tag .. "{" ) * Cc "}}" )
@@ -1892,7 +1974,7 @@
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
- * Lc [[\__piton_end_line:]]
+ * Lc [[ \__piton_end_line: ]]
)
end
end
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-10-18 21:20:00 UTC (rev 72586)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-10-18 21:20:09 UTC (rev 72587)
@@ -19,12 +19,13 @@
%% LaTeX version 2005/12/01 or later.
%% -------------------------------------------
%%
-\def\PitonFileVersion{4.0}
-\def\PitonFileDate{2024/09/22}
+\def\PitonFileVersion{4.1}
+\def\PitonFileDate{2024/10/18}
+
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
@@ -83,8 +84,7 @@
The~file~'README.md'~explains~how~to~retrieve~the~files~'piton.sty'~and~
'piton.lua'.
}
-\file_if_exist:nF { piton.lua }
- { \msg_fatal:nn { piton } { piton.lua~not~found } }
+\file_if_exist:nF { piton.lua } { \__piton_fatal:n { piton.lua~not~found } }
\bool_new:N \g__piton_footnotehyper_bool
\bool_new:N \g__piton_footnote_bool
\bool_new:N \g__piton_math_comments_bool
@@ -164,7 +164,7 @@
}
\lua_now:n
{
- piton.BeamerCommands = lpeg.P ( [[\uncover]] )
+ piton.BeamerCommands = lpeg.P [[\uncover]]
+ [[\only]] + [[\visible]] + [[\invisible]] + [[\alert]] + [[\action]]
piton.beamer_environments = { "uncoverenv" , "onlyenv" , "visibleenv" ,
"invisibleenv" , "alertenv" , "actionenv" }
@@ -208,6 +208,7 @@
\tl_new:N \l__piton_end_of_broken_line_tl
\tl_set:Nn \l__piton_end_of_broken_line_tl { \hspace*{0.5em} \textbackslash }
\bool_new:N \l__piton_break_lines_in_piton_bool
+
\dim_new:N \l__piton_width_dim
\dim_new:N \l__piton_line_width_dim
\bool_new:N \l__piton_width_min_bool
@@ -233,8 +234,7 @@
\int_gadd:Nn \g__piton_indentation_int \l__piton_tab_size_int
}
\int_new:N \l__piton_gobble_int
-\tl_new:N \l__piton_space_tl
-\tl_set_eq:NN \l__piton_space_tl \nobreakspace
+\tl_set_eq:NN \l__piton_space_in_string_tl \nobreakspace
\int_new:N \g__piton_indentation_int
\cs_new_protected:Npn \__piton_leading_space:
{ \int_gincr:N \g__piton_indentation_int }
@@ -267,12 +267,13 @@
}
}
\cs_new_protected:Npn \__piton_trailing_space: { }
+\cs_generate_variant:Nn \__piton_replace_spaces:n { o }
\cs_new_protected:Npn \__piton_replace_spaces:n #1
{
\tl_set:Nn \l_tmpa_tl { #1 }
\bool_if:NTF \l__piton_show_spaces_bool
{
- \tl_set:Nn \l__piton_space_tl { ␣ } % U+2423
+ \tl_set:Nn \l__piton_space_in_string_tl { ␣ } % U+2423
\regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl
}
{
@@ -283,7 +284,7 @@
{ \c { __piton_breakable_space: } }
\l_tmpa_tl
\regex_replace_all:nnN
- { \c { l__piton_space_tl } }
+ { \c { l__piton_space_in_string_tl } }
{ \c { __piton_breakable_space: } }
\l_tmpa_tl
}
@@ -330,12 +331,9 @@
{ \int_compare_p:nNn \l_tmpa_int = \c_one_int }
{ ! \l__piton_skip_empty_lines_bool }
{ \int_gincr:N \g__piton_visual_line_int }
- \bool_if:nT
- {
- \int_compare_p:nNn \l_tmpa_int = \c_one_int
- ||
- ( ! \l__piton_skip_empty_lines_bool && \l__piton_label_empty_lines_bool )
- }
+ \bool_lazy_or:nnT
+ { \int_compare_p:nNn \l_tmpa_int = \c_one_int }
+ { ! \l__piton_skip_empty_lines_bool && \l__piton_label_empty_lines_bool }
\__piton_print_number:
}
\clist_if_empty:NF \l__piton_bg_color_clist
@@ -387,8 +385,9 @@
\tl_set:Ne \l_tmpa_tl { \clist_item:Nn #1 \l_tmpb_int }
\tl_if_eq:NnTF \l_tmpa_tl { none }
{ \dim_zero:N \l__piton_width_dim }
- { \exp_args:No \__piton_color_i:n \l_tmpa_tl }
+ { \__piton_color_i:o \l_tmpa_tl }
}
+\cs_generate_variant:Nn \__piton_color_i:n { o }
\cs_set_protected:Npn \__piton_color_i:n #1
{
\tl_if_head_eq_meaning:nNTF { #1 } [
@@ -520,6 +519,8 @@
}
\keys_define:nn { PitonOptions }
{
+ break-strings-anywhere .code:n =
+ \cs_set_eq:NN \__piton_break_anywhere:n \__piton_actually_break_anywhere:n ,
detected-commands .code:n =
\lua_now:n { piton.addDetectedCommands('#1') } ,
detected-commands .value_required:n = true ,
@@ -559,10 +560,10 @@
math-comments .bool_gset:N = \g__piton_math_comments_bool ,
math-comments .default:n = true ,
math-comments .usage:n = preamble ,
- language .code:n =
+ language .code:n =
\str_set:Ne \l_piton_language_str { \str_lowercase:n { #1 } } ,
- language .value_required:n = true ,
- path .code:n =
+ language .value_required:n = true ,
+ path .code:n =
\seq_clear:N \l__piton_path_seq
\clist_map_inline:nn { #1 }
{
@@ -588,7 +589,7 @@
splittable-on-empty-lines .default:n = true ,
split-on-empty-lines .bool_set:N = \l__piton_split_on_empty_lines_bool ,
- split-on-empty-lines .default:n = true ,
+ split-on-empty-lines .default:n = true ,
split-separation .tl_set:N = \l__piton_split_separation_tl ,
split-separation .value_required:n = true ,
@@ -643,7 +644,8 @@
tab-size .value_required:n = true ,
show-spaces .bool_set:N = \l__piton_show_spaces_bool ,
show-spaces .value_forbidden:n = true ,
- show-spaces-in-strings .code:n = \tl_set:Nn \l__piton_space_tl { ␣ } , % U+2423
+ show-spaces-in-strings .code:n =
+ \tl_set:Nn \l__piton_space_in_string_tl { ␣ } , % U+2423
show-spaces-in-strings .value_forbidden:n = true ,
break-lines-in-Piton .bool_set:N = \l__piton_break_lines_in_Piton_bool ,
break-lines-in-Piton .default:n = true ,
@@ -684,7 +686,7 @@
range .value_required:n = true ,
env-used-by-split .code:n =
- \lua_now:n { piton.env_used_by_split = '#1'} ,
+ \lua_now:n { piton.env_used_by_split = '#1' } ,
env-used-by-split .initial:n = Piton ,
resume .meta:n = line-numbers/resume ,
@@ -695,7 +697,7 @@
all-line-numbers .code:n =
\bool_set_true:N \l__piton_line_numbers_bool
\bool_set_false:N \l__piton_skip_empty_lines_bool ,
- all-line-numbers .value_forbidden:n = true ,
+ all-line-numbers .value_forbidden:n = true
}
\cs_new_protected:Npn \__piton_in_PitonInputFile:n #1
{
@@ -783,8 +785,9 @@
}
\keys_set:nn { NewPitonLanguage } { #3 }
\prop_gput:Non \g__piton_languages_prop \l_tmpa_tl { #3 }
- \exp_args:No \__piton_NewPitonLanguage:nn \l_tmpa_tl { #3 }
+ \__piton_NewPitonLanguage:on \l_tmpa_tl { #3 }
}
+\cs_generate_variant:Nn \__piton_NewPitonLanguage:nn { o }
\cs_new_protected:Npn \__piton_NewPitonLanguage:nn #1 #2
{
\hook_gput_code:nnn { begindocument } { . }
@@ -794,21 +797,23 @@
{
\tl_set:Ne \l_tmpa_tl
{
- \tl_if_blank:nF { #3 } { [ \str_lowercase:n { #3 } ] }
- \str_lowercase:n { #4 }
+ \tl_if_blank:nF { #3 } { [ \str_lowercase:n { #3 } ] }
+ \str_lowercase:n { #4 }
}
\prop_get:NoNTF \g__piton_languages_prop \l_tmpa_tl \l_tmpb_tl
{ \__piton_NewPitonLanguage:nnno { #1 } { #2 } { #5 } \l_tmpb_tl }
{ \__piton_error:n { Language~not~defined } }
}
+\cs_generate_variant:Nn \__piton_NewPitonLanguage:nnnn { n n n o }
\cs_new_protected:Npn \__piton_NewPitonLanguage:nnnn #1 #2 #3 #4
{ \__piton_NewPitonLanguage:nnn { #1 } { #2 } { #4 , #3 } }
-\cs_generate_variant:Nn \__piton_NewPitonLanguage:nnnn { n n n o }
\NewDocumentCommand { \piton } { }
{ \peek_meaning:NTF \bgroup \__piton_piton_standard \__piton_piton_verbatim }
\NewDocumentCommand { \__piton_piton_standard } { m }
{
\group_begin:
+ \bool_if:NT \l__piton_break_lines_in_piton_bool
+ { \tl_set_eq:NN \l__piton_space_in_string_tl \space }
\automatichyphenmode = 1
\cs_set_eq:NN \\ \c_backslash_str
\cs_set_eq:NN \% \c_percent_str
@@ -872,7 +877,7 @@
}
\bool_if:NT \l__piton_show_spaces_bool
{ \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \exp_args:No \__piton_replace_spaces:n \l_tmpa_tl
+ \__piton_replace_spaces:o \l_tmpa_tl
\group_end:
}
\cs_new:Npn \__piton_pre_env:
@@ -890,6 +895,7 @@
\dim_zero:N \lineskip
\cs_set_eq:NN \label \__piton_label:n
}
+\cs_generate_variant:Nn \__piton_compute_left_margin:nn { n o }
\cs_new_protected:Npn \__piton_compute_left_margin:nn #1 #2
{
\bool_lazy_and:nnT \l__piton_left_margin_auto_bool \l__piton_line_numbers_bool
@@ -914,7 +920,6 @@
{ \box_wd:N \l_tmpa_box + \l__piton_numbers_sep_dim + 0.1 em }
}
}
-\cs_generate_variant:Nn \__piton_compute_left_margin:nn { n o }
\cs_new_protected:Npn \__piton_compute_width:
{
\dim_compare:nNnTF \l__piton_line_width_dim = \c_zero_dim
@@ -1163,8 +1168,8 @@
{
\str_set:Ne \l_tmpa_str { \__piton_marker_beginning:n \l__piton_begin_range_str }
\str_set:Ne \l_tmpb_str { \__piton_marker_end:n \l__piton_end_range_str }
- \exp_args:Nno \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpa_str
- \exp_args:Nno \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpb_str
+ \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpa_str
+ \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpb_str
\lua_now:e
{
piton.ComputeRange
@@ -1241,14 +1246,14 @@
{
#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 }
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l__piton_SetPitonStyle_option_str
+ { \l__piton_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
}
}
@@ -1256,8 +1261,6 @@
{
String .meta:n = { String.Long = #1 , String.Short = #1 } ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
- ParseAgain .value_required:n = true ,
unknown .code:n =
\__piton_error:n { Unknown~key~for~SetPitonStyle }
}
@@ -1264,7 +1267,8 @@
\SetPitonStyle[OCaml]
{
TypeExpression =
- \SetPitonStyle { Identifier = \PitonStyle { Name.Type } } \__piton_piton:n ,
+ \SetPitonStyle { Identifier = \PitonStyle { Name.Type } }
+ \__piton_piton:n ,
}
\clist_gput_left:Nn \g__piton_styles_clist { String }
\clist_gsort:Nn \g__piton_styles_clist
@@ -1273,6 +1277,14 @@
\sort_return_same:
\sort_return_swapped:
}
+\cs_set_eq:NN \__piton_break_anywhere:n \prg_do_nothing:
+\cs_new_protected:Npn \__piton_actually_break_anywhere:n #1
+ {
+ \seq_clear:N \l_tmpa_seq
+ \tl_map_inline:nn { #1 }
+ { \seq_put_right:Nn \l_tmpa_seq { ##1 } }
+ \seq_use:Nn \l_tmpa_seq { \- }
+ }
\SetPitonStyle
{
Comment = \color[HTML]{0099FF} \itshape ,
@@ -1292,13 +1304,13 @@
Number = \color[HTML]{FF6600} ,
Operator = \color[HTML]{555555} ,
Operator.Word = \bfseries ,
- String = \color[HTML]{CC3300} ,
+ String = \color[HTML]{CC3300} \__piton_break_anywhere:n ,
String.Doc = \color[HTML]{CC3300} \itshape ,
String.Interpol = \color[HTML]{AA0000} ,
Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
Name.Type = \color[HTML]{336666} ,
InitialValues = \__piton_piton:n ,
- Interpol.Inside = \color{black}\__piton_piton:n ,
+ Interpol.Inside = \l__piton_font_command_tl \__piton_piton:n ,
TypeParameter = \color[HTML]{336666} \itshape ,
Preproc = \color[HTML]{AA6600} \slshape ,
Identifier.Internal = \__piton_identifier:n ,
@@ -1305,9 +1317,8 @@
Identifier = ,
Directive = \color[HTML]{AA6600} ,
Tag = \colorbox{gray!10},
- UserFunction = ,
+ UserFunction = \PitonStyle{Identifier} ,
Prompt = ,
- ParseAgain = \__piton_piton_no_cr:n ,
Discard = \use_none:n
}
\hook_gput_code:nnn { begindocument } { . }
@@ -1336,7 +1347,7 @@
\cs_if_exist_use:cF { PitonIdentifier _ \l_piton_language_str _ #1 }
{
\cs_if_exist_use:cF { PitonIdentifier _ #1 }
- { \PitonStyle { Identifier } }
+ { \PitonStyle { Identifier } }
}
{ #1 }
}
@@ -1365,7 +1376,8 @@
{ \seq_gremove_all:Nn \g__piton_languages_seq { ##1 } }
}
\cs_new_protected:Npn \__piton_clear_functions_i:n #1
- { \exp_args:Ne \__piton_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+ { \__piton_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+\cs_generate_variant:Nn \__piton_clear_functions_ii:n { e }
\cs_new_protected:Npn \__piton_clear_functions_ii:n #1
{
\seq_if_exist:cT { g__piton_functions _ #1 _ seq }
@@ -1386,7 +1398,7 @@
\seq_gclear:N \g__piton_languages_seq
}
\AddToHook { env / piton / begin }
- { \msg_fatal:nn { piton } { No~environment~piton } }
+ { \__piton_fatal:n { No~environment~piton } }
\msg_new:nnn { piton } { No~environment~piton }
{
@@ -1503,6 +1515,7 @@
break-lines,~
break-lines-in-piton,~
break-lines-in-Piton,~
+ break-strings-anywhere,~
continuation-symbol,~
continuation-symbol-on-indentation,~
detected-beamer-commands,~
@@ -1549,7 +1562,7 @@
}
\cs_new_protected:Npn \__piton_test_version:n #1
{
- \str_if_eq:VnF \PitonFileVersion { #1 }
+ \str_if_eq:onF \PitonFileVersion { #1 }
{ \__piton_error:n { bad~version~of~piton.lua } }
}
\hook_gput_code:nnn { begindocument } { . }
@@ -1566,17 +1579,18 @@
lpeg.locale(lpeg)
local P , alpha , C , space , S , V
= lpeg.P , lpeg.alpha , lpeg.C , lpeg.space , lpeg.S , lpeg.V
- local function add(...)
- local s = P ( false )
- for _ , x in ipairs({...}) do s = s + x end
- return s
- end
+ local add
+ function add(...)
+ local s = P ( false )
+ for _ , x in ipairs({...}) do s = s + x end
+ return s
+ end
local my_lpeg =
P { "E" ,
E = ( V "F" * ( "," * V "F" ) ^ 0 ) / add ,
F = space ^ 0 * ( ( alpha ^ 1 ) / "\\%0" ) * space ^ 0
}
- function piton.addDetectedCommands( key_value )
+ function piton.addDetectedCommands ( key_value )
piton.DetectedCommands = piton.DetectedCommands + my_lpeg : match ( key_value )
end
function piton.addBeamerCommands( key_value )
@@ -1583,11 +1597,12 @@
piton.BeamerCommands
= piton.BeamerCommands + my_lpeg : match ( key_value )
end
- local function insert(...)
- local s = piton.beamer_environments
- for _ , x in ipairs({...}) do table.insert(s,x) end
- return s
- end
+ local insert
+ function insert(...)
+ local s = piton.beamer_environments
+ for _ , x in ipairs({...}) do table.insert(s,x) end
+ return s
+ end
local my_lpeg_bis =
P { "E" ,
E = ( V "F" * ( "," * V "F" ) ^ 0 ) / insert ,
More information about the tex-live-commits
mailing list.