diff options
author | Karl Berry <karl@freefriends.org> | 2022-11-29 21:09:19 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-11-29 21:09:19 +0000 |
commit | 8bcb0bdbed8e8df6a76b01d3adf580afb27c1a76 (patch) | |
tree | 0d7de36cc972c1f28c75b6af73b0ad26bd4a9c4b /Master/texmf-dist/tex | |
parent | 24d395b004e4e1f571430b915fcc2e4bb95326cb (diff) |
piton (29nov22)
git-svn-id: svn://tug.org/texlive/trunk@65143 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/piton/piton.sty | 230 |
1 files changed, 165 insertions, 65 deletions
diff --git a/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty index ccfa3c3eb26..5e38b27a12f 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{0.95} -\def\myfiledate{2022/11/09} +\def\myfileversion{0.99} +\def\myfiledate{2022/11/29} @@ -131,8 +131,17 @@ \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_indent_broken_lines_bool +\tl_new:N \l__piton_continuation_symbol_tl +\tl_set:Nn \l__piton_continuation_symbol_tl { + } +\tl_new:N \l__piton_csoi_tl +\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_slim_bool \dim_new:N \l__piton_left_margin_dim +\bool_new:N \l__piton_left_margin_auto_bool \tl_new:N \l__piton_tab_tl \cs_new_protected:Npn \__piton_set_tab_tl:n #1 { @@ -144,18 +153,40 @@ \int_new:N \l__piton_gobble_int \tl_new:N \l__piton_space_tl \tl_set:Nn \l__piton_space_tl { ~ } +\int_new:N \g__piton_indentation_int +\cs_new_protected:Npn \__piton_an_indentation_space: + { \int_gincr:N \g__piton_indentation_int } \cs_set_protected:Npn \__piton_begin_line: #1 \__piton_end_line: { + \int_gzero:N \g__piton_indentation_int \bool_if:NTF \l__piton_slim_bool - { \hbox_set:Nn \l_tmpa_box } + { \hcoffin_set:Nn \l_tmpa_coffin } { \str_if_empty:NTF \l__piton_background_color_str - { \hbox_set_to_wd:Nnn \l_tmpa_box \linewidth } { - \hbox_set_to_wd:Nnn \l_tmpa_box - { \dim_eval:n { \linewidth - 0.5 em } } + \vcoffin_set:Nnn \l_tmpa_coffin + { \dim_eval:n { \linewidth - \l__piton_left_margin_dim } } } + { + \vcoffin_set:Nnn \l_tmpa_coffin + { \dim_eval:n { \linewidth - \l__piton_left_margin_dim - 0.5 em } } + } + } + { + \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 } + \hbox_set:Nn \l_tmpa_box { \skip_horizontal:N \l__piton_left_margin_dim \bool_if:NT \l__piton_line_numbers_bool @@ -164,9 +195,9 @@ { \tl_if_empty:nF { #1 } } \__piton_print_number: } - \strut - \str_if_empty:NF \l__piton_background_color_str \space - #1 \hfil + \str_if_empty:NF \l__piton_background_color_str + { \skip_horizontal:n { 0.5 em } } + \coffin_typeset:Nnnnn \l_tmpa_coffin T l \c_zero_dim \c_zero_dim } \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > \g__piton_width_dim { \dim_gset:Nn \g__piton_width_dim { \box_wd:N \l_tmpa_box } } @@ -207,6 +238,32 @@ } } } +\cs_set_protected:Npn \__piton_breakable_space: + { + \discretionary + { \hbox:n { \color { gray } \l__piton_end_of_broken_line_tl } } + { + \hbox_overlap_left:n + { + { + \normalfont \footnotesize \color { gray } + \l__piton_continuation_symbol_tl + } + \skip_horizontal:n { 0.3 em } + \str_if_empty:NF \l__piton_background_color_str + { \skip_horizontal:n { 0.5 em } } + } + \bool_if:NT \l__piton_indent_broken_lines_bool + { + \hbox:n + { + \prg_replicate:nn { \g__piton_indentation_int } { ~ } + { \color { gray } \l__piton_csoi_tl } + } + } + } + { \hbox { ~ } } + } \bool_new:N \l__piton_line_numbers_bool \bool_new:N \l__piton_all_line_numbers_bool \bool_new:N \l__piton_resume_bool @@ -234,23 +291,53 @@ slim .default:n = true , left-margin .code:n = \str_if_eq:nnTF { #1 } { auto } - { \dim_set:Nn \l__piton_left_margin_dim { -1cm } } + { + \dim_zero:N \l__piton_left_margin_dim + \bool_set_true:N \l__piton_left_margin_auto_bool + } { \dim_set:Nn \l__piton_left_margin_dim { #1 } } , 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 , + 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 , + end-of-broken-line .value_required:n = true , + continuation-symbol .tl_set:N = \l__piton_continuation_symbol_tl , + continuation-symbol .value_required:n = true , + continuation-symbol-on-indentation .tl_set:N = \l__piton_csoi_tl , + continuation-symbol-on-indentation .value_required:n = true , unknown .code:n = \msg_error:nn { piton } { Unknown~key~for~PitonOptions } } -\msg_new:nnn { piton } { Unknown~key~for~PitonOptions } +\msg_new:nnnn { piton } { Unknown~key~for~PitonOptions } { Unknown~key. \\ - The~key~'\l_keys_key_str'~is~unknown~for~\token_to_str:N \PitonOptions.~The~ - available~keys~are:~all-line-numbers,~auto-gobble,~env-gobble,~gobble,~ - left-margin,~line-numbers,~resume,~show-spaces,~slim,~splittable~and~tab-size.\\ - If~you~go~on,~that~key~will~be~ignored. + The~key~'\l_keys_key_str'~is~unknown~for~\token_to_str:N \PitonOptions.~ + It~will~be~ignored.\\ + For~a~list~of~the~available~keys,~type~H~<return>. + } + { + The~available~keys~are~(in~alphabetic~order):~ + all-line-numbers,~ + auto-gobble,~ + break-lines,~ + continuation-symbol,~ + continuation-symbol-on-indentation,~ + end-of-broken-line,~ + env-gobble,~gobble,~ + left-margin,~ + indent-broken-lines,~ + line-numbers,~ + resume,~ + show-spaces,~ + slim,~ + splittable~ + and~tab-size.\\ } \NewDocumentCommand \PitonOptions { } { \keys_set:nn { PitonOptions } } \int_new:N \g__piton_visual_line_int @@ -291,21 +378,37 @@ } } } -\NewDocumentCommand { \piton } { v } +\NewDocumentCommand { \piton } { } + { \peek_meaning:NTF \bgroup \__piton_piton_standard \__piton_piton_verbatim } +\NewDocumentCommand { \__piton_piton_standard } { m } + { + \group_begin: + \ttfamily + \cs_set_eq:NN \\ \c_backslash_str + \cs_set_eq:NN \% \c_percent_str + \cs_set_eq:NN \{ \c_left_brace_str + \cs_set_eq:NN \} \c_right_brace_str + \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 } + \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_argument()) } { #1 } + \lua_now:n { piton.Parse(token.scan_string()) } { #1 } \group_end: } \cs_new_protected:Npn \__piton_piton:n #1 { \group_begin: - \cs_set_protected:Npn \__piton_begin_line: { } - \cs_set_protected:Npn \__piton_end_line: { } - \lua_now:n { piton.Parse(token.scan_argument()) } { #1 } + \cs_set_protected:Npn \__piton_begin_line: { } + \cs_set_protected:Npn \__piton_end_line: { } + \lua_now:n { piton.Parse(token.scan_string()) } { #1 } \group_end: } \cs_new:Npn \__piton_pre_env: @@ -338,31 +441,25 @@ \__piton_pre_env: \mode_if_vertical:TF \mode_leave_vertical: \newline \lua_now:n { piton.CountLinesFile(token.scan_argument()) } { #2 } - \dim_compare:nNnT \l__piton_left_margin_dim < \c_zero_dim + \bool_lazy_and:nnT \l__piton_left_margin_auto_bool \l__piton_line_numbers_bool { - \bool_if:NT \l__piton_line_numbers_bool - { - \hbox_set:Nn \l_tmpa_box + \hbox_set:Nn \l_tmpa_box + { + \footnotesize + \bool_if:NTF \l__piton_all_line_numbers_bool + { + \int_to_arabic:n + { \g__piton_visual_line_int + \l__piton_nb_lines_int } + } { - \footnotesize - \bool_if:NTF \l__piton_all_line_numbers_bool - { - \int_to_arabic:n - { \g__piton_visual_line_int + \l__piton_nb_lines_int } - } - { - \lua_now:n - { piton.CountNonEmptyLinesFile(token.scan_argument()) } - { #2 } - \int_to_arabic:n - { - \g__piton_visual_line_int + - \l__piton_nb_non_empty_lines_int - } - } + \lua_now:n + { piton.CountNonEmptyLinesFile(token.scan_argument()) } + { #2 } + \int_to_arabic:n + { \g__piton_visual_line_int + \l__piton_nb_non_empty_lines_int } } - \dim_set:Nn \l__piton_left_margin_dim { \box_wd:N \l_tmpa_box + 0.5em } } + \dim_set:Nn \l__piton_left_margin_dim { \box_wd:N \l_tmpa_box + 0.5em } } \ttfamily \bool_if:NT \c__piton_footnote_bool { \begin { savenotes } } @@ -393,36 +490,30 @@ \group_end: \mode_if_vertical:TF \mode_leave_vertical: \newline \lua_now:n { piton.CountLines(token.scan_argument()) } { ##1 } - \dim_compare:nNnT \l__piton_left_margin_dim < \c_zero_dim + \bool_lazy_and:nnT \l__piton_left_margin_auto_bool \l__piton_line_numbers_bool { - \bool_if:NT \l__piton_line_numbers_bool + \bool_if:NTF \l__piton_all_line_numbers_bool { - \bool_if:NTF \l__piton_all_line_numbers_bool + \hbox_set:Nn \l_tmpa_box { - \hbox_set:Nn \l_tmpa_box - { - \footnotesize - \int_to_arabic:n - { \g__piton_visual_line_int + \l__piton_nb_lines_int } - } + \footnotesize + \int_to_arabic:n + { \g__piton_visual_line_int + \l__piton_nb_lines_int } } + } + { + \lua_now:n + { piton.CountNonEmptyLines(token.scan_argument()) } + { ##1 } + \hbox_set:Nn \l_tmpa_box { - \lua_now:n - { piton.CountNonEmptyLines(token.scan_argument()) } - { ##1 } - \hbox_set:Nn \l_tmpa_box - { - \footnotesize - \int_to_arabic:n - { - \g__piton_visual_line_int + - \l__piton_nb_non_empty_lines_int - } - } + \footnotesize + \int_to_arabic:n + { \g__piton_visual_line_int + \l__piton_nb_non_empty_lines_int } } - \dim_set:Nn \l__piton_left_margin_dim - { \box_wd:N \l_tmpa_box + 0.5 em } } + \dim_set:Nn \l__piton_left_margin_dim + { \box_wd:N \l_tmpa_box + 0.5 em } } \ttfamily \bool_if:NT \c__piton_footnote_bool { \begin { savenotes } } @@ -636,6 +727,8 @@ local SkipSpace = K ( ( space - P "\r" ) ^ 0 ) 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" * @@ -644,6 +737,8 @@ local EOL = + 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 ":=" @@ -938,6 +1033,7 @@ local Set = local SyntaxPythonAux = Lc ( '\\__piton_begin_line:' ) * ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1 * + SpaceIndentation ^ 0 * ( ( space^1 * -1 ) + EOL + Tab @@ -959,7 +1055,7 @@ local SyntaxPythonAux = + DefClass + Keyword * ( Space + Punct + Delim + EOL + -1) + Decorator - + OperatorWord + + OperatorWord * ( Space + Punct + Delim + EOL + -1) + Builtin * ( Space + Punct + Delim + EOL + -1) + Identifier + Number @@ -970,6 +1066,10 @@ 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 end +function piton.pitonParse(code) + local s = ( Cs ( ( P '##' / '#' + 1 ) ^ 0 ) ) : match ( code ) + return piton.Parse(s) +end function piton.ParseFile(name,first_line,last_line) s = '' local i = 0 |