texlive[72132] Master/texmf-dist: piton (29aug24)
commits+karl at tug.org
commits+karl at tug.org
Thu Aug 29 22:30:59 CEST 2024
Revision: 72132
https://tug.org/svn/texlive?view=revision&revision=72132
Author: karl
Date: 2024-08-29 22:30:59 +0200 (Thu, 29 Aug 2024)
Log Message:
-----------
piton (29aug24)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2024-08-28 23:41:57 UTC (rev 72131)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2024-08-29 20:30:59 UTC (rev 72132)
@@ -123,9 +123,9 @@
avec coloriage syntaxique. Comme elle utilise le Lua de LuaLaTeX, 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.
+programme extérieur et la compilation ne requiert donc pas |--shell-escape| (sauf lorsque
+la clé |write| est utilisée). 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}.
@@ -414,6 +414,8 @@
(voir la partie \ref{API}, p.~\pageref{API}).} de l'environnement courant dans ce
fichier. À la première utilisation du fichier par \pkg{piton}, celui-ci est effacé.
+{\bfseries Cette clé nécessite une compilation avec {\ttfamily lualatex -shell-escape}}.
+
\item \index{path-write} La clé \Definition{path-write} indique un chemin où seront écrits
les fichiers écrits par l'emploi de la clé |write| précédente.
@@ -694,7 +696,7 @@
\medskip
Par exemple, avec la commande
\begin{Verbatim}
-\SetPitonStyle~emphase#[SQL]@{Keywords = \color[HTML]{006699} \bfseries \MakeUppercase}
+\SetPitonStyle~emphase#[SQL]@{Keyword = \color[HTML]{006699} \bfseries \MakeUppercase}
\end{Verbatim}
les mots-clés dans les listings SQL seront composés en lettres capitales, même s'ils
s'apparaissent en minuscules dans le fichier source LaTeX (on rappelle que, en SQL, les
@@ -1814,7 +1816,7 @@
\smallskip
Beamer propose un moyen aisé de changer la couleur utilisée par l'environnement
-|{alertenv}| (et par la commande |\alert| qui s'appuie dessus). Par exemple, on peut
+|{alertenv}| (et par suite la commande |\alert| qui s'appuie dessus). Par exemple, on peut
écrire:
\begin{Verbatim}
@@ -2524,7 +2526,7 @@
\begin{center}
-\begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+\begin{tabularx}{\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
\toprule
\normalfont Style & Usage \\
\midrule
@@ -2571,6 +2573,7 @@
global, if, import, in, lambda, non local,
pass, raise, return, try, while,
with, yield et yield from.\\
+ Identifier & les identificateurs. \\
\bottomrule
\end{tabularx}
\end{center}
@@ -2609,7 +2612,7 @@
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|,
+ Operator.Word & les opérateurs suivants : |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 \\
@@ -2626,14 +2629,14 @@
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| \\
+ |assert|, |as|, |done|, |downto|, |do|, |else|, |exception|, |for|, |function| ,
+ |fun|, |if|, |lazy|, |match|, |mutable|, |new|, |of|, |private|, |raise|,
+ |then|, |to|, |try| , |virtual|, |when|, |while| et |with| \\
+ Keyword.Governing & les mot-clés suivants : |and|, |begin|, |class|, |constraint|,
+ |end|, |external|, |functor|, |include|, |inherit|, |initializer|,
+ |in|, |let|, |method|, |module|, |object|, |open|, |rec|, |sig|,
+ |struct|, |type| et |val|. \\
+ Identifier & les identificateurs. \\
\bottomrule
\end{tabularx}
\end{center}
@@ -2694,6 +2697,7 @@
|thread_local|, |throw|, |typedef|, |union|, |using|, |virtual|, |volatile| et
|while|
\\
+Identifier & les identificateurs. \\
\bottomrule
\end{tabularx}
\end{center}
@@ -2796,6 +2800,7 @@
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) \\
+Identifier & les identificateurs. \\
\bottomrule
\end{tabularx}
\end{center}
@@ -2838,6 +2843,7 @@
Directive & les directives définies dans |\NewPitonLanguage| par la clé |moredirectives| \\
Tag & les «tags» définis par la clé |tag| (les lexèmes détectés à l'intérieur d'un tag
seront aussi composés avec leur propre style) \\
+Identifier & les identificateurs. \\
\bottomrule
\end{tabularx}
\end{center}
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2024-08-28 23:41:57 UTC (rev 72131)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2024-08-29 20:30:59 UTC (rev 72132)
@@ -79,12 +79,12 @@
% \iffalse
%<*STY>
% \fi
-\def\PitonFileVersion{3.1a}
-\def\PitonFileDate{2024/08/12}
+\def\PitonFileVersion{3.1b}
+\def\PitonFileDate{2024/08/29}
% \iffalse
%</STY>
%<*LUA>
-piton_version = "3.1a" -- 2024/08/12
+piton_version = "3.1b" -- 2024/08/29
%</LUA>
%\fi
%
@@ -113,8 +113,9 @@
% listings and typesets them with syntactic highlighting. Since it uses the Lua
% of LuaLaTeX, 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.
+% and the compilation does not require |--shell-escape| (except when the key
+% |write| is used). 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}|.
@@ -399,6 +400,9 @@
% the part~\ref{API}, p.~\pageref{API}).} of the current environment in
% that file. At the first use of a file by \pkg{piton}, it is erased.
%
+% {\bfseries This key requires a compilation with {\ttfamily lualatex
+% -shell-escape}}.
+%
% \item \index{path-write} The key \Definition{path-write} specifies a path
% where the files written by the key |write| will be written.
%
@@ -682,7 +686,7 @@
% \bigskip
% For example, with the command
% \begin{Verbatim}
-% \SetPitonStyle~emphase#[SQL]@{Keywords = \color[HTML]{006699} \bfseries \MakeUppercase}
+% \SetPitonStyle~emphase#[SQL]@{Keyword = \color[HTML]{006699} \bfseries \MakeUppercase}
% \end{Verbatim}
% the keywords in the SQL listings will be composed in capital letters, even if
% they appear in lower case in the LaTeX source (we recall that, in SQL, the
@@ -2306,7 +2310,7 @@
% \vspace{1cm}
%
% \begin{center}
-% \begin{tabularx}{0.9\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
+% \begin{tabularx}{\textwidth}{@{}>{\ttfamily}l>{\raggedright\arraybackslash}X@{}}
% \toprule
% \normalfont Style & Use \\
% \midrule
@@ -2350,6 +2354,7 @@
% global, if, import, in, lambda, non local,
% pass, raise, return, try, while,
% with, yield et yield from.\\
+% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
% \end{center}
@@ -2386,7 +2391,7 @@
% 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| \\
+% Operator.Word & les opérateurs suivants : |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 \\
@@ -2401,15 +2406,15 @@
% TypeParameter & the parameters of the types \\
% Comment & the comments, between |(*| et |*)|; these comments may be nested \\
% Keyword.Constant & |true| et |false| \\
-% Keyword & the following keywords:
-% |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| \\
+% Keyword & the following keywords: |assert|, |as|, |done|, |downto|, |do|,
+% |else|, |exception|, |for|, |function| , |fun|, |if|, |lazy|, |match|,
+% |mutable|, |new|, |of|, |private|, |raise|, |then|, |to|, |try| , |virtual|,
+% |when|, |while| and |with| \\
+% Keyword.Governing & the following keywords: |and|, |begin|, |class|, |constraint|,
+% |end|, |external|, |functor|, |include|, |inherit|, |initializer|,
+% |in|, |let|, |method|, |module|, |object|, |open|, |rec|, |sig|,
+% |struct|, |type| and |val|. \\
+% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
% \end{center}
@@ -2468,6 +2473,7 @@
% |return|, |static|, |static_assert|, |struct|, |switch|, |thread_local|, |throw|,
% |typedef|, |union|, |using|, |virtual|, |volatile| and |while|
% \\
+% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
% \end{center}
@@ -2563,7 +2569,9 @@
% String & the strings (between \texttt{"}) \\
% Comment & the comments (which begin with |#|) \\
% Comment.LaTeX & the comments beginning with \texttt{\#>}, which are composed by
-% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document) \\
+% \pkg{piton} as LaTeX code (merely named ``LaTeX comments'' in this document)
+% \\
+% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
% \end{center}
@@ -2600,6 +2608,7 @@
% |moredirectives| \\
% Tag & the ``tags'' defines by the key |tag| (the lexical units detected within
% the tag will also be formatted with their own style) \\
+% Identifier & the identifiers. \\
% \bottomrule
% \end{tabularx}
% \end{center}
@@ -3024,8 +3033,8 @@
% \end{macrocode}
%
% \medskip
-% Each time the command |\PitonInputFile| of \pkg{piton} is
-% used, the code of that environment will be stored in the following global string.
+% Each time an environment of \pkg{piton} is used, the informatic code in the
+% body of that environment will be stored in the following global string.
% \begin{macrocode}
\tl_new:N \g_piton_last_code_tl
% \end{macrocode}
@@ -3333,18 +3342,6 @@
{ \int_gincr:N \g_@@_indentation_int }
% \end{macrocode}
%
-% \medskip
-% The following command |\@@_beamer_command:n| executes the argument
-% corresponding to its argument but also stores it in |\l_@@_beamer_command_str|.
-% That string is used only in the error message ``|cr~not~allowed|'' raised when
-% there is a carriage return in the mandatory argument of that command.
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_beamer_command:n #1
- {
- \str_set:Nn \l_@@_beamer_command_str { #1 }
- \use:c { #1 }
- }
-% \end{macrocode}
%
% \bigskip
% In the environment |{Piton}|, the command |\label| will be linked to the
@@ -3418,12 +3415,19 @@
}
% \end{macrocode}
%
+%
+% \bigskip
+% The spaces at the end of a line of code are deleted by \pkg{piton}.
+% However, it's not actually true: they are replace by |\@@_trailing_space:|.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_trailing_space: { }
+% \end{macrocode}
+% When we have to rescan some pieces of code with |\@@_piton:n|, we will set
+% |\@@_trailing_space:| equal to |\space|.
%
% \bigskip
% \subsubsection{Treatment of a line of code}
%
-% The following command is only used once. We have written an autonomous function
-% only for legibility.
% \begin{macrocode}
\cs_new_protected:Npn \@@_replace_spaces:n #1
{
@@ -4344,7 +4348,7 @@
%
% \bigskip
% The following command is not a user command. It will be used when we will
-% have to ``rescan'' some chunks of Python code. For example, it will be the
+% have to ``rescan'' some chunks of informatic code. For example, it will be the
% initial value of the Piton style |InitialValues| (the default values of the
% arguments of a Python function).
% \begin{macrocode}
@@ -4355,6 +4359,7 @@
\cs_set_protected:Npn \@@_end_line: { }
\cs_set:cpn { pitonStyle _ \l_piton_language_str _ Prompt } { }
\cs_set:cpn { pitonStyle _ Prompt } { }
+ \cs_set_eq:NN \@@_trailing_space: \space
\bool_lazy_or:nnTF
\l_@@_break_lines_in_piton_bool
\l_@@_break_lines_in_Piton_bool
@@ -4376,26 +4381,13 @@
}
\bool_if:NT \l_@@_show_spaces_bool
{ \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \l_tmpa_tl
+ \exp_args:No \@@_replace_spaces:n \l_tmpa_tl
\group_end:
}
% \end{macrocode}
%
+%
% \bigskip
-% The following command is similar to the previous one but raise a fatal error if
-% its argument contains a carriage return.
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_piton_no_cr:n #1
- {
- \group_begin:
- \cs_set_protected:Npn \@@_newline:
- { \msg_fatal:nn { piton } { cr~not~allowed } }
- \@@_piton:n { #1 }
- \group_end:
- }
-% \end{macrocode}
-%
-% \bigskip
% Despite its name, |\@@_pre_env:| will be used both in |\PitonInputFile| and
% in the environments such as |{Piton}|.
% \begin{macrocode}
@@ -4822,6 +4814,14 @@
\bool_if:NT \l_@@_width_min_bool \@@_width_to_aux:
\group_end:
% \end{macrocode}
+%
+%
+% The following line is to allow programs such as |latexmk| to be aware that the
+% file (read by |\PitonInputFile|) is loaded during the compilation of the LaTeX
+% document.
+% \begin{macrocode}
+ \exp_args:Nx \iow_log:n {(\l_@@_file_name_str)}
+% \end{macrocode}
% We recall that, if we are in Beamer, the command |\PitonInputFile| is
% ``overlay-aware'' and that's why we close now an environment |{uncoverenv}|
% that we have opened at the beginning of the command.
@@ -4901,10 +4901,12 @@
Discard ,
Exception ,
FormattingType ,
+ Identifier.Internal ,
Identifier ,
InitialValues ,
Interpol.Inside ,
Keyword ,
+ Keyword.Governing ,
Keyword.Constant ,
Keyword2 ,
Keyword3 ,
@@ -4937,10 +4939,14 @@
TypeParameter ,
UserFunction ,
% \end{macrocode}
+% |TypeExpression| is an internal style for expressions which defines types in OCaml.
+% \begin{macrocode}
+ TypeExpression ,
+% \end{macrocode}
% Now, specific styles for the languages created with |\NewPitonLanguage| with
% the syntax of \pkg{listings}.
% \begin{macrocode}
- Directive
+ Directive
}
\clist_map_inline:Nn \g_@@_styles_clist
@@ -4962,10 +4968,10 @@
\keys_define:nn { piton / Styles }
{
- String .meta:n = { String.Long = #1 , String.Short = #1 } ,
- Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain.noCR .tl_set:c = pitonStyle _ ParseAgain.noCR ,
- ParseAgain.noCR .value_required:n = true ,
+ String .meta:n = { String.Long = #1 , String.Short = #1 } ,
+ Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
+ ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
+ ParseAgain .value_required:n = true ,
unknown .code:n =
\@@_error:n { Unknown~key~for~SetPitonStyle }
}
@@ -4972,6 +4978,15 @@
% \end{macrocode}
%
% \bigskip
+% \begin{macrocode}
+\SetPitonStyle[OCaml]
+ {
+ TypeExpression =
+ \SetPitonStyle { Identifier = \PitonStyle { Name.Type } } \@@_piton:n
+ }
+% \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|.
%
@@ -5000,38 +5015,45 @@
% \begin{macrocode}
\SetPitonStyle
{
- Comment = \color[HTML]{0099FF} \itshape ,
- Exception = \color[HTML]{CC0000} ,
- Keyword = \color[HTML]{006699} \bfseries ,
- Keyword.Constant = \color[HTML]{006699} \bfseries ,
- Name.Builtin = \color[HTML]{336666} ,
- Name.Decorator = \color[HTML]{9999FF},
- Name.Class = \color[HTML]{00AA88} \bfseries ,
- Name.Function = \color[HTML]{CC00FF} ,
- Name.Namespace = \color[HTML]{00CCFF} ,
- Name.Constructor = \color[HTML]{006000} \bfseries ,
- Name.Field = \color[HTML]{AA6600} ,
- Name.Module = \color[HTML]{0060A0} \bfseries ,
- Name.Table = \color[HTML]{309030} ,
- Number = \color[HTML]{FF6600} ,
- Operator = \color[HTML]{555555} ,
- Operator.Word = \bfseries ,
- String = \color[HTML]{CC3300} ,
- String.Doc = \color[HTML]{CC3300} \itshape ,
- String.Interpol = \color[HTML]{AA0000} ,
- Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
- Name.Type = \color[HTML]{336666} ,
- InitialValues = \@@_piton:n ,
- Interpol.Inside = \color{black}\@@_piton:n ,
- TypeParameter = \color[HTML]{336666} \itshape ,
- Preproc = \color[HTML]{AA6600} \slshape ,
- Identifier = \@@_identifier:n ,
- Directive = \color[HTML]{AA6600} ,
- Tag = \colorbox{gray!10},
- UserFunction = ,
- Prompt = ,
- ParseAgain.noCR = \@@_piton_no_cr:n ,
- Discard = \use_none:n
+ Comment = \color[HTML]{0099FF} \itshape ,
+ Exception = \color[HTML]{CC0000} ,
+ Keyword = \color[HTML]{006699} \bfseries ,
+ Keyword.Governing = \color[HTML]{006699} \bfseries ,
+ Keyword.Constant = \color[HTML]{006699} \bfseries ,
+ Name.Builtin = \color[HTML]{336666} ,
+ Name.Decorator = \color[HTML]{9999FF},
+ Name.Class = \color[HTML]{00AA88} \bfseries ,
+ Name.Function = \color[HTML]{CC00FF} ,
+ Name.Namespace = \color[HTML]{00CCFF} ,
+ Name.Constructor = \color[HTML]{006000} \bfseries ,
+ Name.Field = \color[HTML]{AA6600} ,
+ Name.Module = \color[HTML]{0060A0} \bfseries ,
+ Name.Table = \color[HTML]{309030} ,
+ Number = \color[HTML]{FF6600} ,
+ Operator = \color[HTML]{555555} ,
+ Operator.Word = \bfseries ,
+ String = \color[HTML]{CC3300} ,
+ String.Doc = \color[HTML]{CC3300} \itshape ,
+ String.Interpol = \color[HTML]{AA0000} ,
+ Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
+ Name.Type = \color[HTML]{336666} ,
+ InitialValues = \@@_piton:n ,
+ Interpol.Inside = \color{black}\@@_piton:n ,
+ TypeParameter = \color[HTML]{336666} \itshape ,
+ Preproc = \color[HTML]{AA6600} \slshape ,
+% \end{macrocode}
+% We need the command |\@@_identifier:n| because of the command
+% |\SetPitonIdentifier|. The command |\@@_identifier:n| will potentially call
+% the style |Identifier| (which is a user-style, not an internal style).
+% \begin{macrocode}
+ Identifier.Internal = \@@_identifier:n ,
+ Identifier = ,
+ Directive = \color[HTML]{AA6600} ,
+ Tag = \colorbox{gray!10},
+ UserFunction = ,
+ Prompt = ,
+ ParseAgain = \@@_piton_no_cr:n ,
+ Discard = \use_none:n
}
% \end{macrocode}
% The styles |ParseAgain.noCR| should be considered as
@@ -5081,7 +5103,10 @@
\cs_new_protected:Npn \@@_identifier:n #1
{
\cs_if_exist_use:cF { PitonIdentifier _ \l_piton_language_str _ #1 }
- { \cs_if_exist_use:c { PitonIdentifier _ #1 } }
+ {
+ \cs_if_exist_use:cF { PitonIdentifier _ #1 }
+ { \PitonStyle { Identifier } }
+ }
{ #1 }
}
% \end{macrocode}
@@ -5301,6 +5326,7 @@
% \begin{macrocode}
\@@_msg_new:nn { SyntaxError }
{
+ Syntax~Error.\\
Your~code~of~the~language~"\l_piton_language_str"~is~not~
syntactically~correct.\\
It~won't~be~printed~in~the~PDF~file.
@@ -5308,6 +5334,16 @@
% \end{macrocode}
%
% \begin{macrocode}
+\@@_msg_new:nn { FileError }
+ {
+ File~Error.\\
+ It's~not~possible~to~write~on~the~file~'\l_@@_write_str'.\\
+ \sys_if_shell_unrestricted:F { Be~sure~to~compile~with~'-shell-escape'.\\ }
+ If~you~go~on,~nothing~will~be~written~on~the~file.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
\@@_msg_new:nn { begin~marker~not~found }
{
Marker~not~found.\\
@@ -5395,18 +5431,6 @@
}
% \end{macrocode}
%
-% \bigskip
-% \begin{macrocode}
-\@@_msg_new:nn { cr~not~allowed }
- {
- You~can't~put~any~carriage~return~in~the~argument~
- of~a~command~\c_backslash_str
- \l_@@_beamer_command_str\ within~an~
- environment~of~'piton'.~You~should~consider~using~the~
- corresponding~environment.\\
- That~error~is~fatal.
- }
-% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
@@ -5682,7 +5706,7 @@
% On the other hand, the \textsc{lpeg} |Identifier| (with a capital) also returns
% a \emph{capture}.
% \begin{macrocode}
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
% \end{macrocode}
%
% \bigskip
@@ -5741,12 +5765,12 @@
local Punct = Q ( S ".,:;!" )
-local Tab = "\t" * Lc "\\@@_tab:"
+local Tab = "\t" * Lc [[\@@_tab:]]
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
-local SpaceIndentation = Lc "\\@@_an_indentation_space:" * Q " "
+local SpaceIndentation = Lc [[\@@_an_indentation_space:]] * Q " "
% \end{macrocode}
%
% \bigskip
@@ -5761,10 +5785,21 @@
% However, when the key |show-spaces-in-strings| is in force, |\\l_@@_space_tl| will
% contain ␣ (U+2423) in order to visualize the spaces.
% \begin{macrocode}
-local VisualSpace = space * Lc "\\l_@@_space_tl"
+local VisualSpace = space * Lc [[\l_@@_space_tl]]
% \end{macrocode}
%
% \bigskip
+% Of course, the \textsc{lpeg} |strict_braces| is for balanced braces (without the
+% question of strings of an informatic language).
+% \begin{macrocode}
+ local strict_braces =
+ P { "E" ,
+ E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
+ F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+% \end{macrocode}
+%
+% \bigskip
% \paragraph{Several tools for the construction of the main LPEG}
%
% \begin{macrocode}
@@ -6004,7 +6039,7 @@
% \bigskip
% The following \textsc{lpeg} |EOL| is for the end of lines.
% \begin{macrocode}
-local EOL =
+local EOL_without_space_indentation =
P "\r"
*
(
@@ -6011,7 +6046,7 @@
( space ^ 0 * -1 )
+
% \end{macrocode}
-% We recall that each line in the Python code we have to parse will be sent
+% We recall that each line of the informatic 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
@@ -6021,18 +6056,22 @@
Cc "EOL"
*
Ct (
- Lc "\\@@_end_line:"
+ Lc [[\@@_end_line:]]
* BeamerEndEnvironments
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc "\\@@_newline: \\@@_begin_line:"
+ * Lc [[\@@_newline:\@@_begin_line:]]
* Prompt
)
)
)
+% \end{macrocode}
+%
+% \begin{macrocode}
+local EOL = EOL_without_space_indentation
* ( SpaceIndentation ^ 0 * # ( 1 - S " \r" ) ) ^ -1
% \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 caught must
@@ -6584,12 +6623,12 @@
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc '\\@@_begin_line:'
+ * Lc [[\@@_begin_line:]]
* Prompt
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\@@_end_line:'
+ * Lc [[\@@_end_line:]]
)
% \end{macrocode}
%
@@ -6596,6 +6635,13 @@
%
% \bigskip
% \subsubsection{The language Ocaml}
+%
+% The following LPEG corresponds to the balanced expressions (balanced according
+% to the parenthesis). Of course, we must write |(1 - S "()")| with outer parenthesis.
+% \begin{macrocode}
+local balanced_parens =
+ P { "E" , E = ( "(" * V "E" * ")" + ( 1 - S "()" ) ) ^ 0 }
+% \end{macrocode}
%
% \begin{macrocode}
local Delim = Q ( P "[|" + "|]" + S "[()]" )
@@ -6620,7 +6666,7 @@
% elsewhere in OCaml.
% \begin{macrocode}
local identifier = ( R "az" + "_" ) * ( R "az" + R "AZ" + S "_'" + digit ) ^ 0
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
% \end{macrocode}
%
%
@@ -6647,7 +6693,7 @@
( K ( 'Keyword' , "mutable" ) * SkipSpace ) ^ -1
* K ( 'Name.Field' , identifier ) * SkipSpace
* Q ":" * SkipSpace
- * K ( 'Name.Type' , expression_for_fields )
+ * K ( 'TypeExpression' , expression_for_fields )
* SkipSpace
local OneField =
@@ -6696,21 +6742,25 @@
local OperatorWord =
K ( 'Operator.Word' ,
- P "and" + "asr" + "land" + "lor" + "lsl" + "lxor" + "mod" + "or" )
+ P "asr" + "land" + "lor" + "lsl" + "lxor" + "mod" + "or" )
-local Keyword =
+
+local governing_keyword = P "and" + "begin" + "class" + "constraint" +
+ "end" + "external" + "functor" + "include" + "inherit" + "initializer" +
+ "in" + "let" + "method" + "module" + "object" + "open" + "rec" + "sig" +
+ "struct" + "type" + "val"
+
+local Keyword =
K ( 'Keyword' ,
- P "assert" + "and" + "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" + "with" )
- + K ( 'Keyword.Constant' , P "true" + "false" )
+ P "assert" + "as" + "done" + "downto" + "do" + "else" + "exception"
+ + "for" + "function" + "fun" + "if" + "lazy" + "match" + "mutable"
+ + "new" + "of" + "private" + "raise" + "then" + "to" + "try"
+ + "virtual" + "when" + "while" + "with" )
+ + K ( 'Keyword.Constant' , P "true" + "false" )
+ + K ('Keyword.Governing', governing_keyword )
local Builtin =
- K ( 'Name.Builtin' , P "not" + "incr" + "decr" + "fst" + "snd" )
+ K ( 'Name.Builtin' , P "not" + "incr" + "decr" + "fst" + "snd" + "ref" )
% \end{macrocode}
%
% \bigskip
@@ -6727,8 +6777,20 @@
% \paragraph{The characters in OCaml}
%
% \begin{macrocode}
-local Char =
- K ( 'String.Short' , "'" * ( ( 1 - P "'" ) ^ 0 + "\\'" ) * "'" )
+local Char =
+ K ( 'String.Short',
+ P "'" *
+ (
+ ( 1 - S "'\\" )
+ + "\\"
+ * ( S "\\'ntbr \""
+ + digit * digit * digit
+ + P "x" * ( digit + R "af" + R "AF" )
+ * ( digit + R "af" + R "AF" )
+ * ( digit + R "af" + R "AF" )
+ + P "o" * R "03" * R "07" * R "07" )
+ )
+ * "'" )
% \end{macrocode}
%
%
@@ -6853,18 +6915,20 @@
% \paragraph{The DefFunction}
%
% \begin{macrocode}
-local balanced_parens =
- P { "E" , E = ( "(" * V "E" * ")" + 1 - S "()" ) ^ 0 }
+local Argument =
% \end{macrocode}
-%
+% For the labels of the labeled arguments. Maybe you will, in the future, create
+% a style for those elements.
% \begin{macrocode}
-local Argument =
- K ( 'Identifier' , identifier )
- + Q "(" * SkipSpace
- * K ( 'Identifier' , identifier ) * SkipSpace
- * Q ":" * SkipSpace
- * K ( 'Name.Type' , balanced_parens ) * SkipSpace
- * Q ")"
+ ( Q "~" * Identifier * Q ":" * SkipSpace ) ^ -1
+ *
+ ( K ( 'Identifier.Internal' , identifier )
+ + Q "(" * SkipSpace
+ * K ( 'Identifier.Internal' , identifier ) * SkipSpace
+ * Q ":" * SkipSpace
+ * K ( 'TypeExpression' , balanced_parens ) * SkipSpace
+ * Q ")"
+ )
% \end{macrocode}
%
% Despite its name, then \textsc{lpeg} |DefFunction| deals also with |let open|
@@ -6871,11 +6935,11 @@
% which opens locally a module.
% \begin{macrocode}
local DefFunction =
- K ( 'Keyword' , "let open" )
+ K ( 'Keyword.Governing' , "let open" )
* Space
* K ( 'Name.Module' , cap_identifier )
+
- K ( 'Keyword' , P "let rec" + "let" + "and" )
+ K ( 'Keyword.Governing' , P "let rec" + "let" + "and" )
* Space
* K ( 'Name.Function.Internal' , identifier )
* Space
@@ -6887,7 +6951,7 @@
* (
SkipSpace
* Q ":"
- * K ( 'Name.Type' , ( 1 - P "=" ) ^ 0 )
+ * K ( 'TypeExpression' , ( 1 - P "=" ) ^ 0 )
) ^ -1
)
% \end{macrocode}
@@ -6900,10 +6964,10 @@
% definitions of \emph{types} of modules.
% \begin{macrocode}
local DefModule =
- K ( 'Keyword' , "module" ) * Space
+ K ( 'Keyword.Governing' , "module" ) * Space
*
(
- K ( 'Keyword' , "type" ) * Space
+ K ( 'Keyword.Governing' , "type" ) * Space
* K ( 'Name.Type' , cap_identifier )
+
K ( 'Name.Module' , cap_identifier ) * SkipSpace
@@ -6938,16 +7002,34 @@
) ^ -1
)
+
- K ( 'Keyword' , P "include" + "open" )
+ K ( 'Keyword.Governing' , P "include" + "open" )
* Space * K ( 'Name.Module' , cap_identifier )
% \end{macrocode}
+%
%
% \bigskip
-% \paragraph{The parameters of the types}
-%
+% \paragraph{The DefType}\par
+%
% \begin{macrocode}
-local TypeParameter = K ( 'TypeParameter' , "'" * alpha * # ( 1 - P "'" ) )
+local TypeParameter =
+ K ( 'TypeParameter' , "'" * alpha * ( # ( 1 - P "'" ) + -1 ) )
% \end{macrocode}
+%
+%
+% \bigskip
+% The following LPEG is for the instructions of definitions of types (which
+% begin with |type|).
+% \begin{macrocode}
+local DefType =
+ K ( 'Keyword.Governing' , "type" )
+ * Space
+ * WithStyle
+ (
+ 'TypeExpression' ,
+ ( Q ( 1 - P ";;" - P "\r" ) + EOL_without_space_indentation ) ^ 0
+ )
+ * ( # governing_keyword + Q ";;" + -1 )
+% \end{macrocode}
%
% \bigskip
% \paragraph{The main LPEG for the language OCaml}
@@ -6969,11 +7051,18 @@
+ Comment
+ Delim
+ Operator
+% \end{macrocode}
+% For the labels of the labeled arguments. Maybe you will, in the future, create
+% a style for those elements.
+% \begin{macrocode}
+ + Q ( "~" ) * Identifier * ( Q ":" ) ^ -1
+ + Q ":" * # (1 - P":") * SkipSpace
+ * K ( 'TypeExpression' , balanced_parens ) * SkipSpace * Q ")"
+ Punct
- + FromImport
+ Exception
+ DefFunction
+ DefModule
+ + DefType
+ Record
+ Keyword * EndKeyword
+ OperatorWord * EndKeyword
@@ -6995,18 +7084,31 @@
% \texttt{\textbackslash @@\_begin\_line:}}.
% \begin{macrocode}
LPEG2['ocaml'] =
- Ct (
+ Ct (
+% \end{macrocode}
+% The following lines are in order to allow, in |\piton| (and not in |{Piton}|),
+% judments of type (such as |f : my_type -> 'a list|) or single expressions of
+% type such as |my_type -> 'a list| (in that case, the argument of |\piton|
+% \emph{must} begin by a colon).
+% \begin{macrocode}
+ ( P ":" + Identifier * SkipSpace * Q ":" )
+ * SkipSpace
+ * K ( 'TypeExpression' , ( 1 - P "\r" ) ^ 0 )
+ +
+% \end{macrocode}
+% Now, the main part.
+% \begin{macrocode}
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc '\\@@_begin_line:'
+ * Lc [[\@@_begin_line:]]
* SpaceIndentation ^ 0
- * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * ( ( space * Lc [[\@@_trailing_space:]] ) ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\@@_end_line:'
+ * Lc [[\@@_end_line:]]
)
% \end{macrocode}
%
-%
+%
% \bigskip
% \subsubsection{The language C}
%
@@ -7190,11 +7292,11 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc '\\@@_begin_line:'
+ * Lc [[\@@_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\@@_end_line:'
+ * Lc [[\@@_end_line:]]
)
% \end{macrocode}
%
@@ -7221,7 +7323,7 @@
% \begin{macrocode}
local identifier =
letter * ( alphanum + "-" ) ^ 0
- + '"' * ( ( alphanum + space - '"' ) ^ 1 ) * '"'
+ + P '"' * ( ( 1 - P '"' ) ^ 1 ) * '"'
local Operator =
@@ -7424,11 +7526,11 @@
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[ \@@_begin_line: ]]
+ * Lc [[\@@_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[ \@@_end_line: ]]
+ * Lc [[\@@_end_line:]]
)
% \end{macrocode}
%
@@ -7468,7 +7570,7 @@
local identifier = letter * alphanum ^ 0
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
local Delim = Q ( S "{[()]}" )
@@ -7493,11 +7595,11 @@
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[ \@@_begin_line: ]]
+ * Lc [[\@@_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[ \@@_end_line: ]]
+ * Lc [[\@@_end_line:]]
)
% \bigskip
@@ -7779,9 +7881,13 @@
% environment on an external file.
% \begin{macrocode}
if piton.write and piton.write ~= '' then
- local file = assert ( io.open ( piton.write , piton.write_mode ) )
- file:write ( piton.get_last_code ( ) )
- file:close ( )
+ local file = io.open ( piton.write , piton.write_mode )
+ if file then
+ file:write ( piton.get_last_code ( ) )
+ file:close ( )
+ else
+ sprintL3 [[ \@@_error_or_warning:n { FileError } ]]
+ end
end
end
% \end{macrocode}
@@ -8008,18 +8114,6 @@
end
% \end{macrocode}
%
-% \bigskip
-% Of course, the \textsc{lpeg} |strict_braces| is for balanced braces (without the
-% question of strings of an informatic language). In fact, it \emph{won't} be
-% used for an informatic language (as dealt by \pkg{piton}) but for LaTeX
-% instructions;
-% \begin{macrocode}
- local strict_braces =
- P { "E" ,
- E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
- F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
- }
-% \end{macrocode}
%
% \bigskip
% Now, the first transformation of the definition of the language, as provided
@@ -8135,7 +8229,7 @@
% \begin{macrocode}
local alphanum = letter + digit
local identifier = letter * alphanum ^ 0
- local Identifier = K ( 'Identifier' , identifier )
+ local Identifier = K ( 'Identifier.Internal' , identifier )
% \end{macrocode}
%
%
@@ -8425,7 +8519,7 @@
+ PrefixedKeyword
+ Keyword * ( -1 + # ( 1 - alphanum ) )
+ Punct
- + K ( 'Identifier' , letter * alphanum ^ 0 )
+ + K ( 'Identifier.Internal' , letter * alphanum ^ 0 )
+ Number
+ Word
% \end{macrocode}
@@ -8475,7 +8569,7 @@
+ PrefixedKeyword
+ Keyword * ( -1 + # ( 1 - alphanum ) )
+ Punct
- + K ( 'Identifier' , letter * alphanum ^ 0 )
+ + K ( 'Identifier.Internal' , letter * alphanum ^ 0 )
+ Number
+ Word
LPEG0[lang] = MainWithoutTag ^ 0
@@ -8492,7 +8586,7 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\@@_begin_line:]]
+ * Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-08-28 23:41:57 UTC (rev 72131)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-08-29 20:30:59 UTC (rev 72132)
@@ -20,7 +20,7 @@
-- -------------------------------------------
--
-- This file is part of the LuaLaTeX package 'piton'.
-piton_version = "3.1a" -- 2024/08/12
+piton_version = "3.1b" -- 2024/08/29
@@ -86,7 +86,7 @@
local alphanum = letter + digit
local identifier = letter * alphanum ^ 0
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
local Number =
K ( 'Number' ,
( digit ^ 1 * P "." * # ( 1 - P "." ) * digit ^ 0
@@ -119,10 +119,15 @@
local Punct = Q ( S ".,:;!" )
-local Tab = "\t" * Lc "\\__piton_tab:"
-local SpaceIndentation = Lc "\\__piton_an_indentation_space:" * Q " "
+local Tab = "\t" * Lc [[\__piton_tab:]]
+local SpaceIndentation = Lc [[\__piton_an_indentation_space:]] * Q " "
local Delim = Q ( S "[({})]" )
-local VisualSpace = space * Lc "\\l__piton_space_tl"
+local VisualSpace = space * Lc [[\l__piton_space_tl]]
+ local strict_braces =
+ P { "E" ,
+ E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
+ F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
local LPEG0 = { }
local LPEG1 = { }
local LPEG2 = { }
@@ -243,7 +248,7 @@
local PromptHastyDetection =
( # ( P ">>>" + "..." ) * Lc '\\__piton_prompt:' ) ^ -1
local Prompt = K ( 'Prompt' , ( ( P ">>>" + "..." ) * P " " ^ -1 ) ^ -1 )
-local EOL =
+local EOL_without_space_indentation =
P "\r"
*
(
@@ -253,15 +258,16 @@
Cc "EOL"
*
Ct (
- Lc "\\__piton_end_line:"
+ Lc [[\__piton_end_line:]]
* BeamerEndEnvironments
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc "\\__piton_newline: \\__piton_begin_line:"
+ * Lc [[\__piton_newline:\__piton_begin_line:]]
* Prompt
)
)
)
+local EOL = EOL_without_space_indentation
* ( SpaceIndentation ^ 0 * # ( 1 - S " \r" ) ) ^ -1
local CommentLaTeX =
P(piton.comment_latex)
@@ -555,13 +561,15 @@
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
* PromptHastyDetection
- * Lc '\\__piton_begin_line:'
+ * Lc [[\__piton_begin_line:]]
* Prompt
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\__piton_end_line:'
+ * Lc [[\__piton_end_line:]]
)
+local balanced_parens =
+ P { "E" , E = ( "(" * V "E" * ")" + ( 1 - S "()" ) ) ^ 0 }
local Delim = Q ( P "[|" + "|]" + S "[()]" )
local Punct = Q ( S ",:;!" )
local cap_identifier = R "AZ" * ( R "az" + R "AZ" + S "_'" + digit ) ^ 0
@@ -568,7 +576,7 @@
local Constructor = K ( 'Name.Constructor' , cap_identifier )
local ModuleType = K ( 'Name.Type' , cap_identifier )
local identifier = ( R "az" + "_" ) * ( R "az" + R "AZ" + S "_'" + digit ) ^ 0
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
local expression_for_fields =
P { "E" ,
E = ( "{" * V "F" * "}"
@@ -586,7 +594,7 @@
( K ( 'Keyword' , "mutable" ) * SkipSpace ) ^ -1
* K ( 'Name.Field' , identifier ) * SkipSpace
* Q ":" * SkipSpace
- * K ( 'Name.Type' , expression_for_fields )
+ * K ( 'TypeExpression' , expression_for_fields )
* SkipSpace
local OneField =
@@ -626,21 +634,24 @@
local OperatorWord =
K ( 'Operator.Word' ,
- P "and" + "asr" + "land" + "lor" + "lsl" + "lxor" + "mod" + "or" )
+ P "asr" + "land" + "lor" + "lsl" + "lxor" + "mod" + "or" )
+local governing_keyword = P "and" + "begin" + "class" + "constraint" +
+ "end" + "external" + "functor" + "include" + "inherit" + "initializer" +
+ "in" + "let" + "method" + "module" + "object" + "open" + "rec" + "sig" +
+ "struct" + "type" + "val"
+
local Keyword =
K ( 'Keyword' ,
- P "assert" + "and" + "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" + "with" )
+ P "assert" + "as" + "done" + "downto" + "do" + "else" + "exception"
+ + "for" + "function" + "fun" + "if" + "lazy" + "match" + "mutable"
+ + "new" + "of" + "private" + "raise" + "then" + "to" + "try"
+ + "virtual" + "when" + "while" + "with" )
+ K ( 'Keyword.Constant' , P "true" + "false" )
+ + K ('Keyword.Governing', governing_keyword )
local Builtin =
- K ( 'Name.Builtin' , P "not" + "incr" + "decr" + "fst" + "snd" )
+ K ( 'Name.Builtin' , P "not" + "incr" + "decr" + "fst" + "snd" + "ref" )
local Exception =
K ( 'Exception' ,
P "Division_by_zero" + "End_of_File" + "Failure" + "Invalid_argument" +
@@ -647,7 +658,19 @@
"Match_failure" + "Not_found" + "Out_of_memory" + "Stack_overflow" +
"Sys_blocked_io" + "Sys_error" + "Undefined_recursive_module" )
local Char =
- K ( 'String.Short' , "'" * ( ( 1 - P "'" ) ^ 0 + "\\'" ) * "'" )
+ K ( 'String.Short',
+ P "'" *
+ (
+ ( 1 - S "'\\" )
+ + "\\"
+ * ( S "\\'ntbr \""
+ + digit * digit * digit
+ + P "x" * ( digit + R "af" + R "AF" )
+ * ( digit + R "af" + R "AF" )
+ * ( digit + R "af" + R "AF" )
+ + P "o" * R "03" * R "07" * R "07" )
+ )
+ * "'" )
local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then
Beamer = Compute_Beamer ( 'ocaml' , braces ) -- modified 2024/07/24
@@ -696,21 +719,22 @@
) ^ 0
* Q "*)"
} )
-local balanced_parens =
- P { "E" , E = ( "(" * V "E" * ")" + 1 - S "()" ) ^ 0 }
local Argument =
- K ( 'Identifier' , identifier )
- + Q "(" * SkipSpace
- * K ( 'Identifier' , identifier ) * SkipSpace
- * Q ":" * SkipSpace
- * K ( 'Name.Type' , balanced_parens ) * SkipSpace
- * Q ")"
+ ( Q "~" * Identifier * Q ":" * SkipSpace ) ^ -1
+ *
+ ( K ( 'Identifier.Internal' , identifier )
+ + Q "(" * SkipSpace
+ * K ( 'Identifier.Internal' , identifier ) * SkipSpace
+ * Q ":" * SkipSpace
+ * K ( 'TypeExpression' , balanced_parens ) * SkipSpace
+ * Q ")"
+ )
local DefFunction =
- K ( 'Keyword' , "let open" )
+ K ( 'Keyword.Governing' , "let open" )
* Space
* K ( 'Name.Module' , cap_identifier )
+
- K ( 'Keyword' , P "let rec" + "let" + "and" )
+ K ( 'Keyword.Governing' , P "let rec" + "let" + "and" )
* Space
* K ( 'Name.Function.Internal' , identifier )
* Space
@@ -722,14 +746,14 @@
* (
SkipSpace
* Q ":"
- * K ( 'Name.Type' , ( 1 - P "=" ) ^ 0 )
+ * K ( 'TypeExpression' , ( 1 - P "=" ) ^ 0 )
) ^ -1
)
local DefModule =
- K ( 'Keyword' , "module" ) * Space
+ K ( 'Keyword.Governing' , "module" ) * Space
*
(
- K ( 'Keyword' , "type" ) * Space
+ K ( 'Keyword.Governing' , "type" ) * Space
* K ( 'Name.Type' , cap_identifier )
+
K ( 'Name.Module' , cap_identifier ) * SkipSpace
@@ -764,9 +788,19 @@
) ^ -1
)
+
- K ( 'Keyword' , P "include" + "open" )
+ K ( 'Keyword.Governing' , P "include" + "open" )
* Space * K ( 'Name.Module' , cap_identifier )
-local TypeParameter = K ( 'TypeParameter' , "'" * alpha * # ( 1 - P "'" ) )
+local TypeParameter =
+ K ( 'TypeParameter' , "'" * alpha * ( # ( 1 - P "'" ) + -1 ) )
+local DefType =
+ K ( 'Keyword.Governing' , "type" )
+ * Space
+ * WithStyle
+ (
+ 'TypeExpression' ,
+ ( Q ( 1 - P ";;" - P "\r" ) + EOL_without_space_indentation ) ^ 0
+ )
+ * ( # governing_keyword + Q ";;" + -1 )
local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local Main =
Space
@@ -779,11 +813,14 @@
+ Comment
+ Delim
+ Operator
+ + Q ( "~" ) * Identifier * ( Q ":" ) ^ -1
+ + Q ":" * # (1 - P":") * SkipSpace
+ * K ( 'TypeExpression' , balanced_parens ) * SkipSpace * Q ")"
+ Punct
- + FromImport
+ Exception
+ DefFunction
+ DefModule
+ + DefType
+ Record
+ Keyword * EndKeyword
+ OperatorWord * EndKeyword
@@ -797,13 +834,17 @@
LPEG1['ocaml'] = Main ^ 0
LPEG2['ocaml'] =
Ct (
+ ( P ":" + Identifier * SkipSpace * Q ":" )
+ * SkipSpace
+ * K ( 'TypeExpression' , ( 1 - P "\r" ) ^ 0 )
+ +
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc '\\__piton_begin_line:'
+ * Lc [[\__piton_begin_line:]]
* SpaceIndentation ^ 0
- * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * ( ( space * Lc [[\__piton_trailing_space:]] ) ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\__piton_end_line:'
+ * Lc [[\__piton_end_line:]]
)
local Delim = Q ( S "{[()]}" )
local Punct = Q ( S ",:;!" )
@@ -898,11 +939,11 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc '\\__piton_begin_line:'
+ * Lc [[\__piton_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc '\\__piton_end_line:'
+ * Lc [[\__piton_end_line:]]
)
local function LuaKeyword ( name )
return
@@ -916,7 +957,7 @@
end
local identifier =
letter * ( alphanum + "-" ) ^ 0
- + '"' * ( ( alphanum + space - '"' ) ^ 1 ) * '"'
+ + P '"' * ( ( 1 - P '"' ) ^ 1 ) * '"'
local Operator =
K ( 'Operator' , P "=" + "!=" + "<>" + ">=" + ">" + "<=" + "<" + S "*+/" )
@@ -1039,11 +1080,11 @@
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[ \__piton_begin_line: ]]
+ * Lc [[\__piton_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[ \__piton_end_line: ]]
+ * Lc [[\__piton_end_line:]]
)
local Punct = Q ( S ",:;!\\" )
@@ -1073,7 +1114,7 @@
local identifier = letter * alphanum ^ 0
-local Identifier = K ( 'Identifier' , identifier )
+local Identifier = K ( 'Identifier.Internal' , identifier )
local Delim = Q ( S "{[()]}" )
@@ -1098,11 +1139,11 @@
Ct (
( space ^ 0 * "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[ \__piton_begin_line: ]]
+ * Lc [[\__piton_begin_line:]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
- * Lc [[ \__piton_end_line: ]]
+ * Lc [[\__piton_end_line:]]
)
function piton.Parse ( language , code )
@@ -1251,9 +1292,13 @@
sprintL3 [[ \bool_if:NT \g__piton_footnote_bool \endsavenotes ]]
sprintL3 [[ \par ]]
if piton.write and piton.write ~= '' then
- local file = assert ( io.open ( piton.write , piton.write_mode ) )
- file:write ( piton.get_last_code ( ) )
- file:close ( )
+ local file = io.open ( piton.write , piton.write_mode )
+ if file then
+ file:write ( piton.get_last_code ( ) )
+ file:close ( )
+ else
+ sprintL3 [[ \__piton_error_or_warning:n { FileError } ]]
+ end
end
end
function piton.GobbleSplitParse ( lang , n , code )
@@ -1357,11 +1402,6 @@
other = other + P ( c )
end
end
- local strict_braces =
- P { "E" ,
- E = ( "{" * V "F" * "}" + ( 1 - S ",{}" ) ) ^ 0 ,
- F = ( "{" * V "F" * "}" + ( 1 - S "{}" ) ) ^ 0
- }
local cut_definition =
P { "E" ,
E = Ct ( V "F" * ( "," * V "F" ) ^ 0 ) ,
@@ -1433,7 +1473,7 @@
+ "Ï" + "Î" + "Ô" + "Û" + "Ü"
local alphanum = letter + digit
local identifier = letter * alphanum ^ 0
- local Identifier = K ( 'Identifier' , identifier )
+ local Identifier = K ( 'Identifier.Internal' , identifier )
local split_clist =
P { "E" ,
E = ( "[" * ( 1 - P "]" ) ^ 0 * "]" ) ^ -1
@@ -1636,7 +1676,7 @@
+ PrefixedKeyword
+ Keyword * ( -1 + # ( 1 - alphanum ) )
+ Punct
- + K ( 'Identifier' , letter * alphanum ^ 0 )
+ + K ( 'Identifier.Internal' , letter * alphanum ^ 0 )
+ Number
+ Word
LPEG1[lang] = Main ^ 0
@@ -1672,7 +1712,7 @@
+ PrefixedKeyword
+ Keyword * ( -1 + # ( 1 - alphanum ) )
+ Punct
- + K ( 'Identifier' , letter * alphanum ^ 0 )
+ + K ( 'Identifier.Internal' , letter * alphanum ^ 0 )
+ Number
+ Word
LPEG0[lang] = MainWithoutTag ^ 0
@@ -1689,7 +1729,7 @@
Ct (
( space ^ 0 * P "\r" ) ^ -1
* BeamerBeginEnvironments
- * Lc [[\__piton_begin_line:]]
+ * Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-08-28 23:41:57 UTC (rev 72131)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-08-29 20:30:59 UTC (rev 72132)
@@ -19,8 +19,8 @@
%% LaTeX version 2005/12/01 or later.
%% -------------------------------------------
%%
-\def\PitonFileVersion{3.1a}
-\def\PitonFileDate{2024/08/12}
+\def\PitonFileVersion{3.1b}
+\def\PitonFileDate{2024/08/29}
@@ -229,11 +229,6 @@
\int_new:N \g__piton_indentation_int
\cs_new_protected:Npn \__piton_an_indentation_space:
{ \int_gincr:N \g__piton_indentation_int }
-\cs_new_protected:Npn \__piton_beamer_command:n #1
- {
- \str_set:Nn \l__piton_beamer_command_str { #1 }
- \use:c { #1 }
- }
\cs_new_protected:Npn \__piton_label:n #1
{
\bool_if:NTF \l__piton_line_numbers_bool
@@ -264,6 +259,7 @@
{ \clist_set:NV \l__piton_bg_color_clist \l__piton_prompt_bg_color_tl }
}
}
+\cs_new_protected:Npn \__piton_trailing_space: { }
\cs_new_protected:Npn \__piton_replace_spaces:n #1
{
\tl_set:Nn \l_tmpa_tl { #1 }
@@ -834,6 +830,7 @@
\cs_set_protected:Npn \__piton_end_line: { }
\cs_set:cpn { pitonStyle _ \l_piton_language_str _ Prompt } { }
\cs_set:cpn { pitonStyle _ Prompt } { }
+ \cs_set_eq:NN \__piton_trailing_space: \space
\bool_lazy_or:nnTF
\l__piton_break_lines_in_piton_bool
\l__piton_break_lines_in_Piton_bool
@@ -855,17 +852,9 @@
}
\bool_if:NT \l__piton_show_spaces_bool
{ \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \l_tmpa_tl
+ \exp_args:No \__piton_replace_spaces:n \l_tmpa_tl
\group_end:
}
-\cs_new_protected:Npn \__piton_piton_no_cr:n #1
- {
- \group_begin:
- \cs_set_protected:Npn \__piton_newline:
- { \msg_fatal:nn { piton } { cr~not~allowed } }
- \__piton_piton:n { #1 }
- \group_end:
- }
\cs_new:Npn \__piton_pre_env:
{
\automatichyphenmode = 1
@@ -1122,6 +1111,7 @@
}
\bool_if:NT \l__piton_width_min_bool \__piton_width_to_aux:
\group_end:
+ \exp_args:Nx \iow_log:n {(\l__piton_file_name_str)}
\tl_if_novalue:nF { #1 }
{ \bool_if:NT \g__piton_beamer_bool { \end { uncoverenv } } }
\__piton_write_aux:
@@ -1161,10 +1151,12 @@
Discard ,
Exception ,
FormattingType ,
+ Identifier.Internal ,
Identifier ,
InitialValues ,
Interpol.Inside ,
Keyword ,
+ Keyword.Governing ,
Keyword.Constant ,
Keyword2 ,
Keyword3 ,
@@ -1196,6 +1188,7 @@
Tag ,
TypeParameter ,
UserFunction ,
+ TypeExpression ,
Directive
}
@@ -1218,13 +1211,18 @@
\keys_define:nn { piton / Styles }
{
- String .meta:n = { String.Long = #1 , String.Short = #1 } ,
- Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain.noCR .tl_set:c = pitonStyle _ ParseAgain.noCR ,
- ParseAgain.noCR .value_required:n = true ,
+ String .meta:n = { String.Long = #1 , String.Short = #1 } ,
+ Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
+ ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
+ ParseAgain .value_required:n = true ,
unknown .code:n =
\__piton_error:n { Unknown~key~for~SetPitonStyle }
}
+\SetPitonStyle[OCaml]
+ {
+ TypeExpression =
+ \SetPitonStyle { Identifier = \PitonStyle { Name.Type } } \__piton_piton:n
+ }
\clist_gput_left:Nn \g__piton_styles_clist { String }
\clist_gsort:Nn \g__piton_styles_clist
{
@@ -1234,38 +1232,40 @@
}
\SetPitonStyle
{
- Comment = \color[HTML]{0099FF} \itshape ,
- Exception = \color[HTML]{CC0000} ,
- Keyword = \color[HTML]{006699} \bfseries ,
- Keyword.Constant = \color[HTML]{006699} \bfseries ,
- Name.Builtin = \color[HTML]{336666} ,
- Name.Decorator = \color[HTML]{9999FF},
- Name.Class = \color[HTML]{00AA88} \bfseries ,
- Name.Function = \color[HTML]{CC00FF} ,
- Name.Namespace = \color[HTML]{00CCFF} ,
- Name.Constructor = \color[HTML]{006000} \bfseries ,
- Name.Field = \color[HTML]{AA6600} ,
- Name.Module = \color[HTML]{0060A0} \bfseries ,
- Name.Table = \color[HTML]{309030} ,
- Number = \color[HTML]{FF6600} ,
- Operator = \color[HTML]{555555} ,
- Operator.Word = \bfseries ,
- String = \color[HTML]{CC3300} ,
- String.Doc = \color[HTML]{CC3300} \itshape ,
- String.Interpol = \color[HTML]{AA0000} ,
- Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
- Name.Type = \color[HTML]{336666} ,
- InitialValues = \__piton_piton:n ,
- Interpol.Inside = \color{black}\__piton_piton:n ,
- TypeParameter = \color[HTML]{336666} \itshape ,
- Preproc = \color[HTML]{AA6600} \slshape ,
- Identifier = \__piton_identifier:n ,
- Directive = \color[HTML]{AA6600} ,
- Tag = \colorbox{gray!10},
- UserFunction = ,
- Prompt = ,
- ParseAgain.noCR = \__piton_piton_no_cr:n ,
- Discard = \use_none:n
+ Comment = \color[HTML]{0099FF} \itshape ,
+ Exception = \color[HTML]{CC0000} ,
+ Keyword = \color[HTML]{006699} \bfseries ,
+ Keyword.Governing = \color[HTML]{006699} \bfseries ,
+ Keyword.Constant = \color[HTML]{006699} \bfseries ,
+ Name.Builtin = \color[HTML]{336666} ,
+ Name.Decorator = \color[HTML]{9999FF},
+ Name.Class = \color[HTML]{00AA88} \bfseries ,
+ Name.Function = \color[HTML]{CC00FF} ,
+ Name.Namespace = \color[HTML]{00CCFF} ,
+ Name.Constructor = \color[HTML]{006000} \bfseries ,
+ Name.Field = \color[HTML]{AA6600} ,
+ Name.Module = \color[HTML]{0060A0} \bfseries ,
+ Name.Table = \color[HTML]{309030} ,
+ Number = \color[HTML]{FF6600} ,
+ Operator = \color[HTML]{555555} ,
+ Operator.Word = \bfseries ,
+ String = \color[HTML]{CC3300} ,
+ String.Doc = \color[HTML]{CC3300} \itshape ,
+ String.Interpol = \color[HTML]{AA0000} ,
+ Comment.LaTeX = \normalfont \color[rgb]{.468,.532,.6} ,
+ Name.Type = \color[HTML]{336666} ,
+ InitialValues = \__piton_piton:n ,
+ Interpol.Inside = \color{black}\__piton_piton:n ,
+ TypeParameter = \color[HTML]{336666} \itshape ,
+ Preproc = \color[HTML]{AA6600} \slshape ,
+ Identifier.Internal = \__piton_identifier:n ,
+ Identifier = ,
+ Directive = \color[HTML]{AA6600} ,
+ Tag = \colorbox{gray!10},
+ UserFunction = ,
+ Prompt = ,
+ ParseAgain = \__piton_piton_no_cr:n ,
+ Discard = \use_none:n
}
\AtBeginDocument
{
@@ -1291,7 +1291,10 @@
\cs_new_protected:Npn \__piton_identifier:n #1
{
\cs_if_exist_use:cF { PitonIdentifier _ \l_piton_language_str _ #1 }
- { \cs_if_exist_use:c { PitonIdentifier _ #1 } }
+ {
+ \cs_if_exist_use:cF { PitonIdentifier _ #1 }
+ { \PitonStyle { Identifier } }
+ }
{ #1 }
}
\cs_new_protected:cpn { pitonStyle _ Name.Function.Internal } #1
@@ -1409,10 +1412,18 @@
}
\__piton_msg_new:nn { SyntaxError }
{
+ Syntax~Error.\\
Your~code~of~the~language~"\l_piton_language_str"~is~not~
syntactically~correct.\\
It~won't~be~printed~in~the~PDF~file.
}
+\__piton_msg_new:nn { FileError }
+ {
+ File~Error.\\
+ It's~not~possible~to~write~on~the~file~'\l__piton_write_str'.\\
+ \sys_if_shell_unrestricted:F { Be~sure~to~compile~with~'-shell-escape'.\\ }
+ If~you~go~on,~nothing~will~be~written~on~the~file.
+ }
\__piton_msg_new:nn { begin~marker~not~found }
{
Marker~not~found.\\
@@ -1483,15 +1494,6 @@
because~the~key~'line-numbers'~is~not~active.\\
If~you~go~on,~that~command~will~ignored.
}
-\__piton_msg_new:nn { cr~not~allowed }
- {
- You~can't~put~any~carriage~return~in~the~argument~
- of~a~command~\c_backslash_str
- \l__piton_beamer_command_str\ within~an~
- environment~of~'piton'.~You~should~consider~using~the~
- corresponding~environment.\\
- That~error~is~fatal.
- }
\__piton_msg_new:nn { overlay~without~beamer }
{
You~can't~use~an~argument~<...>~for~your~command~
More information about the tex-live-commits
mailing list.