summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-07-30 20:11:05 +0000
committerKarl Berry <karl@freefriends.org>2024-07-30 20:11:05 +0000
commit1c18406d9af90d03aa3a4bc008fab03e8d7462a9 (patch)
treee349a4ff9219b4d7e708a579e40a0b161a2cccb2 /Master/texmf-dist/tex
parent27dbde03253f3177ba33963113df83dca9c170b0 (diff)
piton (30jul24)
git-svn-id: svn://tug.org/texlive/trunk@71932 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.lua129
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.sty83
2 files changed, 125 insertions, 87 deletions
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.lua b/Master/texmf-dist/tex/lualatex/piton/piton.lua
index 6ec0442b73c..5a81b956db7 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'.
-piton_version = "3.0b" -- 2024/05/23
+piton_version = "3.1" -- 2024/07/30
@@ -124,7 +124,7 @@ local SkipSpace = Q " " ^ 0
local Punct = Q ( S ".,:;!" )
-local Tab = "\t" * Lc "\\l__piton_tab_tl"
+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"
@@ -146,17 +146,19 @@ local function Compute_braces ( lpeg_string ) return
end
local function Compute_DetectedCommands ( lang , braces ) return
Ct ( Cc "Open"
- * C ( piton.ListCommands * P "{" )
+ * C ( piton.DetectedCommands * P "{" )
* Cc "}"
)
- * ( braces / (function ( s ) return LPEG1[lang] : match ( s ) end ) )
+ * ( braces
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* P "}"
* Ct ( Cc "Close" )
end
local function Compute_LPEG_cleaner ( lang , braces ) return
- Ct ( ( piton.ListCommands * "{"
+ Ct ( ( piton.DetectedCommands * "{"
* ( braces
- / ( function ( s ) return LPEG_cleaner[lang] : match ( s ) end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG_cleaner[lang] : match ( s ) end end ) )
* "}"
+ EscapeClean
+ C ( P ( 1 ) )
@@ -165,56 +167,58 @@ end
local Beamer = P ( false )
local BeamerBeginEnvironments = P ( true )
local BeamerEndEnvironments = P ( true )
-local list_beamer_env =
- { "uncoverenv" , "onlyenv" , "visibleenv" ,
- "invisibleenv" , "alertenv" , "actionenv" }
-local BeamerNamesEnvironments = P ( false )
-for _ , x in ipairs ( list_beamer_env ) do
- BeamerNamesEnvironments = BeamerNamesEnvironments + x
+piton.BeamerEnvironments = P ( false )
+for _ , x in ipairs ( piton.beamer_environments ) do
+ piton.BeamerEnvironments = piton.BeamerEnvironments + x
end
BeamerBeginEnvironments =
( space ^ 0 *
L
(
- P "\\begin{" * BeamerNamesEnvironments * "}"
+ P "\\begin{" * piton.BeamerEnvironments * "}"
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
)
* "\r"
) ^ 0
BeamerEndEnvironments =
( space ^ 0 *
- L ( P "\\end{" * BeamerNamesEnvironments * "}" )
+ L ( P "\\end{" * piton.BeamerEnvironments * "}" )
* "\r"
) ^ 0
local function Compute_Beamer ( lang , braces )
local lpeg = L ( P "\\pause" * ( "[" * ( 1 - P "]" ) ^ 0 * "]" ) ^ -1 )
lpeg = lpeg +
Ct ( Cc "Open"
- * C ( ( P "\\uncover" + "\\only" + "\\alert" + "\\visible"
- + "\\invisible" + "\\action" )
+ * C ( piton.BeamerCommands
* ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
* P "{"
)
* Cc "}"
)
- * ( braces / ( function ( s ) return LPEG1[lang] : match ( s ) end ) )
+ * ( braces /
+ ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* "}"
* Ct ( Cc "Close" )
lpeg = lpeg +
L ( P "\\alt" * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
- * K ( 'ParseAgain.noCR' , braces )
+ * ( braces /
+ ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
- * K ( 'ParseAgain.noCR' , braces )
+ * ( braces /
+ ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
lpeg = lpeg +
L ( ( P "\\temporal" ) * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
- * K ( 'ParseAgain.noCR' , braces )
+ * ( braces
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
- * K ( 'ParseAgain.noCR' , braces )
+ * ( braces
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
- * K ( 'ParseAgain.noCR' , braces )
+ * ( braces
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
- for _ , x in ipairs ( list_beamer_env ) do
+ for _ , x in ipairs ( piton.beamer_environments ) do
lpeg = lpeg +
Ct ( Cc "Open"
* C (
@@ -225,7 +229,11 @@ local function Compute_Beamer ( lang , braces )
)
* (
( ( 1 - P ( "\\end{" .. x .. "}" ) ) ^ 0 )
- / ( function ( s ) return LPEG1[lang] : match ( s ) end )
+ / ( function ( s )
+ if s ~= ''
+ then return LPEG1[lang] : match ( s )
+ end
+ end )
)
* P ( "\\end{" .. x .. "}" )
* Ct ( Cc "Close" )
@@ -270,6 +278,11 @@ local Operator =
local OperatorWord =
K ( 'Operator.Word' , P "in" + "is" + "and" + "or" + "not" )
+local For = K ( 'Keyword' , P "for" )
+ * Space
+ * Identifier
+ * Space
+ * K ( 'Keyword' , P "in" )
local Keyword =
K ( 'Keyword' ,
@@ -509,10 +522,11 @@ local DefFunction =
* StringDoc ^ 0 -- there may be additional docstrings
) ^ -1
local ExceptionInConsole = Exception * Q ( ( 1 - P "\r" ) ^ 0 ) * EOL
+local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ -- space ^ 1 * -1
+ -- + space ^ 0 * EOL
+ Space
+ Tab
+ Escape + EscapeMath
+ CommentLaTeX
@@ -523,16 +537,17 @@ local Main =
+ ExceptionInConsole
+ Delim
+ Operator
- + OperatorWord * ( Space + Punct + Delim + EOL + -1 )
+ + OperatorWord * EndKeyword
+ ShortString
+ Punct
+ FromImport
+ RaiseException
+ DefFunction
+ DefClass
- + Keyword * ( Space + Punct + Delim + EOL + -1 )
+ + For
+ + Keyword * EndKeyword
+ Decorator
- + Builtin * ( Space + Punct + Delim + EOL + -1 )
+ + Builtin * EndKeyword
+ Identifier
+ Number
+ Word
@@ -545,7 +560,7 @@ LPEG2['python'] =
* Lc '\\__piton_begin_line:'
* Prompt
* SpaceIndentation ^ 0
- * LPEG1['python']
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc '\\__piton_end_line:'
)
@@ -598,7 +613,7 @@ local DotNotation =
(
K ( 'Name.Module' , cap_identifier )
* Q "."
- * ( Identifier + Constructor + Q "(" + Q "[" + Q "{" )
+ * ( Identifier + Constructor + Q "(" + Q "[" + Q "{" ) ^ ( -1 )
+
Identifier
* Q "."
@@ -637,7 +652,7 @@ local Char =
K ( 'String.Short' , "'" * ( ( 1 - P "'" ) ^ 0 + "\\'" ) * "'" )
braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then
- Beamer = Compute_Beamer ( 'ocaml' , "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
+ Beamer = Compute_Beamer ( 'ocaml' , braces ) -- modified 2024/07/24
end
DetectedCommands = Compute_DetectedCommands ( 'ocaml' , braces )
LPEG_cleaner['ocaml'] = Compute_LPEG_cleaner ( 'ocaml' , braces )
@@ -754,10 +769,9 @@ local DefModule =
K ( 'Keyword' , P "include" + "open" )
* Space * K ( 'Name.Module' , cap_identifier )
local TypeParameter = K ( 'TypeParameter' , "'" * alpha * # ( 1 - P "'" ) )
+local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ Space
+ Tab
+ Escape + EscapeMath
+ Beamer
@@ -773,9 +787,9 @@ local Main =
+ DefFunction
+ DefModule
+ Record
- + Keyword * ( Space + Punct + Delim + EOL + -1 )
- + OperatorWord * ( Space + Punct + Delim + EOL + -1 )
- + Builtin * ( Space + Punct + Delim + EOL + -1 )
+ + Keyword * EndKeyword
+ + OperatorWord * EndKeyword
+ + Builtin * EndKeyword
+ DotNotation
+ Constructor
+ Identifier
@@ -789,7 +803,7 @@ LPEG2['ocaml'] =
* BeamerBeginEnvironments
* Lc '\\__piton_begin_line:'
* SpaceIndentation ^ 0
- * LPEG1['ocaml']
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc '\\__piton_end_line:'
)
@@ -859,10 +873,9 @@ local LongComment =
* ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
* Q "*/"
) -- $
+local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ Space
+ Tab
+ Escape + EscapeMath
+ CommentLaTeX
@@ -876,9 +889,9 @@ local Main =
+ Punct
+ DefFunction
+ DefClass
- + Type * ( Q "*" ^ -1 + Space + Punct + Delim + EOL + -1 )
- + Keyword * ( Space + Punct + Delim + EOL + -1 )
- + Builtin * ( Space + Punct + Delim + EOL + -1 )
+ + Type * ( Q "*" ^ -1 + EndKeyword )
+ + Keyword * EndKeyword
+ + Builtin * EndKeyword
+ Identifier
+ Number
+ Word
@@ -889,7 +902,7 @@ LPEG2['c'] =
* BeamerBeginEnvironments
* Lc '\\__piton_begin_line:'
* SpaceIndentation ^ 0
- * LPEG1['c']
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc '\\__piton_end_line:'
)
@@ -967,6 +980,7 @@ local LongComment =
* ( CommentMath + Q ( ( 1 - P "*/" - S "$\r" ) ^ 1 ) + EOL ) ^ 0
* Q "*/"
) -- $
+local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local TableField =
K ( 'Name.Table' , identifier )
* Q "."
@@ -1005,10 +1019,9 @@ local WeCatchTableNames =
+ LuaKeyword "TABLE"
)
* ( Space + EOL ) * OneTable
+local EndKeyword = Space + Punct + Delim + EOL + Beamer + DetectedCommands + -1
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ Space
+ Tab
+ Escape + EscapeMath
+ CommentLaTeX
@@ -1030,7 +1043,7 @@ LPEG2['sql'] =
* BeamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
- * LPEG1['sql']
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc [[ \__piton_end_line: ]]
)
@@ -1066,9 +1079,7 @@ local Identifier = K ( 'Identifier' , identifier )
local Delim = Q ( S "{[()]}" )
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ Space
+ Tab
+ Escape + EscapeMath
+ CommentLaTeX
@@ -1090,7 +1101,7 @@ LPEG2['minimal'] =
* BeamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
- * LPEG1['minimal']
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc [[ \__piton_end_line: ]]
)
@@ -1334,7 +1345,7 @@ function piton.new_language ( lang , definition )
function add_to_other ( c )
if c ~= " " then
extra_others[c] = true
- other = other + P "c"
+ other = other + P ( c )
end
end
local strict_braces =
@@ -1599,9 +1610,7 @@ function piton.new_language ( lang , definition )
local Delim = Q ( S "{[()]}" )
local Punct = Q ( S "=,:;!\\'\"" )
local Main =
- space ^ 1 * -1
- + space ^ 0 * EOL
- + Space
+ Space
+ Tab
+ Escape + EscapeMath
+ CommentLaTeX
@@ -1623,7 +1632,7 @@ function piton.new_language ( lang , definition )
* BeamerBeginEnvironments
* Lc [[\__piton_begin_line:]]
* SpaceIndentation ^ 0
- * LPEG1[lang]
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
* -1
* Lc [[\__piton_end_line:]]
)
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty
index 72591ea8baa..6c4a824cf3f 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{3.0b}
-\def\PitonFileDate{2024/05/23}
+\def\PitonFileVersion{3.1}
+\def\PitonFileDate{2024/07/30}
@@ -165,7 +165,11 @@
}
\lua_now:n
{
- piton.ListCommands = lpeg.P ( false )
+ piton.BeamerCommands = lpeg.P ( "\\uncover" )
+ + "\\only" + "\\visible" + "\\invisible" + "\\alert" + "\\action"
+ piton.beamer_environments = { "uncoverenv" , "onlyenv" , "visibleenv" ,
+ "invisibleenv" , "alertenv" , "actionenv" }
+ piton.DetectedCommands = lpeg.P ( false )
piton.last_code = ''
piton.last_language = ''
}
@@ -210,24 +214,21 @@
\bool_new:N \l__piton_left_margin_auto_bool
\dim_new:N \l__piton_numbers_sep_dim
\dim_set:Nn \l__piton_numbers_sep_dim { 0.7 em }
-\tl_new:N \l__piton_tab_tl
\seq_new:N \g__piton_languages_seq
-\cs_new_protected:Npn \__piton_set_tab_tl:n #1
+\int_new:N \l__piton_tab_size_int
+\int_set:Nn \l__piton_tab_size_int { 4 }
+\cs_new_protected:Npn \__piton_tab:
{
- \tl_clear:N \l__piton_tab_tl
- \prg_replicate:nn { #1 }
- { \tl_put_right:Nn \l__piton_tab_tl { ~ } }
- }
-\__piton_set_tab_tl:n { 4 }
-\cs_new_protected:Npn \__piton_convert_tab_tl:
- {
- \hbox_set:Nn \l_tmpa_box { \l__piton_tab_tl }
- \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
- \tl_set:Nn \l__piton_tab_tl
+ \bool_if:NTF \l__piton_show_spaces_bool
{
+ \hbox_set:Nn \l_tmpa_box
+ { \prg_replicate:nn \l__piton_tab_size_int { ~ } }
+ \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
\( \mathcolor { gray }
- { \hbox_to_wd:nn \l_tmpa_dim { \rightarrowfill } \) }
+ { \hbox_to_wd:nn \l_tmpa_dim { \rightarrowfill } } \)
}
+ { \hbox:n { \prg_replicate:nn \l__piton_tab_size_int { ~ } } }
+ \int_gadd:Nn \g__piton_indentation_int \l__piton_tab_size_int
}
\int_new:N \l__piton_gobble_int
\tl_new:N \l__piton_space_tl
@@ -431,6 +432,8 @@
\bool_new:N \l__piton_skip_empty_lines_bool
\bool_set_true:N \l__piton_skip_empty_lines_bool
\bool_new:N \l__piton_line_numbers_absolute_bool
+\tl_new:N \l__piton_line_numbers_format_bool
+\tl_set:Nn \l__piton_line_numbers_format_tl { \footnotesize \color { gray } }
\bool_new:N \l__piton_label_empty_lines_bool
\bool_set_true:N \l__piton_label_empty_lines_bool
\int_new:N \l__piton_number_lines_start_int
@@ -500,14 +503,25 @@
sep .dim_set:N = \l__piton_numbers_sep_dim ,
sep .value_required:n = true ,
+ format .tl_set:N = \l__piton_line_numbers_format_tl ,
+ format .value_required:n = true ,
+
unknown .code:n = \__piton_error:n { Unknown~key~for~line-numbers }
}
\keys_define:nn { PitonOptions }
{
detected-commands .code:n =
- \lua_now:n { piton.addListCommands('#1') } ,
+ \lua_now:n { piton.addDetectedCommands('#1') } ,
detected-commands .value_required:n = true ,
detected-commands .usage:n = preamble ,
+ detected-beamer-commands .code:n =
+ \lua_now:n { piton.addBeamerCommands('#1') } ,
+ detected-beamer-commands .value_required:n = true ,
+ detected-beamer-commands .usage:n = preamble ,
+ detected-beamer-environments .code:n =
+ \lua_now:n { piton.addBeamerEnvironments('#1') } ,
+ detected-beamer-environments .value_required:n = true ,
+ detected-beamer-environments .usage:n = preamble ,
begin-escape .code:n =
\lua_now:e { piton.begin_escape = "\lua_escape:n{#1}" } ,
begin-escape .value_required:n = true ,
@@ -610,11 +624,9 @@
} ,
left-margin .value_required:n = true ,
- tab-size .code:n = \__piton_set_tab_tl:n { #1 } ,
+ tab-size .int_set:N = \l__piton_tab_size_int ,
tab-size .value_required:n = true ,
- show-spaces .code:n =
- \bool_set_true:N \l__piton_show_spaces_bool
- \__piton_convert_tab_tl: ,
+ show-spaces .bool_set:N = \l__piton_show_spaces_bool ,
show-spaces .value_forbidden:n = true ,
show-spaces-in-strings .code:n = \tl_set:Nn \l__piton_space_tl { ␣ } , % U+2423
show-spaces-in-strings .value_forbidden:n = true ,
@@ -695,8 +707,7 @@
\hbox_overlap_left:n
{
{
- \color { gray }
- \footnotesize
+ \l__piton_line_numbers_format_tl
\int_to_arabic:n \g__piton_visual_line_int
}
\skip_horizontal:N \l__piton_numbers_sep_dim
@@ -912,7 +923,7 @@
{
\hbox_set:Nn \l_tmpa_box
{
- \footnotesize
+ \l__piton_line_numbers_format_tl
\bool_if:NTF \l__piton_skip_empty_lines_bool
{
\lua_now:n
@@ -1136,7 +1147,6 @@
\__piton_compute_left_margin:no { CountNonEmptyLinesFile } \l__piton_file_name_str
\__piton_compute_width:
\ttfamily
- % \leavevmode
\lua_now:e
{
piton.ParseFile(
@@ -1480,6 +1490,8 @@
break-lines-in-Piton,~
continuation-symbol,~
continuation-symbol-on-indentation,~
+ detected-beamer-commands,~
+ detected-beamer-environments,~
detected-commands,~
end-of-broken-line,~
end-range,~
@@ -1555,8 +1567,25 @@
E = ( V "F" * ( "," * V "F" ) ^ 0 ) / add ,
F = space ^ 0 * ( ( alpha ^ 1 ) / "\\%0" ) * space ^ 0
}
- function piton.addListCommands( key_value )
- piton.ListCommands = piton.ListCommands + my_lpeg : match ( key_value )
+ function piton.addDetectedCommands( key_value )
+ piton.DetectedCommands = piton.DetectedCommands + my_lpeg : match ( key_value )
+ end
+ function piton.addBeamerCommands( key_value )
+ piton.BeamerCommands
+ = piton.BeamerCommands + my_lpeg : match ( key_value )
+ end
+ local function insert(...)
+ local s = piton.beamer_environments
+ for _ , x in ipairs({...}) do table.insert(s,x) end
+ return s
+ end
+ local my_lpeg_bis =
+ P { "E" ,
+ E = ( V "F" * ( "," * V "F" ) ^ 0 ) / insert ,
+ F = space ^ 0 * ( alpha ^ 1 ) * space ^ 0
+ }
+ function piton.addBeamerEnvironments( key_value )
+ piton.beamer_environments = my_lpeg_bis : match ( key_value )
end
\end{luacode*}