summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.lua236
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.sty101
2 files changed, 310 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.lua b/Master/texmf-dist/tex/lualatex/piton/piton.lua
index 5c9d3e539db..bd2645591ac 100644
--- a/Master/texmf-dist/tex/lualatex/piton/piton.lua
+++ b/Master/texmf-dist/tex/lualatex/piton/piton.lua
@@ -60,7 +60,7 @@ local letter = alpha + P "_"
local alphanum = letter + digit
local identifier = letter * alphanum ^ 0
-local Identifier = K ( 'Identifier' , identifier)
+local Identifier = K ( 'Identifier' , identifier )
local Number =
K ( 'Number' ,
( digit^1 * P "." * digit^0 + digit^0 * P "." * digit^1 + digit^1 )
@@ -830,6 +830,8 @@ ocaml =
* Lc ( '\\__piton_end_line:' )
)
languages['ocaml'] = ocaml
+local identifier = letter * alphanum ^ 0
+
local Operator =
K ( 'Operator' ,
P "!=" + P "==" + P "<<" + P ">>" + P "<=" + P ">="
@@ -941,8 +943,6 @@ then
* 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"
*
@@ -1016,15 +1016,241 @@ 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
+local identifier =
+ letter * ( alphanum + P "-" ) ^ 0
+ + P '"' * ( ( alphanum + space - P '"' ) ^ 1 ) * P '"'
+
+local Operator =
+ K ( 'Operator' ,
+ P "=" + P "!=" + P "<>" + P ">=" + P ">" + P "<=" + P "<" + S "*+/"
+ )
+local function Set (list)
+ local set = {}
+ for _, l in ipairs(list) do set[l] = true end
+ return set
+end
+
+local set_keywords = Set
+ {
+ "ADD" , "AFTER" , "ALL" , "ALTER" , "AND" , "AS" , "ASC" , "BETWEEN" , "BY" ,
+ "CHANGE" , "COLUMN" , "CREATE" , "CROSS JOIN" , "DELETE" , "DESC" , "DISTINCT" ,
+ "DROP" , "FROM" , "GROUP" , "HAVING" , "IN" , "INNER" , "INSERT" , "INTO" , "IS" ,
+ "JOIN" , "LEFT" , "LIKE" , "LIMIT" , "MERGE" , "NOT" , "NULL" , "ON" , "OR" ,
+ "ORDER" , "OVER" , "RIGHT" , "SELECT" , "SET" , "TABLE" , "THEN" , "TRUNCATE" ,
+ "UNION" , "UPDATE" , "VALUES" , "WHEN" , "WHERE" , "WITH"
+ }
+
+local set_builtins = Set
+ {
+ "AVG" , "COUNT" , "CHAR_LENGHT" , "CONCAT" , "CURDATE" , "CURRENT_DATE" ,
+ "DATE_FORMAT" , "DAY" , "LOWER" , "LTRIM" , "MAX" , "MIN" , "MONTH" , "NOW" ,
+ "RANK" , "ROUND" , "RTRIM" , "SUBSTRING" , "SUM" , "UPPER" , "YEAR"
+ }
+local Identifier =
+ C ( identifier ) /
+ (
+ function (s)
+ if set_keywords[string.upper(s)] -- the keywords are case-insensitive in SQL
+ then return { "{\\PitonStyle{Keyword}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else if set_builtins[string.upper(s)]
+ then return { "{\\PitonStyle{Name.Builtin}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else return { "{\\PitonStyle{Name.Field}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ end
+ end
+ end
+ )
+local String =
+ K ( 'String.Long' , P "'" * ( 1 - P "'" ) ^ 1 * P "'" )
+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 MainLoopSQL:match(s) end ) )
+ * P "}" * Ct ( Cc "Close" )
+ + OneBeamerEnvironment ( "uncoverenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "onlyenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "visibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "invisibleenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "alertenv" , MainLoopSQL )
+ + OneBeamerEnvironment ( "actionenv" , MainLoopSQL )
+ +
+ 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 EOL =
+ P "\r"
+ *
+ (
+ ( space^0 * -1 )
+ +
+ Ct (
+ Cc "EOL"
+ *
+ Ct (
+ Lc "\\__piton_end_line:"
+ * BeamerEndEnvironments
+ * BeamerBeginEnvironments
+ * Lc "\\__piton_newline: \\__piton_begin_line:"
+ )
+ )
+ )
+ *
+ SpaceIndentation ^ 0
+local CommentMath =
+ P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$"
+
+local Comment =
+ WithStyle ( 'Comment' ,
+ Q ( P "--" ) -- syntax of SQL92
+ * ( 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 function LuaKeyword ( name )
+return
+ Lc ( "{\\PitonStyle{Keyword}{" )
+ * Q ( Cmt (
+ C ( identifier ) ,
+ function(s,i,a) return string.upper(a) == name end
+ )
+ )
+ * Lc ( "}}" )
+end
+local TableField =
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+
+local OneField =
+ (
+ Q ( P "(" * ( 1 - P ")" ) ^ 0 * P ")" )
+ +
+ K ( 'Name.Table' , identifier )
+ * Q ( P "." )
+ * K ( 'Name.Field' , identifier )
+ +
+ K ( 'Name.Field' , identifier )
+ )
+ * (
+ Space * LuaKeyword ( "AS" ) * Space * K ( 'Name.Field' , identifier )
+ ) ^ -1
+ * ( Space * ( LuaKeyword ( "ASC" ) + LuaKeyword ( "DESC" ) ) ) ^ -1
+
+local OneTable =
+ K ( 'Name.Table' , identifier )
+ * (
+ Space
+ * LuaKeyword ( "AS" )
+ * Space
+ * K ( 'Name.Table' , identifier )
+ ) ^ -1
+
+local WeCatchTableNames =
+ LuaKeyword ( "FROM" )
+ * ( Space + EOL )
+ * OneTable * ( SkipSpace * Q ( P "," ) * SkipSpace * OneTable ) ^ 0
+ + (
+ LuaKeyword ( "JOIN" ) + LuaKeyword ( "INTO" ) + LuaKeyword ( "UPDATE" )
+ + LuaKeyword ( "TABLE" )
+ )
+ * ( Space + EOL ) * OneTable
+local MainSQL =
+ EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + CommentLaTeX
+ + Beamer
+ + Comment + LongComment
+ + Delim
+ + Operator
+ + String
+ + Punct
+ + WeCatchTableNames
+ + ( TableField + Identifier ) * ( Space + Operator + Punct + Delim + EOL + -1 )
+ + Number
+ + Word
+MainLoopSQL =
+ ( ( space^1 * -1 )
+ + MainSQL
+ ) ^ 0
+languageSQL =
+ Ct (
+ ( ( space - P "\r" ) ^ 0 * P "\r" ) ^ -1
+ * BeamerBeginEnvironments
+ * Lc '\\__piton_begin_line:'
+ * SpaceIndentation ^ 0
+ * MainLoopSQL
+ * -1
+ * Lc '\\__piton_end_line:'
+ )
+languages['sql'] = languageSQL
function piton.Parse(language,code)
local t = languages[language] : match ( code )
if t == nil
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty
index a23aa1d0320..1a093ae7a9f 100644
--- a/Master/texmf-dist/tex/lualatex/piton/piton.sty
+++ b/Master/texmf-dist/tex/lualatex/piton/piton.sty
@@ -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{2.1}
-\def\myfiledate{2023/08/26}
+\def\myfileversion{2.2}
+\def\myfiledate{2023/09/05}
\NeedsTeXFormat{LaTeX2e}
@@ -153,6 +153,7 @@
\lua_now:n { piton = piton~or { } }
\str_new:N \l__piton_language_str
\str_set:Nn \l__piton_language_str { python }
+\tl_new:N \l__piton_path_seq
\bool_new:N \l__piton_in_PitonOptions_bool
\bool_new:N \l__piton_in_PitonInputFile_bool
\bool_new:N \g__piton_in_document_bool
@@ -166,7 +167,7 @@
\tl_new:N \l__piton_prompt_bg_color_tl
\str_new:N \l__piton_begin_range_str
\str_new:N \l__piton_end_range_str
-\str_new:N \l__piton_file_name_str
+\tl_new:N \l__piton_file_name_tl
\int_new:N \g__piton_env_int
\bool_new:N \l__piton_show_spaces_bool
\bool_new:N \l__piton_break_lines_in_Piton_bool
@@ -187,6 +188,7 @@
\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
{
\tl_clear:N \l__piton_tab_tl
@@ -499,6 +501,9 @@
language .code:n =
\str_set:Nx \l__piton_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
+ path .code:n =
+ \seq_set_from_clist:Nn \l__piton_path_seq { #1 } ,
+ path .value_required:n = true ,
gobble .int_set:N = \l__piton_gobble_int ,
gobble .value_required:n = true ,
auto-gobble .code:n = \int_set:Nn \l__piton_gobble_int { -1 } ,
@@ -807,6 +812,7 @@
{ \box_wd:N \l_tmpa_box + \l__piton_numbers_sep_dim + 0.1 em }
}
}
+\cs_generate_variant:Nn \__piton_compute_left_margin:nn { n V }
\cs_new_protected:Npn \__piton_compute_width:
{
\dim_compare:nNnTF \l__piton_line_width_dim = \c_zero_dim
@@ -902,13 +908,15 @@
}
\NewDocumentCommand { \PitonInputFile } { d < > O { } m }
{
- \file_if_exist:nTF { #3 }
- { \__piton_input_file:nnn { #1 } { #2 } { #3 } }
+ \group_begin:
+ \seq_set_eq:NN \l_file_search_path_seq \l__piton_path_seq
+ \file_get_full_name:nNTF { #3 } \l__piton_file_name_tl
+ { \__piton_input_file:nn { #1 } { #2 } }
{ \msg_error:nnn { piton } { Unknown~file } { #3 } }
+ \group_end:
}
-\cs_new_protected:Npn \__piton_input_file:nnn #1 #2 #3
+\cs_new_protected:Npn \__piton_input_file:nn #1 #2
{
- \str_set:Nn \l__piton_file_name_str { #3 }
\tl_if_novalue:nF { #1 }
{
\bool_if:NTF \g__piton_beamer_bool
@@ -960,8 +968,8 @@
\int_compare:nNnT \g__piton_visual_line_int < 0
{ \int_gzero:N \g__piton_visual_line_int }
\mode_if_vertical:TF \mode_leave_vertical: \newline
- \lua_now:e { piton.CountLinesFile('\l__piton_file_name_str') }
- \__piton_compute_left_margin:nn { CountNonEmptyLinesFile } { #3 }
+ \lua_now:e { piton.CountLinesFile('\l__piton_file_name_tl') }
+ \__piton_compute_left_margin:nV { CountNonEmptyLinesFile } \l__piton_file_name_tl
\__piton_compute_width:
\ttfamily
\bool_if:NT \g__piton_footnote_bool { \begin { savenotes } }
@@ -970,7 +978,7 @@
{
piton.ParseFile(
'\l__piton_language_str' ,
- '\l__piton_file_name_str' ,
+ '\l__piton_file_name_tl' ,
\int_use:N \l__piton_first_line_int ,
\int_use:N \l__piton_last_line_int )
}
@@ -991,11 +999,22 @@
\lua_now:e
{
piton.ComputeRange
- ( '\l_tmpa_str' , '\l_tmpb_str' , '\l__piton_file_name_str' )
+ ( '\l_tmpa_str' , '\l_tmpb_str' , '\l__piton_file_name_tl' )
}
}
-\NewDocumentCommand { \PitonStyle } { m } { \use:c { pitonStyle #1 } }
-\NewDocumentCommand { \SetPitonStyle } { } { \keys_set:nn { piton / Styles } }
+\NewDocumentCommand { \PitonStyle } { m }
+ {
+ \cs_if_exist_use:cF { pitonStyle _ \l__piton_language_str _ #1 }
+ { \use:c { pitonStyle _ #1 } }
+ }
+\NewDocumentCommand { \SetPitonStyle } { O { } m }
+ {
+ \str_set:Nx \l__piton_SetPitonStyle_option_str { \str_lowercase:n { #1 } }
+ \str_if_eq:VnT \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 { $#1$ } }
\clist_new:N \g__piton_style_clist
@@ -1018,6 +1037,7 @@
Name.Function ,
Name.Module ,
Name.Namespace ,
+ Name.Table ,
Name.Type ,
Number ,
Operator ,
@@ -1036,8 +1056,16 @@
{
\keys_define:nn { piton / Styles }
{
- #1 .tl_set:c = pitonStyle #1 ,
- #1 .value_required:n = true
+ #1 .value_required:n = true ,
+ #1 .code:n =
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l__piton_SetPitonStyle_option_str
+ { \l__piton_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
}
}
@@ -1075,6 +1103,7 @@
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 ,
@@ -1088,7 +1117,7 @@
TypeParameter = \color[HTML]{336666} \itshape ,
Preproc = \color[HTML]{AA6600} \slshape ,
Identifier = \__piton_identifier:n ,
- UserFunction = ,
+ UserFunction = ,
Prompt = ,
ParseAgain.noCR = \__piton_piton_no_cr:n ,
ParseAgain = \__piton_piton:n ,
@@ -1115,7 +1144,7 @@
\l__piton_style_tl
}
}
-\cs_new_protected:cpn { pitonStyle Name.Function.Internal } #1
+\cs_new_protected:cpn { pitonStyle _ Name.Function.Internal } #1
{
{ \PitonStyle { Name.Function } { #1 } }
\cs_gset_protected:cpn { PitonIdentifier _ \l__piton_language_str _ #1 }
@@ -1123,8 +1152,25 @@
\seq_if_exist:cF { g__piton_functions _ \l__piton_language_str _ seq }
{ \seq_new:c { g__piton_functions _ \l__piton_language_str _ seq } }
\seq_gput_right:cn { g__piton_functions _ \l__piton_language_str _ seq } { #1 }
+ \seq_if_in:NVF \g__piton_languages_seq \l__piton_language_str
+ { \seq_gput_left:NV \g__piton_languages_seq \l__piton_language_str }
}
-\NewDocumentCommand \PitonClearUserFunctions { ! O { \l__piton_language_str } }
+\NewDocumentCommand \PitonClearUserFunctions { ! o }
+ {
+ \tl_if_novalue:nTF { #1 }
+ { \__piton_clear_all_functions: }
+ { \__piton_clear_list_functions:n { #1 } }
+ }
+\cs_new_protected:Npn \__piton_clear_list_functions:n #1
+ {
+ \clist_set:Nn \l_tmpa_clist { #1 }
+ \clist_map_function:NN \l_tmpa_clist \__piton_clear_functions_i:n
+ \clist_map_inline:nn { #1 }
+ { \seq_gremove_all:Nn \g__piton_languages_seq { ##1 } }
+ }
+\cs_new_protected:Npn \__piton_clear_functions_i:n #1
+ { \exp_args:Nx \__piton_clear_functions_ii:n { \str_lowercase:n { #1 } } }
+\cs_new_protected:Npn \__piton_clear_functions_ii:n #1
{
\seq_if_exist:cT { g__piton_functions _ #1 _ seq }
{
@@ -1133,8 +1179,18 @@
\seq_gclear:c { g__piton_functions _ #1 _ seq }
}
}
+\cs_new_protected:Npn \__piton_clear_functions:n #1
+ {
+ \__piton_clear_functions_i:n { #1 }
+ \seq_gremove_all:Nn \g__piton_languages_seq { #1 }
+ }
+\cs_new_protected:Npn \__piton_clear_all_functions:
+ {
+ \seq_map_function:NN \g__piton_languages_seq \__piton_clear_functions_i:n
+ \seq_gclear:N \g__piton_languages_seq
+ }
\AddToHook { env / piton / begin }
- { \msg_fatal:nn { piton } { No~environment~piton } }
+ { \msg_fatal:nn { piton } { No~environment~piton } }
\msg_new:nnn { piton } { No~environment~piton }
{
@@ -1179,7 +1235,7 @@
Incompatible~keys.\\
You~can't~specify~the~range~of~lines~to~include~by~using~both~
markers~and~explicit~number~of~lines.\\
- Your~whole~file~'\l__piton_file_name_str'~will~be~included.
+ Your~whole~file~'\l__piton_file_name_tl'~will~be~included.
}
\__piton_msg_new:nn { syntax~error }
{
@@ -1193,14 +1249,14 @@
Marker~not~found.\\
The~range~'\l__piton_begin_range_str'~provided~to~the~
command~\token_to_str:N \PitonInputFile\ has~not~been~found.~
- The~whole~file~'\l__piton_file_name_str'~will~be~inserted.
+ The~whole~file~'\l__piton_file_name_tl'~will~be~inserted.
}
\__piton_msg_new:nn { end~marker~not~found }
{
Marker~not~found.\\
The~marker~of~end~of~the~range~'\l__piton_end_range_str'~
provided~to~the~command~\token_to_str:N \PitonInputFile\
- has~not~been~found.~The~file~'\l__piton_file_name_str'~will~
+ has~not~been~found.~The~file~'\l__piton_file_name_tl'~will~
be~inserted~till~the~end.
}
\NewDocumentCommand \PitonBeginMarkerNotFound { }
@@ -1239,6 +1295,7 @@
left-margin,~
line-numbers/,~
marker/,~
+ path,~
prompt-background-color,~
resume,~
show-spaces,~