texlive[67790] Master/texmf-dist: piton (1aug23)
commits+karl at tug.org
commits+karl at tug.org
Tue Aug 1 22:06:59 CEST 2023
Revision: 67790
http://tug.org/svn/texlive?view=revision&revision=67790
Author: karl
Date: 2023-08-01 22:06:59 +0200 (Tue, 01 Aug 2023)
Log Message:
-----------
piton (1aug23)
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/source/lualatex/piton/piton.ins
trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2023-08-01 20:06:48 UTC (rev 67789)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2023-08-01 20:06:59 UTC (rev 67790)
@@ -59,13 +59,12 @@
}
-
-
\NewDocumentCommand {\pkg} {m} {\textsf{#1}}
\NewDocumentCommand {\cls} {m} {\textsf{#1}}
\setlength{\parindent}{0pt}
+\def\CC{{C\nolinebreak[4]\hspace{-.05em}\raisebox{.4ex}{\tiny\bfseries ++}}}
\begin{document}
@@ -81,8 +80,9 @@
\maketitle
\begin{abstract}
-L'extension \pkg{piton} propose des outils pour composer du code Python avec une coloration syntaxique
-en utilisant la bibliothèque Lua LPEG. L'extension \pkg{piton} nécessite l'emploi de LuaLaTeX.
+L'extension \pkg{piton} propose des outils pour composer des codes informatiques en Python, OCaml et C avec une
+coloration syntaxique en utilisant la bibliothèque Lua LPEG. L'extension \pkg{piton} nécessite l'emploi de
+LuaLaTeX.
\end{abstract}
@@ -91,11 +91,11 @@
L'extension \pkg{piton} utilise la librairie Lua nommée LPEG\footnote{LPEG est une librairie de capture de motifs
(\emph{pattern-matching} en anglais) pour Lua, écrite en C, fondée sur les PEG (\emph{parsing expression
- grammars}): \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} pour «parser» le code Python et le composer avec un
-coloriage syntaxique. Comme elle utilise du code Lua, elle fonctionne uniquement avec |lualatex| (et ne va pas
-fonctionner avec les autres moteurs de compilation LaTeX, que ce soit |latex|, |pdflatex| ou |xelatex|). Elle
-n'utilise aucun programme extérieur et la compilation ne requiert donc pas |--shell-escape|. La compilation est
-très rapide puisque tout le travail du parseur est fait par la librairie LPEG, écrite en C.
+ grammars}): \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} pour «parser» le code Python, OCaml ou C et le
+composer avec un coloriage syntaxique. Comme elle utilise du code Lua, elle fonctionne uniquement avec |lualatex|
+(et ne va pas fonctionner avec les autres moteurs de compilation LaTeX, que ce soit |latex|, |pdflatex| ou
+|xelatex|). Elle n'utilise aucun programme extérieur et la compilation ne requiert donc pas |--shell-escape|. La
+compilation est très rapide puisque tout le travail du parseur est fait par la librairie LPEG, écrite en C.
\bigskip
Voici un exemple de code Python composé avec l'environnement |{Piton}| proposé par \pkg{piton}.
@@ -130,8 +130,27 @@
d'installer \pkg{piton} avec une distribution TeX comme MiKTeX, TeX~Live ou MacTeX.
+
\section{Utilisation de l'extension}
+\subsection{Choix du langage}
+
+L'extension \pkg{piton} prend en charge trois langages informatiques : Python, OCaml et C, ou plutôt \CC.
+
+\smallskip
+Par défaut, le language est Python.
+
+\smallskip
+On peut changer de langage avec la clé |language| de |\PitonOptions| :
+
+\smallskip
+|\PitonOptions{language = C}|
+
+\smallskip
+Dans la suite de ce document, on parlera de Python mais les fonctionnalités s'appliquent aussi aux autres langages.
+
+
+
\subsection{Chargement de l'extension}
L'extension \pkg{piton} se charge simplement avec la commande |\usepackage| : |\usepackage{piton}|.
@@ -264,7 +283,7 @@
(\pkg{piton} utilise simplement en interne la commande LaTeX standard |\ttfamily|).
-\subsection{La commande \textbackslash PitonOptions}
+\subsection{Les clés de la commande \textbackslash PitonOptions}
\NewDocumentCommand{\Definition}{m}
{{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily \vphantom{gl}#1}}}
@@ -271,9 +290,15 @@
La commande |\PitonOptions| prend en argument une liste de couples \textsl{clé=valeur}. La portée des réglages
-effectués par cette commande est le groupe TeX courant.\footnote{On rappelle que tout environnement LaTeX est, en particulier, un groupe.}
+effectués par cette commande est le groupe TeX courant.\footnote{On rappelle que tout environnement LaTeX est, en
+ particulier, un groupe.}
+Ces clés peuvent aussi être appliquées à un environnement |{Piton}| individuel (entre crochets).
+
\begin{itemize}
+\item La clé \Definition{language} spécifie le langage informatique considéré (la casse n'est pas prise en compte).
+Trois valeurs sont possibles : |Python|, |OCaml| et |C|. La valeur initiale est |Python|.
+
\item La clé \Definition{gobble} prend comme valeur un entier positif $n$ : les $n$ premiers caractères de chaque
ligne sont alors retirés (avant formatage du code) dans les environnements |{Piton}|. Ces $n$ caractères ne sont
pas nécessairement des espaces.
@@ -294,9 +319,7 @@
\item Avec la clé \Definition{all-line-numbers}, \emph{toutes} les lignes sont numérotées, y compris les lignes vides.
-\item \colorbox{yellow!50}{\textbf{Nouveau 1.5}}\par\nobreak
-
-La clé \Definition{numbers-sep} est la distance horizontale entre les numéros de lignes (insérés par |line-numbers|
+\item La clé \Definition{numbers-sep} est la distance horizontale entre les numéros de lignes (insérés par |line-numbers|
ou |all-line-numbers|) et les lignes du code informatique. La valeur initiale est 0.7~em.
\item La clé \Definition{left-margin} fixe une marge sur la gauche. Cette clé peut être utile, en particulier, en
@@ -327,10 +350,9 @@
(\emph{read-eval-print loop}). Pour un exemple d'utilisation de cette clé, voir la partie \ref{pythonrepl}
p.~\pageref{pythonrepl}.
-\item \colorbox{yellow!50}{\textbf{Nouveau 1.6}}\enskip La clé \Definition{width} fixe la largeur du listing
-produit. Cette largeur s'applique aux fonds colorés spécifiés par les clés |background-color| et
-|prompt-background-color| et également quand une coupure automatique des lignes est demandée par |break-lines|
-(cf.~\ref{line-breaks}, p.~\pageref{line-breaks}).
+\item La clé \Definition{width} fixe la largeur du listing produit. Cette largeur s'applique aux fonds colorés
+spécifiés par les clés |background-color| et |prompt-background-color| et également quand une coupure automatique
+des lignes est demandée par |break-lines| (cf.~\ref{line-breaks}, p.~\pageref{line-breaks}).
Cette clé peut prendre comme valeur une longueur explicite mais aussi la valeur spéciale~|min|. Avec cette valeur,
la largeur sera calculée à partir de la largeur maximale des lignes de code. Attention : l'usage de cette valeur
@@ -361,55 +383,50 @@
\begingroup
\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
\begin{Verbatim}
-~emphase&\PitonOptions{line-numbers,auto-gobble,background-color = gray!15}@
-\begin{Piton}
- from math import pi
-
- def arctan(x,n=10):
- """Calcule la valeur mathématique de arctan(x)
-
- n est le nombre de termes de la somme
- """
- if x < 0:
- return -arctan(-x) # appel récursif
- elif x > 1:
- return pi/2 - arctan(1/x)
- #> (on a utilisé le fait que $\arctan(x)+\arctan(1/x)=\pi/2$ pour $x>0$)
- else:
- s = 0
- for k in range(n):
- s += (-1)**k/(2*k+1)*x**(2*k+1)
- return s
+~emphase&\begin{Piton}[language=C,line-numbers,auto-gobble,background-color = gray!15]@
+ void bubbleSort(int arr[], int n) {
+ int temp;
+ int swapped;
+ for (int i = 0; i < n-1; i++) {
+ swapped = 0;
+ for (int j = 0; j < n - i - 1; j++) {
+ if (arr[j] > arr[j + 1]) {
+ temp = arr[j];
+ arr[j] = arr[j + 1];
+ arr[j + 1] = temp;
+ swapped = 1;
+ }
+ }
+ if (!swapped) break;
+ }
+ }
\end{Piton}
\end{Verbatim}
\endgroup
-\begingroup
-\PitonOptions{line-numbers,auto-gobble,background-color = gray!15}
-\begin{Piton}
- from math import pi
+\begin{Piton}[language=C,line-numbers,auto-gobble,background-color = gray!15]
+ void bubbleSort(int arr[], int n) {
+ int temp;
+ int swapped;
+ for (int i = 0; i < n-1; i++) {
+ swapped = 0;
+ for (int j = 0; j < n - i - 1; j++) {
+ if (arr[j] > arr[j + 1]) {
+ temp = arr[j];
+ arr[j] = arr[j + 1];
+ arr[j + 1] = temp;
+ swapped = 1;
+ }
+ }
+ if (!swapped) break;
+ }
+ }
+\end{Piton}
- def arctan(x,n=10):
- """Compute the value of arctan(x)
- n is the number of terms in the sum
- """
- if x < 0:
- return -arctan(-x) # appel récursif
- elif x > 1:
- return pi/2 - arctan(1/x)
- #> (on a utilisé le fait que $\arctan(x)+\arctan(1/x)=\pi/2$ pour $x>0$)
- else:
- s = 0
- for k in range(n):
- s += (-1)**k/(2*k+1)*x**(2*k+1)
- return s
-\end{Piton}
-\endgroup
-
\bigskip
La commande |\PitonOptions| propose d'autres clés qui seront décrites plus loin (voir en particulier la coupure des
pages et des lignes p.~\pageref{breakable}).
@@ -460,43 +477,6 @@
fond coloré dont la couleur est la couleur HTML |#F0F3F3|. Il est possible d'avoir la même couleur dans |{Piton}|
avec l'instruction : |\PitonOptions{background-color = [HTML]{F0F3F3}}|}
-\begin{table}[htb]
-\centering
-\caption{Les styles proposés par \pkg{piton}}
-\label{Semantic}
-\begin{tabularx}{0.9\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 \\
-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{\}}) \\
-Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \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.Function & le nom des fonctions définies par l'utilisateur \emph{au moment de leur définition}, c'est-à-dire
- après le mot-clé \verb|def| \\
-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| \\
-Exception & le nom des exceptions prédéfinies (ex.: SyntaxError) \\
-Comment & les commentaires commençant par \texttt{\#} \\
-Comment.LaTeX & les commentaires commençant par \texttt{\#>} qui sont composés en LaTeX par \pkg{piton} (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, lambda, non local,
- pass, raise, return, try, while,
- with, yield, yield from.\\
-\bottomrule
-\end{tabularx}
-\end{table}
\bigskip
La commande |\PitonStyle| prend en argument le nom d'un style et permet de récupérer la valeur (en tant que liste
@@ -511,13 +491,12 @@
semi-globales et des commandes à argument présentes dans la valeur courante du style \texttt{\textsl{style}}.
-\vspace{1cm} \colorbox{yellow!50}{\textbf{Nouveau 1.6}}\par\nobreak
-
-Il existe un style spécial nommé |UserFunction|. Ce style s'applique aux noms des fonctions précédemment définies
+\bigskip
+Il existe un style spécial nommé |UserFunction|. Ce style s'applique aux noms des fonctions précédemment définies
par l'utilisateur via une instruction Python \piton{def} dans l'un des listings précédents. La valeur initiale de
ce style est nulle (=vide), ce qui fait que ces noms de fonctions sont formatés comme du texte courant (en noir).
Néanmoins, il est possible de changer la valeur de ce style, comme tous les autres styles, avec la commande
-|\PitonSetStyle|.
+|\SetPitonStyle|.
\medskip
@@ -527,7 +506,7 @@
\begingroup
\begin{Verbatim}
-\PitonSetStyle{~emphase#UserFunction@ = \color[HTML]{CC00FF}}
+\SetPitonStyle{~emphase#UserFunction@ = \color[HTML]{CC00FF}}
\end{Verbatim}
\SetPitonStyle{UserFunction = \color[HTML]{CC00FF}}
@@ -554,7 +533,7 @@
\bigskip
Bien sûr, la liste des noms de fonctions Python précédemment définies est gardée en mémoire de LuaLaTeX (de manière
-globale, c'est-à-dire indépendamment des groupes TeX). L'extension \pkg{piton} fournit une commande pour permet de
+globale, c'est-à-dire indépendamment des groupes TeX). L'extension \pkg{piton} fournit une commande qui permet de
vider cette liste : c'est la commande |\PitonClearUserFunctions|.
@@ -573,13 +552,6 @@
Par exemple, avec l'instruction suivante, un nouvel environnement |{Python}| sera défini avec le même comportement
que l'environnement |{Piton}|:
-{\color{gray}\verb|\NewPitonEnvironment{Python}{}{}{}|}
-
-
-\bigskip
-Si on souhaite un environnement |{Python}| qui prenne en argument optionnel entre crochets les clés de
-|\PitonOptions|, on peut écrire :
-
{\color{gray}\verb|\NewPitonEnvironment{Python}{O{}}{\PitonOptions{#1}}{}|}
\bigskip
@@ -1080,7 +1052,7 @@
Par défaut les listings produits par l'environnement |{Piton}| et par la commande |\PitonInputFile| sont
insécables.
-Néanmoins, la commande |\PitonOptions| propose la clé |splittable| pour autoriser de telles coupures.
+Néanmoins, la commande |\PitonOptions| propose la clé \Definition{splittable} pour autoriser de telles coupures.
\begin{itemize}
\item Si la clé |splittable| est utilisée sans valeur, les listings sont sécables n'importe où.
@@ -1107,13 +1079,13 @@
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).
\begin{itemize}
-\item Avec la clé |break-lines-in-piton|, les coupures de ligne sont autorisées dans la commande |\piton{...}|
-(mais pas dans la commande \verb+\piton|...|+, c'est-à-dire avec la syntaxe verbatim).
+\item Avec la clé \Definition{break-lines-in-piton}, les coupures de ligne sont autorisées dans la commande
+|\piton{...}| (mais pas dans la commande \verb+\piton|...|+, c'est-à-dire avec la syntaxe verbatim).
-\item Avec la clé |break-lines-in-Piton|, les coupures de ligne sont autorisées dans l'environnement |{Piton}|
-(d'où la lettre |P| capitale dans le nom) et les listings produits par |\PitonInputFile|.
+\item Avec la clé \Definition{break-lines-in-Piton}, les coupures de ligne sont autorisées dans l'environnement
+|{Piton}| (d'où la lettre |P| capitale dans le nom) et les listings produits par |\PitonInputFile|.
-\item La clé |break-lines| est la conjonction des deux clés précédentes.
+\item La clé \Definition{break-lines} est la conjonction des deux clés précédentes.
\end{itemize}
\medskip
@@ -1120,17 +1092,18 @@
L'extension \pkg{piton} fournit aussi plusieurs clés pour contrôler l'apparence des coupures de ligne autorisées par |break-lines-in-Piton|.
\begin{itemize}
-\item Avec la clé |indent-broken-lines|, l'indentation de la ligne coupée est respectée à chaque retour à la ligne.
+\item Avec la clé \Definition{indent-broken-lines}, l'indentation de la ligne coupée est respectée à chaque retour
+à la ligne.
-\item La clé |end-of-broken-line| correspond au symbole placé à la fin d'une ligne coupée. Sa valeur initiale est :
+\item La clé \Definition{end-of-broken-line} correspond au symbole placé à la fin d'une ligne coupée. Sa valeur initiale est :
|\hspace*{0.5em}\textbackslash|.
-\item La clé |continuation-symbol| correspond au symbole placé à chaque retour de ligne dans la marge gauche. Sa
-valeur initiale est : |+\;|.
+\item La clé \Definition{continuation-symbol} correspond au symbole placé à chaque retour de ligne dans la marge
+gauche. Sa valeur initiale est : |+\;|.
-\item La clé |continuation-symbol-on-indentation| correspond au symbole placé à chaque retour de ligne au niveau de
-l'indentation (uniquement dans le cas où la clé |indent-broken-lines| est active). Sa valeur initiale est :
-|$\hookrightarrow\;$|.
+\item La clé \Definition{continuation-symbol-on-indentation} correspond au symbole placé à chaque retour de ligne
+au niveau de l'indentation (uniquement dans le cas où la clé |indent-broken-lines| est active). Sa valeur initiale
+est : |$\hookrightarrow\;$|.
\end{itemize}
\bigskip
@@ -1745,7 +1718,176 @@
\end{PitonREPL}
+\newpage
+\section{Les styles pour les différents langages informatiques}
+
+\label{Semantic}
+
+
+\subsection{Le langage Python}
+
+Le langage par défaut de l'extension \pkg{piton} est Python. Si besoin est, on peut revenir au langage Python avec
+|\PitonOptions{language=Python}|.
+
+\vspace{1cm}
+
+\begin{center}
+\begin{tabularx}{0.9\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+|+ \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| \\
+ 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, lambda, non local,
+ pass, raise, return, try, while,
+ with, yield et yield from.\\
+ \bottomrule
+\end{tabularx}
+\end{center}
+
+
+\newpage
+
+\subsection{Le langage OCaml}
+
+On peut basculer vers le langage |OCaml| avec |\PitonOptions{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}
+
+
+\vspace{1cm}
+
+
+\begin{center}
+\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+ \toprule
+ \normalfont Style & Usage \\
+ \midrule
+ Number & les nombres \\
+ String.Short & les caractères (entre \texttt{'}) \\
+ String.Long & les chaînes de caractères, entre |"| mais aussi les \emph{quoted-strings} \\
+ String & cette clé fixe à la fois |String.Short| et |String.Long| \\
+ Operator & les opérateurs, en particulier |+|, |-|, |/|, |*|, |@|, |!=|, |==|, |&&| \\
+ Operator.Word & les opérateurs suivants : |and|, |asr|, |land|, |lor|, |lsl|, |lxor|, |mod| et |or| \\
+ Name.Builtin & les fonctions |not|, |incr|, |decr|, |fst| et |snd| \\
+ Name.Type & le nom des types OCaml \\
+ Name.Field & le nom d'un champ de module \\
+ Name.Constructor & le nom des constructeurs de types (qui débutent par une majuscule) \\
+ Name.Module & le nom des modules \\
+ 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) \\
+ 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 \\
+ Keyword.Constant & |true| et |false| \\
+ Keyword & les mots-clés suivants :
+ |assert|, |as|, |begin|, |class|, |constraint|, |done|,
+ |downto|, |do|, |else|, |end|, |exception|, |external|,
+ |for|, |function|, |functor|, |fun| , |if|
+ |include|, |inherit|, |initializer|, |in| , |lazy|, |let|,
+ |match|, |method|, |module|, |mutable|, |new|, |object|,
+ |of|, |open|, |private|, |raise|, |rec|, |sig|,
+ |struct|, |then|, |to|, |try|, |type|,
+ |value|, |val|, |virtual|, |when|, |while| et |with| \\
+ \bottomrule
+\end{tabularx}
+\end{center}
+
+\newpage
+
+\subsection[Le langage C (et C++)]{Le langage C (et \CC)}
+
+
+On peut basculer vers le langage |C| avec |\PitonOptions{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}
+
+
+\vspace{1cm}
+
+\begin{center}
+\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+\toprule
+\normalfont Style & Usage \\
+\midrule
+Number & les nombres \\
+String.Long & les chaînes de caractères (entre \texttt{"}) \\
+String.Interpol & les éléments \texttt{\%d}, \texttt{\%i}, \texttt{\%f}, \texttt{\%c}, etc. dans les chaînes de
+ caractères ; ce style hérite du style |String.Long| \\
+Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \verb|@| \\
+Name.Type & les types prédéfinis suivants :
+ |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 & 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 mot-clé \verb|class| \\
+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) \\
+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 \pkg{piton} comme du code LaTeX (et
+ appelés simplement «commentaires LaTeX» dans ce document) \\
+Keyword.Constant & |default|, |false|, |NULL|, |nullptr| et |true| \\
+Keyword & les mots-clés suivants :
+|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| et |while|
+\\
+\bottomrule
+\end{tabularx}
+\end{center}
+
+\newpage
+
\section*{Autre documentation}
Le document |piton.pdf| (fourni avec l'extension \pkg{piton}) contient une traduction anglaise de la
@@ -1770,4 +1912,6 @@
\tableofcontents
+
+
\end{document}
\ No newline at end of file
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2023-08-01 20:06:48 UTC (rev 67789)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2023-08-01 20:06:59 UTC (rev 67790)
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{1.6a}
-\def\myfiledate{2023/07/08}
+\def\myfileversion{2.0}
+\def\myfiledate{2023/08/01}
%
%
%<*batchfile>
@@ -61,6 +61,8 @@
\parindent 0pt
\skip\footins = 2\bigskipamount
+\def\CC{{C\nolinebreak[4]\hspace{-.05em}\raisebox{.4ex}{\tiny\bfseries ++}}}
+
\PitonOptions{gobble=2}
\EnableCrossrefs
@@ -80,8 +82,9 @@
% \maketitle
%
% \begin{abstract}
-% The package \pkg{piton} provides tools to typeset Python listings with
-% syntactic highlighting by using the Lua library LPEG. It requires LuaLaTeX.
+% The package \pkg{piton} provides tools to typeset computer listings in Python,
+% OCaml and C with syntactic highlighting by using the Lua library LPEG. It
+% requires LuaLaTeX.
% \end{abstract}
%
%
@@ -91,12 +94,14 @@
%
% The package \pkg{piton} uses the Lua library LPEG\footnote{LPEG is a
% pattern-matching library for Lua, written in C, based on \emph{parsing
-% expression grammars}: \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} for
-% parsing Python listings and typeset them with syntactic highlighting. Since it
-% uses Lua code, it works with |lualatex| only (and won't work with the other
-% engines: |latex|, |pdflatex| and |xelatex|). It does not use external program
-% and the compilation does not require |--shell-escape|. The compilation is very
-% fast since all the parsing is done by the library LPEG, written in C.
+% expression grammars}:
+% \url{http://www.inf.puc-rio.br/~roberto/lpeg/}}
+% for parsing Python OCaml or C listings and typesets them with syntactic
+% highlighting. Since it uses Lua code, it works with |lualatex| only (and won't
+% work with the other engines: |latex|, |pdflatex| and |xelatex|). It does not
+% use external program and the compilation does not require |--shell-escape|.
+% The compilation is very fast since all the parsing is done by the library
+% LPEG, written in C.
%
% \bigskip
% Here is an example of code typeset by \pkg{piton}, with the environment |{Piton}|.
@@ -149,6 +154,22 @@
% another LaTeX engine (|latex|, |pdflatex|, |xelatex|,\dots ) is used, a
% fatal error will be raised.
% \end{itemize}
+%
+% \subsection{Choice of the computer language}
+%
+% In current version, the package \pkg{piton} supports three computer languages:
+% Python, OCaml and C (in fact \CC).
+%
+% \smallskip
+% By default, the language used is Python.
+%
+% \smallskip
+% It's possible to change the current language with the command |\PitonOptions|
+% and its key |language|: |\PitonOptions{language = C}|.
+%
+% \smallskip
+% In what follows, we will speak of Python, but the features described also
+% apply to the other languages.
%
% \subsection{The tools provided to the user}
%
@@ -268,7 +289,7 @@
% current monospaced font. The package \pkg{piton} merely uses internally the
% standard LaTeX command |\texttt|.
%
-% \subsection{The command \textbackslash PitonOptions}
+% \subsection{The keys of the command \textbackslash PitonOptions}
%
%
% \NewDocumentCommand{\Definition}{m}
@@ -279,7 +300,14 @@
% the current TeX group.\footnote{We remind that a LaTeX environment is, in
% particular, a TeX group.}
%
+% These keys may also be applied to an individual environment |{Piton}| (between
+% square brackets).
+%
% \begin{itemize}
+% \item The key \Definition{language} speficies which computer language is
+% considered (that key is case-insensitive). Three values are allowed :
+% |Python|, |OCaml| and |C|. the initial value is |Python|.
+%
% \item The key \Definition{gobble} takes in as value a
% positive integer~$n$: the first $n$ characters are discarded (before the
% process of highlightning of the code) for each line of the environment
@@ -307,9 +335,7 @@
% \item With the key \Definition{all-line-numbers}, \emph{all} the lines are numbered,
% including the empty ones.
%
-% \item \colorbox{yellow!50}{\bfseries{New 1.5}}\par\nobreak
-%
-% The key \Definition{numbers-sep} is the horizontal distance between the
+% \item The key \Definition{numbers-sep} is the horizontal distance between the
% numbers of lines (inserted by |line-numbers| of |all-line-numbers|) and the
% beginning of the lines of code. The initial value is 0.7~em.
%
@@ -348,11 +374,11 @@
% continuation ``|...|'') characteristic of the Python consoles with
% \textsc{repl} (\emph{read-eval-print loop}).
%
-% \item \colorbox{yellow!50}{\textbf{New 1.6}}\enskip The key |width| will fix
-% the width of the listing. That width applies to the colored backgrounds
-% specified by |background-color| and |prompt-background-color| but also for the
-% automatic breaking of the lines (when required by |break-lines|:
-% cf.~\ref{line-breaks}, p.~\pageref{line-breaks}).
+% \item The key |width| will fix the width of the listing. That width applies to
+% the colored backgrounds specified by |background-color| and
+% |prompt-background-color| but also for the automatic breaking of the lines
+% (when required by |break-lines|: cf.~\ref{line-breaks},
+% p.~\pageref{line-breaks}).
%
% That key may take in as value a numeric value but also the special
% value~|min|. With that value, the width will be computed from the maximal
@@ -383,54 +409,52 @@
% \end{itemize}
%
% \bigskip
-%
% \begingroup
% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
% \begin{Verbatim}
-% ~emphase&\PitonOptions{line-numbers,auto-gobble,background-color = gray!15}@
-% \begin{Piton}
-% from math import pi
-% def arctan(x,n=10):
-% """Compute the mathematical value of arctan(x)
-%
-% n is the number of terms in the sum
-% """
-% if x < 0:
-% return -arctan(-x) # recursive call
-% elif x > 1:
-% return pi/2 - arctan(1/x)
-% #> (we have used that $\arctan(x)+\arctan(1/x)=\frac{\pi}{2}$ pour $x>0$)
-% else
-% s = 0
-% for k in range(n):
-% s += (-1)**k/(2*k+1)*x**(2*k+1)
-% return s
+% ~emphase&\begin{Piton}[language=C,line-numbers,auto-gobble,background-color = gray!15]@
+% void bubbleSort(int arr[], int n) {
+% int temp;
+% int swapped;
+% for (int i = 0; i < n-1; i++) {
+% swapped = 0;
+% for (int j = 0; j < n - i - 1; j++) {
+% if (arr[j] > arr[j + 1]) {
+% temp = arr[j];
+% arr[j] = arr[j + 1];
+% arr[j + 1] = temp;
+% swapped = 1;
+% }
+% }
+% if (!swapped) break;
+% }
+% }
% \end{Piton}
% \end{Verbatim}
% \endgroup
%
% \begingroup
-% \PitonOptions{line-numbers,background-color = gray!15}
-% \begin{Piton}
-% from math import pi
+% \PitonOptions{language=C,line-numbers,gobble=6,background-color = gray!15}
+% \begin{Piton}
+% void bubbleSort(int arr[], int n) {
+% int temp;
+% int swapped;
+% for (int i = 0; i < n-1; i++) {
+% swapped = 0;
+% for (int j = 0; j < n - i - 1; j++) {
+% if (arr[j] > arr[j + 1]) {
+% temp = arr[j];
+% arr[j] = arr[j + 1];
+% arr[j + 1] = temp;
+% swapped = 1;
+% }
+% }
+% if (!swapped) break;
+% }
+% }
+% \end{Piton}
+% \endgroup
%
-% def arctan(x,n=10):
-% """Compute the mathematical value of arctan(x)
-%
-% n is the number of terms in the sum
-% """
-% if x < 0:
-% return -arctan(-x) # recursive call
-% elif x > 1:
-% return pi/2 - arctan(1/x)
-% #> (we have used that $\arctan(x)+\arctan(1/x)=\frac{\pi}{2}$ for $x>0$)
-% else
-% s = 0
-% for k in range(n):
-% s += (-1)**k/(2*k+1)*x**(2*k+1)
-% return s
-% \end{Piton}
-% \endgroup
%
% \bigskip
% The command |\PitonOptions| provides in fact several other keys which will be
@@ -499,57 +523,14 @@
% with arguments which may be present in the definition of the style
% \texttt{\textsl{style}}.
%
-% \begin{table}[b]
-% \centering
-% \caption{Usage of the different styles}
-% \label{Semantic}
-% \begin{tabular}{@{}>{\ttfamily}l>{\RaggedRight\arraybackslash}p{9cm}@{}}
-% \toprule
-% \normalfont Style & Usage \\
-% \midrule
-% Number & the numbers \\
-% String.Short & the short strings (between \texttt{'} or \verb|"|) \\
-% String.Long & the long strings (between \texttt{'''} or \verb|"""|) except the
-% documentation strings \\
-% String & that keys sets both |String.Short| and |String.Long| \\
-% String.Doc & the documentation strings (only between \texttt{"""} following
-% PEP~257) \\
-% String.Interpol & the syntactic elements of the fields of the f-strings (that
-% is to say the characters \texttt{\{} and \texttt{\}}) \\
-% Operator & the following operators : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ \verb|@|\\
-% Operator.Word & the following operators : \texttt{in}, \texttt{is},
-% \texttt{and}, \texttt{or} and \texttt{not} \\
-% Name.Builtin & the predefined functions of Python \\
-% Name.Function & the name of the functions defined by the user, at the point of
-% their definition (that is to say after the keyword |def|) \\
-% Name.Decorator & the decorators (instructions beginning by \verb|@|) \\
-% Name.Namespace & the name of the modules (= external libraries) \\
-% Name.Class & the name of the classes at the point of their definition (that is
-% to say after the keyword |class|) \\
-% Exception & the names of the exceptions (eg: \texttt{SyntaxError}) \\
-% Comment & the comments beginning with \verb|#| \\
-% Comment.LaTeX & the comments beginning by \verb|#>|, which are composed in LaTeX by
-% \pkg{piton} (and simply called ``LaTeX comments'' in this document) \\
-% Keyword.Constant & |True|, |False| and |None| \\
-% Keyword & the following keywords :
-% \ttfamily as, assert, break, case, continue, def, del,
-% elif, else, except, exec, finally, for, from,
-% global, if, import, lambda, non local,
-% pass, raise, return, try, while,
-% with, yield, yield from.\\
-% \bottomrule
-% \end{tabular}
-% \end{table}
+% \bigskip
%
-%
-% \vspace{1cm} \colorbox{yellow!50}{\textbf{New 1.6}}\par\nobreak
-%
% The extension \pkg{piton} provides a special style called~|UserFunction|. That
% style applies to the names of the functions previously defined by the user via
% an instruction Python \piton{def} in one of the previous listings. The initial
% value of that style is empty, and, therefore, the names of the functions are
% formatted as standard text (in black). However, it's possible to change the
-% value of that style, as any other style, with the command |\PitonSetStyle|.
+% value of that style, as any other style, with the command |\SetPitonStyle|.
%
% \medskip
% In the following example, we fix as value for that style |UserFunction| the
@@ -559,7 +540,7 @@
% \begingroup
%
% \begin{Verbatim}
-% \PitonSetStyle{~emphase#UserFunction@ = \color[HTML]{CC00FF}}
+% \SetPitonStyle{~emphase#UserFunction@ = \color[HTML]{CC00FF}}
% \end{Verbatim}
%
% \SetPitonStyle{UserFunction = \color[HTML]{CC00FF}}
@@ -609,13 +590,6 @@
% With the following instruction, a new environment |{Python}| will be
% constructed with the same behaviour as |{Piton}|:
%
-% {\color{gray}\verb|\NewPitonEnvironment{Python}{}{}{}|}
-%
-% \bigskip
-% If one wishes an environment |{Python}| with takes in as optional argument
-% (between square brackets) the keys of the command |\PitonOptions|, it's
-% possible to program as follows:
-%
% {\color{gray}\verb|\NewPitonEnvironment{Python}{O{}}{\PitonOptions{#1}}{}|}
%
% \bigskip
@@ -1130,12 +1104,12 @@
% By default, the listings produced by the environment |{Piton}| and the command
% |\PitonInputFile| are not breakable.
%
-% However, the command |\PitonOptions| provides the key |splittable| to allow such
-% breaks.
+% However, the command |\PitonOptions| provides the key \Definition{splittable}
+% to allow such breaks.
%
% \begin{itemize}
-% \item If the key |splittable| is used without any value, the listings are
-% breakable everywhere.
+% \item If the key |splittable| is used without any value, the
+% listings are breakable everywhere.
% \item If the key |splittable| is used with a numeric value~$n$ (which must be
% a non-negative integer number), the listings are breakable but no break will
% occur within the first $n$ lines and within the last $n$ lines. Therefore,
@@ -1159,13 +1133,13 @@
% line. However, there are keys to allow such breaks (the possible breaking
% points are the spaces, even the spaces in the Python strings).
% \begin{itemize}
-% \item With the key |break-lines-in-piton|, the line breaks are allowed in the
-% command |\piton{...}| (but not in the command \verb+\piton|...|+, that is to say
-% the command |\piton| in verbatim mode).
-% \item With the key |break-lines-in-Piton|, the line breaks are allowed in the
-% environment |{Piton}| (hence the capital letter |P| in the name) and in the
+% \item With the key \Definition{break-lines-in-piton}, the line breaks are
+% allowed in the command |\piton{...}| (but not in the command
+% \verb+\piton|...|+, that is to say the command |\piton| in verbatim mode).
+% \item With the key \Definition{break-lines-in-Piton}, the line breaks are
+% allowed in the environment |{Piton}| (hence the capital letter |P| in the name) and in the
% listings produced by |\PitonInputFile|.
-% \item The key |break-lines| is a conjonction of the two previous keys.
+% \item The key \Definition{break-lines} is a conjonction of the two previous keys.
% \end{itemize}
%
% \bigskip
@@ -1173,18 +1147,19 @@
% on the line breaks allowed by |break-lines-in-Piton|.
%
% \begin{itemize}
-% \item With the key |indent-broken-lines|, the indentation of a broken line is
-% respected at carriage return.
+% \item With the key \Definition{indent-broken-lines}, the indentation of a
+% broken line is respected at carriage return.
%
-% \item The key |end-of-broken-line| corresponds to the symbol placed at the end
-% of a broken line. The initial value is: |\hspace*{0.5em}\textbackslash|.
+% \item The key \Definition{end-of-broken-line} corresponds to the symbol placed
+% at the end of a broken line. The initial value is:
+% |\hspace*{0.5em}\textbackslash|.
%
-% \item The key |continuation-symbol| corresponds to the symbol placed at each
-% carriage return. The initial value is: |+\;|.
+% \item The key \Definition{continuation-symbol} corresponds to the symbol
+% placed at each carriage return. The initial value is: |+\;|.
%
-% \item The key |continuation-symbol-on-indentation| coresponds to the symbol
-% placed at each carriage return, on the position of the indentation (only when
-% the key |indent-broken-line| is in force). The initial value is:
+% \item The key \Definition{continuation-symbol-on-indentation} corresponds to
+% the symbol placed at each carriage return, on the position of the indentation
+% (only when the key |indent-broken-line| is in force). The initial value is:
% |$\hookrightarrow\;$|.
% \end{itemize}
%
@@ -1646,7 +1621,185 @@
%
% \bigskip
% \clearpage
+% \section{The styles for the different computer languages}
%
+% \label{Semantic}
+%
+%
+% \subsection{The language Python}
+%
+% In \pkg{piton}, the default language is Python. If necessary, it's possible to
+% come back to the language Python with |\PitonOptions{language=Python}|.
+%
+%
+% \vspace{1cm}
+%
+% \begin{center}
+% \begin{tabularx}{0.9\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, lambda, non local,
+% pass, raise, return, try, while,
+% with, yield et yield from.\\
+% \bottomrule
+% \end{tabularx}
+% \end{center}
+%
+%
+% \newpage
+%
+% \subsection{The language OCaml}
+%
+% It's possible to switch to the language |OCaml| with |\PitonOptions{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}
+%
+%
+% \vspace{1cm}
+%
+%
+% \begin{center}
+% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+% \toprule
+% \normalfont Style & Use \\
+% \midrule
+% Number & the numbers \\
+% String.Short & the characters (between \texttt{'}) \\
+% String.Long & the strings, between |"| but also the \emph{quoted-strings} \\
+% String & that key fixes both |String.Short| and |String.Long| \\
+% Operator & les opérateurs, en particulier |+|, |-|, |/|, |*|, |@|, |!=|, |==|, |&&| \\
+% Operator.Word & les opérateurs suivants : |and|, |asr|, |land|, |lor|, |lsl|, |lxor|, |mod| et |or| \\
+% Name.Builtin & les fonctions |not|, |incr|, |decr|, |fst| et |snd| \\
+% Name.Type & the name of a type of OCaml \\
+% Name.Field & the name of a field of a module \\
+% Name.Constructor & the name of the constructors of types (which begins by a capital) \\
+% Name.Module & the name of the modules \\
+% Name.Function & the name of the Python functions defined by the user \emph{at their
+% point of definition} (with the keyword |let|) \\
+% UserFunction & the name of the Python functions previously defined by the user
+% (the initial value of that parameter is empty and these
+% elements are drawn in the current color, usually black) \\
+% Exception & the predefined exceptions (eg : |End_of_File|) \\
+% TypeParameter & the parameters of the type \\
+% Comment & the comments, between |(*| et |*)|; these comments may be nested \\
+% Keyword.Constant & |true| et |false| \\
+% Keyword & the following keywords:
+% |assert|, |as|, |begin|, |class|, |constraint|, |done|,
+% |downto|, |do|, |else|, |end|, |exception|, |external|,
+% |for|, |function|, |functor|, |fun| , |if|
+% |include|, |inherit|, |initializer|, |in| , |lazy|, |let|,
+% |match|, |method|, |module|, |mutable|, |new|, |object|,
+% |of|, |open|, |private|, |raise|, |rec|, |sig|,
+% |struct|, |then|, |to|, |try|, |type|,
+% |value|, |val|, |virtual|, |when|, |while| and |with| \\
+% \bottomrule
+% \end{tabularx}
+% \end{center}
+%
+% \newpage
+%
+% \subsection[The language C (and C++)]{The language C (and \CC)}
+%
+%
+% It's possible to switch to the language |C| with |\PitonOptions{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}
+%
+%
+% \vspace{1cm}
+%
+% \begin{center}
+% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+% \toprule
+% \normalfont Style & Use \\
+% \midrule
+% Number & the numbers \\
+% String.Long & the strings (between \texttt{"}) \\
+% 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|@| \\
+% 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
+% après le mot-clé \verb|class| \\
+% 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) \\
+% 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
+% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
+% Keyword.Constant & |default|, |false|, |NULL|, |nullptr| and |true| \\
+% 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|
+% \\
+% \bottomrule
+% \end{tabularx}
+% \end{center}
+%
+%
+% \newpage
+%
% \section{Implementation}
%
% % \medskip
@@ -2554,7 +2707,8 @@
% \begin{macrocode}
\keys_define:nn { PitonOptions }
{
- language .str_set:N = \l_@@_language_str ,
+ language .code:n =
+ \str_set:Nx \l_@@_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
gobble .int_set:N = \l_@@_gobble_int ,
gobble .value_required:n = true ,
@@ -3086,8 +3240,9 @@
% \begin{macrocode}
\bool_if:NTF \c_@@_beamer_bool
{
- \NewPitonEnvironment { Piton } { d < > }
+ \NewPitonEnvironment { Piton } { d < > O { } }
{
+ \PitonOptions { #2 }
\IfValueTF { #1 }
{ \begin { uncoverenv } < #1 > }
{ \begin { uncoverenv } }
@@ -3094,7 +3249,10 @@
}
{ \end { uncoverenv } }
}
- { \NewPitonEnvironment { Piton } { } { } { } }
+ { \NewPitonEnvironment { Piton } { O { } }
+ { \PitonOptions { #1 } }
+ { }
+ }
% \end{macrocode}
%
%
@@ -3194,117 +3352,85 @@
%
% \medskip
% \begin{macrocode}
+\clist_new:N \g_@@_style_clist
+\clist_set:Nn \g_@@_styles_clist
+ {
+ Comment ,
+ Comment.LaTeX ,
+ Exception ,
+ FormattingType ,
+ Identifier ,
+ InitialValues ,
+ Interpol.Inside ,
+ Keyword ,
+ Keyword.Constant ,
+ Name.Builtin ,
+ Name.Class ,
+ Name.Constructor ,
+ Name.Decorator ,
+ Name.Field ,
+ Name.Function ,
+ Name.Module ,
+ Name.Namespace ,
+ Name.Type ,
+ Number ,
+ Operator ,
+ Operator.Word ,
+ Preproc ,
+ Prompt ,
+ String.Doc ,
+ String.Interpol ,
+ String.Long ,
+ String.Short ,
+ TypeParameter ,
+ UserFunction
+ }
+
+\clist_map_inline:Nn \g_@@_styles_clist
+ {
+ \keys_define:nn { piton / Styles }
+ {
+ #1 .tl_set:c = pitonStyle #1 ,
+ #1 .value_required:n = true
+ }
+ }
+
\keys_define:nn { piton / Styles }
{
- String.Interpol .tl_set:c = pitonStyle String.Interpol ,
- String.Interpol .value_required:n = true ,
- FormattingType .tl_set:c = pitonStyle FormattingType ,
- FormattingType .value_required:n = true ,
- Dict.Value .tl_set:c = pitonStyle Dict.Value ,
- Dict.Value .value_required:n = true ,
- Name.Decorator .tl_set:c = pitonStyle Name.Decorator ,
- Name.Decorator .value_required:n = true ,
- Name.Field .tl_set:c = pitonStyle Name.Field ,
- Name.Field .value_required:n = true ,
- Name.Function .tl_set:c = pitonStyle Name.Function ,
- Name.Function .value_required:n = true ,
- UserFunction .tl_set:c = pitonStyle UserFunction ,
- UserFunction .value_required:n = true ,
- Keyword .tl_set:c = pitonStyle Keyword ,
- Keyword .value_required:n = true ,
- Keyword.Constant .tl_set:c = pitonStyle Keyword.Constant ,
- Keyword.constant .value_required:n = true ,
- String.Doc .tl_set:c = pitonStyle String.Doc ,
- String.Doc .value_required:n = true ,
- Interpol.Inside .tl_set:c = pitonStyle Interpol.Inside ,
- Interpol.Inside .value_required:n = true ,
- String.Long .tl_set:c = pitonStyle String.Long ,
- String.Long .value_required:n = true ,
- String.Short .tl_set:c = pitonStyle String.Short ,
- String.Short .value_required:n = true ,
- String .meta:n = { String.Long = #1 , String.Short = #1 } ,
- Comment.Math .tl_set:c = pitonStyle Comment.Math ,
- Comment.Math .default:n = \@@_math_scantokens:n ,
- Comment.Math .initial:n = ,
- Comment .tl_set:c = pitonStyle Comment ,
- Comment .value_required:n = true ,
- Name.Constructor .tl_set:c = pitonStyle Name.Constructor ,
- Name.Constructor .value_required:n = true ,
- InitialValues .tl_set:c = pitonStyle InitialValues ,
- InitialValues .value_required:n = true ,
- Number .tl_set:c = pitonStyle Number ,
- Number .value_required:n = true ,
- Name.Namespace .tl_set:c = pitonStyle Name.Namespace ,
- Name.Namespace .value_required:n = true ,
- Name.Module .tl_set:c = pitonStyle Name.Module ,
- Name.Module .value_required:n = true ,
- Name.Class .tl_set:c = pitonStyle Name.Class ,
- Name.Class .value_required:n = true ,
- Name.Builtin .tl_set:c = pitonStyle Name.Builtin ,
- Name.Builtin .value_required:n = true ,
- TypeParameter .tl_set:c = pitonStyle TypeParameter ,
- TypeParameter .value_required:n = true ,
- Name.Type .tl_set:c = pitonStyle Name.Type ,
- Name.Type .value_required:n = true ,
- Operator .tl_set:c = pitonStyle Operator ,
- Operator .value_required:n = true ,
- Operator.Word .tl_set:c = pitonStyle Operator.Word ,
- Operator.Word .value_required:n = true ,
- Exception .tl_set:c = pitonStyle Exception ,
- Exception .value_required:n = true ,
- Comment.LaTeX .tl_set:c = pitonStyle Comment.LaTeX ,
- Comment.LaTeX .value_required:n = true ,
- Identifier .tl_set:c = pitonStyle Identifier ,
- Comment.LaTeX .value_required:n = true ,
- ParseAgain.noCR .tl_set:c = pitonStyle ParseAgain.noCR ,
- ParseAgain.noCR .value_required:n = true ,
- ParseAgain .tl_set:c = pitonStyle ParseAgain ,
- ParseAgain .value_required:n = true ,
- Prompt .tl_set:c = pitonStyle Prompt ,
- Prompt .value_required:n = true ,
- unknown .code:n =
+ String .meta:n = { String.Long = #1 , String.Short = #1 } ,
+ Comment.Math .tl_set:c = pitonStyle Comment.Math ,
+ Comment.Math .default:n = \@@_math_scantokens:n ,
+ Comment.Math .initial:n = ,
+ ParseAgain .tl_set:c = pitonStyle ParseAgain ,
+ ParseAgain .value_required:n = true ,
+ ParseAgain.noCR .tl_set:c = pitonStyle ParseAgain.noCR ,
+ ParseAgain.noCR .value_required:n = true ,
+ unknown .code:n =
\msg_error:nn { piton } { Unknown~key~for~SetPitonStyle }
}
% \end{macrocode}
-%
-%
+%
% \bigskip
+% We add the word |String| to the list of the styles because we will use that
+% list in the error message for an unknown key in |\SetPitonStyle|.
+%
% \begin{macrocode}
-\msg_new:nnn { piton } { Unknown~key~for~SetPitonStyle }
- {
- The~style~'\l_keys_key_str'~is~unknown.\\
- This~key~will~be~ignored.\\
- The~available~styles~are~(in~alphabetic~order):~
- Comment,~
- Comment.LaTeX,~
- Dict.Value,~
- Exception,~
- Identifier,~
- InitialValues,~
- Keyword,~
- Keyword.Constant,~
- Name.Builtin,~
- Name.Class,~
- Name.Constructor,~
- Name.Decorator,~
- Name.Field,~
- Name.Function,~
- Name.Module,~
- Name.Namespace,~
- UserFunction,~
- Number,~
- Operator,~
- Operator.Word,~
- Prompt,~
- String,~
- String.Doc,~
- String.Long,~
- String.Short,~and~
- String.Interpol.
- }
+\clist_gput_left:Nn \g_@@_styles_clist { String }
% \end{macrocode}
%
% \bigskip
+% Of course, we sort that clist.
+% \begin{macrocode}
+\clist_gsort:Nn \g_@@_styles_clist
+ {
+ \str_compare:nNnTF { #1 } < { #2 }
+ \sort_return_same:
+ \sort_return_swapped:
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
% \subsubsection{The initial styles}
%
% The initial styles are inspired by the style ``manni'' of Pygments.
@@ -3334,9 +3460,9 @@
Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
Name.Type = \color[HTML]{336666} ,
InitialValues = \@@_piton:n ,
- Dict.Value = \@@_piton:n ,
Interpol.Inside = \color{black}\@@_piton:n ,
TypeParameter = \color[HTML]{336666} \itshape ,
+ Preproc = \color[HTML]{AA6600} \slshape ,
Identifier = \@@_identifier:n ,
UserFunction = ,
Prompt = ,
@@ -3463,6 +3589,17 @@
%
% \bigskip
% \subsubsection{The error messages of the package}
+%
+%
+% \begin{macrocode}
+\msg_new:nnn { piton } { Unknown~key~for~SetPitonStyle }
+ {
+ The~style~'\l_keys_key_str'~is~unknown.\\
+ This~key~will~be~ignored.\\
+ The~available~styles~are~(in~alphabetic~order):~
+ \clist_use:Nnnn \g_@@_styles_clist { ~and~ } { ,~ } { ~and~ }.
+ }
+% \end{macrocode}
%
% \begin{macrocode}
\msg_new:nnn { piton } { syntax~error }
@@ -3814,8 +3951,72 @@
local VisualSpace = space * Lc "\\l_@@_space_tl"
% \end{macrocode}
%
+% \bigskip
+% If the classe Beamer is used, some environemnts and commands of Beamer are
+% automatically detected in the listings of \pkg{piton}.
+% \begin{macrocode}
+local Beamer = P ( false )
+local BeamerBeginEnvironments = P ( true )
+local BeamerEndEnvironments = P ( true )
+if piton_beamer
+then
+% \bigskip
+% The following function will return a \textsc{lpeg} which will catch an
+% environment of Beamer (supported by \pkg{piton}), that is to say |{uncover}|,
+% |{only}|, etc.
+% \begin{macrocode}
+ local BeamerNamesEnvironments =
+ P "uncoverenv" + P "onlyenv" + P "visibleenv" + P "invisibleenv"
+ + P "alertenv" + P "actionenv"
+ BeamerBeginEnvironments =
+ ( space ^ 0 *
+ L
+ (
+ P "\\begin{" * BeamerNamesEnvironments * "}"
+ * ( P "<" * ( 1 - P ">" ) ^ 0 * P ">" ) ^ -1
+ )
+ * P "\r"
+ ) ^ 0
+ BeamerEndEnvironments =
+ ( space ^ 0 *
+ L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
+ * P "\r"
+ ) ^ 0
+% \end{macrocode}
%
+%
% \bigskip
+% The following function will return a \textsc{lpeg} which will catch an
+% environment of Beamer (supported by \pkg{piton}), that is to say
+% |{uncoverenv}|, etc. The argument |lpeg| should be |MainLoopPython|,
+% |MainLoopC|, etc.
+% \begin{macrocode}
+ function OneBeamerEnvironment(name,lpeg)
+ return
+ Ct ( Cc "Open"
+ * C (
+ P ( "\\begin{" .. name .. "}" )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ )
+ * Cc ( "\\end{" .. name .. "}" )
+ )
+ * (
+ C ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
+ / ( function (s) return lpeg : match(s) end )
+ )
+ * P ( "\\end{" .. name .. "}" ) * Ct ( Cc "Close" )
+ end
+end
+% \end{macrocode}
+%
+%
+%
+% \bigskip
+% \begin{macrocode}
+local languages = { }
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{The LPEG python}
%
% \bigskip
@@ -3964,7 +4165,7 @@
% names of our \textsc{lpeg}, prefixes to distinguish the \textsc{lpeg} dealing
% with that categories of strings, as presented in the following tabular.
% \begin{center}
-% \begin{tabular}{ccc}
+% \begin{tabular}{@{}lcc@{}}
% \toprule
% & |Single| & |Double| \\
% \midrule
@@ -4069,7 +4270,7 @@
% \bigskip
% \paragraph{Beamer}
%
-% The following \textsc{lpeg} |balanced_braces| will be used for the (mandatory)
+% The following pattern |balanced_braces| will be used for the (mandatory)
% argument of the commands |\only| and \emph{al.} of Beamer. It's necessary to
% use a \emph{grammar} because that pattern mainly checks the correct nesting of
% the delimiters (and it's known in the theory of formal languages that this
@@ -4087,46 +4288,9 @@
) ^ 0
}
% \end{macrocode}
-%
%
-% \bigskip
-% If Beamer is used (or if the key |beamer| is used at load-time), the following
-% LPEG will be redefined.
-% \begin{macrocode}
-local Beamer = P ( false )
-local BeamerBeginEnvironments = P ( true )
-local BeamerEndEnvironments = P ( true )
-local BeamerNamesEnvironments =
- P "uncoverenv" + P "onlyenv" + P "visibleenv" + P "invisibleenv"
- + P "alertenv" + P "actionenv"
-% \end{macrocode}
-%
-%
% \bigskip
-% The following function will return a \textsc{lpeg} which will catch an
-% environment of Beamer (supported by \pkg{piton}), that is to say |{uncover}|,
-% |{only}|, etc.
% \begin{macrocode}
-function OneBeamerEnvironment(name)
- return
- Ct ( Cc "Open"
- * C (
- P ( "\\begin{" .. name .. "}" )
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * Cc ( "\\end{" .. name .. "}" )
- )
- * (
- C ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
- / ( function (s) return MainLoopPython:match(s) end )
- )
- * P ( "\\end{" .. name .. "}" ) * Ct ( Cc "Close" )
-end
-% \end{macrocode}
-%
-%
-% \bigskip
-% \begin{macrocode}
if piton_beamer
then
Beamer =
@@ -4145,12 +4309,12 @@
)
* ( C ( balanced_braces ) / (function (s) return MainLoopPython:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
- + OneBeamerEnvironment "uncoverenv"
- + OneBeamerEnvironment "onlyenv"
- + OneBeamerEnvironment "visibleenv"
- + OneBeamerEnvironment "invisibleenv"
- + OneBeamerEnvironment "alertenv"
- + OneBeamerEnvironment "actionenv"
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopPython )
+
L (
% \end{macrocode}
@@ -4167,7 +4331,7 @@
+
L (
% \end{macrocode}
-% For |\\alt|, the specification of the overlays (between angular brackets) is mandatory.
+% For |\\temporal|, the specification of the overlays (between angular brackets) is mandatory.
% \begin{macrocode}
( P "\\temporal" )
* P "<" * (1 - P ">") ^ 0 * P ">"
@@ -4179,23 +4343,6 @@
* L ( P "}{" )
* K ( 'ParseAgain.noCR' , balanced_braces )
* L ( P "}" )
-% \end{macrocode}
-% Now for the environemnts.
-% \begin{macrocode}
- BeamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P "\\begin{" * BeamerNamesEnvironments * "}"
- * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * P "\r"
- ) ^ 0
- BeamerEndEnvironments =
- ( space ^ 0 *
- L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
- * P "\r"
- ) ^ 0
end
% \end{macrocode}
%
@@ -4460,40 +4607,7 @@
% catched as keyword by the \textsc{lpeg} |Keyword| (useful if, for example, the
% final user wants to speak of the keyword \piton{def}).
%
-% \bigskip
-% \paragraph{The dictionaries of Python}
%
-% We have \textsc{lpeg} dealing with dictionaries of Python because, in
-% typesettings of explicit Python dictionaries, one may prefer to have all the
-% values formatted in black (in order to see more clearly the keys which are
-% usually Python strings). That's why we have a \pkg{piton} style |Dict.Value|.
-%
-% The initial value of that \pkg{piton} style is |\@@_piton:n|, which means that
-% the value of the entry of the dictionary is parsed once again by \pkg{piton}
-% (and nothing special is done for the dictionary). In the following example, we
-% have set the \pkg{piton} style |Dict.Value| to |\color{black}|:
-%
-% \medskip
-% \begingroup
-% \SetPitonStyle{Dict.Value = \color{black}}
-% \piton{mydict = { 'name' : 'Paul', 'sex' : 'male', 'age' : 31 } }
-% \endgroup
-%
-% \medskip
-% At this time, this mechanism works only for explicit dictionaries on a single line!
-%
-% \begin{macrocode}
-local ItemDict =
- ShortString * SkipSpace * Q ( P ":" ) * K ( 'Dict.Value' , expression )
-
-local ItemOfSet = SkipSpace * ( ItemDict + ShortString ) * SkipSpace
-
-local Set =
- Q ( P "{" )
- * ItemOfSet * ( Q ( P "," ) * ItemOfSet ) ^ 0
- * Q ( P "}" )
-% \end{macrocode}
-%
% \paragraph{Miscellaneous}
%
% \begin{macrocode}
@@ -4502,7 +4616,7 @@
%
%
% \bigskip
-% \paragraph{The main LPEG}
+% \paragraph{The main LPEG for the language Python}
%
% First, the main loop :
% \begin{macrocode}
@@ -4516,7 +4630,6 @@
+ LongString
+ Comment
+ ExceptionInConsole
- + Set
+ Delim
+ Operator
+ OperatorWord * ( Space + Punct + Delim + EOL + -1 )
@@ -4566,11 +4679,10 @@
% \end{macrocode}
%
% \begin{macrocode}
-local languages = { }
languages['python'] = python
% \end{macrocode}
%
-% % \bigskip
+% \bigskip
% \subsubsection{The LPEG ocaml}
%
% \begin{macrocode}
@@ -4592,7 +4704,7 @@
local ModuleType = K ( 'Name.Type' , cap_identifier )
% \end{macrocode}
%
-% The identifiers which begin with a lower case letter of an underscore are used
+% The identifiers which begin with a lower case letter or an underscore are used
% elsewhere in OCaml.
% \begin{macrocode}
local identifier =
@@ -4681,11 +4793,11 @@
K ( 'Keyword' ,
P "assert" + P "as" + P "begin" + P "class" + P "constraint" + P "done"
+ P "downto" + P "do" + P "else" + P "end" + P "exception" + P "external"
- + P "false" + P "for" + P "function" + P "functor" + P "fun" + P "if"
+ + P "for" + P "function" + P "functor" + P "fun" + P "if"
+ P "include" + P "inherit" + P "initializer" + P "in" + P "lazy" + P "let"
+ P "match" + P "method" + P "module" + P "mutable" + P "new" + P "object"
+ P "of" + P "open" + P "private" + P "raise" + P "rec" + P "sig"
- + P "struct" + P "then" + P "to" + P "true" + P "try" + P "type"
+ + P "struct" + P "then" + P "to" + P "try" + P "type"
+ P "value" + P "val" + P "virtual" + P "when" + P "while" + P "with" )
+ K ( 'Keyword.Constant' , P "true" + P "false" )
@@ -4731,26 +4843,38 @@
}
% \end{macrocode}
%
-%
+%
+% \bigskip
% \begin{macrocode}
if piton_beamer
then
Beamer =
- L ( P "\\pause" * ( P "[" * (1 - P "]") ^ 0 * P "]" ) ^ -1 )
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+
- ( P "\\uncover" * Lc ( '\\@@_beamer_command:n{uncover}' )
- + P "\\only" * Lc ( '\\@@_beamer_command:n{only}' )
- + P "\\alert" * Lc ( '\\@@_beamer_command:n{alert}' )
- + P "\\visible" * Lc ( '\\@@_beamer_command:n{visible}' )
- + P "\\invisible" * Lc ( '\\@@_beamer_command:n{invisible}' )
- + P "\\action" * Lc ( '\\@@_beamer_command:n{action}' )
- )
- *
- L ( ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1 * P "{" )
- * K ( 'ParseAgain.noCR' , balanced_braces )
- * L ( P "}" )
- +
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopOCaml:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopOCaml )
+ +
L (
+% \end{macrocode}
+% For |\\alt|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
( P "\\alt" )
* P "<" * (1 - P ">") ^ 0 * P ">"
* P "{"
@@ -4761,6 +4885,9 @@
* L ( P "}" )
+
L (
+% \end{macrocode}
+% For |\\temporal|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
( P "\\temporal" )
* P "<" * (1 - P ">") ^ 0 * P ">"
* P "{"
@@ -4771,23 +4898,10 @@
* L ( P "}{" )
* K ( 'ParseAgain.noCR' , balanced_braces )
* L ( P "}" )
- BeamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P "\\begin{" * BeamerNamesEnvironments * "}"
- * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * P "\r"
- ) ^ 0
- BeamerEndEnvironments =
- ( space ^ 0 *
- L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
- * P "\r"
- ) ^ 0
end
% \end{macrocode}
%
+%
% \bigskip
% \paragraph{EOL}
% \begin{macrocode}
@@ -4814,13 +4928,11 @@
SpaceIndentation ^ 0
% \end{macrocode}
%
-%
-% \begin{macrocode}
%
-% \paragraph{The strings}
+% \paragraph{The strings en OCaml}
%
-% We need a pattern |string| without captures because it will be used within the
-% comments of OCaml.
+% We need a pattern |ocaml_string| without captures because it will be used
+% within the comments of OCaml.
% \begin{macrocode}
local ocaml_string =
Q ( P "\"" )
@@ -4887,7 +4999,7 @@
% \paragraph{The comments in the OCaml listings}
%
% In OCaml, the delimiters for the comments are |(*| and |*)|. There are
-% unsymmetrical and, therefore, the comments may be nested. That's why we need a
+% unsymmetrical and OCaml allow those comments to be nested. That's why we need a
% grammar.
%
% In these comments, we embed the math comments (between |$| and |$|) and we
@@ -4961,7 +5073,7 @@
%
%
% \bigskip
-% \paragraph{The DefModule}
+% \paragraph{The DefModule}\par
%
% The following LPEG will be used in the definitions of modules but also in the
% definitions of \emph{types} of modules.
@@ -5017,7 +5129,7 @@
% \end{macrocode}
%
% \bigskip
-% \paragraph{The main LPEG}
+% \paragraph{The main LPEG for the language OCaml}
%
% First, the main loop :
% \begin{macrocode}
@@ -5079,16 +5191,349 @@
% \begin{macrocode}
languages['ocaml'] = ocaml
% \end{macrocode}
+%
+% \bigskip
+% \subsubsection{The LPEG language C}
%
% \bigskip
+% Some strings of length 2 are explicit because we want the corresponding
+% ligatures available in some fonts such as \emph{Fira Code} to be active.
+% \begin{macrocode}
+local Operator =
+ K ( 'Operator' ,
+ P "!=" + P "==" + P "<<" + P ">>" + P "<=" + P ">="
+ + P "||" + P "&&" + S "-~+/*%=<>&.@|!"
+ )
+
+local Keyword =
+ K ( 'Keyword' ,
+ P "alignas" + P "asm" + P "auto" + P "break" + P "case" + P "catch"
+ + P "class" + P "const" + P "constexpr" + P "continue"
+ + P "decltype" + P "do" + P "else" + P "enum" + P "extern"
+ + P "for" + P "goto" + P "if" + P "nexcept" + P "private" + P "public"
+ + P "register" + P "restricted" + P "return" + P "static" + P "static_assert"
+ + P "struct" + P "switch" + P "thread_local" + P "throw" + P "try"
+ + P "typedef" + P "union" + P "using" + P "virtual" + P "volatile"
+ + P "while"
+ )
+ + K ( 'Keyword.Constant' ,
+ P "default" + P "false" + P "NULL" + P "nullptr" + P "true"
+ )
+
+local Builtin =
+ K ( 'Name.Builtin' ,
+ P "alignof" + P "malloc" + P "printf" + P "scanf" + P "sizeof"
+ )
+
+local Type =
+ K ( 'Name.Type' ,
+ P "bool" + P "char" + P "char16_t" + P "char32_t" + P "double"
+ + P "float" + P "int" + P "int8_t" + P "int16_t" + P "int32_t"
+ + P "int64_t" + P "long" + P "short" + P "signed" + P "unsigned"
+ + P "void" + P "wchar_t"
+ )
+
+local DefFunction =
+ Type
+ * Space
+ * K ( 'Name.Function.Internal' , identifier )
+ * SkipSpace
+ * # P "("
+% \end{macrocode}
+% We remind that the marker |#| of \textsc{lpeg} specifies that the pattern will be
+% detected but won't consume any character.
+%
+% \bigskip
+% The following \textsc{lpeg} |DefClass| will be used to detect the definition of a
+% new class (the name of that new class will be formatted with the \pkg{piton}
+% style |Name.Class|).
+%
+% \smallskip
+% Example:\enskip \piton{class myclass:}
+% \begin{macrocode}
+local DefClass =
+ K ( 'Keyword' , P "class" ) * Space * K ( 'Name.Class' , identifier )
+% \end{macrocode}
+%
+% If the word |class| is not followed by a identifier, it will be catched as
+% keyword by the \textsc{lpeg} |Keyword| (useful if we want to type a
+% list of keywords).
+%
+% \bigskip
+% \paragraph{The strings of C}
+%
+% \begin{macrocode}
+local String =
+ WithStyle ( 'String.Long' ,
+ Q "\""
+ * ( VisualSpace
+ + K ( 'String.Interpol' ,
+ P "%" * ( S "difcspxXou" + P "ld" + P "li" + P "hd" + P "hi" )
+ )
+ + Q ( ( P "\\\"" + 1 - S " \"" ) ^ 1 )
+ ) ^ 0
+ * Q "\""
+ )
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{Beamer}
+%
+% The following \textsc{lpeg} |balanced_braces| will be used for the (mandatory)
+% argument of the commands |\only| and \emph{al.} of Beamer. It's necessary to
+% use a \emph{grammar} because that pattern mainly checks the correct nesting of
+% the delimiters (and it's known in the theory of formal languages that this
+% can't be done with regular expressions \emph{stricto sensu} only).
+% \begin{macrocode}
+local balanced_braces =
+ P { "E" ,
+ E =
+ (
+ P "{" * V "E" * P "}"
+ +
+ String
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
+% \begin{macrocode}
+if piton_beamer
+then
+ Beamer =
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+ +
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopC:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopC )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopC )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopC )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopC )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopC )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopC )
+ +
+ L (
+% \end{macrocode}
+% For |\\alt|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
+ ( P "\\alt" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+ +
+ L (
+% \end{macrocode}
+% For |\\temporal|, the specification of the overlays (between angular brackets) is mandatory.
+% \begin{macrocode}
+ ( P "\\temporal" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+end
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{EOL}
+%
+% \bigskip
+% The following LPEG will detect the Python prompts when the user is typesetting
+% an interactive session of Python (directly or through |{pyconsole}| of
+% \pkg{pyluatex}). We have to detect that prompt twice. The first detection
+% (called \emph{hasty detection}) will be before the |\@@_begin_line:| because
+% you want to trigger a special background color for that row (and, after the
+% |\@@_begin_line:|, it's too late to change de background).
+% \begin{macrocode}
+local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\@@_prompt:' ) ) ^ -1
+% \end{macrocode}
+% We remind that the marker |#| of \textsc{lpeg} specifies that the pattern will be
+% detected but won't consume any character.
+%
+% \medskip
+% With the following \textsc{lpeg}, a style will actually be applied to the
+% prompt (for instance, it's possible to decide to discard these prompts).
+% \begin{macrocode}
+local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
+% \end{macrocode}
+%
+%
+%
+% \bigskip
+% The following \textsc{lpeg} |EOL| is for the end of lines.
+% \begin{macrocode}
+local EOL =
+ P "\r"
+ *
+ (
+ ( space^0 * -1 )
+ +
+% \end{macrocode}
+% We recall that each line in the Python code we have to parse will be sent
+% back to LaTeX between a pair |\@@_begin_line:| --
+% |\@@_end_line:|\footnote{Remember that the \texttt{\textbackslash
+% @@\_end\_line:} must be explicit because it will be used as marker in order to
+% delimit the argument of the command \texttt{\textbackslash @@\_begin\_line:}}.
+% \begin{macrocode}
+ Ct (
+ Cc "EOL"
+ *
+ Ct (
+ Lc "\\@@_end_line:"
+ * BeamerEndEnvironments
+ * BeamerBeginEnvironments
+ * PromptHastyDetection
+ * Lc "\\@@_newline: \\@@_begin_line:"
+ * Prompt
+ )
+ )
+ )
+ *
+ SpaceIndentation ^ 0
+% \end{macrocode}
+%
+% \bigskip
+% \paragraph{The directives of the preprocessor}
+%
+% \begin{macrocode}
+local Preproc =
+ K ( 'Preproc' , P "#" * (1 - P "\r" ) ^ 0 ) * ( EOL + -1 )
+% \end{macrocode}
+%
+%
+% \bigskip
+% \paragraph{The comments in the C listings}
+%
+% We define different \textsc{lpeg} dealing with comments in the C listings.
+% \begin{macrocode}
+local CommentMath =
+ P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$"
+
+local Comment =
+ WithStyle ( 'Comment' ,
+ Q ( P "//" )
+ * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 )
+ * ( EOL + -1 )
+
+local LongComment =
+ WithStyle ( 'Comment' ,
+ Q ( P "/*" )
+ * ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
+ * Q ( P "*/" )
+ ) -- $
+% \end{macrocode}
+%
+%
+% \bigskip
+% The following \textsc{lpeg} |CommentLaTeX| is for what is called in that
+% document the ``LaTeX comments''. Since the elements that will be catched must
+% be sent to LaTeX with standard LaTeX catcodes, we put the capture (done by
+% the function~|C|) in a table (by using~|Ct|, which is an alias for |lpeg.Ct|).
+% \begin{macrocode}
+local CommentLaTeX =
+ P(piton.comment_latex)
+ * Lc "{\\PitonStyle{Comment.LaTeX}{\\ignorespaces"
+ * L ( ( 1 - P "\r" ) ^ 0 )
+ * Lc "}}"
+ * ( EOL + -1 )
+% \end{macrocode}
+%
+%
+%
+%
+% \bigskip
+% \paragraph{The main LPEG for the language C}
+%
+% First, the main loop :
+% \begin{macrocode}
+local MainC =
+ EOL
+ + Space
+ + Tab
+ + Escape
+ + CommentLaTeX
+ + Beamer
+ + Preproc
+ + Comment + LongComment
+ + Delim
+ + Operator
+ + String
+ + Punct
+ + DefFunction
+ + DefClass
+ + Type * ( Q ( "*" ) ^ -1 + Space + Punct + Delim + EOL + -1 )
+ + Keyword * ( Space + Punct + Delim + EOL + -1 )
+ + Builtin * ( Space + Punct + Delim + EOL + -1 )
+ + Identifier
+ + Number
+ + Word
+% \end{macrocode}
+%
+% Ici, il ne faut pas mettre |local| !
+% \begin{macrocode}
+MainLoopC =
+ ( ( space^1 * -1 )
+ + MainC
+ ) ^ 0
+% \end{macrocode}
+%
+% \bigskip
+% We recall that each line in the C code to parse will be sent back to
+% LaTeX between a pair |\@@_begin_line:| -- |\@@_end_line:|\footnote{Remember
+% that the \texttt{\textbackslash @@\_end\_line:} must be explicit because it
+% will be used as marker in order to delimit the argument of the command
+% \texttt{\textbackslash @@\_begin\_line:}}.
+% \begin{macrocode}
+languageC =
+ Ct (
+ ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * PromptHastyDetection
+ * Lc '\\@@_begin_line:'
+ * Prompt
+ * SpaceIndentation ^ 0
+ * MainLoopC
+ * -1
+ * Lc '\\@@_end_line:'
+ )
+% \end{macrocode}
+%
+% \begin{macrocode}
+languages['c'] = languageC
+% \end{macrocode}
+%
+%
+% \bigskip
% \subsubsection{The function Parse}
%
%
-% The function |Parse| is the main function of the package \pkg{piton}.
-% It parses its argument and sends back to LaTeX the code with interlaced
+% The function |Parse| is the main function of the package \pkg{piton}. It
+% parses its argument and sends back to LaTeX the code with interlaced
% formatting LaTeX instructions. In fact, everything is done by the
-% \textsc{lpeg} |python| which returns as capture a Lua table containing
-% data to send to LaTeX.
+% \textsc{lpeg} corresponding to the considered language (|languages[language]|)
+% which returns as capture a Lua table containing data to send to LaTeX.
%
% \bigskip
% \begin{macrocode}
@@ -5410,6 +5855,11 @@
%
% \verb|https://github.com/fpantigny/piton|
%
+% \subsection*{Changes between versions 1.6 and 2.0}
+%
+% The extension \pkg{piton} nows supports the computer languages OCaml and C
+% (and, of course, Python).
+%
% \subsection*{Changes between versions 1.5 and 1.6}
%
% New key |width| (for the total width of the listing).
Modified: trunk/Master/texmf-dist/source/lualatex/piton/piton.ins
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/piton/piton.ins 2023-08-01 20:06:48 UTC (rev 67789)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.ins 2023-08-01 20:06:59 UTC (rev 67790)
@@ -36,7 +36,7 @@
\Msg{* To finish the installation you have to move the}
\Msg{* following files into a directory searched by TeX:}
\Msg{*}
-\Msg{* \space\space piton.sty\space\space and\space\space piton.lua}
+\Msg{* \space\space piton.sty}
\Msg{*}
\Msg{* To produce the documentation run the file piton.dtx}
\Msg{* through LuaLaTeX.}
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2023-08-01 20:06:48 UTC (rev 67789)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2023-08-01 20:06:59 UTC (rev 67790)
@@ -18,8 +18,8 @@
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
-\def\myfileversion{1.6a}
-\def\myfiledate{2023/07/08}
+\def\myfileversion{2.0}
+\def\myfiledate{2023/08/01}
\NeedsTeXFormat{LaTeX2e}
@@ -359,7 +359,8 @@
\bool_new:N \l__piton_resume_bool
\keys_define:nn { PitonOptions }
{
- language .str_set:N = \l__piton_language_str ,
+ language .code:n =
+ \str_set:Nx \l__piton_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
gobble .int_set:N = \l__piton_gobble_int ,
gobble .value_required:n = true ,
@@ -696,8 +697,9 @@
}
\bool_if:NTF \c__piton_beamer_bool
{
- \NewPitonEnvironment { Piton } { d < > }
+ \NewPitonEnvironment { Piton } { d < > O { } }
{
+ \PitonOptions { #2 }
\IfValueTF { #1 }
{ \begin { uncoverenv } < #1 > }
{ \begin { uncoverenv } }
@@ -704,7 +706,10 @@
}
{ \end { uncoverenv } }
}
- { \NewPitonEnvironment { Piton } { } { } { } }
+ { \NewPitonEnvironment { Piton } { O { } }
+ { \PitonOptions { #1 } }
+ { }
+ }
\NewDocumentCommand { \PitonInputFile } { d < > O { } m }
{
\file_if_exist:nTF { #3 }
@@ -753,108 +758,68 @@
\NewDocumentCommand { \SetPitonStyle } { } { \keys_set:nn { piton / Styles } }
\cs_new_protected:Npn \__piton_math_scantokens:n #1
{ \normalfont \scantextokens { $#1$ } }
+\clist_new:N \g__piton_style_clist
+\clist_set:Nn \g__piton_styles_clist
+ {
+ Comment ,
+ Comment.LaTeX ,
+ Exception ,
+ FormattingType ,
+ Identifier ,
+ InitialValues ,
+ Interpol.Inside ,
+ Keyword ,
+ Keyword.Constant ,
+ Name.Builtin ,
+ Name.Class ,
+ Name.Constructor ,
+ Name.Decorator ,
+ Name.Field ,
+ Name.Function ,
+ Name.Module ,
+ Name.Namespace ,
+ Name.Type ,
+ Number ,
+ Operator ,
+ Operator.Word ,
+ Preproc ,
+ Prompt ,
+ String.Doc ,
+ String.Interpol ,
+ String.Long ,
+ String.Short ,
+ TypeParameter ,
+ UserFunction
+ }
+
+\clist_map_inline:Nn \g__piton_styles_clist
+ {
+ \keys_define:nn { piton / Styles }
+ {
+ #1 .tl_set:c = pitonStyle #1 ,
+ #1 .value_required:n = true
+ }
+ }
+
\keys_define:nn { piton / Styles }
{
- String.Interpol .tl_set:c = pitonStyle String.Interpol ,
- String.Interpol .value_required:n = true ,
- FormattingType .tl_set:c = pitonStyle FormattingType ,
- FormattingType .value_required:n = true ,
- Dict.Value .tl_set:c = pitonStyle Dict.Value ,
- Dict.Value .value_required:n = true ,
- Name.Decorator .tl_set:c = pitonStyle Name.Decorator ,
- Name.Decorator .value_required:n = true ,
- Name.Field .tl_set:c = pitonStyle Name.Field ,
- Name.Field .value_required:n = true ,
- Name.Function .tl_set:c = pitonStyle Name.Function ,
- Name.Function .value_required:n = true ,
- UserFunction .tl_set:c = pitonStyle UserFunction ,
- UserFunction .value_required:n = true ,
- Keyword .tl_set:c = pitonStyle Keyword ,
- Keyword .value_required:n = true ,
- Keyword.Constant .tl_set:c = pitonStyle Keyword.Constant ,
- Keyword.constant .value_required:n = true ,
- String.Doc .tl_set:c = pitonStyle String.Doc ,
- String.Doc .value_required:n = true ,
- Interpol.Inside .tl_set:c = pitonStyle Interpol.Inside ,
- Interpol.Inside .value_required:n = true ,
- String.Long .tl_set:c = pitonStyle String.Long ,
- String.Long .value_required:n = true ,
- String.Short .tl_set:c = pitonStyle String.Short ,
- String.Short .value_required:n = true ,
- String .meta:n = { String.Long = #1 , String.Short = #1 } ,
- Comment.Math .tl_set:c = pitonStyle Comment.Math ,
- Comment.Math .default:n = \__piton_math_scantokens:n ,
- Comment.Math .initial:n = ,
- Comment .tl_set:c = pitonStyle Comment ,
- Comment .value_required:n = true ,
- Name.Constructor .tl_set:c = pitonStyle Name.Constructor ,
- Name.Constructor .value_required:n = true ,
- InitialValues .tl_set:c = pitonStyle InitialValues ,
- InitialValues .value_required:n = true ,
- Number .tl_set:c = pitonStyle Number ,
- Number .value_required:n = true ,
- Name.Namespace .tl_set:c = pitonStyle Name.Namespace ,
- Name.Namespace .value_required:n = true ,
- Name.Module .tl_set:c = pitonStyle Name.Module ,
- Name.Module .value_required:n = true ,
- Name.Class .tl_set:c = pitonStyle Name.Class ,
- Name.Class .value_required:n = true ,
- Name.Builtin .tl_set:c = pitonStyle Name.Builtin ,
- Name.Builtin .value_required:n = true ,
- TypeParameter .tl_set:c = pitonStyle TypeParameter ,
- TypeParameter .value_required:n = true ,
- Name.Type .tl_set:c = pitonStyle Name.Type ,
- Name.Type .value_required:n = true ,
- Operator .tl_set:c = pitonStyle Operator ,
- Operator .value_required:n = true ,
- Operator.Word .tl_set:c = pitonStyle Operator.Word ,
- Operator.Word .value_required:n = true ,
- Exception .tl_set:c = pitonStyle Exception ,
- Exception .value_required:n = true ,
- Comment.LaTeX .tl_set:c = pitonStyle Comment.LaTeX ,
- Comment.LaTeX .value_required:n = true ,
- Identifier .tl_set:c = pitonStyle Identifier ,
- Comment.LaTeX .value_required:n = true ,
- ParseAgain.noCR .tl_set:c = pitonStyle ParseAgain.noCR ,
- ParseAgain.noCR .value_required:n = true ,
- ParseAgain .tl_set:c = pitonStyle ParseAgain ,
- ParseAgain .value_required:n = true ,
- Prompt .tl_set:c = pitonStyle Prompt ,
- Prompt .value_required:n = true ,
- unknown .code:n =
+ String .meta:n = { String.Long = #1 , String.Short = #1 } ,
+ Comment.Math .tl_set:c = pitonStyle Comment.Math ,
+ Comment.Math .default:n = \__piton_math_scantokens:n ,
+ Comment.Math .initial:n = ,
+ ParseAgain .tl_set:c = pitonStyle ParseAgain ,
+ ParseAgain .value_required:n = true ,
+ ParseAgain.noCR .tl_set:c = pitonStyle ParseAgain.noCR ,
+ ParseAgain.noCR .value_required:n = true ,
+ unknown .code:n =
\msg_error:nn { piton } { Unknown~key~for~SetPitonStyle }
}
-\msg_new:nnn { piton } { Unknown~key~for~SetPitonStyle }
+\clist_gput_left:Nn \g__piton_styles_clist { String }
+\clist_gsort:Nn \g__piton_styles_clist
{
- The~style~'\l_keys_key_str'~is~unknown.\\
- This~key~will~be~ignored.\\
- The~available~styles~are~(in~alphabetic~order):~
- Comment,~
- Comment.LaTeX,~
- Dict.Value,~
- Exception,~
- Identifier,~
- InitialValues,~
- Keyword,~
- Keyword.Constant,~
- Name.Builtin,~
- Name.Class,~
- Name.Constructor,~
- Name.Decorator,~
- Name.Field,~
- Name.Function,~
- Name.Module,~
- Name.Namespace,~
- UserFunction,~
- Number,~
- Operator,~
- Operator.Word,~
- Prompt,~
- String,~
- String.Doc,~
- String.Long,~
- String.Short,~and~
- String.Interpol.
+ \str_compare:nNnTF { #1 } < { #2 }
+ \sort_return_same:
+ \sort_return_swapped:
}
\SetPitonStyle
{
@@ -879,9 +844,9 @@
Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
Name.Type = \color[HTML]{336666} ,
InitialValues = \__piton_piton:n ,
- Dict.Value = \__piton_piton:n ,
Interpol.Inside = \color{black}\__piton_piton:n ,
TypeParameter = \color[HTML]{336666} \itshape ,
+ Preproc = \color[HTML]{AA6600} \slshape ,
Identifier = \__piton_identifier:n ,
UserFunction = ,
Prompt = ,
@@ -938,6 +903,13 @@
\token_to_str:N \piton\ but~there~is~no~environment~
{piton}.~This~error~is~fatal.
}
+\msg_new:nnn { piton } { Unknown~key~for~SetPitonStyle }
+ {
+ The~style~'\l_keys_key_str'~is~unknown.\\
+ This~key~will~be~ignored.\\
+ The~available~styles~are~(in~alphabetic~order):~
+ \clist_use:Nnnn \g__piton_styles_clist { ~and~ } { ,~ } { ~and~ }.
+ }
\msg_new:nnn { piton } { syntax~error }
{
Your~code~is~not~syntactically~correct.\\
@@ -1082,6 +1054,45 @@
local SpaceIndentation = Lc ( '\\__piton_an_indentation_space:' ) * ( Q " " )
local Delim = Q ( S "[()]" )
local VisualSpace = space * Lc "\\l__piton_space_tl"
+local Beamer = P ( false )
+local BeamerBeginEnvironments = P ( true )
+local BeamerEndEnvironments = P ( true )
+if piton_beamer
+then
+ local BeamerNamesEnvironments =
+ P "uncoverenv" + P "onlyenv" + P "visibleenv" + P "invisibleenv"
+ + P "alertenv" + P "actionenv"
+ BeamerBeginEnvironments =
+ ( space ^ 0 *
+ L
+ (
+ P "\\begin{" * BeamerNamesEnvironments * "}"
+ * ( P "<" * ( 1 - P ">" ) ^ 0 * P ">" ) ^ -1
+ )
+ * P "\r"
+ ) ^ 0
+ BeamerEndEnvironments =
+ ( space ^ 0 *
+ L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
+ * P "\r"
+ ) ^ 0
+ function OneBeamerEnvironment(name,lpeg)
+ return
+ Ct ( Cc "Open"
+ * C (
+ P ( "\\begin{" .. name .. "}" )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ )
+ * Cc ( "\\end{" .. name .. "}" )
+ )
+ * (
+ C ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
+ / ( function (s) return lpeg : match(s) end )
+ )
+ * P ( "\\end{" .. name .. "}" ) * Ct ( Cc "Close" )
+ end
+end
+local languages = { }
local Operator =
K ( 'Operator' ,
P "!=" + P "<>" + P "==" + P "<<" + P ">>" + P "<=" + P ">=" + P ":="
@@ -1227,27 +1238,6 @@
( 1 - S "{}" )
) ^ 0
}
-local Beamer = P ( false )
-local BeamerBeginEnvironments = P ( true )
-local BeamerEndEnvironments = P ( true )
-local BeamerNamesEnvironments =
- P "uncoverenv" + P "onlyenv" + P "visibleenv" + P "invisibleenv"
- + P "alertenv" + P "actionenv"
-function OneBeamerEnvironment(name)
- return
- Ct ( Cc "Open"
- * C (
- P ( "\\begin{" .. name .. "}" )
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * Cc ( "\\end{" .. name .. "}" )
- )
- * (
- C ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
- / ( function (s) return MainLoopPython:match(s) end )
- )
- * P ( "\\end{" .. name .. "}" ) * Ct ( Cc "Close" )
-end
if piton_beamer
then
Beamer =
@@ -1266,12 +1256,12 @@
)
* ( C ( balanced_braces ) / (function (s) return MainLoopPython:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
- + OneBeamerEnvironment "uncoverenv"
- + OneBeamerEnvironment "onlyenv"
- + OneBeamerEnvironment "visibleenv"
- + OneBeamerEnvironment "invisibleenv"
- + OneBeamerEnvironment "alertenv"
- + OneBeamerEnvironment "actionenv"
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopPython )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopPython )
+
L (
( P "\\alt" )
@@ -1294,20 +1284,6 @@
* L ( P "}{" )
* K ( 'ParseAgain.noCR' , balanced_braces )
* L ( P "}" )
- BeamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P "\\begin{" * BeamerNamesEnvironments * "}"
- * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * P "\r"
- ) ^ 0
- BeamerEndEnvironments =
- ( space ^ 0 *
- L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
- * P "\r"
- ) ^ 0
end
local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\__piton_prompt:' ) ) ^ -1
local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
@@ -1444,15 +1420,6 @@
* SkipSpace
* StringDoc ^ 0 -- there may be additionnal docstrings
) ^ -1
-local ItemDict =
- ShortString * SkipSpace * Q ( P ":" ) * K ( 'Dict.Value' , expression )
-
-local ItemOfSet = SkipSpace * ( ItemDict + ShortString ) * SkipSpace
-
-local Set =
- Q ( P "{" )
- * ItemOfSet * ( Q ( P "," ) * ItemOfSet ) ^ 0
- * Q ( P "}" )
local ExceptionInConsole = Exception * Q ( ( 1 - P "\r" ) ^ 0 ) * EOL
local MainPython =
EOL
@@ -1464,7 +1431,6 @@
+ LongString
+ Comment
+ ExceptionInConsole
- + Set
+ Delim
+ Operator
+ OperatorWord * ( Space + Punct + Delim + EOL + -1 )
@@ -1498,7 +1464,6 @@
* -1
* Lc '\\__piton_end_line:'
)
-local languages = { }
languages['python'] = python
local Delim = Q ( P "[|" + P "|]" + S "[()]" )
local Punct = Q ( S ",:;!" )
@@ -1573,11 +1538,11 @@
K ( 'Keyword' ,
P "assert" + P "as" + P "begin" + P "class" + P "constraint" + P "done"
+ P "downto" + P "do" + P "else" + P "end" + P "exception" + P "external"
- + P "false" + P "for" + P "function" + P "functor" + P "fun" + P "if"
+ + P "for" + P "function" + P "functor" + P "fun" + P "if"
+ P "include" + P "inherit" + P "initializer" + P "in" + P "lazy" + P "let"
+ P "match" + P "method" + P "module" + P "mutable" + P "new" + P "object"
+ P "of" + P "open" + P "private" + P "raise" + P "rec" + P "sig"
- + P "struct" + P "then" + P "to" + P "true" + P "try" + P "type"
+ + P "struct" + P "then" + P "to" + P "try" + P "type"
+ P "value" + P "val" + P "virtual" + P "when" + P "while" + P "with" )
+ K ( 'Keyword.Constant' , P "true" + P "false" )
@@ -1605,19 +1570,27 @@
if piton_beamer
then
Beamer =
- L ( P "\\pause" * ( P "[" * (1 - P "]") ^ 0 * P "]" ) ^ -1 )
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+
- ( P "\\uncover" * Lc ( '\\__piton_beamer_command:n{uncover}' )
- + P "\\only" * Lc ( '\\__piton_beamer_command:n{only}' )
- + P "\\alert" * Lc ( '\\__piton_beamer_command:n{alert}' )
- + P "\\visible" * Lc ( '\\__piton_beamer_command:n{visible}' )
- + P "\\invisible" * Lc ( '\\__piton_beamer_command:n{invisible}' )
- + P "\\action" * Lc ( '\\__piton_beamer_command:n{action}' )
- )
- *
- L ( ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1 * P "{" )
- * K ( 'ParseAgain.noCR' , balanced_braces )
- * L ( P "}" )
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopOCaml:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopOCaml )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopOCaml )
+
L (
( P "\\alt" )
@@ -1640,20 +1613,6 @@
* L ( P "}{" )
* K ( 'ParseAgain.noCR' , balanced_braces )
* L ( P "}" )
- BeamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P "\\begin{" * BeamerNamesEnvironments * "}"
- * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1
- )
- * P "\r"
- ) ^ 0
- BeamerEndEnvironments =
- ( space ^ 0 *
- L ( P "\\end{" * BeamerNamesEnvironments * P "}" )
- * P "\r"
- ) ^ 0
end
local EOL =
P "\r"
@@ -1842,6 +1801,201 @@
* Lc ( '\\__piton_end_line:' )
)
languages['ocaml'] = ocaml
+local Operator =
+ K ( 'Operator' ,
+ P "!=" + P "==" + P "<<" + P ">>" + P "<=" + P ">="
+ + P "||" + P "&&" + S "-~+/*%=<>&.@|!"
+ )
+
+local Keyword =
+ K ( 'Keyword' ,
+ P "alignas" + P "asm" + P "auto" + P "break" + P "case" + P "catch"
+ + P "class" + P "const" + P "constexpr" + P "continue"
+ + P "decltype" + P "do" + P "else" + P "enum" + P "extern"
+ + P "for" + P "goto" + P "if" + P "nexcept" + P "private" + P "public"
+ + P "register" + P "restricted" + P "return" + P "static" + P "static_assert"
+ + P "struct" + P "switch" + P "thread_local" + P "throw" + P "try"
+ + P "typedef" + P "union" + P "using" + P "virtual" + P "volatile"
+ + P "while"
+ )
+ + K ( 'Keyword.Constant' ,
+ P "default" + P "false" + P "NULL" + P "nullptr" + P "true"
+ )
+
+local Builtin =
+ K ( 'Name.Builtin' ,
+ P "alignof" + P "malloc" + P "printf" + P "scanf" + P "sizeof"
+ )
+
+local Type =
+ K ( 'Name.Type' ,
+ P "bool" + P "char" + P "char16_t" + P "char32_t" + P "double"
+ + P "float" + P "int" + P "int8_t" + P "int16_t" + P "int32_t"
+ + P "int64_t" + P "long" + P "short" + P "signed" + P "unsigned"
+ + P "void" + P "wchar_t"
+ )
+
+local DefFunction =
+ Type
+ * Space
+ * K ( 'Name.Function.Internal' , identifier )
+ * SkipSpace
+ * # P "("
+local DefClass =
+ K ( 'Keyword' , P "class" ) * Space * K ( 'Name.Class' , identifier )
+local String =
+ WithStyle ( 'String.Long' ,
+ Q "\""
+ * ( VisualSpace
+ + K ( 'String.Interpol' ,
+ P "%" * ( S "difcspxXou" + P "ld" + P "li" + P "hd" + P "hi" )
+ )
+ + Q ( ( P "\\\"" + 1 - S " \"" ) ^ 1 )
+ ) ^ 0
+ * Q "\""
+ )
+local balanced_braces =
+ P { "E" ,
+ E =
+ (
+ P "{" * V "E" * P "}"
+ +
+ String
+ +
+ ( 1 - S "{}" )
+ ) ^ 0
+ }
+if piton_beamer
+then
+ Beamer =
+ L ( P "\\pause" * ( P "[" * ( 1 - P "]" ) ^ 0 * P "]" ) ^ -1 )
+ +
+ Ct ( Cc "Open"
+ * C (
+ (
+ P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible"
+ + P "\\invisible" + P "\\action"
+ )
+ * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * P "{"
+ )
+ * Cc "}"
+ )
+ * ( C ( balanced_braces ) / (function (s) return MainLoopC:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopC )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopC )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopC )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopC )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopC )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopC )
+ +
+ L (
+ ( P "\\alt" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+ +
+ L (
+ ( P "\\temporal" )
+ * P "<" * (1 - P ">") ^ 0 * P ">"
+ * P "{"
+ )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}{" )
+ * K ( 'ParseAgain.noCR' , balanced_braces )
+ * L ( P "}" )
+end
+local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\__piton_prompt:' ) ) ^ -1
+local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
+local EOL =
+ P "\r"
+ *
+ (
+ ( space^0 * -1 )
+ +
+ Ct (
+ Cc "EOL"
+ *
+ Ct (
+ Lc "\\__piton_end_line:"
+ * BeamerEndEnvironments
+ * BeamerBeginEnvironments
+ * PromptHastyDetection
+ * Lc "\\__piton_newline: \\__piton_begin_line:"
+ * Prompt
+ )
+ )
+ )
+ *
+ SpaceIndentation ^ 0
+local Preproc =
+ K ( 'Preproc' , P "#" * (1 - P "\r" ) ^ 0 ) * ( EOL + -1 )
+local CommentMath =
+ P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$"
+
+local Comment =
+ WithStyle ( 'Comment' ,
+ Q ( P "//" )
+ * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 )
+ * ( EOL + -1 )
+
+local LongComment =
+ WithStyle ( 'Comment' ,
+ Q ( P "/*" )
+ * ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
+ * Q ( P "*/" )
+ ) -- $
+local CommentLaTeX =
+ P(piton.comment_latex)
+ * Lc "{\\PitonStyle{Comment.LaTeX}{\\ignorespaces"
+ * L ( ( 1 - P "\r" ) ^ 0 )
+ * Lc "}}"
+ * ( EOL + -1 )
+local MainC =
+ EOL
+ + Space
+ + Tab
+ + Escape
+ + CommentLaTeX
+ + Beamer
+ + Preproc
+ + Comment + LongComment
+ + Delim
+ + Operator
+ + String
+ + Punct
+ + DefFunction
+ + DefClass
+ + Type * ( Q ( "*" ) ^ -1 + Space + Punct + Delim + EOL + -1 )
+ + Keyword * ( Space + Punct + Delim + EOL + -1 )
+ + Builtin * ( Space + Punct + Delim + EOL + -1 )
+ + Identifier
+ + Number
+ + Word
+MainLoopC =
+ ( ( space^1 * -1 )
+ + MainC
+ ) ^ 0
+languageC =
+ Ct (
+ ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * PromptHastyDetection
+ * Lc '\\__piton_begin_line:'
+ * Prompt
+ * SpaceIndentation ^ 0
+ * MainLoopC
+ * -1
+ * Lc '\\__piton_end_line:'
+ )
+languages['c'] = languageC
function piton.Parse(language,code)
local t = languages[language] : match ( code )
if t == nil
More information about the tex-live-commits
mailing list.