diff options
author | Karl Berry <karl@freefriends.org> | 2023-01-16 21:10:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-01-16 21:10:15 +0000 |
commit | 1ab45cfa9a8a257edc4a1678d187de97c3f9ce6a (patch) | |
tree | 6cf06821f9fee64cb0862bf4cbeffae7d49034f4 /Master/texmf-dist/tex | |
parent | 4bbebef6908cbe4af13028e80b8d098758767dfe (diff) |
piton (16jan23)
git-svn-id: svn://tug.org/texlive/trunk@65557 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/piton/piton.sty | 326 |
1 files changed, 235 insertions, 91 deletions
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty index dd5d94ef6d8..3142a900c8e 100644 --- a/Master/texmf-dist/tex/lualatex/piton/piton.sty +++ b/Master/texmf-dist/tex/lualatex/piton/piton.sty @@ -18,10 +18,14 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{1.1} -\def\myfiledate{2023/01/07} +\def\myfileversion{1.2} +\def\myfiledate{2023/01/16} +\bigskip + +%% + \NeedsTeXFormat{LaTeX2e} \RequirePackage{l3keys2e} @@ -136,7 +140,8 @@ \dim_new:N \g__piton_width_dim \dim_new:N \l__piton_width_on_aux_dim \int_new:N \g__piton_env_int -\bool_new:N \l__piton_break_lines_bool +\bool_new:N \l__piton_show_spaces_bool +\bool_new:N \l__piton_break_lines_in_Piton_bool \bool_new:N \l__piton_indent_broken_lines_bool \tl_new:N \l__piton_continuation_symbol_tl \tl_set:Nn \l__piton_continuation_symbol_tl { + } @@ -144,6 +149,7 @@ \tl_set:Nn \l__piton_csoi_tl { $ \hookrightarrow \; $ } \tl_new:N \l__piton_end_of_broken_line_tl \tl_set:Nn \l__piton_end_of_broken_line_tl { \hspace*{0.5em} \textbackslash } +\bool_new:N \l__piton_break_lines_in_piton_bool \bool_new:N \l__piton_slim_bool \dim_new:N \l__piton_left_margin_dim \bool_new:N \l__piton_left_margin_auto_bool @@ -161,6 +167,28 @@ \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_replace_spaces:n #1 + { + \tl_set:Nn \l_tmpa_tl { #1 } + \bool_if:NTF \l__piton_show_spaces_bool + { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423 + { + \bool_if:NT \l__piton_break_lines_in_Piton_bool + { + \regex_replace_all:nnN + { \x20 } + { \c { __piton_breakable_space: } } + \l_tmpa_tl + } + } + \l_tmpa_tl + } +\cs_generate_variant:Nn \__piton_replace_spaces:n { x } \cs_set_protected:Npn \__piton_begin_line: #1 \__piton_end_line: { \int_gzero:N \g__piton_indentation_int @@ -181,15 +209,8 @@ \language = -1 \raggedright \strut - \tl_set:Nn \l_tmpa_tl { #1 } - \bool_if:NT \l__piton_break_lines_bool - { - \regex_replace_all:nnN - { \x20 } - { \c { __piton_breakable_space: } } - \l_tmpa_tl - } - \l_tmpa_tl \strut \hfil + \__piton_replace_spaces:n { #1 } + \strut \hfil } \hbox_set:Nn \l_tmpa_box { @@ -306,10 +327,16 @@ left-margin .value_required:n = true , tab-size .code:n = \__piton_set_tab_tl:n { #1 } , tab-size .value_required:n = true , - show-spaces .code:n = \tl_set:Nn \l__piton_space_tl { ␣ } , % U+2423 - show-spaces .value_forbidden:n = true , - break-lines .bool_set:N = \l__piton_break_lines_bool , - break-lines .default:n = true , + show-spaces .bool_set:N = \l__piton_show_spaces_bool , + show-spaces .default: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 , + break-lines-in-Piton .bool_set:N = \l__piton_break_lines_in_Piton_bool , + break-lines-in-Piton .default:n = true , + break-lines-in-piton .bool_set:N = \l__piton_break_lines_in_piton_bool , + break-lines-in-piton .default:n = true , + break-lines .meta:n = { break-lines-in-piton , break-lines-in-Piton } , + break-lines .value_forbidden:n = true , indent-broken-lines .bool_set:N = \l__piton_indent_broken_lines_bool , indent-broken-lines .default:n = true , end-of-broken-line .tl_set:N = \l__piton_end_of_broken_line_tl , @@ -333,6 +360,8 @@ all-line-numbers,~ auto-gobble,~ break-lines,~ + break-lines-in-piton,~ + break-lines-in-Piton,~ continuation-symbol,~ continuation-symbol-on-indentation,~ end-of-broken-line,~ @@ -343,6 +372,7 @@ line-numbers,~ resume,~ show-spaces,~ + show-spaces-in-strings,~ slim,~ splittable,~ tabs-auto-gobble,~ @@ -400,16 +430,28 @@ \cs_set_eq:NN \$ \c_dollar_str \cs_set_protected:Npn \__piton_begin_line: { } \cs_set_protected:Npn \__piton_end_line: { } - \lua_now:n { piton.pitonParse(token.scan_string()) } { #1 } + \tl_set:Nx \l_tmpa_tl + { \lua_now:n { piton.pitonParse(token.scan_string()) } { #1 } } + \bool_if:NTF \l__piton_show_spaces_bool + { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423 + { + \bool_if:NT \l__piton_break_lines_in_piton_bool + { \regex_replace_all:nnN { \x20 } { \x20 } \l_tmpa_tl } + } + \l_tmpa_tl \group_end: } \NewDocumentCommand { \__piton_piton_verbatim } { v } { \group_begin: - \ttfamily - \cs_set_protected:Npn \__piton_begin_line: { } - \cs_set_protected:Npn \__piton_end_line: { } - \lua_now:n { piton.Parse(token.scan_string()) } { #1 } + \ttfamily + \cs_set_protected:Npn \__piton_begin_line: { } + \cs_set_protected:Npn \__piton_end_line: { } + \tl_set:Nx \l_tmpa_tl + { \lua_now:n { piton.Parse(token.scan_string()) } { #1 } } + \bool_if:NT \l__piton_show_spaces_bool + { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423 + \l_tmpa_tl \group_end: } \cs_new_protected:Npn \__piton_piton:n #1 @@ -417,7 +459,25 @@ \group_begin: \cs_set_protected:Npn \__piton_begin_line: { } \cs_set_protected:Npn \__piton_end_line: { } - \lua_now:n { piton.Parse(token.scan_string()) } { #1 } + \tl_set:Nx \l_tmpa_tl + { \lua_now:n { piton.Parse(token.scan_string()) } { #1 } } + \bool_if:NT \l__piton_show_spaces_bool + { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423 + \l_tmpa_tl + \group_end: + } +\cs_new_protected:Npn \__piton_piton_no_cr:n #1 + { + \group_begin: + \cs_set_protected:Npn \__piton_begin_line: { } + \cs_set_protected:Npn \__piton_end_line: { } + \cs_set_protected:Npn \__piton_newline: + { \msg_fatal:nn { piton } { cr~not~allowed } } + \tl_set:Nx \l_tmpa_tl + { \lua_now:n { piton.Parse(token.scan_string()) } { #1 } } + \bool_if:NT \l__piton_show_spaces_bool + { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423 + \l_tmpa_tl \group_end: } \cs_new:Npn \__piton_pre_env: @@ -663,7 +723,7 @@ InitialValues = \__piton_piton:n , Dict.Value = \__piton_piton:n , Interpol.Inside = \color{black}\__piton_piton:n , - Beamer = \__piton_piton:n , + Beamer = \__piton_piton_no_cr:n , Post.Function = \__piton_piton:n , } \bool_if:NT \c__piton_math_comments_bool @@ -678,6 +738,15 @@ \token_to_str:N \piton\ but~there~is~no~environment~ {piton}.~This~error~is~fatal. } +\msg_new:nnn { piton } { 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. + } \ExplSyntaxOff \RequirePackage{luacode} \begin{luacode*} @@ -741,16 +810,7 @@ local Punct = K ( S ".,:;!" ) local Tab = P "\t" * Lc ( '\\l__piton_tab_tl' ) local SpaceIndentation = Lc ( '\\__piton_an_indentation_space:' ) * K " " -local EOL = - P "\r" - * - ( - ( space^0 * -1 ) - + - Lc ( '\\__piton_end_line: \\__piton_newline: \\__piton_begin_line:' ) - ) - * - SpaceIndentation ^ 0 + local Delim = K ( S "[()]" ) local Operator = K ( P "!=" + P "<>" + P "==" + P "<<" + P ">>" + P "<=" + P ">=" + P ":=" @@ -811,7 +871,6 @@ local Exception = local RaiseException = K ( P "raise" , 'Keyword' ) * SkipSpace * Exception * K ( P "(" ) -local ExceptionInConsole = Exception * K ( ( 1 - P "\r" ) ^ 0 ) * EOL local Decorator = K ( P "@" * letter^1 , 'Name.Decorator' ) local DefClass = K ( P "class" , 'Keyword' ) * Space * K ( identifier , 'Name.Class' ) @@ -912,6 +971,102 @@ local DoubleShortString = * Lc ( "}}" ) local ShortString = SingleShortString + DoubleShortString +local BalancedBraces = + P { "E" , + E = ( ShortString + ( 1 - S "{}" ) ) ^ 0 + * + ( + P "{" * V "E" * P "}" + * ( ShortString + ( 1 - S "{}" ) ) ^ 0 + ) ^ 0 + } +local Beamer = P ( false ) +local BeamerBeginEnvironments = P ( true ) +local BeamerEndEnvironments = P ( true ) +local BeamerNamesEnvironments = + P "uncoverenv" + P "onlyenv" + P "visibleenv" + P "invisibleenv" + +if piton_beamer +then + Beamer = + L ( P "\\pause" * ( P "[" * (1 - P "]") ^ 0 * P "]" ) ^ -1 ) + + + ( P "\\uncover" * Lc ( '\\__piton_beamer_command:n{uncover}' ) + + P "\\only" * Lc ( '\\__piton_beamer_command:n{only}' ) + + P "\\alert" * Lc ( '\\__piton_beamer_command:n{alert}' ) + + P "\\visible" * Lc ( '\\__piton_beamer_command:n{visible}' ) + + P "\\invisible" * Lc ( '\\__piton_beamer_command:n{invisible}' ) + + P "\\action" * Lc ( '\\__piton_beamer_command:n{action}' ) + ) + * + L ( ( P "<" * (1 - P ">") ^ 0 * P ">" ) ^ -1 * P "{" ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}" ) + + + L ( + ( P "\\alt" ) + * P "<" * (1 - P ">") ^ 0 * P ">" + * P "{" + ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}{" ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}" ) + + + L ( + ( P "\\temporal" ) + * P "<" * (1 - P ">") ^ 0 * P ">" + * P "{" + ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}{" ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}{" ) + * K ( BalancedBraces , 'Beamer' ) + * L ( P "}" ) + BeamerBeginEnvironments = + ( space ^ 0 * + L + ( + P "\\begin{" * BeamerNamesEnvironments * "}" + * ( P "<" * ( 1 - P ">") ^ 0 * P ">" ) ^ -1 + ) + * P "\r" + ) ^ 0 + BeamerEndEnvironments = + ( space ^ 0 * + L ( P "\\end{" * BeamerNamesEnvironments * P "}" ) + * P "\r" + ) ^ 0 +end +local EOL +if piton_beamer +then +EOL = + P "\r" + * + ( + ( space^0 * -1 ) + + + Lc ( '\\__piton_end_line:' ) + * BeamerEndEnvironments + * BeamerBeginEnvironments + * Lc ( '\\__piton_newline: \\__piton_begin_line:' ) + ) + * + SpaceIndentation ^ 0 +else +EOL = + P "\r" + * + ( + ( space^0 * -1 ) + + + Lc ( '\\__piton_end_line: \\__piton_newline: \\__piton_begin_line:' ) + ) + * + SpaceIndentation ^ 0 +end local SingleLongString = Lc "{\\PitonStyle{String.Long}{" * ( @@ -1044,65 +1199,54 @@ local Set = K ( P "{" ) * ItemOfSet * ( K ( P "," ) * ItemOfSet ) ^ 0 * K ( P "}" ) -local Beamer = P ( "blablabla" ) +local ExceptionInConsole = Exception * K ( ( 1 - P "\r" ) ^ 0 ) * EOL +UserEnvironments = P ( true ) +MainLoop = + ( ( space^1 * -1 ) + + EOL + + Tab + + Space + + Escape + + CommentLaTeX + + Beamer + + LongString + + Comment + + ExceptionInConsole + + Set + + Delim + + Operator + + ShortString + + Punct + + FromImport + + ImportAs + + RaiseException + + DefFunction + + DefClass + + Keyword * ( Space + Punct + Delim + EOL + -1) + + Decorator + + OperatorWord * ( Space + Punct + Delim + EOL + -1) + + Builtin * ( Space + Punct + Delim + EOL + -1) + + Identifier + + Number + + Word + ) ^ 0 +local SyntaxPython = P ( true ) -if piton_beamer then - Beamer = - L ( - ( P "\\uncover" + P "\\only" + P "\\alert" + P "\\visible" - + P "\\invisible" + P "\\action" - ) - * P "<" - * (1 - P ">") ^ 0 - * P ">{" - ) - * K ( Expression , 'Beamer' ) - * L ( P "}" ) - + - L ( - ( P "\\alt" ) - * P "<" - * (1 - P ">") ^ 0 - * P ">{" - ) - * K ( Expression , 'Beamer' ) - * L ( P "}{" ) - * K ( Expression , 'Beamer' ) - * L ( P "}" ) +function piton.defSyntaxPython() + SyntaxPython = + Ct ( + ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1 + * BeamerBeginEnvironments + * UserEnvironments + * Lc ( '\\__piton_begin_line:' ) + * SpaceIndentation ^ 0 + * MainLoop + * -1 + * Lc ( '\\__piton_end_line:' ) + ) end -local SyntaxPythonAux = - Lc ( '\\__piton_begin_line:' ) * - ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1 * - SpaceIndentation ^ 0 * - ( ( space^1 * -1 ) - + EOL - + Tab - + Space - + Escape - + CommentLaTeX - + Beamer - + LongString - + Comment - + ExceptionInConsole - + Set - + Delim - + Operator - + ShortString - + Punct - + FromImport - + ImportAs - + RaiseException - + DefFunction - + DefClass - + Keyword * ( Space + Punct + Delim + EOL + -1) - + Decorator - + OperatorWord * ( Space + Punct + Delim + EOL + -1) - + Builtin * ( Space + Punct + Delim + EOL + -1) - + Identifier - + Number - + Word - ) ^0 * -1 * Lc ( '\\__piton_end_line:' ) -local SyntaxPython = Ct ( SyntaxPythonAux ) + +piton.defSyntaxPython() function piton.Parse(code) local t = SyntaxPython : match ( code ) -- match is a method of the LPEG for _ , s in ipairs(t) do tex.tprint(s) end |