summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-02-27 20:48:03 +0000
committerKarl Berry <karl@freefriends.org>2024-02-27 20:48:03 +0000
commitd17bed7049c85db6da51c9e2e72ff6e468e4cbc6 (patch)
tree9b723d3c7e32b05a3e2d3c2c65a9f493556433c9 /Master/texmf-dist/tex/lualatex
parent6797aad4f67e4add52f59847446bb8eb8e1266c6 (diff)
piton (27feb24)
git-svn-id: svn://tug.org/texlive/trunk@70204 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.lua234
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.sty58
2 files changed, 161 insertions, 131 deletions
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.lua b/Master/texmf-dist/tex/lualatex/piton/piton.lua
index 4aa19b97759..804b18ab8ec 100644
--- a/Master/texmf-dist/tex/lualatex/piton/piton.lua
+++ b/Master/texmf-dist/tex/lualatex/piton/piton.lua
@@ -20,7 +20,7 @@
-- -------------------------------------------
--
-- This file is part of the LuaLaTeX package 'piton'.
--- Version 2.5 of 2024/02/20
+-- Version 2.6 of 2024/02/27
if piton.comment_latex == nil then piton.comment_latex = ">" end
@@ -32,7 +32,7 @@ function piton.close_brace ()
tex.sprint("}")
end
local P, S, V, C, Ct, Cc = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cc
-local Cf, Cs , Cg , Cmt , Cb = lpeg.Cf, lpeg.Cs, lpeg.Cg , lpeg.Cmt , lpeg.Cb
+local Cs , Cg , Cmt , Cb = lpeg.Cs, lpeg.Cg , lpeg.Cmt , lpeg.Cb
local R = lpeg.R
local function Q(pattern)
return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
@@ -56,12 +56,17 @@ local function WithStyle(style,pattern)
* Ct ( Cc "Close" )
end
Escape = P ( false )
+EscapeClean = P ( false )
if piton.begin_escape ~= nil
then
Escape =
P(piton.begin_escape)
* L ( ( 1 - P(piton.end_escape) ) ^ 1 )
* P(piton.end_escape)
+ EscapeClean =
+ P(piton.begin_escape)
+ * ( 1 - P(piton.end_escape) ) ^ 1
+ * P(piton.end_escape)
end
EscapeMath = P ( false )
if piton.begin_escape_math ~= nil
@@ -133,18 +138,19 @@ then
Ct ( Cc "Open"
* C (
P ( "\\begin{" .. name .. "}" )
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
+ * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1
)
* Cc ( "\\end{" .. name .. "}" )
)
* (
- C ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
- / ( function (s) return lpeg : match(s) end )
+ ( ( 1 - P ( "\\end{" .. name .. "}" ) ) ^ 0 )
+ / ( function (s) return lpeg : match(s) end )
)
* P ( "\\end{" .. name .. "}" ) * Ct ( Cc "Close" )
end
end
local languages = { }
+local CleanLPEGs = { }
local Operator =
K ( 'Operator' ,
P "!=" + P "<>" + P "==" + P "<<" + P ">>" + P "<=" + P ">=" + P ":="
@@ -260,7 +266,7 @@ local DoubleShortString =
Q ( P "f\"" + P "F\"" )
* (
K ( 'String.Interpol' , P "{" )
- * Q ( ( 1 - S "}\":" ) ^ 0 , 'Interpol.Inside' )
+ * K ( 'Interpol.Inside' , ( 1 - S "}\":" ) ^ 0 )
* ( K ( 'String.Interpol' , P ":" ) * Q ( (1 - S "}:\"") ^ 0 ) ) ^ -1
* K ( 'String.Interpol' , P "}" )
+
@@ -306,7 +312,7 @@ then
)
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopPython:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopPython:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+ OneBeamerEnvironment ( "uncoverenv" , MainLoopPython )
+ OneBeamerEnvironment ( "onlyenv" , MainLoopPython )
@@ -339,15 +345,19 @@ then
end
DetectedCommands =
Ct ( Cc "Open"
- * C (
- piton.ListCommands
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- * P "{"
- )
+ * C ( piton.ListCommands * P "{" )
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopPython:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopPython:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+CleanLPEGs['python']
+ = Ct ( ( piton.ListCommands * P "{"
+ * ( balanced_braces
+ / ( function (s) return CleanLPEGs['python']:match(s) end ) )
+ * P "}"
+ + EscapeClean
+ + C ( P ( 1 ) )
+ ) ^ 0 ) / table.concat
local PromptHastyDetection = ( # ( P ">>>" + P "..." ) * Lc ( '\\__piton_prompt:' ) ) ^ -1
local Prompt = K ( 'Prompt' , ( ( P ">>>" + P "..." ) * P " " ^ -1 ) ^ -1 )
local EOL =
@@ -428,7 +438,7 @@ local DoubleLongString =
)
local LongString = SingleLongString + DoubleLongString
local StringDoc =
- K ( 'String.Doc' , P "\"\"\"" )
+ K ( 'String.Doc' , P "r" ^ -1 * P "\"\"\"" )
* ( K ( 'String.Doc' , (1 - P "\"\"\"" - P "\r" ) ^ 0 ) * EOL
* Tab ^ 0
) ^ 0
@@ -461,7 +471,7 @@ local expression =
+ ( 1 - S "{}()[]\r\"'" ) ) ^ 0
}
local Param =
- SkipSpace * Identifier * SkipSpace
+ SkipSpace * ( Identifier + Q "*args" + Q "**kwargs" ) * SkipSpace
* (
K ( 'InitialValues' , P "=" * expression )
+ Q ( P ":" ) * SkipSpace * K ( 'Name.Type' , letter ^ 1 )
@@ -542,8 +552,8 @@ local expression_for_fields =
E = ( P "{" * V "F" * P "}"
+ P "(" * V "F" * P ")"
+ P "[" * V "F" * P "]"
- + P "\"" * (P "\\\"" + 1 - S "\"\r" )^0 * P "\""
- + P "'" * ( P "\\'" + 1 - S "'\r" )^0 * P "'"
+ + P "\"" * (P "\\\"" + 1 - S "\"\r" ) ^ 0 * P "\""
+ + P "'" * ( P "\\'" + 1 - S "'\r" ) ^ 0 * P "'"
+ ( 1 - S "{}()[]\r;" ) ) ^ 0 ,
F = ( P "{" * V "F" * P "}"
+ P "(" * V "F" * P ")"
@@ -560,7 +570,7 @@ local OneFieldDefinition =
local OneField =
K ( 'Name.Field' , identifier ) * SkipSpace
* Q "=" * SkipSpace
- * ( C ( expression_for_fields ) / ( function (s) return LoopOCaml:match(s) end ) )
+ * ( expression_for_fields / ( function (s) return LoopOCaml:match(s) end ) )
* SkipSpace
local Record =
@@ -602,7 +612,7 @@ local Keyword =
K ( 'Keyword' ,
P "assert" + P "and" + P "as" + P "begin" + P "class" + P "constraint" + P "done"
+ P "downto" + P "do" + P "else" + P "end" + P "exception" + P "external"
- + 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"
@@ -647,7 +657,7 @@ then
)
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopOCaml:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopOCaml:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+ OneBeamerEnvironment ( "uncoverenv" , MainLoopOCaml )
+ OneBeamerEnvironment ( "onlyenv" , MainLoopOCaml )
@@ -680,15 +690,19 @@ then
end
DetectedCommands =
Ct ( Cc "Open"
- * C (
- piton.ListCommands
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- * P "{"
- )
- * Cc "}"
+ * C ( piton.ListCommands * P "{" ) * Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopOCaml:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopOCaml:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+CleanLPEGs['ocaml']
+ = Ct ( ( piton.ListCommands * P "{"
+ * ( balanced_braces
+ / ( function (s) return CleanLPEGs['ocaml']:match(s) end ) )
+ * P "}"
+ + EscapeClean
+ + C ( P ( 1 ) )
+ ) ^ 0 ) / table.concat
+
local EOL =
P "\r"
*
@@ -726,7 +740,7 @@ local open = "{" * Cg(ext, 'init') * "|"
local close = "|" * C(ext) * "}"
local closeeq =
Cmt ( close * Cb('init'),
- function (s, i, a, b) return a==b end )
+ function (s, i, a, b) return a == b end )
local QuotedStringBis =
WithStyle ( 'String.Long' ,
(
@@ -962,7 +976,7 @@ then
)
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopC:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopC:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+ OneBeamerEnvironment ( "uncoverenv" , MainLoopC )
+ OneBeamerEnvironment ( "onlyenv" , MainLoopC )
@@ -995,15 +1009,18 @@ then
end
DetectedCommands =
Ct ( Cc "Open"
- * C (
- piton.ListCommands
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- * P "{"
- )
- * Cc "}"
+ * C ( piton.ListCommands * P "{" ) * Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopC:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopC:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+CleanLPEGs['c']
+ = Ct ( ( piton.ListCommands * P "{"
+ * ( balanced_braces
+ / ( function (s) return CleanLPEGs['c']:match(s) end ) )
+ * P "}"
+ + EscapeClean
+ + C ( P ( 1 ) )
+ ) ^ 0 ) / table.concat
local EOL =
P "\r"
*
@@ -1163,7 +1180,7 @@ then
)
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopSQL:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopSQL:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+ OneBeamerEnvironment ( "uncoverenv" , MainLoopSQL )
+ OneBeamerEnvironment ( "onlyenv" , MainLoopSQL )
@@ -1196,15 +1213,18 @@ then
end
DetectedCommands =
Ct ( Cc "Open"
- * C (
- piton.ListCommands
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- * P "{"
- )
- * Cc "}"
+ * C ( piton.ListCommands * P "{" ) * Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopSQL:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopSQL:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+CleanLPEGs['sql']
+ = Ct ( ( piton.ListCommands * P "{"
+ * ( balanced_braces
+ / ( function (s) return CleanLPEGs['sql']:match(s) end ) )
+ * P "}"
+ + EscapeClean
+ + C ( P ( 1 ) )
+ ) ^ 0 ) / table.concat
local EOL =
P "\r"
*
@@ -1373,7 +1393,7 @@ then
)
* Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopMinimal:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopMinimal:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+ OneBeamerEnvironment ( "uncoverenv" , MainLoopMinimal )
+ OneBeamerEnvironment ( "onlyenv" , MainLoopMinimal )
@@ -1407,16 +1427,20 @@ end
DetectedCommands =
Ct ( Cc "Open"
- * C (
- piton.ListCommands
- * ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1
- * P "{"
- )
- * Cc "}"
+ * C ( piton.ListCommands * P "{" ) * Cc "}"
)
- * ( C ( balanced_braces ) / (function (s) return MainLoopMinimal:match(s) end ) )
+ * ( balanced_braces / (function (s) return MainLoopMinimal:match(s) end ) )
* P "}" * Ct ( Cc "Close" )
+CleanLPEGs['minimal']
+ = Ct ( ( piton.ListCommands * P "{"
+ * ( balanced_braces
+ / ( function (s) return CleanLPEGs['minimal']:match(s) end ) )
+ * P "}"
+ + EscapeClean
+ + C ( P ( 1 ) )
+ ) ^ 0 ) / table.concat
+
local EOL =
P "\r"
*
@@ -1558,58 +1582,57 @@ function piton.ParseTer(language,code)
return piton.Parse(language,s)
end
local function gobble(n,code)
- function concat(acc,new_value)
- return acc .. new_value
- end
if n==0
then return code
else
- return Cf (
- Cc ( "" ) *
- ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
- * ( C ( P "\r" )
- * ( 1 - P "\r" ) ^ (-n)
- * C ( ( 1 - P "\r" ) ^ 0 )
- ) ^ 0 ,
- concat
- ) : match ( code )
+ return ( Ct (
+ ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
+ * ( C ( P "\r" )
+ * ( 1 - P "\r" ) ^ (-n)
+ * C ( ( 1 - P "\r" ) ^ 0 )
+ ) ^ 0
+ ) / table.concat ) : match ( code )
end
end
-local function add(acc,new_value)
- return acc + new_value
+local function count_captures(...)
+ local acc = 0
+ for _ in ipairs({...}) do
+ acc = acc + 1
+ end
+ return acc
end
local AutoGobbleLPEG =
- ( space ^ 0 * P "\r" ) ^ -1
- * Cf (
- (
- ( P " " ) ^ 0 * P "\r"
- +
- Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add )
- * ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 * P "\r"
- ) ^ 0
- *
- ( Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add )
- * ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 ) ^ -1 ,
- math.min
- )
+ (
+ (
+ P " " ^ 0 * P "\r"
+ +
+ C ( P " " ) ^ 0 / count_captures * ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 * P "\r"
+ ) ^ 0
+ *
+ ( C ( P " " ) ^ 0 / count_captures * ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 ) ^ -1
+ ) / math.min
local TabsAutoGobbleLPEG =
- ( space ^ 0 * P "\r" ) ^ -1
- * Cf (
- (
- ( P "\t" ) ^ 0 * P "\r"
- +
- Cf ( Cc(0) * ( P "\t" * Cc(1) ) ^ 0 , add )
- * ( 1 - P "\t" ) * ( 1 - P "\r" ) ^ 0 * P "\r"
- ) ^ 0
- *
- ( Cf ( Cc(0) * ( P "\t" * Cc(1) ) ^ 0 , add )
- * ( 1 - P "\t" ) * ( 1 - P "\r" ) ^ 0 ) ^ -1 ,
- math.min
- )
+ (
+ (
+ P "\t" ^ 0 * P "\r"
+ +
+ C ( P " " ) ^ 0 / count_captures * ( 1 - P "\t" ) * ( 1 - P "\r" ) ^ 0 * P "\r"
+ ) ^ 0
+ *
+ ( C ( P " " ) ^ 0 / count_captures * ( 1 - P "\t" ) * ( 1 - P "\r" ) ^ 0 ) ^ -1
+ ) / math.min
local EnvGobbleLPEG =
- ( ( 1 - P "\r" ) ^ 0 * P "\r" ) ^ 0
- * Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add ) * -1
+ ( ( 1 - P "\r" ) ^ 0 * P "\r" ) ^ 0 * ( C ( P " " ) ^ 0 / count_captures ) * -1
+local function remove_before_cr(input_string)
+ local match_result = P("\r") : match(input_string)
+ if match_result then
+ return string.sub(input_string, match_result )
+ else
+ return input_string
+ end
+end
function piton.GobbleParse(language,n,code)
+ code = remove_before_cr(code)
if n==-1
then n = AutoGobbleLPEG : match(code)
else if n==-2
@@ -1619,13 +1642,18 @@ function piton.GobbleParse(language,n,code)
end
end
end
- piton.Parse(language,gobble(n,code))
+ piton.last_code = gobble(n,code)
+ piton.Parse(language,piton.last_code)
+ piton.last_language = language
if piton.write ~= ''
then local file = assert(io.open(piton.write,piton.write_mode))
- file:write(code)
+ file:write(piton.get_last_code())
file:close()
end
end
+function piton.get_last_code ( )
+ return CleanLPEGs[piton.last_language] : match(piton.last_code)
+end
function piton.CountLines(code)
local count = 0
for i in code : gmatch ( "\r" ) do count = count + 1 end
@@ -1636,21 +1664,19 @@ end
function piton.CountNonEmptyLines(code)
local count = 0
count =
- ( Cf ( Cc(0) *
- (
+ ( ( ( (
( P " " ) ^ 0 * P "\r"
- + ( 1 - P "\r" ) ^ 0 * P "\r" * Cc(1)
- ) ^ 0
- * (1 - P "\r" ) ^ 0 ,
- add
- ) * -1 ) : match (code)
+ + ( 1 - P "\r" ) ^ 0 * C ( P "\r" )
+ ) ^ 0
+ * (1 - P "\r" ) ^ 0
+ ) / count_captures ) * -1 ) : match (code)
tex.sprint(
luatexbase.catcodetables.expl ,
'\\int_set:Nn \\l__piton_nb_non_empty_lines_int {' .. count .. '}' )
end
function piton.CountLinesFile(name)
local count = 0
- io.open(name) -- added
+ io.open(name)
for line in io.lines(name) do count = count + 1 end
tex.sprint(
luatexbase.catcodetables.expl ,
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty
index e82d97f4e58..9831b33ee97 100644
--- a/Master/texmf-dist/tex/lualatex/piton/piton.sty
+++ b/Master/texmf-dist/tex/lualatex/piton/piton.sty
@@ -19,8 +19,8 @@
%% LaTeX version 2005/12/01 or later.
%% -------------------------------------------
%%
-\def\PitonFileVersion{2.5}
-\def\PitonFileDate{2024/02/20}
+\def\PitonFileVersion{2.6}
+\def\PitonFileDate{2024/02/27}
\NeedsTeXFormat{LaTeX2e}
@@ -29,7 +29,7 @@
{piton}
{\PitonFileDate}
{\PitonFileVersion}
- {Highlight Python codes with LPEG on LuaLaTeX}
+ {Highlight informatic listings with LPEG on LuaLaTeX}
\cs_new_protected:Npn \__piton_error:n { \msg_error:nn { piton } }
\cs_new_protected:Npn \__piton_warning:n { \msg_warning:nn { piton } }
\cs_new_protected:Npn \__piton_error:nn { \msg_error:nnn { piton } }
@@ -55,6 +55,7 @@
}
\sys_if_engine_luatex:F { \msg_critical:nn { piton } { LuaLaTeX~mandatory } }
\RequirePackage { luatexbase }
+\RequirePackage { luacode }
\__piton_msg_new:nnn { piton.lua~not~found }
{
The~file~'piton.lua'~can't~be~found.\\
@@ -161,9 +162,12 @@
{
piton = piton~or { }
piton.ListCommands = lpeg.P ( false )
+ piton.last_code = ''
+ piton.last_language = ''
}
\str_new:N \l_piton_language_str
\str_set:Nn \l_piton_language_str { python }
+\tl_new:N \g_piton_last_code_tl
\str_new:N \l__piton_path_str
\str_new:N \l__piton_path_write_str
\bool_new:N \l__piton_in_PitonOptions_bool
@@ -239,14 +243,14 @@
}
\cs_new_protected:Npn \__piton_marker_beginning:n #1 { }
\cs_new_protected:Npn \__piton_marker_end:n #1 { }
-\cs_new_protected:Npn \__piton_open_brace: { \directlua { piton.open_brace() } }
-\cs_new_protected:Npn \__piton_close_brace: { \directlua { piton.close_brace() } }
+\cs_new_protected:Npn \__piton_open_brace: { \lua_now:n { piton.open_brace() } }
+\cs_new_protected:Npn \__piton_close_brace: { \lua_now:n { piton.close_brace() } }
\tl_new:N \g__piton_begin_line_hook_tl
\cs_new_protected:Npn \__piton_prompt:
{
\tl_gset:Nn \g__piton_begin_line_hook_tl
{
- \tl_if_empty:NF \l__piton_prompt_bg_color_tl % added 2023-04-24
+ \tl_if_empty:NF \l__piton_prompt_bg_color_tl
{ \clist_set:NV \l__piton_bg_color_clist \l__piton_prompt_bg_color_tl }
}
}
@@ -485,7 +489,8 @@
}
\keys_define:nn { PitonOptions }
{
- detected-commands .code:n = \__piton_detected_commands:n { #1 } ,
+ detected-commands .code:n =
+ \lua_now:n { piton.addListCommands('#1') } ,
detected-commands .value_required:n = true ,
detected-commands .usage:n = preamble ,
begin-escape .code:n =
@@ -881,7 +886,7 @@
{ \lua_now:e { piton.write = "\l__piton_write_str" } }
{
\lua_now:e
- { piton.write = "\l__piton_path_write_str / \l__piton_write_str" }
+ { piton.write = "\l__piton_path_write_str / \l__piton_write_str" }
}
\str_if_empty:NF \l__piton_write_str
{
@@ -1050,16 +1055,16 @@
}
\NewDocumentCommand { \SetPitonStyle } { O { } m }
{
+ \str_clear_new:N \l__piton_SetPitonStyle_option_str
\str_set:Nx \l__piton_SetPitonStyle_option_str { \str_lowercase:n { #1 } }
\str_if_eq:onT \l__piton_SetPitonStyle_option_str { current-language }
{ \str_set_eq:NN \l__piton_SetPitonStyle_option_str \l_piton_language_str }
\keys_set:nn { piton / Styles } { #2 }
- \str_clear:N \l__piton_SetPitonStyle_option_str
}
\cs_new_protected:Npn \__piton_math_scantokens:n #1
{ \normalfont \scantextokens { \begin{math} #1 \end{math} } }
-\clist_new:N \g__piton_style_clist
-\clist_set:Nn \g__piton_styles_clist
+\clist_new:N \g__piton_styles_clist
+\clist_gset:Nn \g__piton_styles_clist
{
Comment ,
Comment.LaTeX ,
@@ -1403,26 +1408,25 @@
}
\hook_gput_code:nnn { begindocument } { . }
{ \lua_now:e { require("piton.lua") } }
-\cs_new_protected:Npn \__piton_detected_commands:n #1
- { \lua_now:n { piton.addListCommands('#1') } }
\ExplSyntaxOff
-\directlua
- {
+\begin{luacode*}
lpeg.locale(lpeg)
- local P , alpha , C , Cf, space
- = lpeg.P , lpeg.alpha , lpeg.C , lpeg.Cf , lpeg.space
- local S = lpeg.S
- local One_P
- = space ^ 0
- * C ( alpha ^ 1 ) / ( function (s) return P ( string.char(92) .. s ) end )
- * space ^ 0
+ local P , alpha , C , space , S , V
+ = lpeg.P , lpeg.alpha , lpeg.C , lpeg.space , lpeg.S , lpeg.V
+ local function add(...)
+ local s = P ( false )
+ for _ , x in ipairs({...}) do s = s + x end
+ return s
+ end
+ local my_lpeg =
+ P { "E" ,
+ E = ( V "F" * ( P "," * V "F" ) ^ 0 ) / add ,
+ F = space ^ 0 * ( alpha ^ 1 ) / "\\%0" * space ^ 0
+ }
function piton.addListCommands( key_value )
- piton.ListCommands =
- piton.ListCommands +
- Cf ( One_P * ( P "," * One_P ) ^ 0 ,
- ( function (s,t) return s + t end ) ) : match ( key_value )
+ piton.ListCommands = piton.ListCommands + my_lpeg : match ( key_value )
end
- }
+\end{luacode*}
\endinput
%%