%%%==============================================================================
%% Copyright 2026-present by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
%%   version 1.3c (or later), and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version {1.0} {2026/11/27}
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/codehighlight
%%
%%%==============================================================================
\NeedsTeXFormat{LaTeX2e}[2026-06-01]

%%%%%%%
%%%
%%% Just an attempt at having my package's info in a regular way
%%%   \pkginfograb_set:nn {<pkg-name>} { props} sets package info
%%%
%%%   \pkginfograbProvidesExplPackage {<pkg-name>} { props} sets package info
%%%     and calls \ProvidesExplPackage
%%%
%%%%%%%
\RequirePackage{pkginfograb}
\pkginfograbProvidesExplPackage {codehighlight}
  {
     name        = {codehighlight} ,
     prefix      = {codehl} ,
     date        = {2026/11/27} ,
     version     = {1.0} ,
     description = {Code highlighting for codedescribe/codelisting/codeverbatim}
  }
%%%%%%%
%%% End of cut-n-paste
%%%%%%%

%%%%%%%
%%% For the many context stacks
%%%%%%%
\RequirePackage{ tokglobalstack }

\cs_generate_variant:Nn \vcoffin_set:Nnn { NnV , Nne }
\cs_generate_variant:Nn \dim_set:Nn { Ne }
\cs_generate_variant:Nn \tl_show:n { e }
\cs_generate_variant:Nn \tl_put_left:Nn { Ne }
\cs_generate_variant:Nn \tl_put_right:Nn { Ne }
\cs_generate_variant:Nn \tl_retokenize:n { o }

\cs_generate_variant:Nn \regex_set:Nn { c , ce }

\cs_generate_variant:Nn \seq_concat:NNN { cc }

\cs_generate_variant:Nn \int_set:Nn { Ne }

\cs_generate_variant:Nn \msg_error:nnnnnn { nnne , nnneee }
\cs_generate_variant:Nn \msg_error:nnnn   { nnne }
\cs_generate_variant:Nn \msg_show:nnnn    { nnne , nnox }
\cs_generate_variant:Nn \msg_note:nnnnn   { nnne }
\cs_generate_variant:Nn \msg_note:nnnnnn  { nnne , nnnne , nnnee , nnneee }
\cs_generate_variant:Nn \msg_info:nnnnn   { nnne }
\cs_generate_variant:Nn \msg_info:nnnnnn  { nnnne , nnnee , nnneee }

\prg_generate_conditional_variant:Nnn \tl_if_blank:n { v } {TF}
\prg_generate_conditional_variant:Nnn \bool_if:n { o } { TF }
\prg_generate_conditional_variant:Nnn \str_compare:nNn  { nNo , oNo } { TF }

%%%%%%%
%%% CTAN/log
%%% false => CTAN distribution
%%% true  => log the many _register:nn commands
%%%%%%%
\bool_new:N \l__codehl_register_bool
%\bool_set_true:N \l__codehl_register_bool

%%%%%%%
%%%
%%% WinEdt regex
%%%
%%% (C:/Users*>*><File*>            => nothing
%%% <)>                             => nothing
%%% Package codehl*\(0\\__code\)    => |\0|         minus the |
%%% \{><(codehl*\ \(~[\ ]\)         => |\{ \0|      minus the |
%%% def><(code*\}>                  => |def \}|     minus the |
%%% >>                              => |>|          removing blank lines
%%%
%%% @                               => | |          single space
%%%
%%%%%%%

\msg_new:nnnn { codehl / basefmt } { alias err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~the ~set~#2~ is ~a ~ defined ~ base ~ format ~ set. ~ (alias~ ignored)
  }
  {
    (#1)~You ~ tried~ to ~ define~ {#2} ~ as ~ an ~ alias, ~ but ~ it's ~ a~ defined~ base ~ format ~ set~ (alias~ ignored).
  }

\msg_new:nnnn { codehl / basefmt } { based on syntax }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base~descriptor:~{#2}~(ignored)
  }
  {
    (#1)~The~expected~syntax: R|F[<int>]<base-basefmt> ~or~ just~ <base-basefmt>.
  }

\msg_new:nnnn { codehl / basefmt } { non existant base }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base:~{#2}
  }
  {
    (#1)~The~format~base~doesn't~exist.
  }

\msg_new:nnnn { codehl / basefmt } { invalid code }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~based~on~code:~{#2}
  }
  {
    (#1)~The~options~are:~R~(remap)~or~S~(set).
  }

\msg_new:nnnn { codehl /  basefmt } { non existant }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~format~{#2}~isn't~defined.
  }
  {
    (#1)~You~tried~to~use ~a ~non ~defined~ format~ set.
  }

\msg_new:nnnn { codehl / settings } { alias err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~The ~set ~{#2}~ is ~a ~ defined ~ settings ~ ID ~ (alias~ ignored)
  }
  {
    (#1)~You ~ tried~ to ~ define~ {#2} ~ as ~ an ~ alias, ~ but ~ it's ~ a~ defined~ settings ~ID~ (alias~ ignored).
  }

\msg_new:nnnn { codehl / settings } { based on syntax }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base~descriptor:~{#2}~(ignored)
  }
  {
    (#1)~The~expected~syntax: R|F[<int>]<base-settings> ~or~ just~ <base-settings>.
  }

\msg_new:nnnn { codehl / settings } { non existant base }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base:~{#2}
  }
  {
    (#1)~The~settings ~ID ~doesn't~exist.
  }

\msg_new:nnnn { codehl / settings } { invalid code }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~based~on~code:~{#2}
  }
  {
    (#1)~The~options~are:~R~(remap)~or~S~(set).
  }

\msg_new:nnnn { codehl /  settings } { non existant }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~settings ~ID ~{#2}~isn't~defined.
  }
  {
    (#1)~You~tried~to~use ~a ~non ~defined~ settings ~ID.
  }

\msg_new:nnnn { codehl / hlset } { alias err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~the set~{#2}~ is ~a ~ defined ~ highlight ~ set. ~ (alias~ ignored)
  }
  {
    (#1)~You ~ tried~ to ~ define~ {#2} ~ as ~ an ~ alias, ~ but ~ it's ~ a~ defined~ highlight ~ set~ (alias~ ignored).
  }

\msg_new:nnnn { codehl / hlset } { based on syntax }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base~descriptor:~{#2}~(ignored)
  }
  {
    (#1)~The~expected~syntax: R|F[<int>]<base-hlset> ~or~ just~ <base-hlset>.
  }

\msg_new:nnnn { codehl / hlset } { non existant base }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base:~{#2}
  }
  {
    (#1)~The~format~base~doesn't~exist.
  }

\msg_new:nnnn { codehl / hlset } { invalid code }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~based~on~code:~{#2}
  }
  {
    (#1)~The~options~are:~R~(remap)~or~S~(set).
  }

\msg_new:nnnn { codehl /  hlset } { non existant }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~format~{#2}~isn't~defined.
  }
  {
    (#1)~You~tried~to~use ~a ~non ~defined~ highlight~ set.
  }

\msg_new:nnnn { codehl / keyset } { alias err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Language~{#2}~ is ~a ~ defined ~ keywd ~ set. ~ (alias~ ignored)
  }
  {
    (#1)~You ~ tried~ to ~ define~ #2 ~ as ~ an ~ alias, ~ but ~ it's ~ a~ defined~ keywd ~ set~ (alias~ ignored).
  }

\msg_new:nnnn { codehl / keyset } { based on syntax }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~keywd-set~base~descriptor:~{#2}~(ignored)
  }
  {
    (#1)~The~expected~syntax: { R|S } { <int>} { base-keywd-set }.
  }

\msg_new:nnnn { codehl / keyset } { non existant base }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base:~{#2}~(ignored)
  }
  {
    (#1)~The~format~base~doesn't~exist.
  }

\msg_new:nnnn { codehl / keyset } { invalid code }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~based~on~code:~{#2}
  }
  {
    (#1)~The~options~are:~R~(remap)~or~S~(set).
  }

\msg_new:nnnn { codehl / keyset } { non existant }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~keywd-set~{#2}~isn't~defined.
  }
  {
    (#1)~You~tried~to~use ~a ~non ~defined~ keyword~ set.
  }

\msg_new:nnnn { codehl / lang } { alias err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Language~{#2}~ is ~a ~ defined ~ language. ~ (alias~ ignored)
  }
  {
    (#1)~You ~ tried~ to ~ define~ #2 ~ as ~ an ~ alias, ~ but ~ it's ~ a~ defined~ language~ (alias~ ignored).
  }

\msg_new:nnnn { codehl / lang } { based on syntax }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~lang~base~descriptor:~{#2}~(ignored)
  }
  {
    (#1)~The~expected~syntax: { R|S } { <int>} { base-lang }.
  }

\msg_new:nnnn { codehl / lang } { non existant base }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~base:~{#2}~(ignored)
  }
  {
    (#1)~The~format~base~doesn't~exist.
  }

\msg_new:nnnn { codehl / lang } { invalid code }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Invalid~based~on~code:~{#2}
  }
  {
    (#1)~The~options~are:~R~(remap)~or~S~(set).
  }

\msg_new:nnnn { codehl / lang } { non existant }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~language~{#2}~isn't~defined.
  }
  {
    (#1)~You~tried~to~use ~a ~non ~defined~ language.
  }

\msg_new:nnnn { codehl / keyset } { syntax err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Syntax ~Error: ~{#3}.
  }
  {
    (#1)~Defining~ keywd-set:~#2. ~Expected~syntax:~#4
  }

\msg_new:nnnn { codehl /  hlset } { syntax err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Syntax ~Error: ~{#3}.
  }
  {
    (#1)~Defining~ format:~{#2}. ~Expected~syntax:~#4
  }

\msg_new:nnnn { codehl / lang } { syntax err }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1)~Syntax ~Error: ~{#3}.
  }
  {
    (#1)~Defining~ lang:~{#2}. ~Expected~syntax:~#4
  }

\msg_new:nnnn { codehl / lang } { pre def }
  {
    \msg_line_context: \use:n { ~ } (without ~ outer ~braces)\iow_newline:
    (#1) ~ non ~ existant ~ Language: ~ {#2}
  }
  {
    (#1) ~The ~ language ~ {#2}~ isn't~ pre-defined
  }

\int_new:N \l__codehl_tmpa_int

  
\bool_if:NTF \l__codehl_register_bool
  {
    \cs_new_protected:Npn \__codehl_note:nnnnnn #1#2#3#4
      {
        \int_set:Nn \l__codehl_tmpa_int { 25 - \str_count:n { #4 } }
        \tl_set:Nn  \l__codehl_tmpa_tl { #4 }
        \int_while_do:nNnn { \l__codehl_tmpa_int } > { 0 }
          { 
            \tl_put_right:Nn \l__codehl_tmpa_tl { \exp_not:n { @ }  }
            \int_decr:N \l__codehl_tmpa_int
          }
        \msg_note:nnnenn { #1 } { #2 } { #3 } { \l__codehl_tmpa_tl }
      }  
  }
  {
    \cs_new_protected:Npn \__codehl_note:nnnnnn 
      {
        \msg_note:nnnnnn 
      }  
  }
\cs_generate_variant:Nn   \__codehl_note:nnnnnn { nnnnen , nnneee }

\bool_if:NTF \l__codehl_register_bool
  {
    \msg_new:nnnn { codehl / lang } { info note }
      {
        \__codehl_lang_register:nn  ~ \use:n { ~ } \use:n { ~ }  { ~ #2 ~ } ~ { ~ #3 ~ }
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ Language: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }
  {
    \msg_new:nnnn { codehl / lang } { info note }
      {
        \msg_line_context: ~ \use:n { ~ } (file ~ #3)\iow_newline:
        In ~  Language: ~ {#2} \iow_newline:
        #4
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ Language: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }

\msg_new:nnnn { codehl / keyset } { pre def }
  {
    \msg_line_context: \iow_newline:
    (#1) ~ non ~ existant ~ keywd-set: ~ #2
  }
  {
    (#1) ~The ~ keywd-set ~ #2~ isn't~ pre-defined
  }

\bool_if:NTF \l__codehl_register_bool
  {
    \msg_new:nnnn { codehl / keyset } { info note }
      {
        \__codehl_keyset_register:nn { ~ #2 ~ } ~ { ~ #3 ~ }
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ keyword ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }
  {
    \msg_new:nnnn { codehl / keyset } { info note }
      {
        \msg_line_context: ~ \use:n { ~ } (file ~ #3)\iow_newline:
        In ~  keyword ~ set: ~ {#2} \iow_newline:
        #4
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ keyword ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }

\msg_new:nnnn { codehl / hlset } { pre def }
  {
    \msg_line_context: \iow_newline:
    (#1) ~ non ~ existant ~ Language: ~ #2
  }
  {
    (#1) ~The ~ highlight ~ set ~ #2~ isn't~ pre-defined
  }

\bool_if:NTF \l__codehl_register_bool
  {
    \msg_new:nnnn { codehl / hlset } { info note }
      {
        \__codehl_hlset_register:nn { ~ #2 ~ } ~ { ~ #3 ~ }
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ highlight ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }
  {
    \msg_new:nnnn { codehl / hlset } { info note }
      {
        \msg_line_context: ~ \use:n { ~ } (file ~ #3)\iow_newline:
        In ~  highlight ~ set: ~ {#2} \iow_newline:
        #4
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ highlight ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }

\msg_new:nnnn { codehl / basefmt } { pre def }
  {
    \msg_line_context: \iow_newline:
    (#1) ~ non ~ existant ~ Language: ~ #2
  }
  {
    (#1) ~The ~ base ~ format ~ set ~ #2~ isn't~ pre-defined
  }

\bool_if:NTF \l__codehl_register_bool
  {
    \msg_new:nnnn { codehl / basefmt } { info note }
      {
        \__codehl_basefmt_register:nn { ~ #2 ~ } ~ { ~ #3 ~ }
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ base ~ format ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }
  {
    \msg_new:nnnn { codehl / basefmt } { info note }
      {
        \msg_line_context: ~ \use:n { ~ } (file ~ #3)\iow_newline:
        In ~  base ~ format ~ set: ~ {#2} \iow_newline:
        #4
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ base ~ format ~ set: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }

\msg_new:nnnn { codehl / settings } { pre def }
  {
    \msg_line_context: \iow_newline:
    (#1) ~ non ~ existant ~ settings ~ ID: ~ #2
  }
  {
    (#1) ~The ~ settings ~ ID ~ #2~ isn't~ pre-defined
  }

\bool_if:NTF \l__codehl_register_bool
  {
    \msg_new:nnnn { codehl / settings } { info note }
      {
        \__codehl_settings_register:nn { ~ #2 ~ } ~ { ~ #3 ~ }
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ settings ~ID: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }
  {
    \msg_new:nnnn { codehl / settings } { info note }
      {
        \msg_line_context: ~ \use:n { ~ } (file ~ #3)\iow_newline:
        In ~  settings ~ ID: ~ {#2} \iow_newline:
        #4
      }
      {
        (#1) ~ note ~ found ~ in ~ the ~ definition ~ of ~ settings ~ID: ~ #2 ~ in ~ file ~ #3:\iow_newline:
        #4
      }
  }

\msg_new:nnnn { codehl / lang } { struct info }
  {
    \msg_line_context: \iow_newline:
    Language~\{#1\}~definitions ~(without ~outer ~blaces): \iow_newline:
    #2
  }
  {  }

\msg_new:nnnn { codehl / keyset } { struct info }
  {
    \msg_line_context: \iow_newline:
    Keywords' ~sets~\{#1\}~ (without ~outer ~blaces): \iow_newline:
    #2
  }
  {  }

\msg_new:nnnn { codehl / hlset } { struct info }
  {
    \msg_line_context: \iow_newline:
    Highlight ~format ~set~\{#1\}~ (without ~outer ~blaces): \iow_newline:
    #2
  }
  {  }

\msg_new:nnnn { codehl / basefmt } { struct info }
  {
    \msg_line_context: \iow_newline:
    Base ~format ~\{#1\}~ (without ~outer ~blaces): \iow_newline:
    #2
  }
  {  }

\msg_new:nnnn { codehl / settings } { struct info }
  {
    \msg_line_context: \iow_newline:
    Settings ~ ID ~\{#1\}~ (without ~outer ~blaces): \iow_newline:
    #2
  }
  {  }

\msg_new:nnnn { codehl / settings } { active }
  {
    \msg_line_context: \iow_newline:
    Currently  ~ active ~ settings ~ (without ~outer ~blaces): \iow_newline:
    #1
  }
  {  }

\msg_new:nnnn { codehl / display } { undef }
  {
    \msg_line_context: \iow_newline:
   (#1) ~Can't ~ extend ~ an ~ undefined/void~ #2.
  }
  {
    To~be~ able~ to ~ extend ~ the ~ definitions ~ of ~ a ~ #2 ~ set, ~ first ~ a ~ valid~ one
    ~ has ~ to ~ be ~ selected~ with ~ \codehl_settings:n.
  }

\msg_new:nnnn { codehl / display } { based on err }
  {
    \msg_line_context: \iow_newline:
   (#1) ~Can't ~ use ~ based ~on ~ key ~ on~ this ~ context.
  }
  {
    Based~ on ~ keys ~ aren't ~ alowed ~ when ~ (late) ~ extending ~ the ~ definition ~ of ~ a ~ #2 ~ set.
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     pre-registering languages/keywords sets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\prop_new_linked:N \g__codehl_predef_lang_prop
\prop_new_linked:N \g__codehl_predef_keyset_prop
\prop_new_linked:N \g__codehl_predef_hlset_prop
\prop_new_linked:N \g__codehl_predef_basefmt_prop
\prop_new_linked:N \g__codehl_predef_settings_prop

\prop_new_linked:N \g__codehl_loaded_files_prop

\cs_new_protected:Npn \__codehl_lang_register:nn #1#2
  {
    \prop_gput:Nnn \g__codehl_predef_lang_prop
      { #1 } { #2 }
  }
\cs_new_protected:Npn \__codehl_keyset_register:nn #1#2
  {
    \prop_gput:Nnn \g__codehl_predef_keyset_prop
      { #1 } { #2 }
  }
\cs_new_protected:Npn \__codehl_hlset_register:nn #1#2
  {
    \prop_gput:Nnn \g__codehl_predef_hlset_prop
      { #1 } { #2 }
  }
\cs_new_protected:Npn \__codehl_basefmt_register:nn #1#2
  {
    \prop_gput:Nnn \g__codehl_predef_basefmt_prop
      { #1 } { #2 }
  }
\cs_new_protected:Npn \__codehl_settings_register:nn #1#2
  {
    \prop_gput:Nnn \g__codehl_predef_settings_prop
      { #1 } { #2 }
  }

\msg_new:nnnn { codehl / reg } { reg info }
  {
    \msg_line_context: \iow_newline:
    These ~ are ~ the ~ currently ~ known ~ (pre-registered) ~ #1: \iow_newline:
   #2
  }
  { }

\msg_new:nnnn { codehl / reg } { def info }
  {
    \msg_line_context: \iow_newline:
    These ~ are ~ the ~ currently ~ defined ~ #1: \iow_newline:
   #2
  }
  { }

\cs_new_protected:Npn \__codehl_reg_info:Nn #1#2
  {
    \tl_clear:N \l__codehl_tmpa_tl
    \prop_if_empty:NTF #1
      {
        \tl_set:Nn \l__codehl_tmpa_tl
          {~-NONE-~}
      }
      {
        \prop_map_inline:Nn #1
          {
            \tl_put_right:Nn \l__codehl_tmpa_tl
              {in ~ file:~##2 ~=> ~ ##1 \iow_newline:}
          }
      }
    \msg_show:nnnx { codehl / reg } { reg info }
      { #2 }
      \l__codehl_tmpa_tl
  }

\cs_new_protected:Npn \__codehl_def_info:Nn #1#2
  {
    \tl_clear:N \l__codehl_tmpa_tl
    \prop_if_empty:NTF #1
      {
        \tl_set:Nn \l__codehl_tmpa_tl
          {~-NONE-~}
      }
      {
        \prop_map_inline:Nn #1
          {
            \str_if_eq:nnTF { ##1 } { ##2 }
              {
                \tl_put_right:Nn \l__codehl_tmpa_tl
                  { ~ ##1 \iow_newline: }
              }
              {
                \tl_put_right:Nn \l__codehl_tmpa_tl
                  { ~ ##1 ~=> ~ ##2 \iow_newline: }
              }
          }
      }
    \msg_show:nnnx { codehl / reg } { def info }
      { #2 }
      \l__codehl_tmpa_tl
  }

\keys_define:nn { codehl / reg info }
  {
    registered ~ lang .code:n =
      {
        \__codehl_reg_info:Nn
          \g__codehl_predef_lang_prop
          { languages }
      }  ,
    registered ~ keyset .code:n =
      {
        \__codehl_reg_info:Nn
          \g__codehl_predef_keyset_prop
          { keyword ~sets ~(keyset) }
      }  ,
    registered ~ hlset .code:n =
      {
        \__codehl_reg_info:Nn
          \g__codehl_predef_hlset_prop
          { highlight ~sets ~(hlset) }
      }  ,
    registered ~ basefmt .code:n =
      {
        \__codehl_reg_info:Nn
          \g__codehl_predef_basefmt_prop
          { base ~ format ~sets ~(basefmt) }
      }  ,
    registered ~ settings .code:n =
      {
        \__codehl_reg_info:Nn
          \g__codehl_predef_settings_prop
          { settings }
      }  ,
    all ~ registered .meta:n = { registered ~ lang, registered ~ keyset, registered ~ hlset, registered ~ basefmt, registered ~ settings }  ,

    defined ~ lang .code:n =
      {
        \__codehl_def_info:Nn
          \l__codehl_sets_lang_prop
          { languages }
      }  ,
    defined ~ keyset .code:n =
      {
        \__codehl_def_info:Nn
          \l__codehl_sets_keyset_prop
          { Keywords ~sets ~(keyset) }
      }  ,
    defined ~ hlset .code:n =
      {
        \__codehl_def_info:Nn
          \l__codehl_sets_hlset_prop
          { highlight ~sets ~(hlset) }
      }  ,
    defined ~ basefmt .code:n =
      {
        \__codehl_def_info:Nn
          \l__codehl_sets_basefmt_prop
          { base ~ format ~sets ~(basefmt) }
      }  ,
    defined ~ settings .code:n =
      {
        \__codehl_def_info:Nn
          \l__codehl_sets_settings_prop
          { settings }
      }  ,
    all ~ defined .meta:n = { defined ~ lang, defined ~ keyset, defined ~ hlset, defined ~ basefmt, defined ~ settings }  ,

    lang  ~ show .code:n =
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \codehl_lang_show:n { ##1 }
          }
      }  ,
    lang  ~ show ~ all.code:n =
      {
        \prop_map_inline:Nn \l__codehl_sets_lang_prop
          {
            \codehl_lang_show:n { ##1 }
          }
      }  ,

    keyset  ~ show .code:n =
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \codehl_keyset_show:n { ##1 }
          }
      }  ,
    keyset  ~ show ~ all.code:n =
      {
        \prop_map_inline:Nn \l__codehl_sets_keyset_prop
          {
            \codehl_keyset_show:n { ##1 }
          }
      }  ,

    hlset  ~ show .code:n =
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \codehl_hlset_show:n { ##1 }
          }
      }  ,
    hlset  ~ show ~ all.code:n =
      {
        \prop_map_inline:Nn \l__codehl_sets_hlset_prop
          {
            \codehl_hlset_show:n { ##1 }
          }
      }  ,

    basefmt  ~ show .code:n =
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \codehl_basefmt_show:n { ##1 }
          }
      }  ,
    basefmt  ~ show ~ all.code:n =
      {
        \prop_map_inline:Nn \l__codehl_sets_basefmt_prop
          {
            \codehl_basefmt_show:n { ##1 }
          }
      }  ,

    settings  ~ show .code:n =
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \codehl_settings_show:n { ##1 }
          }
        \codehl_settings_show:n { }
      }  ,
    settings  ~ show ~ all.code:n =
      {
        \prop_map_inline:Nn \l__codehl_sets_settings_prop
          {
            \codehl_settings_show:n { ##1 }
          }
        \codehl_settings_show:n { }
      }  ,
  }

\cs_new_protected:Npn \codehl_show:n #1
  {
    \keys_set:nn { codehl / reg info } { #1 }
  }
\cs_set_eq:NN \hlShow \codehl_show:n

\prg_new_protected_conditional:Npnn \__codehl_lang_load_if_predef:n #1 { TF }
  {
        \prop_get:NnNTF \g__codehl_predef_lang_prop
          { #1 } \l__codehl_tmpa_tl
          {
            \prop_if_in:NoTF \g__codehl_loaded_files_prop
              \l__codehl_tmpa_tl
              { }
              {
                \prop_gput:Non \g__codehl_loaded_files_prop
                  \l__codehl_tmpa_tl { }
                \file_input:V \l__codehl_tmpa_tl
              }
            \prg_return_true:
          }
          { \prg_return_false: }
  }

\cs_new_protected:Npn \codehl_lang_preload:n #1
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \__codehl_lang_load_if_predef:nTF { ##1 }
          { }
          { %err
            \msg_error:nnnn { codehl / lang } { pre def }
              { predef01 } { ##1 }
          }
      }
  }
\cs_set_eq:NN \hlLangLoad  \codehl_lang_preload:n

\prg_new_protected_conditional:Npnn \__codehl_keyset_load_if_predef:n #1 { TF }
  {
        \prop_get:NnNTF \g__codehl_predef_keyset_prop
          { #1 } \l__codehl_tmpa_tl
          {
            \prop_if_in:NoTF \g__codehl_loaded_files_prop
              \l__codehl_tmpa_tl
              { }
              {
                \prop_gput:Non \g__codehl_loaded_files_prop
                  \l__codehl_tmpa_tl { }
                \file_input:V \l__codehl_tmpa_tl
              }
            \prg_return_true:
          }
          { \prg_return_false: }
  }

\cs_new_protected:Npn \codehl_keyset_preload:n #1
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \__codehl_keyset_load_if_predef:nTF { ##1 }
          { }
          { %err
            \msg_error:nnnn { codehl / keyset } { pre def }
              { predef02 } { ##1 }
          }
      }
  }
\cs_set_eq:NN \hlKeysetLoad  \codehl_keyset_preload:n

\prg_new_protected_conditional:Npnn \__codehl_hlset_load_if_predef:n #1 { TF }
  {
        \prop_get:NnNTF \g__codehl_predef_hlset_prop
          { #1 } \l__codehl_tmpa_tl
          {
            \prop_if_in:NoTF \g__codehl_loaded_files_prop
              \l__codehl_tmpa_tl
              { }
              {
                \prop_gput:Non \g__codehl_loaded_files_prop
                  \l__codehl_tmpa_tl { }
                \file_input:V \l__codehl_tmpa_tl
              }
            \prg_return_true:
          }
          { \prg_return_false: }
  }

\cs_new_protected:Npn \codehl_hlset_preload:n #1
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \__codehl_hlset_load_if_predef:nTF { ##1 }
          { }
          { %err
            \msg_error:nnnn { codehl / hlset } { pre def }
              { predef02 } { ##1 }
          }
      }
  }
\cs_set_eq:NN \hlHLsetLoad  \codehl_hlset_preload:n

\prg_new_protected_conditional:Npnn \__codehl_basefmt_load_if_predef:n #1 { TF }
  {
        \prop_get:NnNTF \g__codehl_predef_basefmt_prop
          { #1 } \l__codehl_tmpa_tl
          {
            \prop_if_in:NoTF \g__codehl_loaded_files_prop
              \l__codehl_tmpa_tl
              { }
              {
                \prop_gput:Non \g__codehl_loaded_files_prop
                  \l__codehl_tmpa_tl { }
                \file_input:V \l__codehl_tmpa_tl
              }
            \prg_return_true:
          }
          { \prg_return_false: }
  }

\cs_new_protected:Npn \codehl_basefmt_preload:n #1
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \__codehl_basefmt_load_if_predef:nTF { ##1 }
          { }
          { %err
            \msg_error:nnnn { codehl / basefmt } { pre def }
              { predef02 } { ##1 }
          }
      }
  }
\cs_set_eq:NN \hlBasefmtLoad  \codehl_basefmt_preload:n

\prg_new_protected_conditional:Npnn \__codehl_settings_load_if_predef:n #1 { TF }
  {
        \prop_get:NnNTF \g__codehl_predef_settings_prop
          { #1 } \l__codehl_tmpa_tl
          {
            \prop_if_in:NoTF \g__codehl_loaded_files_prop
              \l__codehl_tmpa_tl
              { }
              {
                \prop_gput:Non \g__codehl_loaded_files_prop
                  \l__codehl_tmpa_tl { }
                \file_input:V \l__codehl_tmpa_tl
              }
            \prg_return_true:
          }
          { \prg_return_false: }
  }

\cs_new_protected:Npn \codehl_settings_preload:n #1
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \__codehl_settings_load_if_predef:nTF { ##1 }
          { }
          { %err
            \msg_error:nnnn { codehl / settings } { pre def }
              { predef02 } { ##1 }
          }
      }
  }
\cs_set_eq:NN \hlSettingsLoad  \codehl_settings_preload:n

%%%%%%%
%%% auxiliary, hack, commands
%%%
%%% \ProvidesExplFile :
%%%      it doesn't save the current code régime (like \ProvidesExplClass or \ProvidesExplPackage)
%%%      and it doesn't restore the code régime at its end... :/
%%% The hack below saves and restore \l__kernel_expl_bool
%%%%%%%
\globalstack_csnew:n    { __codehl_preexpl_stack }
\cs_generate_variant:Nn  \__codehl_preexpl_stack_gpush:n { e }

\bool_new:N \l__codehl_preexpl_bool
\cs_new_protected:Npn \__codehl_explfile_test:
  {
    \bool_if:NTF \l__codehl_preexpl_bool
      {
        \__codehl_preexpl_stack_gpush:n
          { \bool_set_true:N \l__codehl_preexpl_bool }
      }
      {
        \__codehl_preexpl_stack_gpush:n
          { \bool_set_false:N \l__codehl_preexpl_bool }
      }
    
    \bool_set_eq:NN \l__codehl_preexpl_bool  \l__kernel_expl_bool  %%% yeah, this shouldn't happen... but, ProvidesExplFile doesn't account for it... :/
    \bool_if:NTF \l__codehl_preexpl_bool
      {  }
      { \ExplSyntaxOn }

  }
\cs_set_eq:NN \hlExplFileTest \__codehl_explfile_test:

\cs_new_protected:Npn \__codehl_explfile_out:
  {
    \bool_if:NTF \l__codehl_preexpl_bool
      {  }
      { \ExplSyntaxOff }
    \__codehl_preexpl_stack_gpop:
  }
\cs_set_eq:NN \hlExplFileOut \__codehl_explfile_out:

\bool_if:NT \l__codehl_register_bool
  {
    %%%%%%%
    %%% "sets" for double-check/validation
    %%%%%%%
    \__codehl_lang_register:nn { 00 } { codehighlight-00.def }
    \__codehl_lang_register:nn { 01 } { codehighlight-01.def }
    \__codehl_lang_register:nn { 02 } { codehighlight-02.def }
    \__codehl_lang_register:nn { 03 } { codehighlight-03.def }
    \__codehl_lang_register:nn { 04 } { codehighlight-04.def }
    \__codehl_lang_register:nn { 05 } { codehighlight-05.def }
    \__codehl_lang_register:nn { 06 } { codehighlight-06.def }
    \__codehl_lang_register:nn { 07 } { codehighlight-07.def }
    \__codehl_lang_register:nn { 08 } { codehighlight-08.def }
    \__codehl_lang_register:nn { 09 } { codehighlight-09.def }
    \__codehl_lang_register:nn { 0A } { codehighlight-0A.def }
    \__codehl_lang_register:nn { 0B } { codehighlight-0B.def }
    \__codehl_lang_register:nn { 0C } { codehighlight-0C.def }
    \__codehl_lang_register:nn { 0D } { codehighlight-0D.def }
    \__codehl_lang_register:nn { 0E } { codehighlight-0E.def }
    \__codehl_lang_register:nn { 0F } { codehighlight-0F.def }

    \__codehl_lang_register:nn { 10 } { codehighlight-10.def }
    \__codehl_lang_register:nn { 11 } { codehighlight-11.def }
    \__codehl_lang_register:nn { 12 } { codehighlight-12.def }
    \__codehl_lang_register:nn { 13 } { codehighlight-13.def }
    \__codehl_lang_register:nn { 14 } { codehighlight-14.def }
    \__codehl_lang_register:nn { 15 } { codehighlight-15.def }
    \__codehl_lang_register:nn { 16 } { codehighlight-16.def }
    \__codehl_lang_register:nn { 17 } { codehighlight-17.def }
    \__codehl_lang_register:nn { 18 } { codehighlight-18.def }
    \__codehl_lang_register:nn { 19 } { codehighlight-19.def }
    \__codehl_lang_register:nn { 1A } { codehighlight-1A.def }
    \__codehl_lang_register:nn { 1B } { codehighlight-1B.def }
    \__codehl_lang_register:nn { 1C } { codehighlight-1C.def }
    \__codehl_lang_register:nn { 1D } { codehighlight-1D.def }
    \__codehl_lang_register:nn { 1E } { codehighlight-1E.def }
    \__codehl_lang_register:nn { 1F } { codehighlight-1F.def }

    \__codehl_lang_register:nn { 20 } { codehighlight-20.def }
    \__codehl_lang_register:nn { 21 } { codehighlight-21.def }
    \__codehl_lang_register:nn { 22 } { codehighlight-22.def }
    \__codehl_lang_register:nn { 23 } { codehighlight-23.def }
    \__codehl_lang_register:nn { 24 } { codehighlight-24.def }
    \__codehl_lang_register:nn { 25 } { codehighlight-25.def }
    \__codehl_lang_register:nn { 26 } { codehighlight-26.def }
    \__codehl_lang_register:nn { 27 } { codehighlight-27.def }
    \__codehl_lang_register:nn { 28 } { codehighlight-28.def }
    \__codehl_lang_register:nn { 29 } { codehighlight-29.def }
    \__codehl_lang_register:nn { 2A } { codehighlight-2A.def }
    \__codehl_lang_register:nn { 2B } { codehighlight-2B.def }
    \__codehl_lang_register:nn { 2C } { codehighlight-2C.def }
    \__codehl_lang_register:nn { 2D } { codehighlight-2D.def }
    \__codehl_lang_register:nn { 2E } { codehighlight-2E.def }
    \__codehl_lang_register:nn { 2F } { codehighlight-2F.def }
  }

%%%%%%%
%%% pre-defined sets (generate from above...)
%%%%%%%

\__codehl_lang_register:nn   { C.89                      } { codehighlight-00.def }
\__codehl_lang_register:nn   { C.99                      } { codehighlight-00.def }
\__codehl_lang_register:nn   { C.11                      } { codehighlight-00.def }
\__codehl_lang_register:nn   { C.17                      } { codehighlight-00.def }
\__codehl_lang_register:nn   { C.23                      } { codehighlight-00.def }
\__codehl_keyset_register:nn { C.89                      } { codehighlight-00.def }
\__codehl_keyset_register:nn { C.99                      } { codehighlight-00.def }
\__codehl_keyset_register:nn { C.11                      } { codehighlight-00.def }
\__codehl_keyset_register:nn { C.17                      } { codehighlight-00.def }
\__codehl_keyset_register:nn { C.23                      } { codehighlight-00.def }
\__codehl_lang_register:nn   { C++.98                    } { codehighlight-00.def }
\__codehl_lang_register:nn   { C++.11                    } { codehighlight-00.def }
\__codehl_lang_register:nn   { C++.20                    } { codehighlight-00.def }
\__codehl_lang_register:nn   { C++.23                    } { codehighlight-00.def }
\__codehl_keyset_register:nn { C++.98                    } { codehighlight-00.def }
\__codehl_keyset_register:nn { C++.11                    } { codehighlight-00.def }
\__codehl_keyset_register:nn { C++.20                    } { codehighlight-00.def }
\__codehl_keyset_register:nn { C++.23                    } { codehighlight-00.def }
\__codehl_lang_register:nn   { C                         } { codehighlight-00.def }
\__codehl_keyset_register:nn { C                         } { codehighlight-00.def }
\__codehl_lang_register:nn   { C++                       } { codehighlight-00.def }
\__codehl_keyset_register:nn { C++                       } { codehighlight-00.def }
\__codehl_lang_register:nn   { Csharp.1                  } { codehighlight-01.def }
\__codehl_lang_register:nn   { Csharp.6                  } { codehighlight-01.def }
\__codehl_lang_register:nn   { Csharp.11                 } { codehighlight-01.def }
\__codehl_lang_register:nn   { Csharp.13                 } { codehighlight-01.def }
\__codehl_keyset_register:nn { Csharp.1                  } { codehighlight-01.def }
\__codehl_keyset_register:nn { Csharp.6                  } { codehighlight-01.def }
\__codehl_keyset_register:nn { Csharp.13                 } { codehighlight-01.def }
\__codehl_lang_register:nn   { Csharp                    } { codehighlight-01.def }
\__codehl_keyset_register:nn { Csharp                    } { codehighlight-01.def }
\__codehl_lang_register:nn   { java.SE25                 } { codehighlight-02.def }
\__codehl_keyset_register:nn { java.SE25                 } { codehighlight-02.def }
\__codehl_lang_register:nn   { java                      } { codehighlight-02.def }
\__codehl_keyset_register:nn { java                      } { codehighlight-02.def }
\__codehl_lang_register:nn   { python.2.7                } { codehighlight-03.def }
\__codehl_lang_register:nn   { python.3.0                } { codehighlight-03.def }
\__codehl_lang_register:nn   { python.3.6                } { codehighlight-03.def }
\__codehl_lang_register:nn   { python.3.12               } { codehighlight-03.def }
\__codehl_keyset_register:nn { python.2.7                } { codehighlight-03.def }
\__codehl_keyset_register:nn { python.3.0                } { codehighlight-03.def }
\__codehl_keyset_register:nn { python.3.6                } { codehighlight-03.def }
\__codehl_keyset_register:nn { python.3.12               } { codehighlight-03.def }
\__codehl_lang_register:nn   { python                    } { codehighlight-03.def }
\__codehl_keyset_register:nn { python                    } { codehighlight-03.def }
\__codehl_lang_register:nn   { SQL.92                    } { codehighlight-04.def }
\__codehl_lang_register:nn   { SQL.23                    } { codehighlight-04.def }
\__codehl_keyset_register:nn { SQL.92                    } { codehighlight-04.def }
\__codehl_keyset_register:nn { SQL.23                    } { codehighlight-04.def }
\__codehl_keyset_register:nn { SQL.PostgreSQL            } { codehighlight-04.def }
\__codehl_keyset_register:nn { SQL.MySQL                 } { codehighlight-04.def }
\__codehl_lang_register:nn   { PL/SQL                    } { codehighlight-04.def }
\__codehl_keyset_register:nn { PL/SQL                    } { codehighlight-04.def }
\__codehl_lang_register:nn   { SQL                       } { codehighlight-04.def }
\__codehl_keyset_register:nn { SQL                       } { codehighlight-04.def }
\__codehl_lang_register:nn   { perl                      } { codehighlight-05.def }
\__codehl_keyset_register:nn { perl                      } { codehighlight-05.def }
\__codehl_lang_register:nn   { lua.5.5                   } { codehighlight-06.def }
\__codehl_keyset_register:nn { lua.5.5                   } { codehighlight-06.def }
\__codehl_lang_register:nn   { lua                       } { codehighlight-06.def }
\__codehl_keyset_register:nn { lua                       } { codehighlight-06.def }
\__codehl_lang_register:nn   { html.5                    } { codehighlight-07.def }
\__codehl_keyset_register:nn { html.5                    } { codehighlight-07.def }
\__codehl_lang_register:nn   { html                      } { codehighlight-07.def }
\__codehl_keyset_register:nn { html                      } { codehighlight-07.def }
\__codehl_lang_register:nn   { php.8                     } { codehighlight-08.def }
\__codehl_keyset_register:nn { php.8                     } { codehighlight-08.def }
\__codehl_keyset_register:nn { php.mysqli                } { codehighlight-08.def }
\__codehl_keyset_register:nn { php.pgsql                 } { codehighlight-08.def }
\__codehl_keyset_register:nn { php.xml-json              } { codehighlight-08.def }
\__codehl_keyset_register:nn { php.date                  } { codehighlight-08.def }
\__codehl_lang_register:nn   { php                       } { codehighlight-08.def }
\__codehl_keyset_register:nn { php                       } { codehighlight-08.def }
\__codehl_lang_register:nn   { JavaScript                } { codehighlight-09.def }
\__codehl_keyset_register:nn { JavaScript                } { codehighlight-09.def }
\__codehl_lang_register:nn   { scala.3.10                } { codehighlight-0A.def }
\__codehl_keyset_register:nn { scala.3.10                } { codehighlight-0A.def }
\__codehl_lang_register:nn   { scala                     } { codehighlight-0A.def }
\__codehl_keyset_register:nn { scala                     } { codehighlight-0A.def }
\__codehl_lang_register:nn   { VB.6                      } { codehighlight-0B.def }
\__codehl_lang_register:nn   { VB.17                     } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VB.6                      } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VB.8                      } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VB.12                     } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VB.17                     } { codehighlight-0B.def }
\__codehl_lang_register:nn   { VisualBasicClassic        } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VisualBasicClassic        } { codehighlight-0B.def }
\__codehl_lang_register:nn   { VisualBasic               } { codehighlight-0B.def }
\__codehl_keyset_register:nn { VisualBasic               } { codehighlight-0B.def }
\__codehl_lang_register:nn   { Delphi.7                  } { codehighlight-0C.def }
\__codehl_lang_register:nn   { Delphi.13                 } { codehighlight-0C.def }
\__codehl_keyset_register:nn { Delphi.7                  } { codehighlight-0C.def }
\__codehl_keyset_register:nn { Delphi.XE8                } { codehighlight-0C.def }
\__codehl_keyset_register:nn { Delphi.13                 } { codehighlight-0C.def }
\__codehl_lang_register:nn   { Delphi                    } { codehighlight-0C.def }
\__codehl_keyset_register:nn { Delphi                    } { codehighlight-0C.def }
\__codehl_lang_register:nn   { Modula-2                  } { codehighlight-0D.def }
\__codehl_keyset_register:nn { Modula-2                  } { codehighlight-0D.def }
\__codehl_lang_register:nn   { Oberon                    } { codehighlight-0D.def }
\__codehl_keyset_register:nn { Oberon                    } { codehighlight-0D.def }
\__codehl_lang_register:nn   { Oberon+                   } { codehighlight-0D.def }
\__codehl_keyset_register:nn { Oberon+                   } { codehighlight-0D.def }
\__codehl_lang_register:nn   { COBOL.74                  } { codehighlight-0E.def }
\__codehl_lang_register:nn   { COBOL.85                  } { codehighlight-0E.def }
\__codehl_lang_register:nn   { COBOL.02                  } { codehighlight-0E.def }
\__codehl_keyset_register:nn { COBOL.74                  } { codehighlight-0E.def }
\__codehl_keyset_register:nn { COBOL.85                  } { codehighlight-0E.def }
\__codehl_keyset_register:nn { COBOL.02                  } { codehighlight-0E.def }
\__codehl_lang_register:nn   { COBOL                     } { codehighlight-0E.def }
\__codehl_keyset_register:nn { COBOL                     } { codehighlight-0E.def }
\__codehl_lang_register:nn   { FORTRAN.77                } { codehighlight-0F.def }
\__codehl_lang_register:nn   { FORTRAN.95                } { codehighlight-0F.def }
\__codehl_lang_register:nn   { FORTRAN.03                } { codehighlight-0F.def }
\__codehl_lang_register:nn   { FORTRAN.18                } { codehighlight-0F.def }
\__codehl_keyset_register:nn { FORTRAN.77                } { codehighlight-0F.def }
\__codehl_keyset_register:nn { FORTRAN.95                } { codehighlight-0F.def }
\__codehl_keyset_register:nn { FORTRAN.03                } { codehighlight-0F.def }
\__codehl_keyset_register:nn { FORTRAN.18                } { codehighlight-0F.def }
\__codehl_lang_register:nn   { FORTRAN                   } { codehighlight-0F.def }
\__codehl_keyset_register:nn { FORTRAN                   } { codehighlight-0F.def }
\__codehl_lang_register:nn   { Rust.1.99                 } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust.1.99                 } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust.1.99.core            } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust.1.99.alloc           } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust.1.99.std             } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust.1.99.all             } { codehighlight-10.def }
\__codehl_lang_register:nn   { Rust                      } { codehighlight-10.def }
\__codehl_keyset_register:nn { Rust                      } { codehighlight-10.def }
\__codehl_lang_register:nn   { R                         } { codehighlight-11.def }
\__codehl_keyset_register:nn { R                         } { codehighlight-11.def }
\__codehl_lang_register:nn   { Ada.95                    } { codehighlight-12.def }
\__codehl_lang_register:nn   { Ada.22                    } { codehighlight-12.def }
\__codehl_keyset_register:nn { Ada.95                    } { codehighlight-12.def }
\__codehl_keyset_register:nn { Ada.22                    } { codehighlight-12.def }
\__codehl_lang_register:nn   { Ada                       } { codehighlight-12.def }
\__codehl_keyset_register:nn { Ada                       } { codehighlight-12.def }
\__codehl_lang_register:nn   { julia.1.x                 } { codehighlight-13.def }
\__codehl_keyset_register:nn { julia.1.x                 } { codehighlight-13.def }
\__codehl_lang_register:nn   { julia                     } { codehighlight-13.def }
\__codehl_keyset_register:nn { julia                     } { codehighlight-13.def }
\__codehl_lang_register:nn   { Ruby.4                    } { codehighlight-14.def }
\__codehl_keyset_register:nn { Ruby.4                    } { codehighlight-14.def }
\__codehl_lang_register:nn   { Ruby                      } { codehighlight-14.def }
\__codehl_keyset_register:nn { Ruby                      } { codehighlight-14.def }
\__codehl_lang_register:nn   { lisp.CL                   } { codehighlight-15.def }
\__codehl_keyset_register:nn { lisp.CL                   } { codehighlight-15.def }
\__codehl_lang_register:nn   { CommonLisp                } { codehighlight-15.def }
\__codehl_keyset_register:nn { CommonLisp                } { codehighlight-15.def }
\__codehl_lang_register:nn   { elisp                     } { codehighlight-16.def }
\__codehl_keyset_register:nn { elisp                     } { codehighlight-16.def }
\__codehl_keyset_register:nn { elisp.fullset             } { codehighlight-17.def }
\__codehl_lang_register:nn   { awk.posix                 } { codehighlight-18.def }
\__codehl_lang_register:nn   { awk.gnu                   } { codehighlight-18.def }
\__codehl_keyset_register:nn { awk.posix                 } { codehighlight-18.def }
\__codehl_keyset_register:nn { awk.gnu                   } { codehighlight-18.def }
\__codehl_lang_register:nn   { postscript.level3         } { codehighlight-19.def }
\__codehl_keyset_register:nn { postscript.level3         } { codehighlight-19.def }
\__codehl_lang_register:nn   { postscript                } { codehighlight-19.def }
\__codehl_keyset_register:nn { postscript                } { codehighlight-19.def }
\__codehl_lang_register:nn   { MetaFont                  } { codehighlight-1A.def }
\__codehl_lang_register:nn   { MetaPost                  } { codehighlight-1A.def }
\__codehl_keyset_register:nn { MetaFont                  } { codehighlight-1A.def }
\__codehl_keyset_register:nn { MetaPost                  } { codehighlight-1A.def }
\__codehl_lang_register:nn   { TeX                       } { codehighlight-1B.def }
\__codehl_lang_register:nn   { TeX.l3                    } { codehighlight-1B.def }
\__codehl_lang_register:nn   { TeX.l3sign                } { codehighlight-1B.def }
\__codehl_keyset_register:nn { TeX.common                } { codehighlight-1B.def }
\__codehl_keyset_register:nn { TeX.primitives            } { codehighlight-1C.def }
\__codehl_keyset_register:nn { TeX.pdfTeX                } { codehighlight-1D.def }
\__codehl_keyset_register:nn { TeX.luaTeX                } { codehighlight-1D.def }
\__codehl_keyset_register:nn { TeX.l3kernel              } { codehighlight-1E.def }
\__codehl_keyset_register:nn { TeX.l3kernelsign          } { codehighlight-1F.def }
\__codehl_keyset_register:nn { TeX.l3exp                 } { codehighlight-20.def }
\__codehl_keyset_register:nn { TeX.l3expsign             } { codehighlight-21.def }
\__codehl_keyset_register:nn { TeX.l3ams                 } { codehighlight-22.def }
\__codehl_keyset_register:nn { TeX.l3amssign             } { codehighlight-23.def }
\__codehl_keyset_register:nn { TeX.l3pgf                 } { codehighlight-24.def }
\__codehl_keyset_register:nn { TeX.l3pgfsign             } { codehighlight-25.def }
\__codehl_keyset_register:nn { TeX.l3bibtex              } { codehighlight-26.def }
\__codehl_keyset_register:nn { TeX.l3bibtexsign          } { codehighlight-27.def }
\__codehl_keyset_register:nn { TeX.babel                 } { codehighlight-28.def }
\__codehl_keyset_register:nn { TeX.hyperref              } { codehighlight-29.def }
\__codehl_keyset_register:nn { TeX.kernel                } { codehighlight-2A.def }
\__codehl_keyset_register:nn { TeX.xpacks                } { codehighlight-2B.def }
\__codehl_keyset_register:nn { TeX.ams                   } { codehighlight-2C.def }
\__codehl_keyset_register:nn { TeX.bibtex                } { codehighlight-2D.def }
\__codehl_keyset_register:nn { TeX.pgf                   } { codehighlight-2E.def }
\__codehl_keyset_register:nn { TeX.pgfplots              } { codehighlight-2F.def }

%%%%%%%
%%% package settings
%%%%%%%

\keys_define:nn { codehl / pkg settings }
  {

    info / note .choices:nn =
      { note , info , none }
      {
        \if_case:w \l_keys_choice_int
        \or:
          \msg_redirect_name:nnn { codehl / lang } { info note } {note }
          \msg_redirect_name:nnn { codehl / keyset } { info note } { note }
          \msg_redirect_name:nnn { codehl / hlset } { info note } { note }
          \msg_redirect_name:nnn { codehl / basefmt } { info note } { note }
          \msg_redirect_name:nnn { codehl / settings } { info note } { note }
        \or:
          \msg_redirect_name:nnn { codehl / lang } { info note } { info }
          \msg_redirect_name:nnn { codehl / keyset } { info note } { info }
          \msg_redirect_name:nnn { codehl / hlset } { info note } { info }
          \msg_redirect_name:nnn { codehl / basefmt } { info note } { info }
          \msg_redirect_name:nnn { codehl / settings } { info note } { info }
        \or:
          \msg_redirect_name:nnn { codehl / lang } { info note } { none }
          \msg_redirect_name:nnn { codehl / keyset } { info note } { none }
          \msg_redirect_name:nnn { codehl / hlset } { info note } { none }
          \msg_redirect_name:nnn { codehl / basefmt } { info note } { none }
          \msg_redirect_name:nnn { codehl / settings } { info note } { none }
        \fi:
      } ,
    info / note .default:n = all ,
  }

\cs_new_protected:Npn \codehl_pkg_settings:n #1
  {
    \keys_set:nn { codehl / pkg settings } { #1 }
  }
\cs_set_eq:NN \hlPkgSettings \codehl_pkg_settings:n

%%%%%%%
%%% the many variables
%%%%%%%

\tl_new:N     \l__codehl_def_basefmt_tl
\tl_new:N     \l__codehl_def_hlset_tl
\tl_new:N     \l__codehl_def_keyset_tl
\tl_new:N     \l__codehl_def_lang_tl
\tl_new:N     \l__codehl_def_settings_tl

\seq_new:N    \l__codehl_basedon_tmp_seq

\tl_new:N     \l__codehl_tmpa_tl
\tl_new:N     \l__codehl_tmpb_tl
\tl_new:N     \l__codehl_tmpab_tl
\tl_new:N     \l__codehl_tmpc_tl
\tl_new:N     \l__codehl_tmpd_tl
\tl_new:N     \l__codehl_tmpcd_tl
\tl_new:N     \l__codehl_tmpe_tl

\tl_new:N     \l__codehl_pattern_tmp_tl

\seq_new:N    \l__codehl_basedon_tmpa_seq
\int_new:N    \l__codehl_remapcount_int

\tl_new:N     \l__codehl_basedon_tmpa_tl
\tl_new:N     \l__codehl_basedon_tmpb_tl
\tl_new:N     \l__codehl_basedon_tmpc_tl
\tl_new:N     \l__codehl_basedon_tmpd_tl

%%%
%%% These are for: 1.if exist 2.alias
\prop_new_linked:N    \l__codehl_sets_lang_prop
\prop_new_linked:N    \l__codehl_sets_keyset_prop
\prop_new_linked:N    \l__codehl_sets_hlset_prop
\prop_new_linked:N    \l__codehl_sets_basefmt_prop
\prop_new_linked:N    \l__codehl_sets_settings_prop

\tl_new:N    \l__codehl_alias_lang_tl
\tl_new:N    \l__codehl_alias_keyset_tl
\tl_new:N    \l__codehl_alias_hlset_tl
\tl_new:N    \l__codehl_alias_basefmt_tl
\tl_new:N    \l__codehl_alias_settings_tl

\int_new:N    \l__codehl_lang_dlimit_cntA_int
\int_new:N    \l__codehl_lang_dlimit_cntB_int

\tl_new:N   \l__codehl_keyset_case_key_tl

\tl_new:N \l__codehl_lang_opt_key_tl
\tl_new:N \l__codehl_lang_opt_nestkey_tl
\tl_new:N \l__codehl_lang_opt_tagkey_tl

\bool_new:N   \l__codehl_tok_lineset_bool

\seq_new:N    \l__codehl_tmpi_seq
\seq_new:N    \l__codehl_tmpa_seq
\seq_new:N    \l__codehl_tmpb_seq

\bool_new:N   \l__codehl_activ_basefmt_change_bool
\bool_new:N   \l__codehl_activ_keyset_change_bool
\bool_new:N   \l__codehl_activ_hlset_change_bool
\bool_new:N   \l__codehl_activ_lang_change_bool

\bool_new:N   \l__codehl_display_bool
\tl_new:N     \l__codehl_tok_inline_aux_tl

\tl_new:N     \l__codehl_tok_tmpa_tl
\tl_new:N     \l__codehl_tok_tmpb_tl

\tl_new:N     \l__codehl_tok_activ_basefmt_tl
\tl_new:N     \l__codehl_tok_activ_hlset_tl
\tl_new:N     \l__codehl_tok_activ_keyset_tl
\tl_new:N     \l__codehl_tok_activ_lang_tl

\tl_new:N     \l__codehl_tok_curr_ident_tl
\tl_new:N     \l__codehl_tok_curr_token_tl

\tl_new:N     \l__codehl_tok_build_line_tl
\tl_new:N     \l__codehl_tok_build_line_tmp_tl
\tl_new:N     \l__codehl_tok_build_prekeywd_tl
\tl_new:N     \l__codehl_tok_build_keywd_tl
\tl_new:N     \l__codehl_tok_build_dlimit_tl
\tl_new:N     \l__codehl_tok_build_utf_tl

\tl_new:N     \l__codehl_tok_discard_tl

\int_new:N    \l__codehl_tok_line_int
\int_new:N    \l__codehl_tok_col_int
\int_new:N    \l__codehl_tok_gbbl_int
\int_new:N    \l__codehl_tok_gbbl_cnt_int

\coffin_new:N \l__codehl_linenum_coffin
\coffin_new:N \l__codehl_hrule_coffin
\coffin_new:N \l__codehl_vrule_coffin

\dim_new:N    \l__codehl_tok_Tsep_dim
\dim_new:N    \l__codehl_tok_Bsep_dim
\dim_new:N    \l__codehl_tok_Lsep_dim
\dim_new:N    \l__codehl_tok_Rsep_dim
\dim_new:N    \l__codehl_tok_Twidth_dim
\dim_new:N    \l__codehl_tok_Windent_dim
\dim_new:N    \l__codehl_tok_Rlinewidht_dim
\dim_new:N    \l__codehl_tok_Fsep_dim
\dim_new:N    \l__codehl_tok_Vrule_xtra_dim
\dim_new:N    \l__codehl_tok_Vrule_delta_dim
\dim_new:N    \l__codehl_tok_rule_wd_dim

\dim_new:N    \l__codehl_vrule_height_dim

\bool_new:N   \l__codehl_tok_stack_eol_bool

\cs_set:Npn   \__codehl_tok_end_scan: {}
\cs_set:Npn   \__codehl_tok_test_escape: {}
\cs_set:Npn   \__codehl_tok_start:N {}
\cs_set:Npn   \__codehl_tok_proc:N {}
\cs_set:Npn   \__codehl_tok_current_base:N {}

%%%%%%%
%%% yeah... for 'nested' identifiers
%%%%%%%
\bool_new:N   \l__codehl_tok_ident_bool
\tl_new:N     \l__codehl_tok_curr_tag_tl

%%%%%%%
%%% <tok> stack related ones
%%%%%%%
\bool_new:N \l__codehl_tok_upto_eol_bool

%%%%%%%
%%% for language definition / _scan: commandos
%%%%%%%
\prop_new_linked:N  \l__codehl_lang_BUILD_tr_prop       %%% replace patterns

\prop_new_linked:N  \l__codehl_lang_BUILD_tag_prop      %%% mark as <tag*> everything except <tag>
\prop_new_linked:N  \l__codehl_lang_BUILD_tagX_prop     %%% '1st' char based, nested scan
\prop_new_linked:N  \l__codehl_lang_BUILD_tagstr_prop   %%% also mark <ident> as <str*> (if to be nested)
\prop_new_linked:N  \l__codehl_lang_BUILD_tagstrX_prop  %%% '1st' char based, nested scan
\prop_new_linked:N  \l__codehl_lang_BUILD_tagcmt_prop
\prop_new_linked:N  \l__codehl_lang_BUILD_tagcmtX_prop  %%% '1st' char based, nested scan

\prop_new_linked:N \l__codehl_lang_BUILD_base_prop     %%% all but <!>
\prop_new_linked:N \l__codehl_lang_BUILD_basestr_prop  %%% also mark <ident> as <str*> (if to be nested)
\prop_new_linked:N \l__codehl_lang_BUILD_basestrX_prop %%% '1st' char based, nested scan
\prop_new_linked:N \l__codehl_lang_BUILD_basecmt_prop
\prop_new_linked:N \l__codehl_lang_BUILD_basecmtX_prop %%% '1st' char based, nested scan

\bool_new:N   \l__codehl_lang_BUILD_tagged_bool        %%% if any <tagged area> is defined
\bool_new:N   \l__codehl_lang_BUILD_tr_bool            %%% if <replace> is defined

\tl_new:N     \l__codehl_lang_build_postfix_tl         %%% post fix when building a nested/fmtless one

\tl_new:N     \l__codehl_peek_build_tmpC_tl
\tl_new:N     \l__codehl_peek_build_tmpD_tl

\tl_new:N     \l__codehl_peek_build_endscanT_tl
\tl_new:N     \l__codehl_peek_build_endscanF_tl

\tl_new:N     \l__codehl_peek_endscan_caseB_tl

\tl_new:N     \l__codehl_peek_build_scanTpre_tl
\tl_new:N     \l__codehl_peek_build_scanT_tl
\tl_new:N     \l__codehl_peek_build_scanF_tl

\tl_new:N \l__codehl_peek_end_regex_tl
\tl_new:N \l__codehl_peek_end_patt_tl
\tl_new:N \l__codehl_peek_beg_regex_tl
\tl_new:N \l__codehl_peek_beg_patt_tl

\tl_new:N \l__codehl_build_stack_tl

\tl_new:N \l__codehl_stack_cmt_tl
\tl_new:N \l__codehl_stack_cmtline_tl
\tl_new:N \l__codehl_stack_cmttex_tl
\tl_new:N \l__codehl_stack_cmttexline_tl
\tl_new:N \l__codehl_stack_cmtdisc_tl
\tl_new:N \l__codehl_stack_cmtdiscline_tl
\tl_new:N \l__codehl_stack_string_tl
\tl_new:N \l__codehl_stack_ident_tl

%% pois, pois (pt Portugal)
%\prg_set_eq_conditional:NNn \token_if_eq_charcode:nN \token_if_eq_charcode:NN { TF }
%\prg_generate_conditional_variant:Nnn \token_if_eq_charcode:nN { o } { TF }

\coffin_new:N \l__codehl_line_coffin
\coffin_new:N \l__codehl_lineb_coffin
\coffin_new:N \l__codehl_bckline_coffin
\dim_new:N    \l__codehl_coffin_ht_dim
\dim_new:N    \l__codehl_coffin_wd_dim

\group_begin:
  \char_set_catcode_other:n { `\^^J }

  \cs_new:Npn \__codehl_tok_coffin_line_proc:w #1 ^^J
    {
      \quark_if_nil:nTF { #1 }
      {
        \bool_if:NTF \l__codehl_tok_lineset_bool
          {
            \__codehl_Brule_coffin_attach:

            \coffin_typeset:Nnnnn \l__codehl_line_coffin
              { l } { b } { 0pt } { 0pt }
  %\coffin_show:N \l__codehl_line_coffin
            \skip_vertical:n { 0pt } %{ -0.05ex }{ -0.05ex }
            \bool_set_false:N \l__codehl_tok_lineset_bool
          }
          { }
        \cs_set_eq:NN \__codehl_tok_next_line:w \prg_do_nothing:
      }
      {

        \bool_if:NTF \l__codehl_tok_lineset_bool
          {
            \coffin_typeset:Nnnnn \l__codehl_line_coffin
              { l } { b } { 0pt } { 0pt }
  %\coffin_show:N \l__codehl_line_coffin
            \skip_vertical:n { 0pt } %{ -0.05ex }
            \bool_set_false:N \l__codehl_tok_lineset_bool
          }
          { }
        \tl_clear:N \l__codehl_tok_build_line_tl
        \tl_clear:N \l__codehl_tok_build_keywd_tl

        \__codehl_tok_prepgobble:  %%% this sets \__codehl_tok_proc:N  from \__codehl_tok_start:N

        \int_incr:N \l__codehl_tok_line_int
        \int_zero:N \l__codehl_tok_col_int

        \__codehl_tok_proc:N #1 \q_nil %%%
        \__codehl_tok_disp_line:
      }
      \__codehl_tok_next_line:w
    }

  \cs_new:Npn \__codehl_tok_inline_proc:w #1 ^^J
    {
      \quark_if_nil:nTF { #1 }
      {
        \cs_set_eq:NN \__codehl_tok_next_line:w \prg_do_nothing:
      }
      {
        \tl_clear:N \l__codehl_tok_build_line_tl
        \tl_clear:N \l__codehl_tok_build_keywd_tl

        \__codehl_tok_prepgobble:   %%% this sets \__codehl_tok_proc:N  from \__codehl_tok_start:N

        \int_incr:N \l__codehl_tok_line_int
        \int_zero:N \l__codehl_tok_col_int

        \__codehl_tok_proc:N #1 \q_nil %%%
        \__codehl_tok_disp_line:
      }
      \__codehl_tok_next_line:w
    }

\group_end:

%\makeatletter
%\box_new:N \strutboxX
%\setbox\strutboxX\hbox{ %
%  \vrule\@height.7\baselineskip
%        \@depth.5\baselineskip
%        \@width\z@}%
%\makeatother
%\def\strutX{ \relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi }

\cs_new_protected:Npn \__codehl_attach_leftnum:
  {
    \vcoffin_set:Nne \l__codehl_linenum_coffin { \marginparwidth }
      {
        \exp_not:N \raggedleft \exp_not:N \strut
        \exp_not:o \l__codehl_tok_style_numbersfmt_tl
        { \exp_not:V \l__codehl_tok_line_int }
      }
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { T }
      \l__codehl_linenum_coffin { r } { T }
      { - \l__codehl_tok_style_numberssep_tl } { 0pt }
  }

\cs_new_protected:Npn \__codehl_attach_rightnum:
  {
    \vcoffin_set:Nne \l__codehl_linenum_coffin { \marginparwidth }
      {
        \exp_not:N \raggedright \exp_not:N \strut
        \exp_not:o \l__codehl_tok_style_numbersfmt_tl
        { \exp_not:V \l__codehl_tok_line_int }
      }
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { r } { T }
      \l__codehl_linenum_coffin { l } { T }
      { \l__codehl_tok_style_numberssep_tl } { 0pt }
  }

\cs_new_protected:Npn \__codehl_attach_Trule:
  {
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { t }
      \l__codehl_hrule_coffin { l } { b }
      { - \l__codehl_tok_Fsep_dim - \l__codehl_tok_Rlinewidht_dim } { \l__codehl_tok_Tsep_dim }
    \cs_set_eq:NN \__codehl_set_Trule: \prg_do_nothing:
  }

\cs_new_protected:Npn \__codehl_attach_Brule:
  {
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { b }
      \l__codehl_hrule_coffin { l } { t }
      { - \l__codehl_tok_Fsep_dim  - \l__codehl_tok_Rlinewidht_dim  } { - \l__codehl_tok_Bsep_dim }
  }

\cs_new_protected:Npn \__codehl_attach_bckgnd:
  {
    \coffin_set_eq:NN \l__codehl_lineb_coffin \l__codehl_line_coffin

     %%% TODO: find a better solution!!
     %%% this is to 'assure' background continuity (no gaps)
    \dim_set:Ne \l__codehl_coffin_ht_dim { \coffin_ht_plus_dp:N \l__codehl_line_coffin + 1pt}

%    \dim_set:Ne \l__codehl_coffin_wd_dim { \coffin_wd:N \l__codehl_line_coffin }
    \dim_set:Ne \l__codehl_coffin_wd_dim { \l__codehl_tok_Twidth_dim }

    \vcoffin_set:Nne \l__codehl_bckline_coffin  { \l__codehl_tok_Twidth_dim }
      {
        \exp_not:N \color_select:n { \l__codehl_tok_style_bckgndcolor_tl }
        \exp_not:N \raggedright
        \exp_not:N \rule { \exp_not:V \l__codehl_coffin_wd_dim } { \exp_not:V \l__codehl_coffin_ht_dim }
      }
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { b }
      \l__codehl_bckline_coffin { l } { b }
      { 0pt } { 0pt }

    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { b }
      \l__codehl_lineb_coffin { l } { b }
      { 0pt } { 0pt }
  }

\cs_new_protected:Npn \__codehl_attach_Lrule_coffin:
  {
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { r } { vc }
      \l__codehl_vrule_coffin { l } { vc }
      { \l__codehl_tok_Rsep_dim } { \l__codehl_tok_Vrule_delta_dim }
  }

\cs_new_protected:Npn \__codehl_attach_Rrule:
  {
    \coffin_attach:NnnNnnnn
      \l__codehl_line_coffin { l } { vc }
      \l__codehl_vrule_coffin { r } { vc }
      { - \l__codehl_tok_Lsep_dim } { \l__codehl_tok_Vrule_delta_dim }
  }

\cs_new_protected:Npn \__codehl_vrule_set_coffin:
  {
    \dim_set:Nn \l__codehl_vrule_height_dim
      { \coffin_ht_plus_dp:N \l__codehl_line_coffin + \l__codehl_tok_Vrule_xtra_dim }

    \hcoffin_set:Nn \l__codehl_vrule_coffin
      {
        \raggedright
        { \color { \l__codehl_tok_style_Rcolor_tl } \rule  { \l__codehl_tok_Rlinewidht_dim } { \l__codehl_vrule_height_dim } }
      }
  }

\cs_new_protected:Npn \__codehl_tok_inline_set:
  {
    \l__codehl_tok_inline_aux_tl
    \l__codehl_tok_build_line_tl

    \tl_clear:N \l__codehl_tok_build_line_tl
    \tl_set:Nn \l__codehl_tok_inline_aux_tl { \skip_vertical:n { 0pt } }
  }

\cs_new_protected:Npn \__codehl_tok_coffin_set_line:
  {
      \vcoffin_set:Nne \l__codehl_line_coffin  { \l__codehl_tok_Twidth_dim }
        {
          \exp_not:N \raggedright
          \exp_not:N \leftskip=\l__codehl_tok_Windent_dim
          \exp_not:N \parindent=-\l__codehl_tok_Windent_dim
          \exp_not:N \strut
          \exp_not:o \l__codehl_tok_build_line_tl
          \exp_not:N \strut
        }

      \__codehl_set_num:
      \__codehl_set_bckgnd:
      \__codehl_set_Trule:

      \__codehl_set_Vrule_coffin:
      \__codehl_set_Lrule:
      \__codehl_set_Rrule:

      \bool_set_true:N \l__codehl_tok_lineset_bool
      \tl_clear:N \l__codehl_tok_build_line_tl
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     remapping
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% Global stack for recursive remapping
%%%%%%%
\globalstack_csnew:n    { __codehl_restack }
\cs_generate_variant:Nn  \__codehl_restack_gpush:n { e }

\cs_new_protected:Npn \__codehl_remapcount_push:
  {
    \__codehl_restack_gpush:e
      {
        \exp_not:N \int_set:Nn 
          \exp_not:N \l__codehl_remapcount_int 
          { \int_use:N \l__codehl_remapcount_int }
      }
  }

\cs_set_eq:NN \__codehl_remapcount_pop:   \__codehl_restack_gpop:

%%%%%%%
%%% remaping functions will be used in a expansion context.
%%% Do not protect them.
%%% 'default' ...
%%%%%%%
\cs_new:Npn \__codehl_class_remap_default:n #1
  { #1 }

\cs_new:Npn \__codehl_class_remap_n:n #1
  { \int_eval:w \l__codehl_remapcount_int + #1 }

\cs_new:Npn \__codehl_class_set:n #1
  {
    \if_int_compare:w #1 < 0
      #1
    \else:
      \int_use:N \l__codehl_remapcount_int
    \fi:
  }

\cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_default:n

\cs_new_protected:Npn \__codehl_build_remap:nnnnn #1#2#3#4#5
  {
    \int_add:Nn \l__codehl_remapcount_int { #4 }
    \if_int_compare:w #3 = 2
      \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_set:n
      \seq_map_inline:cn { l__codehl_ #1 _ #5 _basedonB_seq }
        { \__codehl_build_set:nnnnn { #1 } { #2 } ##1 }
    \else:
      \seq_map_inline:cn { l__codehl_ #1 _ #5 _basedonB_seq }
        {
          \__codehl_remapcount_push:
          \__codehl_build_remap:nnnnn { #1 } { #2 } ##1
          \__codehl_remapcount_pop:
        }
    \fi:

    \__codehl_build_cmd:nn { #2 } { #5 }

    \if_int_compare:w #3 = 2
      \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_n:n
    \fi:
  }

\cs_new_protected:Npn \__codehl_build_set:nnnnn #1#2#3#4#5
  {
    \seq_map_inline:cn { l__codehl_ #1 _ #5 _basedonB_seq }
      { \__codehl_build_set:nnnnn { #1 } { #2 } ##1 }

    \__codehl_build_cmd:nn { #2 } { #5 }
  }

\cs_new_protected:Npn \__codehl_set_build_false:nn #1#2
  {
    \bool_if:cTF { l__codehl_ #1 _ #2 _build_bool }
      {
        \bool_set_false:c { l__codehl_ #1 _ #2 _build_bool }
        \use:c { l__codehl_ #1 _ #2 _clear_tl }
        \tl_clear:c { l__codehl_ #1 _ #2 _clear_tl }
      }
      { }

    \seq_if_empty:cTF { l__codehl_ #1 _ #2 _derived_seq }
      { }
      {
        \seq_map_inline:cn { l__codehl_ #1 _ #2 _derived_seq }
          { \__codehl_set_build_false:nn { #1 } { ##1 } }
      }
  }
\cs_generate_variant:Nn \__codehl_set_build_false:nn { no }

\cs_new_protected:Npn \__codehl_set_build_derived_false:nn #1#2
  {
    \seq_if_empty:cTF { l__codehl_ #1 _ #2 _derived_seq }
      { }
      {
        \seq_map_inline:cn { l__codehl_ #1 _ #2 _derived_seq }
          { \__codehl_set_build_false:nn { #1 } { ##1 } }
      }
  }
\cs_generate_variant:Nn \__codehl_set_build_derived_false:nn { no }

%%%%%%%
%%% generic based on
%%%%%%%
\regex_const:Nn \c__codehl_basedon_regex
  { ([RS])\[(\d+)\](.+) }

%%%
%%% what needs to be saved right before potentially loading a file (and triggering a nested definition)
%%% \l__codehl_basedon_tmp[a-c]_tl
%%% \l__codehl_def_[...]_tl
%%% \__codehl_basedon_AUX_if_def:nNTF
%%%
%%% TODO: others if 'the logic changes' :/
%%%
\globalstack_csnew:n    { __codehl_basedon_stack }
\cs_generate_variant:Nn  \__codehl_basedon_stack_gpush:n { e }

\prg_new_conditional:Npnn \__codehl_basedon_if_def:nN #1#2 { TF }
  {
    \__codehl_basedon_stack_gpush:e
      { \exp_not:o \l__codehl_basedon_stack_tl }

    %%% _eff_if_def: might trigger a file loading (if pre-defs)
    \__codehl_basedon_eff_if_def:nNTF { #1 } #2
      {
        \__codehl_basedon_stack_gpop:
        \prg_return_true:
      }
      {
        \__codehl_basedon_stack_gpop:
        \prg_return_alse:
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_basedon_if_def:nN { o } { TF }

\prg_new_protected_conditional:Npnn \__codehl_basedon_extract:nnn #1#2#3 { TF }
  {
    \tl_set:Ne \l__codehl_basedon_stack_tl
      {
        %%% the current _if_def:nNTF
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_basedon_eff_if_def:nNTF
          { \exp_not:o \__codehl_basedon_eff_if_def:nNTF }
        %%% the loading file might contain more than one declaration
        %%% but only this need to be saved.
        \exp_not:N \tl_set:Nn
          \exp_not:c { l__codehl_def_ #1 _tl }
          { \exp_not:v { l__codehl_def_ #1 _tl } }
      }
    
    \regex_extract_all:NnNTF \c__codehl_basedon_regex { #3 } \l__codehl_basedon_tmpa_seq
      {
        \seq_pop_left:NN \l__codehl_basedon_tmpa_seq \l__codehl_basedon_tmpa_tl %% whole string, discarded
        \seq_pop_left:NN \l__codehl_basedon_tmpa_seq \l__codehl_basedon_tmpa_tl %% kind R or S
        \seq_pop_left:NN \l__codehl_basedon_tmpa_seq \l__codehl_basedon_tmpb_tl %% <int>
        \seq_pop_left:NN \l__codehl_basedon_tmpa_seq \l__codehl_basedon_tmpc_tl %% parent

        \tl_put_right:Ne \l__codehl_basedon_stack_tl
          {
            \exp_not:N \tl_set:Nn
              \exp_not:N \l__codehl_basedon_tmpa_tl
              { \exp_not:o \l__codehl_basedon_tmpa_tl }
            \exp_not:N \tl_set:Nn
              \exp_not:N \l__codehl_basedon_tmpb_tl
              { \exp_not:o \l__codehl_basedon_tmpb_tl }
            \exp_not:N \tl_set:Nn
              \exp_not:N \l__codehl_basedon_tmpc_tl
              { \exp_not:o \l__codehl_basedon_tmpc_tl }
          }
          
        \__codehl_basedon_if_def:oNTF
          \l__codehl_basedon_tmpc_tl \l__codehl_basedon_tmpd_tl
          {
            \str_case:onTF \l__codehl_basedon_tmpa_tl
              {
                { R }   %% remap case
                  {
                    \seq_put_right:co { l__codehl_ #1 _ #2 _basedon_seq } \l__codehl_basedon_tmpd_tl
                    \seq_put_right:ce { l__codehl_ #1 _ #2 _basedonB_seq } { { 1 } { \l__codehl_basedon_tmpb_tl } { \l__codehl_basedon_tmpd_tl } }
                    \seq_put_right:cn { l__codehl_ #1 _ \l__codehl_basedon_tmpd_tl _derived_seq } { #2 }
                  }
                { S }   %% set case
                  {
                    \seq_put_right:co { l__codehl_ #1 _ #2 _basedon_seq } \l__codehl_basedon_tmpd_tl
                    \seq_put_right:ce { l__codehl_ #1 _ #2 _basedonB_seq } { { 2 } { \l__codehl_basedon_tmpb_tl } { \l__codehl_basedon_tmpd_tl } }
                    \seq_put_right:cn { l__codehl_ #1 _ \l__codehl_basedon_tmpd_tl _derived_seq } { #2 }
                  }
              }
              { \prg_return_true: }
              {
                \msg_error:nnne { codehl / #1 } { invalid code }
                  { based01 } \l__codehl_basedon_tmpa_tl
                \prg_return_false:
              } %% err
          }
          {
            \msg_error:nnne { codehl / #1 } { non existant base }
              { based02 } \l__codehl_basedon_tmpc_tl
            \prg_return_false:
          }
      }
      {
        \__codehl_basedon_if_def:nNTF
          { #3 } \l__codehl_basedon_tmpd_tl
          {
            \seq_put_right:ce { l__codehl_ #1 _ #2 _basedon_seq } { \exp_not:o \l__codehl_basedon_tmpd_tl }
            \seq_put_right:ce { l__codehl_ #1 _ #2 _basedonB_seq } { { 0 } { 0 } { \exp_not:o \l__codehl_basedon_tmpd_tl } }
            \seq_put_right:cn { l__codehl_ #1 _ \l__codehl_basedon_tmpd_tl _derived_seq } { #2 }
            \prg_return_true:
          }
          {
            \msg_error:nnnn { codehl / #1 } { non existant base }
              { based03 } { #3 }
            \prg_return_false:
          }
      }
  }
\prg_generate_conditional_variant:Nnn  \__codehl_basedon_extract:nnn { no } { TF }

\cs_new_protected:Npn \__codehl_basedon:nnn #1#2#3
  {
    \seq_set_from_clist:Nn \l__codehl_basedon_tmp_seq
      { #3 }

    \seq_map_inline:cn { l__codehl_ #1 _ #2 _basedon_seq }
      {
        \seq_remove_all:cn { l__codehl_ #1 _ ##1 _derived_seq }
          { #2 }
      }
    \seq_clear:c  { l__codehl_ #1 _ #2 _basedon_seq } %% those are the 'to be' remapped ones
    \seq_clear:c  { l__codehl_ #1 _ #2 _basedonB_seq } %% those are the 'to be' remapped ones

    \seq_map_inline:Nn \l__codehl_basedon_tmp_seq
      {
        \__codehl_basedon_extract:nnnTF { #1 } { #2 } { ##1 }
          { } %% OK, no errors
          {
            %%% TODO: there was already an error mensage !
            \msg_error:nnnn { codehl /  #1  } { based on syntax }
              { based04 } { ##1 }
          }
      }
  }
\cs_generate_variant:Nn   \__codehl_basedon:nnn { no }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     testing if at least i, ii, iii, iv or v parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\prg_new_protected_conditional:Npnn \__codehl_test_i:nw #1 #2 \q_stop { TF }
  {
    \tl_if_empty:nTF { #2 }
      { \prg_return_false: }      %%% No param
      {
        \quark_if_nil:nTF { #2 }
          \prg_return_true:       %%% exactly one param
          \prg_return_false:      %%% at least one param
      }
  }

\prg_new_protected_conditional:Npnn \__codehl_test_ii:nw #1 #2 \q_stop { TF }
  {
    \tl_if_empty:nTF { #2 }
      { \prg_return_false: }      %%% No param
      {
        \quark_if_nil:nTF { #2 }
          \prg_return_false:      %%% exactly one param
          \prg_return_true:       %%% at least two param
      }
  }

\prg_new_protected_conditional:Npnn \__codehl_test_iii:nw #1 #2 \q_stop { TF }
  {
    \tl_if_empty:nTF { #2 }
      { \prg_return_false: }      %%% No param
      {
        \quark_if_nil:nTF { #2 }
          { \prg_return_false: }                    %%% exactly one param
          { \__codehl_test_iii_aux:nw #2 \q_stop }  %%% at least two param
      }
  }

\cs_new_protected:Npn \__codehl_test_iii_aux:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      \prg_return_false:          %%% exactly two
      \prg_return_true:           %%% at least three
  }

\prg_new_protected_conditional:Npnn \__codehl_test_iv:nw #1 #2 \q_stop { TF }
  {
    \tl_if_empty:nTF { #2 }
      { \prg_return_false: }      %%% No param
      {
        \quark_if_nil:nTF { #2 }
          { \prg_return_false:}                     %%% exactly one param
          { \__codehl_test_iv_auxi:nw #2 \q_stop }  %%% at least two param
      }
  }

\cs_new_protected:Npn \__codehl_test_iv_auxi:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      { \prg_return_false: }                        %%% exactly two
      { \__codehl_test_iv_auxii:nw #2 \q_stop }     %%% at least three param
  }

\cs_new_protected:Npn \__codehl_test_iv_auxii:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      \prg_return_false:          %%% exactly three
      \prg_return_true:           %%% at least four
  }

\prg_new_protected_conditional:Npnn \__codehl_test_v:nw #1 #2 \q_stop { TF }
  {
    \tl_if_empty:nTF { #2 }
      { \prg_return_false: }      %%% No param
      {
        \quark_if_nil:nTF { #2 }
          { \prg_return_false:}                     %%% exactly one param
          { \__codehl_test_v_auxi:nw #2 \q_stop }  %%% at least two param
      }
  }

\cs_new_protected:Npn \__codehl_test_v_auxi:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      { \prg_return_false: }                        %%% exactly two
      { \__codehl_test_v_auxii:nw #2 \q_stop }     %%% at least three param
  }

\cs_new_protected:Npn \__codehl_test_v_auxii:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      { \prg_return_false: }                        %%% exactly three
      { \__codehl_test_v_auxiii:nw #2 \q_stop }     %%% at least four
  }

\cs_new_protected:Npn \__codehl_test_v_auxiii:nw #1 #2 \q_stop
  {
    \quark_if_nil:nTF { #2 }
      \prg_return_false:          %%% exactly four
      \prg_return_true:           %%% at least five
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     base format(ing)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% That's the base/default format
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_basefmt_base_keys_prop
  {
    base fmt      = { \ttfamily \footnotesize }        ,
    bckgnd color  = {  }        ,
    numbers fmt   = { \tiny }   ,
    numbers sep   = { 2pt }     ,
    numbers at    = { none }    ,
    F sep         = { 2pt }     ,
    L sep         = { 0pt }     ,
    R sep         = { 0pt }     ,
    T sep         = { 0pt }     ,
    B sep         = { 0pt }     ,
    T width       = { \linewidth } ,
    W indent      = { 2em }     ,
    R line width  = { 0.25pt }  ,
    gbbl          = { 0 }       ,
    R color       = { black }   ,
  }

\prop_const_linked_from_keyval:Nn \c__codehl_basefmt_base_bool_keys_prop
  {
    numbers       = \c_false_bool ,
    bckgnd color  = \c_false_bool ,
    spaces        = \c_false_bool ,
    L frame       = \c_false_bool ,
    R frame       = \c_false_bool ,
    T frame       = \c_false_bool ,
    B frame       = \c_false_bool ,
    keywd         = \c_false_bool ,
    inline        = \c_false_bool ,
    S verb        = \c_false_bool ,
  }

%%%%%%%
%%% <keys> internal => external labels
%%% The ones 'not defined here' won't show at \codehl_basefmt_show:n
%%% (hidden properties)
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_basefmt_keys_name_prop
  {
    base fmt      = base ~ format       ,
    bckgnd color  = background          ,
    numbers fmt   = numbers ~ format    ,
    numbers at    = numbers             ,
    numbers sep   = numbers ~ sep       ,
    F sep         = frame ~ sep         ,
    L sep         = left ~ sep          ,
    R sep         = right ~ sep         ,
    T sep         = top ~ sep           ,
    B sep         = bottom ~ sep        ,
    T width       = text ~ width        ,
    W indent      = wrap ~ indent       ,
    R line width  = rule ~ width        ,
    gbbl          = gobble              ,
    R color       = rule ~ color        ,

%    numbers       = show ~ numbers      ,
%    L numbers     = numbers ~ at ~ left ,
    bckgnd color  = background          ,
    spaces        = show ~ spaces       ,
    L frame       = left ~ frame        ,
    R frame       = right ~ frame       ,
    T frame       = top ~ frame         ,
    B frame       = bottom ~ frame      ,
    inline        = inline              ,
    S verb        = add ~ endmark        ,
  }

\keys_define:nn { codehl / base fmt }
  {
    based ~ on .code:n =
      {
        \bool_if:NTF \l__codehl_display_bool
          {
            \msg_error:nnnn { codehl / display } { based on err }
              { disp01 } { base~fmt }
          }
          {
            \cs_set:Npn \__codehl_basedon_eff_if_def:nNTF
              { \__codehl_basefmt_if_def:nNTF }
            \__codehl_basedon:non { base fmt } \l__codehl_def_basefmt_tl { #1 }
            \__codehl_set_build_false:no { base fmt } \l__codehl_def_basefmt_tl
          }
      } ,
    based ~ on .value_required:n = true ,

    background .code:n =
      {
        \tl_if_blank:nTF { #1 }
          {
            \__codehl_basefmt_set_bool_style:nN
              { bckgnd color } \c_false_bool
          }
          {
            \__codehl_basefmt_set_bool_style:nN
              { bckgnd color } \c_true_bool
          }
        \__codehl_basefmt_set_style:nn
          { bckgnd color } { #1 }
      } ,
    background .value_required:n = true ,

    numbers .choices:nn =
      { none , left , right }
      {
        \__codehl_basefmt_set_style:nn
          { numbers at } { #1 }
        \if_case:w \l_keys_choice_int
        \or:
          \__codehl_basefmt_set_bool_style:nN
            { L numbers } \c_true_bool
          \__codehl_basefmt_set_bool_style:nN
            { numbers } \c_false_bool
        \or:
          \__codehl_basefmt_set_bool_style:nN
            { L numbers } \c_true_bool
          \__codehl_basefmt_set_bool_style:nN
            { numbers } \c_true_bool
        \or:
          \__codehl_basefmt_set_bool_style:nN
            { L numbers } \c_false_bool
          \__codehl_basefmt_set_bool_style:nN
            { numbers } \c_true_bool
        \fi:
      } ,
    numbers .value_required:n = true ,

    info / note .code:n =
      {
        \str_set:Nn \l__codehl_tmpa_tl { #1 }
        \tl_regex_replace_all:NNn \l__codehl_tmpa_tl
          \c__codehl_note_regex { \c{iow_newline:} }

        \__codehl_note:nnneee { codehl / basefmt } { info note }
          { basemft00 }
          \l__codehl_def_keyset_tl
          { \g_file_curr_name_str \g_file_curr_ext_str }
          { \l__codehl_tmpa_tl }
      } ,

  }

\prop_new_linked:N \l__codehl_basefmt_cmds_prop

\cs_new_protected:Npn \__codehl_basefmt_keycmd_register:nn
  { \prop_put:Nnn \l__codehl_basefmt_cmds_prop }

\__codehl_basefmt_keycmd_register:nn { bckgnd color }
  {
    \bool_if:NTF \l__codehl_tok_style_bckgndcolor_bool
      { \cs_set_eq:NN \__codehl_set_bckgnd: \__codehl_attach_bckgnd: }
      { \cs_set_eq:NN \__codehl_set_bckgnd: \prg_do_nothing: }
  }

%%% Hmmm... really?
%\__codehl_basefmt_keycmd_register:nn { L numbers } { }

\__codehl_basefmt_keycmd_register:nn { numbers }
  {
    \bool_if:NTF \l__codehl_tok_style_numbers_bool
      {
        \bool_if:NTF \l__codehl_tok_style_Lnumbers_bool
          { \cs_set_eq:NN \__codehl_set_num: \__codehl_attach_leftnum: }
          { \cs_set_eq:NN \__codehl_set_num: \__codehl_attach_rightnum: }
      }
      { \cs_set_eq:NN \__codehl_set_num: \prg_do_nothing: }
  }

\cs_new_protected:Npn \__codehl_basefmt_keys_define:nnn #1#2#3
  {
    \keys_define:nn { codehl / base fmt }
      {
        #1 .code:n =
          {
            \__codehl_basefmt_set_style:nn
              { #2 } { ##1 }
          } ,
        #1 .value_required:n = true ,
      }
    \tl_if_empty:nTF { #3 }
      { }
      {
        \__codehl_basefmt_keycmd_register:nn
          { #2 }
          { #3 }
      }
%    \__codehl_basefmt_keycmd_register:nn
%      { #2 }
%      { #3 }
  }

\cs_new_protected:Npn \__codehl_basefmt_keys_define_bool:nnnn #1#2#3#4
  {
    \keys_define:nn { codehl / base fmt }
      {
        #1 .choices:nn =
          { true , false }
          {
            \if_int_compare:w \l_keys_choice_int = 1
              \__codehl_basefmt_set_bool_style:nN
                { #2 } \c_true_bool
            \else:
              \__codehl_basefmt_set_bool_style:nN
                { #2 } \c_false_bool
            \fi:
          } ,
        #1 .default:n = { #3 } ,
      }
    \tl_if_empty:nTF { #4 }
      { }
      {
        \__codehl_basefmt_keycmd_register:nn
          { #2 }
          { #4 }
      }
%    \__codehl_basefmt_keycmd_register:nn
%      { #2 }
%      { #4 }
  }

\__codehl_basefmt_keys_define:nnn { numbers ~ format } { numbers fmt }
  { }

\__codehl_basefmt_keys_define:nnn { numbers ~ sep } { numbers sep }
  { }

\__codehl_basefmt_keys_define:nnn { base ~ format } { base fmt }
  { }

\__codehl_basefmt_keys_define_bool:nnnn { inline } { inline } { true }
  { }

\__codehl_basefmt_keys_define_bool:nnnn { add ~ endmark } { S verb } { true }
  { }

\__codehl_basefmt_keys_define_bool:nnnn { show ~ spaces } { spaces } { true }
  {
    \bool_if:NTF  \l__codehl_tok_style_spaces_bool
      { \cs_set_eq:NN \__codehl_tok_test_space: \__codehl_tok_show_space: }
      { \cs_set_eq:NN \__codehl_tok_test_space: \__codehl_tok_space: }
  }

\__codehl_basefmt_keys_define_bool:nnnn { left ~ frame } { L frame } { true }
  {
    \bool_if:NTF \l__codehl_tok_style_Lframe_bool
      { \cs_set_eq:NN \__codehl_set_Lrule: \__codehl_attach_Lrule_coffin: }
      { \cs_set_eq:NN \__codehl_set_Lrule: \prg_do_nothing: }
  }

\__codehl_basefmt_keys_define_bool:nnnn { right ~ frame } { R frame } { true }
  {
    \bool_if:NTF \l__codehl_tok_style_Rframe_bool
      { \cs_set_eq:NN \__codehl_set_Rrule: \__codehl_attach_Rrule: }
      { \cs_set_eq:NN \__codehl_set_Rrule: \prg_do_nothing: }
  }

\__codehl_basefmt_keys_define_bool:nnnn { top ~ frame } { T frame } { true }
  {
    \bool_if:NTF \l__codehl_tok_style_Tframe_bool
      { \cs_set_eq:NN \__codehl_set_Trule: \__codehl_attach_Trule: }
      { \cs_set_eq:NN \__codehl_set_Trule: \prg_do_nothing: }
  }

\__codehl_basefmt_keys_define_bool:nnnn { bottom ~ frame } { B frame } { true }
  {
    \bool_if:NTF \l__codehl_tok_style_Bframe_bool
      { \cs_set_eq:NN \__codehl_Brule_coffin_attach: \__codehl_attach_Brule: }
      { \cs_set_eq:NN \__codehl_Brule_coffin_attach: \prg_do_nothing: }
  }

\__codehl_basefmt_keys_define:nnn { gobble } { gbbl }
  {
    \int_set:Nn   \l__codehl_tok_gbbl_int     \l__codehl_tok_style_gbbl_tl
    \int_compare:nNnTF
      { \l__codehl_tok_gbbl_int } > { 0 }
      { \cs_set_eq:NN \__codehl_tok_prepgobble: \__codehl_tok_gobble_true: }
      { \cs_set_eq:NN \__codehl_tok_prepgobble: \__codehl_tok_gobble_false: }
  }

\cs_new_protected:Npn \__codehl_basefmt_set_dims:
  {
    %%% TODO... could add some conditionals framed/not framed... but questionable...
    %%% anyway, only needed if not inline !

    \dim_set:Nn \l__codehl_tok_Fsep_dim
      { \l__codehl_tok_style_Fsep_tl }
    \dim_set:Nn \l__codehl_tok_Lsep_dim
      { \l__codehl_tok_style_Fsep_tl +  \l__codehl_tok_style_Lsep_tl }
    \dim_set:Nn \l__codehl_tok_Rsep_dim
      { \l__codehl_tok_style_Fsep_tl +  \l__codehl_tok_style_Rsep_tl }
    \dim_set:Nn \l__codehl_tok_Tsep_dim
      { \l__codehl_tok_style_Fsep_tl +  \l__codehl_tok_style_Tsep_tl }
    \dim_set:Nn \l__codehl_tok_Bsep_dim
      { \l__codehl_tok_style_Fsep_tl +  \l__codehl_tok_style_Bsep_tl }
    \dim_set:Nn \l__codehl_tok_Twidth_dim
      { \l__codehl_tok_style_Twidth_tl }
    \dim_set:Nn \l__codehl_tok_Windent_dim
      { \l__codehl_tok_style_Windent_tl }
    \dim_set:Nn \l__codehl_tok_Rlinewidht_dim
      { \l__codehl_tok_style_Rlinewidth_tl }

    \bool_lazy_or:nnTF { \l__codehl_tok_style_Rframe_bool } { \l__codehl_tok_style_Lframe_bool }
      { \cs_set_eq:NN \__codehl_set_Vrule_coffin: \__codehl_vrule_set_coffin: }
      { \cs_set_eq:NN \__codehl_set_Vrule_coffin: \prg_do_nothing: }

    %%% After everything else
    \dim_set:Nn \l__codehl_tok_rule_wd_dim
      {
        \l__codehl_tok_Twidth_dim +  \l__codehl_tok_Lsep_dim +
        \l__codehl_tok_Rsep_dim   +  \l__codehl_tok_Rlinewidht_dim * 2
      }

    \dim_set:Nn \l__codehl_tok_Vrule_xtra_dim
      { \l__codehl_tok_Tsep_dim + \l__codehl_tok_Bsep_dim }
    \dim_set:Nn \l__codehl_tok_Vrule_delta_dim
      { \l__codehl_tok_Tsep_dim - \l__codehl_tok_Bsep_dim }

    \vcoffin_set:Nnn \l__codehl_hrule_coffin  { \l__codehl_tok_rule_wd_dim }
      {
        \raggedright
        { \color { \l__codehl_tok_style_Rcolor_tl } \rule { \l__codehl_tok_rule_wd_dim } { \l__codehl_tok_Rlinewidht_dim } }
      }

  }

\__codehl_basefmt_keys_define:nnn { frame ~ sep } { F sep }
  {  }

\__codehl_basefmt_keys_define:nnn { left ~ sep } { L sep }
  {  }

\__codehl_basefmt_keys_define:nnn { right ~ sep } { R sep }
  {  }

\__codehl_basefmt_keys_define:nnn { top ~ sep } { T sep }
  {  }

\__codehl_basefmt_keys_define:nnn { bottom ~ sep } { B sep }
  {  }

\__codehl_basefmt_keys_define:nnn { text ~ width } { T width }
  {  }

\__codehl_basefmt_keys_define:nnn { wrap ~ indent } { W indent }
  {  }

\__codehl_basefmt_keys_define:nnn { rule ~ width } { R line width }
  {  }

\__codehl_basefmt_keys_define:nnn { rule ~ color } { R color }
  {  }

\cs_new_protected:Npn \__codehl_basefmt_null_set:nn #1#2
  { }

%%%
%%% TODO optimize this (and the original prop)
%%%
\cs_new_protected:Npn \__codehl_basefmt_display_set_tok_style:nn #1#2
  {
    \tl_set:cn { l__codehl_tok_style_ #1 _tl } { #2 }
    \prop_item:Nn \l__codehl_basefmt_cmds_prop { #1 }
  }

\cs_set_eq:NN \__codehl_basefmt_display_set:nn \__codehl_basefmt_null_set:nn

\cs_new_protected:Npn \__codehl_basefmt_display_set_tok_bool_style:nn #1#2
  {
    \bool_set_eq:cN { l__codehl_tok_style_ #1 _bool } #2
    \prop_item:Nn \l__codehl_basefmt_cmds_prop { #1 }
  }

\cs_set_eq:NN \__codehl_basefmt_display_bool_set:nn \__codehl_basefmt_null_set:nn

\cs_new_protected:Npn \__codehl_basefmt_set_style:nn #1#2
  {
    \prop_put:cnn { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _keys_prop }
      { #1 } { #2 }
    \bool_if:cTF { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_bool }
      {
        \prop_put:cnn { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_keys_prop }
          { #1 } { #2 }
        \__codehl_basefmt_display_set:nn
          { #1 } { #2 }
      }
      { }
  }
\cs_generate_variant:Nn \__codehl_basefmt_set_style:nn { no , nV }

\cs_new_protected:Npn \__codehl_basefmt_set_bool_style:nN #1#2
  {
    \prop_put:cne { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _bool_keys_prop }
      { #1 } { #2 }
    \bool_if:cTF { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_bool }
      {
        \prop_put:cne { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_bool_keys_prop }
          { #1 } { #2 }
        \__codehl_basefmt_display_bool_set:nn
          { #1 } { #2 }
      }
      { }
  }

\prg_new_conditional:Npnn \__codehl_basefmt_if_def:nN #1#2 { TF }
  {
    \prop_get:NnNTF \l__codehl_sets_basefmt_prop
      { #1 } #2
      { \prg_return_true: }
      {
        \__codehl_basefmt_load_if_predef:nTF { #1 }
          {
            \prop_get:NnNTF \l__codehl_sets_basefmt_prop
              { #1 } #2
              { \prg_return_true: }
              { \prg_return_false: } %%% it shouldn't be the case
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_basefmt_if_def:nN { o } { TF }

\prg_new_conditional:Npnn \__codehl_basefmt_alias:n #1 { TF }
  {
    \__codehl_basefmt_if_def:nNTF
      { #1 } \l__codehl_def_basefmt_tl
      {
        \str_if_eq:noTF { #1 } \l__codehl_def_basefmt_tl
          { \prg_return_false: }
          { \prg_return_true: }
      }
      { \prg_return_true: }
  }

\cs_new_protected:Npn \codehl_basefmt_alias:nn #1#2
  {
    \__codehl_basefmt_alias:nTF { #1 }
      {
        %%% OK... new or redefining an alias
        \__codehl_basefmt_if_def:nNTF
          { #2 } \l__codehl_def_basefmt_tl
          {
            \prop_put:Nno \l__codehl_sets_basefmt_prop
              { #1 }
              \l__codehl_def_basefmt_tl

            \__codehl_note:nnnnen { codehl / basefmt } { info note }
              { basefmt02c }
              { #1 }
              { \g_file_curr_name_str \g_file_curr_ext_str }
              { Alias ~ definition: ~ { #1 } ~ => ~ { #2 } }
          }
          {
            \msg_error:nnnn { codehl / basefmt } { non existant }
              { basefmt02a } { #2 }
          }
      }
      {
        %%% Err... it's a 'basefmt definition'
        \msg_error:nnnn { codehl / basefmt } { alias err }
          { basefmt02b } { #1 }
      }
  }
\cs_generate_variant:Nn \codehl_basefmt_alias:nn { ee }

\cs_new_protected:Npn \hlBasefmtAlias #1#2
  {
    \codehl_basefmt_alias:ee 
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }

\cs_new_protected:Npn \codehl_basefmt_def:nn #1#2
  {
    \__codehl_basefmt_if_def:nNTF
      { #1 } \l__codehl_def_basefmt_tl
      {
        \__codehl_set_build_derived_false:no { basefmt } \l__codehl_def_basefmt_tl
      }
      {
        \tl_set:Nn \l__codehl_def_basefmt_tl { #1 }

        \prop_put:Nnn \l__codehl_sets_basefmt_prop
          { #1 }
          { #1 }

        %% this will store common itens (background, numbers, frame ...)
        \prop_new_linked:c { l__codehl_basefmt_  #1 _keys_prop }
        \prop_new_linked:c { l__codehl_basefmt_  #1 _build_keys_prop } %% same, when building up a format

        %% this will store boolean itens IF (background, numbers, frame ...)
        \prop_new_linked:c { l__codehl_basefmt_  #1 _bool_keys_prop }
        \prop_new_linked:c { l__codehl_basefmt_  #1 _build_bool_keys_prop } %% same, when building up a format

        \bool_new:c { l__codehl_basefmt_ #1 _build_bool }

        %%% plain seq of derived ones from this
        \seq_new:c  { l__codehl_basefmt_ #1 _derived_seq }

        %%% those are the 'to be' remapped ones
        %%% _basedon_ contains just a plain list
        %%% _basedonB_ contains { <case> } { <int> } { <basedon> }
        \seq_new:c  { l__codehl_basefmt_ #1 _basedon_seq }
        \seq_new:c  { l__codehl_basefmt_ #1 _basedonB_seq }

      }

    \keys_set:nn { codehl / base fmt } { #2 }
  }
\cs_generate_variant:Nn \codehl_basefmt_def:nn { e }
  
\cs_new_protected:Npn \hlBasefmtDef #1
  {
    \tl_trim_spaces_apply:nN { #1 } \codehl_basefmt_def:nn 
  }

\cs_new_protected:Npn \__codehl_basefmt_build_cmd:nn #1#2
  {
    \prop_concat:ccc
      { l__codehl_basefmt_  #1 _build_keys_prop }
      { l__codehl_basefmt_  #1 _build_keys_prop }
      { l__codehl_basefmt_  #2 _keys_prop }
    \prop_concat:ccc
      { l__codehl_basefmt_  #1 _build_bool_keys_prop }
      { l__codehl_basefmt_  #1 _build_bool_keys_prop }
      { l__codehl_basefmt_  #2 _bool_keys_prop }
  }

\cs_new_protected:Npn \__codehl_basefmt_build:n #1
  {
    \prop_set_eq:cN { l__codehl_basefmt_ #1 _build_keys_prop } \c__codehl_basefmt_base_keys_prop
    \prop_set_eq:cN { l__codehl_basefmt_ #1 _build_bool_keys_prop } \c__codehl_basefmt_base_bool_keys_prop

    \cs_set_eq:NN \__codehl_build_cmd:nn \__codehl_basefmt_build_cmd:nn
    \__codehl_build_remap:nnnnn { base fmt } { #1 } { 0 } { 0 } { #1 }

    \bool_set_true:c { l__codehl_basefmt_ #1 _build_bool }
  }

%%% This assumes it exists!
\cs_new_protected:Npn \__codehl_basefmt_build_ifnot:nn #1#2
  {
    \bool_if:cF { l__codehl_basefmt_ #1 _build_bool }
      {
        \__codehl_basefmt_build:n { #1 }
        #2
      }
  }
\cs_generate_variant:Nn \__codehl_basefmt_build_ifnot:nn { o }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     highlight format sets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\keys_define:nn { codehl / hlset }
  {
    based ~ on .code:n =
      {
        \bool_if:NTF \l__codehl_display_bool
          {
            \msg_error:nnnn { codehl / display } { based on err }
              { disp02 } { hl~set }
          }
          {
            \cs_set:Npn \__codehl_basedon_eff_if_def:nNTF
              { \__codehl_hlset_if_def:nNTF }
            \__codehl_basedon:non { hlset } \l__codehl_def_hlset_tl { #1 }
            \__codehl_set_build_false:no { hlset } \l__codehl_def_hlset_tl
          }
      } ,
    based ~ on .value_required:n = true ,

    comment .code:n =
      {
        \__codehl_hlset_set:nn { comment } { #1 }
      } ,
    comment .value_required:n = true ,

    string .code:n =
      {
        \__codehl_hlset_set:nn { string } { #1 }
      } ,
    string .value_required:n = true ,

    keywd .code:n =
      {
        \__codehl_hlset_set:nn { keywd } { #1 }
      } ,
    keywd .value_required:n = true ,

    unknown .code:n =
      {
        \__codehl_hlset_set:on \l_keys_key_str { #1 }
      } ,
    unknown .value_required:n = true ,

    info / note .code:n =
      {
        \str_set:Nn \l__codehl_tmpa_tl { #1 }
        \tl_regex_replace_all:NNn \l__codehl_tmpa_tl
          \c__codehl_note_regex { \c{iow_newline:} }

        \__codehl_note:nnneee { codehl / hlset } { info note }
          { hlset00 }
          \l__codehl_def_keyset_tl
          { \g_file_curr_name_str \g_file_curr_ext_str }
          { \l__codehl_tmpa_tl }
      } ,

  }

\cs_new_protected:Npn \__codehl_hlset_set:nn #1#2
  {
     \__codehl_test_ii:nwTF #2 \q_nil \q_stop
      {
        \__codehl_hlset_set:nnnwn { #1 } #2 \q_nil \q_stop { #2 }
      }
      {
        \msg_error:nnnenn { codehl /  hlset } { syntax err }
          { hlset01b }
          \l__codehl_def_hlset_tl
          { #1 ~=~ #2 }
          { #1 ~=~ { <class> } { <format~cmds> } }
      }
  }
\cs_generate_variant:Nn \__codehl_hlset_set:nn { o }

%%%%%%%
%%% <hlset-key> ~=~ { <hlset-key> } { <class> } { <format> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_hlset_set:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \prop_if_exist:cTF { l__codehl_hlset_  \l__codehl_def_hlset_tl _ #1 _prop }
          {  }
          {
            \prop_new_linked:c { l__codehl_hlset_  \l__codehl_def_hlset_tl _ #1 _prop }
            \seq_put_right:cn { l__codehl_hlset_  \l__codehl_def_hlset_tl _seq } { #1 }
          }
        \prop_put:cnn { l__codehl_hlset_  \l__codehl_def_hlset_tl _ #1 _prop }
          { #2 }
          { #3 }
        \bool_if:cTF { l__codehl_hlset_  \l__codehl_def_hlset_tl _build_bool }
          {
            \__codehl_hlset_build_prop:on \l__codehl_def_hlset_tl { #1 }
            \prop_put:cen { l__codehl_hlset_ \l__codehl_def_hlset_tl _ #1 _prop }
              { #2 } { #3 }
            \prop_put:cen { l__codehl_hlset_ \l__codehl_def_hlset_tl _ #1 _build_prop }
              { #2 } { #3 }

            \__codehl_hlset_build_set:onnn \l__codehl_def_hlset_tl { #1 } { #2 } { #3 }
          }
          { }
      }
      { %err
        \msg_error:nnnenn { codehl /  hlset } { syntax err }
          { hlset01a }
          \l__codehl_def_hlset_tl
          { #1 ~=~ #5 }
          { #1 ~=~ { <class> } { <format~cmds> } }
      }
  }

\prg_new_conditional:Npnn \__codehl_hlset_if_def:nN #1#2 { TF }
  {
    \prop_get:NnNTF \l__codehl_sets_hlset_prop
      { #1 } #2
      { \prg_return_true: }
      {
        \__codehl_hlset_load_if_predef:nTF { #1 }
          {
            \prop_get:NnNTF \l__codehl_sets_hlset_prop
              { #1 } #2
              { \prg_return_true: }
              { \prg_return_false: } %%% it shouldn't be the case
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_hlset_if_def:nN { o } { TF }

\prg_new_conditional:Npnn \__codehl_hlset_alias:n #1 { TF }
  {
    \__codehl_hlset_if_def:nNTF
      { #1 } \l__codehl_def_hlset_tl
      {
        \str_if_eq:noTF { #1 } \l__codehl_def_hlset_tl
          { \prg_return_false: }
          { \prg_return_true: }
      }
      { \prg_return_true: }
  }

\cs_new_protected:Npn \codehl_hlset_alias:nn #1#2
  {
    \__codehl_hlset_alias:nTF { #1 }
      {
        %%% OK... new or redefining an alias
        \__codehl_hlset_if_def:nNTF
          { #2 } \l__codehl_def_hlset_tl
          {
            \prop_put:Nno \l__codehl_sets_hlset_prop
              { #1 }
              \l__codehl_def_hlset_tl

            \__codehl_note:nnnnen { codehl / hlset } { info note }
              { hlset02c }
              { #1 }
              { \g_file_curr_name_str \g_file_curr_ext_str }
              { Alias ~ definition: ~ { #1 } ~ => ~ { #2 } }
          }
          {
            \msg_error:nnnn { codehl / hlset } { non existant }
              { hlset02a } { #2 }
          }
      }
      {
        %%% Err... it's a 'hlsetuage definition'
        \msg_error:nnnn { codehl / hlset } { alias err }
          { hlset02b } { #1 }
      }
  }
\cs_generate_variant:Nn \codehl_hlset_alias:nn { ee }

\cs_new_protected:Npn \hlHLsetAlias #1#2
  {
    \codehl_hlset_alias:ee 
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }  

\cs_new_protected:Npn \codehl_hlset_def:nn #1#2
  {
    \prop_get:NnNTF \l__codehl_sets_hlset_prop
      { #1 } \l__codehl_def_hlset_tl
      {
        \__codehl_set_build_derived_false:no { hlset } \l__codehl_def_hlset_tl
      }
      {
        \tl_set:Nn \l__codehl_def_hlset_tl { #1 }

        \prop_put:Nnn \l__codehl_sets_hlset_prop
          { #1 }
          { #1 }

        %% this will store the many  'keys' (comment,string,keywd...) each key will have its prop...
        \seq_new:c { l__codehl_hlset_  #1 _seq }

        \bool_new:c { l__codehl_hlset_ #1 _build_bool }
        \seq_new:c  { l__codehl_hlset_ #1 _build_seq }
        \tl_new:c   { l__codehl_hlset_ #1 _clear_tl }  %% this undefines all tl variables (in case of re-definitions)

        %%% plain seq of derived ones from this
        \seq_new:c  { l__codehl_hlset_ #1 _derived_seq }

        %%% those are the 'to be' remapped ones
        %%% _basedon_ contains just a plain list
        %%% _basedonB_ contains { <case> } { <int> } { <basedon> }
        \seq_new:c  { l__codehl_hlset_ #1 _basedon_seq }
        \seq_new:c  { l__codehl_hlset_ #1 _basedonB_seq }
      }

    \keys_set:nn { codehl / hlset } { #2 }
  }
\cs_generate_variant:Nn \codehl_hlset_def:nn { e }

\cs_new_protected:Npn \hlHLsetDef #1
  {
    \tl_trim_spaces_apply:nN { #1 } \codehl_hlset_def:nn
  }  

\cs_new_protected:Npn \codehl_hlset_fmt:nn
  { 
    \codehl_hlset_fmt:nnn \l__codehl_tok_activ_hlset_tl 
  }
  
\cs_new_protected:Npn \codehl_hlset_fmt:nnn #1#2#3
  { 
    \use:c { l__codehl_hlset_ #1 _ #2 _ #3 _tl } 
  }
\cs_generate_variant:Nn \codehl_hlset_fmt:nnn { eee , nee }
  
\cs_new_protected:Npn \hlFmt #1#2
  { 
%    \exp_args:No \hlSetFmt \l__codehl_tok_activ_hlset_tl 
    \codehl_hlset_fmt:nee
      { \l__codehl_tok_activ_hlset_tl }
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }

\cs_new_protected:Npn  \hlSetFmt #1#2#3
  {
    \codehl_hlset_fmt:eee
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
      { \tl_trim_spaces:n { #3 } }
  }

%%% for ref. that would be cleaner... but \use:c expands to nothing, if not defined.
%%%    \tl_if_exist:cT { l__codehl_hlset_ #1 _ #2 _ #3 _tl }
%%%      { \use:c { l__codehl_hlset_ #1 _ #2 _ #3 _tl } }

\cs_new_protected:Npn \__codehl_hlset_build_set:nnnn #1#2#3#4
  {
    \tl_if_blank:nTF { #4 }
      {
        \cs_undefine:c { l__codehl_hlset_ #1 _ #2 _ #3 _tl }
      }
      {
        \tl_set:cn { l__codehl_hlset_ #1 _ #2 _ #3 _tl }
          { #4 }
        \tl_put_left:ce
          { l__codehl_hlset_ #1 _clear_tl }
          {
            \exp_not:N \cs_undefine:N
              \exp_not:c { l__codehl_hlset_ #1 _ #2 _ #3 _tl }
          }
      }
  }
\cs_generate_variant:Nn \__codehl_hlset_build_set:nnnn { o }

\cs_new_protected:Npn \__codehl_hlset_build:nn #1#2
  {
    \seq_map_inline:cn { l__codehl_hlset_  #1 _build_seq }
      {
        \prop_map_inline:cn { l__codehl_hlset_  #1 _ ##1 _build_prop }
          {
            \__codehl_hlset_build_set:nnnn { #2 } { ##1 } { ####1 } { ####2 }
          }
      }
  }
\cs_generate_variant:Nn \__codehl_hlset_build:nn { o }

\cs_new_protected:Npn \__codehl_hlset_build_prop:nn #1#2
  {
    \prop_if_exist:cF
      { l__codehl_hlset_ #1 _ #2 _build_prop }
      {
        \prop_new:c { l__codehl_hlset_ #1 _ #2 _build_prop }
        \tl_put_left:ce
          { l__codehl_hlset_ #1 _clear_tl }
          {
            \exp_not:N \prop_clear:N
              \exp_not:c { l__codehl_hlset_ #1 _ #2 _build_prop }
          }
      }
  }
\cs_generate_variant:Nn \__codehl_hlset_build_prop:nn { o }

\cs_new_protected:Npn \__codehl_hlset_build_cmd:nn #1#2
  {
    \seq_concat:ccc
      { l__codehl_hlset_ #1 _build_seq }
      { l__codehl_hlset_ #1 _build_seq }
      { l__codehl_hlset_ #2 _seq }

    \seq_map_inline:cn { l__codehl_hlset_  #2 _seq }
      {
        \__codehl_hlset_build_prop:nn { #1 } { ##1 }
        \prop_map_inline:cn { l__codehl_hlset_ #2 _ ##1 _prop }
          {
            \prop_put:cen { l__codehl_hlset_ #1 _ ##1 _build_prop }
              { \__codehl_class_remap:n { ####1 } } { ####2 }
          }
      }
  }

\cs_new_protected:Npn \__codehl_hlset_build:n #1
  {
    \tl_clear:c { l__codehl_hlset_ #1 _clear_tl }
    \seq_clear:c { l__codehl_hlset_ #1 _build_seq }

    \int_zero:N  \l__codehl_remapcount_int

    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_n:n
    \cs_set_eq:NN \__codehl_build_cmd:nn \__codehl_hlset_build_cmd:nn
    \__codehl_build_remap:nnnnn { hlset } { #1 } { 0 } { 0 } { #1 }

    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_default:n
    \seq_remove_duplicates:c { l__codehl_hlset_ #1 _build_seq }

    \__codehl_hlset_build:nn { #1 } { #1 }

    \bool_set_true:c { l__codehl_hlset_ #1 _build_bool }
  }

%%% This assumes it exists!
\cs_new_protected:Npn \__codehl_hlset_build_ifnot:n #1
  {
    \bool_if:cF { l__codehl_hlset_ #1 _build_bool }
      { \__codehl_hlset_build:n { #1 } }
  }
\cs_generate_variant:Nn \__codehl_hlset_build_ifnot:n { o }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     keywords  sets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% single exception
%%% (external) emph => (internal) keywd
%%% all others (external) == (internal)
%%% ... when building up the many effective _tl vars.
%%%%%%%
\tl_const:Nn \c__codehl_keyset_hack_emph_tl { keywd }

\regex_const:Nn \c__codehl_suppress_regex {suppress\s+(\S.*)}
\regex_const:Nn \c__codehl_lc_regex {(.*)\*}
\regex_const:Nn \c__codehl_uc_regex {(.*)\!}

\regex_const:Nn \c__codehl_note_regex { \\ \\ } %%% that's the usual breakline

\keys_define:nn { codehl / keyset }
  {
    based ~ on .code:n =
      {
        \bool_if:NTF \l__codehl_display_bool
          {
            \msg_error:nnnn { codehl / display } { based on err }
              { disp03 } { keywd ~set }
          }
          {
            \cs_set:Npn \__codehl_basedon_eff_if_def:nNTF
              { \__codehl_keyset_if_def:nNTF }
            \__codehl_basedon:non { keyset } \l__codehl_def_keyset_tl {  #1 }
            \__codehl_set_build_false:no { keyset } \l__codehl_def_keyset_tl
          }
      } ,
    based ~ on .value_required:n = true ,

    info / note .code:n =
      {
        \str_set:Nn \l__codehl_tmpa_tl { #1 }
        \tl_regex_replace_all:NNn \l__codehl_tmpa_tl
          \c__codehl_note_regex { \c{iow_newline:} }

        \__codehl_note:nnneee { codehl / keyset } { info note }
          { keyset00 }
          \l__codehl_def_keyset_tl
          { \g_file_curr_name_str \g_file_curr_ext_str }
          { \l__codehl_tmpa_tl }
      } ,

    keywd .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 0 }
        \__codehl_keys_set:nn { keywd } { #1 }
      } ,
    keywd .value_required:n = true ,

    keywd* .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 1 }
        \__codehl_keys_set:nn { keywd } { #1 }
      } ,
    keywd* .value_required:n = true ,

    keywd! .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 2 }
        \__codehl_keys_set:nn { keywd } { #1 }
      } ,
    keywd! .value_required:n = true ,

    emph .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 0 }
        \__codehl_keys_set:nn { emph } { #1 }
      } ,
    emph .value_required:n = true ,

    emph* .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 1 }
        \__codehl_keys_set:nn { emph } { #1 }
      } ,
    emph* .value_required:n = true ,

    emph! .code:n =
      {
        \tl_set:Nn \l__codehl_keyset_case_key_tl
          { 2 }
        \__codehl_keys_set:nn { emph } { #1 }
      } ,
    emph! .value_required:n = true ,

    unknown .code:n =
      {
        \regex_replace_once:NnNTF \c__codehl_lc_regex {\1} \l_keys_key_str
          {
            \tl_set:Nn \l__codehl_keyset_case_key_tl
              { 1 }
          }
          {
            \regex_replace_once:NnNTF \c__codehl_uc_regex {\1} \l_keys_key_str
              {
                \tl_set:Nn \l__codehl_keyset_case_key_tl
                  { 2 }
              }
              {
                \tl_set:Nn \l__codehl_keyset_case_key_tl
                  { 0 }
              }
          }

        \regex_replace_once:NnNTF \c__codehl_suppress_regex {\1} \l_keys_key_str
          { \__codehl_keys_set_suppress:on \l_keys_key_str { #1 } }
          { \__codehl_keys_set:on \l_keys_key_str { #1 } }
      } ,
    unknown .value_required:n = true ,
  }

\cs_new_protected:Npn \__codehl_keys_set_suppress:nn #1#2
  {
     \__codehl_test_ii:nwTF #2 \q_nil \q_stop
      {
        \__codehl_keys_set_suppress:nnnwn { #1 } #2 \q_nil \q_stop { #2 }
      }
      {
        \msg_error:nnnenn { codehl / keyset } { syntax err }
          { keyset01b }
          \l__codehl_def_keyset_tl
          { suppress ~ #1 ~=~ #2 }
          { suppress ~ #1 ~=~ { <class> } { <keywords~list> } }
      }
  }
\cs_generate_variant:Nn \__codehl_keys_set_suppress:nn { o }

\cs_new_protected:Npn \__codehl_keys_set_suppress:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \__codehl_keys_set:nnnwn { #1 } { -10000 } { #3 } \q_nil \q_stop { #5 }
      }
      { %err
        \msg_error:nnnenn { codehl / keyset } { syntax err }
          { keyset01a }
          \l__codehl_def_keyset_tl
          { suppress ~ #1 ~=~ #5 }
          { suppress ~ #1 ~=~ { <class> } { <keywords~list> } }
      }

  }

\cs_new_protected:Npn \__codehl_keys_set:nn #1#2
  {
     \__codehl_test_ii:nwTF #2 \q_nil \q_stop
      {
        \__codehl_keys_set:nnnwn { #1 } #2 \q_nil \q_stop { #2 }
      }
      {
        \msg_error:nnnenn { codehl / keyset } { syntax err }
          { keyset01b }
          \l__codehl_def_keyset_tl
          { #1 ~=~ #2 }
          { #1 ~=~ { <class> } { <keywords~list> } }
      }
  }
\cs_generate_variant:Nn \__codehl_keys_set:nn { o }

%%%%%%%
%%% <keyset-key> ~=~ { <external-key-name> } { <class> } { <clist> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_keys_set:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \if_case:w \l__codehl_keyset_case_key_tl
          \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #3 }
        \or:
          \seq_set_from_clist:Nn \l__codehl_tmpb_seq { #3 }
          \seq_clear:N \l__codehl_tmpa_seq
          \seq_map_inline:Nn \l__codehl_tmpb_seq
            {
              \seq_put_right:Ne \l__codehl_tmpa_seq
                { \str_lowercase:n { ##1 } }
            }
        \or:
          \seq_set_from_clist:Nn \l__codehl_tmpb_seq { #3 }
          \seq_clear:N \l__codehl_tmpa_seq
          \seq_map_inline:Nn \l__codehl_tmpb_seq
            {
              \seq_put_right:Ne \l__codehl_tmpa_seq
                { \str_uppercase:n { ##1 } }
            }
        \fi:

        \bool_if:cTF { l__codehl_keyset_  \l__codehl_def_keyset_tl _build_bool }
          {
            \prop_if_exist:cTF { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _ #1 _prop }
              { }
              {
                \prop_new_linked:c { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _ #1 _prop }
                \tl_put_right:ce { l__codehl_keyset_ \l__codehl_def_keyset_tl _clear_tl }
                  {
                    \exp_not:N \cs_undefine:N
                      \exp_not:c { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _ #1 _prop }
                  }
                \prop_put:cne { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _prop }
                  { #1 }
                  { \exp_not:c { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _ #1 _prop } }
              }

            \tl_if_exist:cTF { c__codehl_keyset_hack_ #1 _tl }
              { \tl_set_eq:Nc \l__codehl_tmpa_tl { c__codehl_keyset_hack_ #1 _tl } }
              { \tl_set:Nn \l__codehl_tmpa_tl { #1 } }

            \seq_map_inline:Nn \l__codehl_tmpa_seq
              {
                \__codehl_keyset_set_keywd:nnnnn
                  { \l__codehl_def_keyset_tl } { ##1 } { \l__codehl_tmpa_tl } { #1 } { #2 }

                \prop_put:cne { l__codehl_keyset_  \l__codehl_def_keyset_tl _build _ #1 _prop }
                  { ##1 }
                  {  #2 }
              }
          }
          { }

        %%%%%%%
        %%%%%%%
        \prop_if_exist:cTF { l__codehl_keyset_  \l__codehl_def_keyset_tl _ #1 _prop }
          { }
          {
            \prop_new_linked:c { l__codehl_keyset_  \l__codehl_def_keyset_tl _ #1 _prop }
            \prop_put:cne { l__codehl_keyset_  \l__codehl_def_keyset_tl _prop }
              { #1 }
              { \exp_not:c { l__codehl_keyset_  \l__codehl_def_keyset_tl _ #1 _prop } }
          }
        \seq_map_inline:Nn \l__codehl_tmpa_seq
          {
            \prop_put:cnn { l__codehl_keyset_  \l__codehl_def_keyset_tl _ #1 _prop }
              { ##1 }
              { #2 }
          }
      }
      { %err
        \msg_error:nnnenn { codehl / keyset } { syntax err }
          { keyset01a }
          \l__codehl_def_keyset_tl
          { #1 ~=~ #5 }
          { #1 ~=~ { <class> } { <keywords~list> } }

      }
  }

\prg_new_conditional:Npnn \__codehl_keyset_if_def:nN #1#2 { TF }
  {
    \prop_get:NnNTF \l__codehl_sets_keyset_prop
      { #1 } #2
      { \prg_return_true: }
      {
        \__codehl_keyset_load_if_predef:nTF { #1 }
          {
            \prop_get:NnNTF \l__codehl_sets_keyset_prop
              { #1 } #2
              { \prg_return_true: }
              { \prg_return_false: }  %%% it shouldn't be the case
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_keyset_if_def:nN { o } { TF }

\prg_new_conditional:Npnn \__codehl_keyset_alias:n #1 { TF }
  {
    \__codehl_keyset_if_def:nNTF
      { #1 } \l__codehl_def_keyset_tl
      {
        \str_if_eq:noTF { #1 } \l__codehl_def_keyset_tl
          { \prg_return_false: }
          { \prg_return_true: }
      }
      { \prg_return_true: }
  }

\cs_new_protected:Npn \codehl_keyset_alias:nn #1#2
  {
    \__codehl_keyset_alias:nTF { #1 }
      {
        %%% OK... new or redefining an alias
        \__codehl_keyset_if_def:nNTF
          { #2 } \l__codehl_def_keyset_tl
          {
            \prop_put:Nno \l__codehl_sets_keyset_prop
              { #1 }
              \l__codehl_def_keyset_tl

            \__codehl_note:nnnnen { codehl / keyset } { info note }
              { keyset02c }
              { #1 }
              { \g_file_curr_name_str \g_file_curr_ext_str }
              { Alias ~ definition: ~ { #1 } ~ => ~ { #2 } }
          }
          {
            \msg_error:nnnn { codehl / keyset } { non existant }
              { keyset02a } { #2 }
          }
      }
      {
        %%% Err... it's a 'keyset definition'
        \msg_error:nnnn { codehl / keyset } { alias err }
          { keyset02b } { #1 }
      }
  }
\cs_generate_variant:Nn \codehl_keyset_alias:nn { ee }

\cs_new_protected:Npn \hlKeysetAlias #1#2
  {
    \codehl_keyset_alias:ee 
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }

\cs_new_protected:Npn \codehl_keyset_def:nn #1#2
  {
    \__codehl_keyset_if_def:nNTF
      { #1 } \l__codehl_def_keyset_tl
      {
        \__codehl_set_build_derived_false:no { keyset } \l__codehl_def_keyset_tl
      }
      {
        \prop_put:Nnn \l__codehl_sets_keyset_prop
          { #1 }
          { #1 }

        \tl_set:Nn \l__codehl_def_keyset_tl { #1 }

        %% This will store 'keywd', 'emph', ... 'texcs'...etc
        %% value will be .. #1 _ <key> _prop which shall have the <keys><=><class>
        \prop_new_linked:c  { l__codehl_keyset_  #1 _prop }

        %%% plain seq of derived ones from this
        \seq_new:c          { l__codehl_keyset_ #1 _derived_seq } % The ones derived from this one

        \bool_new:c         { l__codehl_keyset_ #1 _build_bool }
        \tl_new:c           { l__codehl_keyset_ #1 _clear_tl }

        %%% those are the 'to be' remapped ones
        %%% _basedon_ contains just a plain list
        %%% _basedonB_ contains { <case> } { <int> } { <basedon> }
        \seq_new:c          { l__codehl_keyset_ #1 _basedon_seq }
        \seq_new:c          { l__codehl_keyset_ #1 _basedonB_seq }

        %% if _build_bool true, this holds the agregated 'final' keys (after based on remapping)
        \prop_new_linked:c  { l__codehl_keyset_  #1 _build_prop }
      }

    \keys_set:nn { codehl / keyset } { #2 }
  }
\cs_generate_variant:Nn \codehl_keyset_def:nn { e }
  
\cs_new_protected:Npn \hlKeysetDef #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_keyset_def:nn 
  }

%%%%%%%
%%% { <keyset> } { <key-word> } { <internal> } { <external> } { <class> }
%%%%%%%
\cs_new_protected:Npn \__codehl_keyset_set_keywd:nnnnn #1#2#3#4#5
  {
    \tl_set:ce
      { l__codehl_keyset_ #1 _ #3 _ #2 _tl }
      { \exp_not:N \use:c { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ #4 _ #5 _tl } }
    \tl_put_right:ce { l__codehl_keyset_ #1 _clear_tl }
      {
        \exp_not:N \cs_undefine:N
          \exp_not:c { l__codehl_keyset_ #1 _ #3 _ #2 _tl }
      }
  }

\cs_new_protected:Npn \__codehl_keyset_build_cmd:nn #1#2
  {
    \prop_map_inline:cn { l__codehl_keyset_  #2 _prop }
      {
        \prop_if_exist:cTF { l__codehl_keyset_  #1 _build _ ##1 _prop }
          { }
          {
            \prop_new_linked:c { l__codehl_keyset_  #1 _build _ ##1 _prop }
            \tl_put_right:ce { l__codehl_keyset_ #1 _clear_tl }
              {
                \exp_not:N \cs_undefine:N
                  \exp_not:c { l__codehl_keyset_  #1 _build _ ##1 _prop }
              }
            \prop_put:cne { l__codehl_keyset_  #1 _build _prop }
              { ##1 }
              { \exp_not:c { l__codehl_keyset_  #1 _build _ ##1 _prop } }
          }
        \prop_map_inline:Nn ##2
          {
                % ####1 <key>
                % ####2 <class>
            \prop_put:cne { l__codehl_keyset_  #1 _build _ ##1 _prop }
              { ####1 }
              { \__codehl_class_remap:n { ####2 } }
          }
      }
  }

\cs_new_protected:Npn \__codehl_keyset_build:n #1
  {
    \tl_use:c { l__codehl_keyset_ #1 _clear_tl }
    \tl_clear:c { l__codehl_keyset_ #1 _clear_tl }
    \int_zero:N \l__codehl_remapcount_int
    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_n:n
    \cs_set_eq:NN \__codehl_build_cmd:nn \__codehl_keyset_build_cmd:nn
    \__codehl_build_remap:nnnnn { keyset } { #1 } { 0 } { 0 } { #1 }

    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_default:n
    \bool_set_true:c { l__codehl_keyset_ #1 _build_bool }

    \prop_map_inline:cn { l__codehl_keyset_  #1 _build _prop }
      {
        \tl_if_exist:cTF { c__codehl_keyset_hack_ ##1 _tl }
          { \tl_set_eq:Nc \l__codehl_tmpa_tl { c__codehl_keyset_hack_ ##1 _tl } }
          { \tl_set:Nn \l__codehl_tmpa_tl { ##1 } }
        \prop_map_inline:Nn ##2
          {
                % ####1 <key>
                % ####2 <class>
            \if_int_compare:w ####2 < 0
            \else:
              \__codehl_keyset_set_keywd:nnnnn
                { #1 } { ####1 } { \l__codehl_tmpa_tl } { ##1 } { ####2 }
            \fi:
          }
      }
  }

%%% This assumes it exists!
\cs_new_protected:Npn \__codehl_keyset_build_ifnot:n #1
  {
    \bool_if:cF { l__codehl_keyset_ #1 _build_bool }
      { \__codehl_keyset_build:n { #1 } }
  }
\cs_generate_variant:Nn \__codehl_keyset_build_ifnot:n { o }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     language sets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\keys_define:nn { codehl / lang / opt }
  {
    nestable .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_nestkey_tl { 1 }
      } ,
    nestable .value_forbidden:n = true ,

    tagged   .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_tagkey_tl { 1 }
      } ,
    tagged   .value_forbidden:n = true ,

    non ~ tagged   .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_tagkey_tl { 2 }
      } ,
    non ~ tagged   .value_forbidden:n = true ,
  }

\cs_new_protected:Npn \__codehl_lang_options:n #1
  {
    \tl_set:Nn \l__codehl_lang_opt_nestkey_tl { 0 }
    \tl_set:Nn \l__codehl_lang_opt_tagkey_tl { 0 }
    \keys_set:nn { codehl / lang / opt } { #1 }
  }

\keys_define:nn { codehl / lang }
  {
    %% TODO: to be REPORTED: it fails (undefined command)
    %based ~ on .tl_set:c = { l__codehl_lang_ \l__codehl_def_lang_tl _baselang_tl } ,

    based ~ on .code:n =
      {
        \cs_set:Npn \__codehl_basedon_eff_if_def:nNTF
          { \__codehl_lang_if_def:nNTF }
        \__codehl_basedon:non { lang } \l__codehl_def_lang_tl { #1 }
      } ,
    based ~ on .value_required:n = true ,

    %%
    %  { class } { start-patt } { end-patt } { options }
    %%
    comment .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { comment }
        \__codehl_lang_comment_new:n { #1 }
      } ,
    comment .value_required:n = true ,

    %%
    %  { class } { start-patt } { options }
    %%
    comment ~ line .code:n =
      {
        \__codehl_lang_commentline_new:n { #1 }
      } ,
    comment ~ line .value_required:n = true ,

    %%
    %  { class } { start-patt } { column } { options }
    %%
    comment ~ line ~ at .code:n =
      {
        \__codehl_lang_commentline_at_new:n { #1 }
      } ,
    comment ~ line ~ at .value_required:n = true ,

    %%
    %  { class } { start-patt } { column } { options }
    %%
    discard ~ comment ~ line ~ at .code:n =
      {
        \__codehl_lang_discardline_at_new:n { #1 }
      } ,
    discard ~ comment ~ line ~ at .value_required:n = true ,

    %%
    %  { class } { start-patt } { end-patt } { options }
    %%
    active ~ comment .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { active ~ comment }
        \__codehl_lang_act_comment_new:n { #1 }
      } ,
    active ~ comment .value_required:n = true ,

    %%
    %  { class } { start-patt } { options }
    %%
    active ~ comment ~ line .code:n =
      {
        \__codehl_lang_act_commentline_new:n { #1 }
      } ,
    active ~ comment ~ line .value_required:n = true ,

    %%
    %  { class } { start-patt } { end-patt } { options }
    %%
    discard ~ comment .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { discard ~ comment }
        \__codehl_lang_discard_new:n { #1 }
      } ,
    discard ~ comment .value_required:n = true ,

    %%
    %  { class } { start-patt } { options }
    %%
    discard ~ comment ~ line .code:n =
      {
        \__codehl_lang_discardline_new:n { #1 }
      } ,
    discard ~ comment ~ line .value_required:n = true ,

    %%
    %  { class } { string-marker } { escape-char } { options }
    %%
    string .code:n =  % simetric, equal start/end
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { string }
        \__codehl_lang_string_new:n { #1 }
      } ,
    string .value_required:n = true ,

    %%
    %  { class } { start-marker } { end-marker } { escape-char } { options }
    %%
    delimited ~ string .code:n =    % asimetric, diff start/end
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { delimited ~ string }
        \__codehl_lang_stringdlimit_new:n { #1 }
      } ,
    delimited ~ string .value_required:n = true ,

%    %%
%    %  { true/false }
%    %%
%    keywords ~ with ~numbers .code:n =
%      {  } ,

    %%
    %  { ident-name } { ident-char } { options }
    %%
    identifier .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { identifier }
        \__codehl_lang_ident_new:n { #1 }
      } ,
    identifier .value_required:n = true ,

    %%
    %  { tagged-name } { start-patt } { end-patt } { options }
    %%
    tagged ~ area .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { tagged ~ area }
        \__codehl_lang_tagged_new:n { #1 }
      } ,
    tagged ~ area .value_required:n = true ,

    %%
    %  { start-patt } { end-patt }
    %%
    replace .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { replace }
        \bool_set_true:N \l__codehl_lang_opt_tr_bool
        \__codehl_lang_tr_new:n { #1 }
      } ,
    replace .value_required:n = true ,

    %%
    %  { start-patt } { end-patt }
    %%
    replace* .code:n =
      {
        \tl_set:Nn \l__codehl_lang_opt_key_tl { replace* }
        \bool_set_false:N \l__codehl_lang_opt_tr_bool
        \__codehl_lang_tr_new:n { #1 }
      } ,
    replace* .value_required:n = true ,

%    %% TODO ??
%    %  { ident-name } { ident-start } { ident-end } { options }
%    %%
%    delimited ~ identifier .code:n =
%      {
%        \__codehl_lang_identdlimit_new:n { #1 }
%      } ,
%    delimited ~ identifier .value_required:n = true ,
%

    %%
    %  { pattern }
    %%
    suppress .code:n =
      {
        \__codehl_lang_suppress_new:n { #1 }
      } ,
    suppress .value_required:n = true ,

    %%
    % "one ofs"
    %%

    oletter .code:n =
      {
        \__codehl_lang_keys:nn
          { oletter }
          { #1 }
      } ,
    oletter .value_required:n = true ,

    digits .code:n =
      {
        \__codehl_lang_keys:nn
          { digits }
          { 0-9 #1 }
      } ,
    digits .value_required:n = true ,

    digits* .code:n =
      {
        \__codehl_lang_keys:nn
          { digits }
          { #1 }
      } ,
    digits* .value_required:n = true ,

    case ~ sensitive .choices:nn =
      { true , false , lower ~ case , upper ~ case }
      {
        \if_case:w \l_keys_choice_int
        \or:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
            { case }
            { 0 }   %%% case sensitive
        \or:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
            { case }
            { 1 }   %%% case insensitive lowercase
        \or:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
            { case }
            { 1 }   %%% case insensitive lowercase
        \or:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
            { case }
            { 2 }   %%% case insensitive uppercase
        \fi:
      } ,
    case ~ sensitive .default:n = { true } ,

    alphanumeric .choices:nn =
      { true , false }
      {
        \if_int_compare:w \l_keys_choice_int = 1
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _bool_keys_prop }
            { alpha }
            { \c_true_bool }
        \else:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _bool_keys_prop }
            { alpha }
            { \c_false_bool }
        \fi:
      } ,
    alphanumeric .default:n = { true } ,

    keywd ~ in ~ string .choices:nn =
      { true , false }
      {
        \if_int_compare:w \l_keys_choice_int = 1
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _bool_keys_prop }
            { keywd }
            { \c_true_bool }
        \else:
          \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _bool_keys_prop }
            { keywd }
            { \c_false_bool }
        \fi:
      } ,
    keywd ~ in ~ string .default:n = { true } ,

    info / note .code:n =
      {
        \str_set:Nn \l__codehl_tmpa_tl { #1 }
        \tl_regex_replace_all:NNn \l__codehl_tmpa_tl
          \c__codehl_note_regex { \c{iow_newline:} }

%        \msg_note:nnneee { codehl / lang } { info note }
        \__codehl_note:nnneee { codehl / lang } { info note }
          { lang00 }
          \l__codehl_def_lang_tl
          { \g_file_curr_name_str \g_file_curr_ext_str }
          { \l__codehl_tmpa_tl }
      } ,
  }

%%%%%%%
%%% That's the base/default format
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_lang_base_keys_prop
  {
    digits        = { 0-9 }   ,
    oletter       = {  }      ,
    case          = { 0 }     ,  %%% case sensitive, by default
  }

\prop_const_linked_from_keyval:Nn \c__codehl_lang_base_bool_keys_prop
  {
    alpha         = \c_false_bool ,
    keywd         = \c_false_bool ,
  }

%%%%%%%
%%% <keys> internal => external labels
%%% The ones 'not defined here' won't show at \codehl_lang_show:n
%%% (hidden properties)
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_lang_keys_name_prop
  {
    digits        = digits              ,
    oletter       = oletter             ,
    case          = case ~ sensitive    ,
    alpha         = alphanumeric        ,
    keywd         = keywd ~ in ~ string ,
  }

\cs_new_protected:Npn \__codehl_lang_keys:nn #1#2
  {
    \tl_if_empty:nTF { #2 }
      {
        \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
          { #1 }
          { }
      }
      {
        \__codehl_lang_get_dlimit:nNNN
          { #2 }
          \l__codehl_tmpab_tl
          \l__codehl_tmpa_tl \l__codehl_tmpb_tl
        \prop_put:cnn { l__codehl_lang_  \l__codehl_def_lang_tl _keys_prop }
          { #1 }
          { #2 }
      }
  }

\prg_new_conditional:Npnn \__codehl_lang_if_def:nN #1#2 { TF }
  {
    \prop_get:NnNTF \l__codehl_sets_lang_prop
      { #1 } #2
      { \prg_return_true: }
      {
        \__codehl_lang_load_if_predef:nTF { #1 }
          {
            \prop_get:NnNTF \l__codehl_sets_lang_prop
              { #1 } #2
              { \prg_return_true: }
              { \prg_return_false: } %%% it shouldn't be the case
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_lang_if_def:nN { o } { TF }

\prg_new_conditional:Npnn \__codehl_lang_alias:n #1 { TF }
  {
    \__codehl_lang_if_def:nNTF
      { #1 } \l__codehl_def_lang_tl
      {
        \str_if_eq:noTF { #1 } \l__codehl_def_lang_tl
          { \prg_return_false: }
          { \prg_return_true: }
      }
      { \prg_return_true: }
  }

\cs_new_protected:Npn \codehl_lang_alias:nn #1#2
  {
    \__codehl_lang_alias:nTF { #1 }
      {
        %%% OK... new or redefining an alias
        \__codehl_lang_if_def:nNTF
          { #2 } \l__codehl_def_lang_tl
          {
            \prop_put:Nno \l__codehl_sets_lang_prop
              { #1 }
              \l__codehl_def_lang_tl

            \__codehl_note:nnnnen { codehl / lang } { info note }
              { lang02c }
              { #1 }
              { \g_file_curr_name_str \g_file_curr_ext_str }
              { Alias ~ definition: ~ { #1 } ~ => ~ { #2 } }
          }
          {
            \msg_error:nnnn { codehl / lang } { non existant }
              { lang02a } { #2 }
          }
      }
      {
        %%% Err... it's a 'language definition'
        \msg_error:nnnn { codehl / lang } { alias err }
          { lang02b } { #1 }
      }
  }
\cs_generate_variant:Nn \codehl_lang_alias:nn { ee }

\cs_new_protected:Npn \hlLangAlias #1#2
  {
    \codehl_lang_alias:ee 
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }

\cs_new_protected:Npn \codehl_lang_def:nn #1#2
  {
    \tl_set:Nn \l__codehl_alias_lang_tl { #1 }
    \__codehl_lang_if_def:nNTF
      { #1 } \l__codehl_def_lang_tl
      {
        \__codehl_set_build_false:no { lang } \l__codehl_def_lang_tl
      }
      {
        \tl_set:Nn \l__codehl_def_lang_tl { #1 }

        \prop_put:Nnn \l__codehl_sets_lang_prop
          { #1 }
          { #1 }

        %%% plain seq of derived ones from this
        \seq_new:c         { l__codehl_lang_ #1 _derived_seq }

        %%% those are the 'to be' remapped ones
        %%% _basedon_ contains just a plain list
        %%% _basedonB_ contains { <case> } { <int> } { <basedon> }
        \seq_new:c         { l__codehl_lang_ #1 _basedon_seq }
        \seq_new:c         { l__codehl_lang_ #1 _basedonB_seq } %% those are the 'to be' remapped ones

        \bool_new:c        { l__codehl_lang_ #1 _build_bool }

        %%% for the general 'set build false'
        %%% not used otherwise
        \tl_new:c          { l__codehl_lang_ #1 _clear_tl }

        %%% main pattern prop/seq
        %%% prop => { <begin-pattern> } => { <class> } { <rest> }
        %%% seq => { <begin-pattern> } preserving definition order
        \prop_new_linked:c { l__codehl_lang_ #1 _pattern_prop }
        \seq_new:c         { l__codehl_lang_ #1 _pattern_seq }

        %%% This is the effective _pattern (after build)...
        %%% also used by language_show:
        \prop_new_linked:c { l__codehl_lang_ #1 _build _pattern_prop }
        \seq_new:c         { l__codehl_lang_ #1 _build _pattern_seq }

        %% this will store common itens (digits, case ...)
        \prop_new_linked:c { l__codehl_lang_  #1 _keys_prop }
        \prop_new_linked:c { l__codehl_lang_  #1 _build_keys_prop } %% same, when building up

        %% this will store boolean itens IF (if digits set, if case set...)
        \prop_new_linked:c { l__codehl_lang_  #1 _bool_keys_prop }
        \prop_new_linked:c { l__codehl_lang_  #1 _build_bool_keys_prop } %% same, when building up
      }

    \keys_set:nn { codehl / lang } { #2 }

  }
\cs_generate_variant:Nn \codehl_lang_def:nn { e }
  
\cs_new_protected:Npn \hlLangDef #1
  {
    \tl_trim_spaces_apply:nN { #1 } \codehl_lang_def:nn 
  }

%% #1 => \l__codehl_lang_BUILD_prop
%% #2 => \l__codehl_lang_dlimit_count_int
%% #3 => _nestedA / _fmtlessB / ....
%% #4 => 1st char (mark start)
%% #5 => { {}{}{}{}... }
\cs_new_protected:Npn \__codehl_lang_dlimit_add:NNnnn #1#2#3#4#5
  {
    \prop_if_in:NnTF #1
      #4
      {
        \prop_get:NnN #1
          #4
          \l__codehl_tmpe_tl
      }
      {
        \int_incr:N #2
        \seq_clear_new:c {  l__codehl_lang_BUILD_ \int_use:N #2 #3 _seq }
        \tl_set:Ne \l__codehl_tmpe_tl
          {
            \exp_not:c
              { l__codehl_lang_BUILD_ \int_use:N #2 #3 _seq }
          }

        \prop_put:Nno #1
          #4
          \l__codehl_tmpe_tl
      }

    \exp_last_unbraced:No
    \seq_put_right:Nn \l__codehl_tmpe_tl
      { #5 }

  }

%%%%%%%
%%% This will build up the many auxiliary properties
%%% based on #2 case (set via _lang_case_split:
%%%%%%%
\int_new:N \l__codehl_lang_basestr_int
\int_new:N \l__codehl_lang_basecmt_int
\int_new:N \l__codehl_lang_base_int
\int_new:N \l__codehl_lang_tagstr_int
\int_new:N \l__codehl_lang_tagcmt_int
\int_new:N \l__codehl_lang_tag_int
\int_new:N \l__codehl_lang_tr_int

\bool_new:N \l__codehl_lang_case_intag_bool
\bool_new:N \l__codehl_lang_case_incase_bool
\bool_new:N \l__codehl_lang_case_instr_bool
\bool_new:N \l__codehl_lang_case_incmt_bool
\bool_new:N \l__codehl_lang_case_intr_bool

\cs_new_protected:Npn \__codehl_lang_dlimit_add:nnnnnnn #1#2#3 #4#5#6#7
  {
    \__codehl_lang_case_split:w #2

    \bool_if:NTF \l__codehl_lang_case_intag_bool
      {
            \__codehl_lang_dlimit_add:NNnnn
              \l__codehl_lang_BUILD_tag_prop
              \l__codehl_lang_tag_int
              { _tag }
              { #3 }
              {
                { #3 } %% 1st char (mark start)
                { #4 } %% { regex } { start patt }
                { #5 } %% 1st char (mark end)
                { #6 } %% { regex } { end patt }
                { #7 } %%% "escape char" provision OR column (at col)
                { #1 } %% 'class'
                { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
              }
        \bool_if:NTF \l__codehl_lang_case_nestable_bool
          {
            \bool_if:NTF \l__codehl_lang_case_instr_bool
              {
                \__codehl_lang_dlimit_add:NNnnn
                  \l__codehl_lang_BUILD_tagstr_prop
                  \l__codehl_lang_tagstr_int
                  { _tagstr }
                  { #3 }
                  {
                    { #3 } %% 1st char (mark start)
                    { #4 } %% { regex } { start patt }
                    { #5 } %% 1st char (mark end)
                    { #6 } %% { regex } { end patt }
                    { #7 } %%% "escape char" provision OR column (at col)
                    { #1 } %% 'class'
                    { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
                  }
              }
              { }
            \bool_if:NTF \l__codehl_lang_case_incmt_bool
              {
                \__codehl_lang_dlimit_add:NNnnn
                  \l__codehl_lang_BUILD_tagcmt_prop
                  \l__codehl_lang_tagcmt_int
                  { _tagcmt }
                  { #3 }
                  {
                    { #3 } %% 1st char (mark start)
                    { #4 } %% { regex } { start patt }
                    { #5 } %% 1st char (mark end)
                    { #6 } %% { regex } { end patt }
                    { #7 } %%% "escape char" provision OR column (at col)
                    { #1 } %% 'class'
                    { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
                  }
              }
              { }
          } {}
      } {}

    \bool_if:NTF \l__codehl_lang_case_inbase_bool
      {
            \__codehl_lang_dlimit_add:NNnnn
              \l__codehl_lang_BUILD_base_prop
              \l__codehl_lang_base_int
              { _base }
              { #3 }
              {
                { #3 } %% 1st char (mark start)
                { #4 } %% { regex } { start patt }
                { #5 } %% 1st char (mark end)
                { #6 } %% { regex } { end patt }
                { #7 } %%% "escape char" provision OR column (at col)
                { #1 } %% 'class'
                { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
              }
        \bool_if:NTF \l__codehl_lang_case_nestable_bool
          {
            \bool_if:NTF \l__codehl_lang_case_instr_bool
              {
                \__codehl_lang_dlimit_add:NNnnn
                  \l__codehl_lang_BUILD_basestr_prop
                  \l__codehl_lang_basestr_int
                  { _basestr }
                  { #3 }
                  {
                    { #3 } %% 1st char (mark start)
                    { #4 } %% { regex } { start patt }
                    { #5 } %% 1st char (mark end)
                    { #6 } %% { regex } { end patt }
                    { #7 } %%% "escape char" provision OR column (at col)
                    { #1 } %% 'class'
                    { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
                  }
              }
              { }
            \bool_if:NTF \l__codehl_lang_case_incmt_bool
              {
                \__codehl_lang_dlimit_add:NNnnn
                  \l__codehl_lang_BUILD_basecmt_prop
                  \l__codehl_lang_basecmt_int
                  { _basecmt }
                  { #3 }
                  {
                    { #3 } %% 1st char (mark start)
                    { #4 } %% { regex } { start patt }
                    { #5 } %% 1st char (mark end)
                    { #6 } %% { regex } { end patt }
                    { #7 } %%% "escape char" provision OR column (at col)
                    { #1 } %% 'class'
                    { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
                  }
              }
              { }
          } { }
      } {}

    \bool_if:NTF \l__codehl_lang_case_intr_bool
      {
        %%% exception: _tr_ either appears in all above or only here
        \bool_set_true:N \l__codehl_lang_BUILD_tr_bool

            \__codehl_lang_dlimit_add:NNnnn
              \l__codehl_lang_BUILD_tr_prop
              \l__codehl_lang_tr_int
              { _tr }
              { #3 }
              {
                { #3 } %% 1st char (mark start)
                { #4 } %% { regex } { start patt }
                { #5 } %% 1st char (mark end) err: <replace code> in this case
                { #6 } %% { regex } { end patt }
                { #7 } %%% "escape char" provision OR column (at col)
                { #1 } %% 'class'
                { #2 } %% case (5 digits) 0/1 fmt/fmtless , 0/1: def as nestable , can hold nested , col at or nestable or not , 'case'
              }
      } { }
  }

\cs_new_protected:Npn \__codehl_lang_pattern_add:nnn #1#2#3
  {

    \prop_if_in:cnTF { l__codehl_lang_ #1 _pattern_prop }
      { #2 }
      { }
      { \seq_put_right:cn { l__codehl_lang_ #1 _pattern_seq } { #2 } }
    \prop_put:cnn { l__codehl_lang_ #1 _pattern_prop }
      { #2 }
      { #3 }
  }
\cs_generate_variant:Nn \__codehl_lang_pattern_add:nnn { oee }

%%%%%%%
%%% suppress ~=~ { <start-pattern> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_suppress_new:n #1
  {
        \tl_if_blank:nTF { #1 }
          { % nothing giving... => msg_error
          }
          {
            \__codehl_lang_get_dlimit:nNNN
              { #1 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              { { } { } } %% nothing, no dlimit triggered, but it has to be nn
          }
  }

\cs_new_protected:Npn \__codehl_lang_comment_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_comment_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang10d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% comment ~=~ { <class> } { <start-pattern> } { <end-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_comment_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang10a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
          }
          {
            \tl_if_blank:nTF { #3 }
              { % nothing giving... => msg_error
                \msg_error:nnneee { codehl / lang } { syntax err }
                  { lang10b }
                  \l__codehl_alias_lang_tl
                  { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
                  { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
              }
              {
                \__codehl_lang_options:n { #4 }

                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl

                \__codehl_lang_get_dlimit:nNNN
                  { #3 }
                  \l__codehl_tmpcd_tl
                  \l__codehl_tmpc_tl \l__codehl_tmpd_tl

                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                      {
                        %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:0>
                        { \l__codehl_lang_opt_nestkey_tl
                          \l__codehl_lang_opt_tagkey_tl . 00                  . 0 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                        {
                          { \exp_not:o \l__codehl_tmpd_tl }
                          { \exp_not:o \l__codehl_tmpcd_tl }
                        }   %% { regex } { end patt }
                        { }                                  %%% "escape char" provision OR column (at col)
                      }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang10c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_act_comment_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_act_comment_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang11d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% active ~ comment ~=~ { <class> } { <start-pattern> } { <end-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_act_comment_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang11a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
          }
          {
            \tl_if_blank:nTF { #3 }
              { % nothing giving... => msg_error
                \msg_error:nnneee { codehl / lang } { syntax err }
                  { lang11b }
                  \l__codehl_alias_lang_tl
                  { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
                  { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
              }
              {
                \__codehl_lang_options:n { #4 }

                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl

                \__codehl_lang_get_dlimit:nNNN
                  { #3 }
                  \l__codehl_tmpcd_tl
                  \l__codehl_tmpc_tl \l__codehl_tmpd_tl

                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                      {
                        %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:1>
                        { \l__codehl_lang_opt_nestkey_tl
                          \l__codehl_lang_opt_tagkey_tl . 00                  . 1 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                        {
                          { \exp_not:o \l__codehl_tmpd_tl }
                          { \exp_not:o \l__codehl_tmpcd_tl }
                        }   %% { regex } { end patt }
                        { }                                  %%% "escape char" provision OR column (at col)
                      }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang11c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_commentline_new:n #1
  {
    \__codehl_test_iii:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_commentline_new:nnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang22c }
          \l__codehl_alias_lang_tl
          { comment ~line ~=~ #1 }
          { comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% comment ~ line ~=~ { <class> } { <start-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_commentline_new:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnnenn { codehl / lang } { syntax err }
              { lang22a }
              \l__codehl_alias_lang_tl
              { comment ~line ~=~ #5 }
              { comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #3 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              {
                  { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                  {
                    %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:2>
                    { \l__codehl_lang_opt_nestkey_tl
                      \l__codehl_lang_opt_tagkey_tl . 00                  . 2 }
                    { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                    { }                                 %% 1st char (mark end)
                    { { } { } }                         %% { regex } { end patt }
                    { }                                 %%% "escape char" provision OR column (at col)
                  }
              }

          }
      }
      {
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang22b }
          \l__codehl_alias_lang_tl
          { comment ~line ~=~ #5 }
          { comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }

  }

\cs_new_protected:Npn \__codehl_lang_commentline_at_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_commentline_at_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang32c }
          \l__codehl_alias_lang_tl
          { comment ~line ~ at ~ =~ #1 }
          { comment ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
      }
  }

%%%%%%%
%%% comment ~ line ~=~ { <class> } { <start-pattern> } { column } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_commentline_at_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnnenn { codehl / lang } { syntax err }
              { lang32a }
              \l__codehl_alias_lang_tl
              { comment ~line ~ at ~ =~ #6 }
              { comment ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #4 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              {
                  { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                  {
                    %%%   <nestable><tag case>      . <incmt:0><col at:1> . <case:2>
                    { \l__codehl_lang_opt_nestkey_tl
                      \l__codehl_lang_opt_tagkey_tl . 01                  . 2 }
                    { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                    { }                                 %% 1st char (mark end)
                    { { } { } }                                 %% { regex } { end patt }
                    { \exp_not:n { #3 } }               %%% column (at col)
                  }
              }
          }
      }
      {
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang32b }
          \l__codehl_alias_lang_tl
          { comment ~line ~ at ~ =~ #6 }
          { comment ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
      }

  }

\cs_new_protected:Npn \__codehl_lang_act_commentline_new:n #1
  {
    \__codehl_test_iii:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_act_commentline_new:nnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang23c }
          \l__codehl_alias_lang_tl
          { active ~comment ~line ~=~ #1 }
          { active ~comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% active ~ comment ~ line ~=~ { <class> } { <start-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_act_commentline_new:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnnenn { codehl / lang } { syntax err }
              { lang23a }
              \l__codehl_alias_lang_tl
              { active ~comment ~line ~=~ #5 }
              { active ~comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #3 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              {
                  { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                  {
                    %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:3>
                    { \l__codehl_lang_opt_nestkey_tl
                      \l__codehl_lang_opt_tagkey_tl . 00                  . 3 }
                    { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                    {
                      { \exp_not:o \l__codehl_tmpb_tl }
                      { \exp_not:o \l__codehl_tmpab_tl }
                    }   %% { regex } { start patt }
                    { }                                 %% 1st char (mark end)
                    { { } { } }                                 %% { regex } { end patt }
                    { }                                 %%% "escape char" provision OR column (at col)
                  }
              }

          }
      }
      { % err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang23b }
          \l__codehl_alias_lang_tl
          { active ~comment ~line ~=~ #5 }
          { active ~comment ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_discard_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_discard_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang15d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl  ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl  ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% discard ~comment  ~=~ { <class> } { <start-pattern> } { <end-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_discard_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang15a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl  ~=~ \exp_not:n { #6 } }
              { \l__codehl_lang_opt_key_tl  ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #4 }

            \tl_if_blank:nTF { #3 }
              { % nothing giving... => msg_error
                \msg_error:nnneee { codehl / lang } { syntax err }
                  { lang15b }
                  \l__codehl_alias_lang_tl
                  { \l__codehl_lang_opt_key_tl  ~=~ \exp_not:n { #6 } }
                  { \l__codehl_lang_opt_key_tl  ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
              }
              {
                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl

                \__codehl_lang_get_dlimit:nNNN
                  { #3 }
                  \l__codehl_tmpcd_tl
                  \l__codehl_tmpc_tl \l__codehl_tmpd_tl

                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { 0 } %% 'class'  -- ignored in this case
                      {
                        %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:3>
                        { \l__codehl_lang_opt_nestkey_tl
                          \l__codehl_lang_opt_tagkey_tl . 00                  . 5 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                        {
                          { \exp_not:o \l__codehl_tmpd_tl }
                          { \exp_not:o \l__codehl_tmpcd_tl }
                        }   %% { regex } { end patt }
                        { }                                  %%% "escape char" provision OR column (at col)
                      }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang15c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl  ~=~ \exp_not:n { #6 } }
          { \l__codehl_lang_opt_key_tl  ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_discardline_new:n #1
  {
    \__codehl_test_iii:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_discardline_new:nnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang26c }
            \l__codehl_alias_lang_tl
            { discard ~comment  ~line ~=~ #1 }
            { discard ~comment  ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }
  }

%%%%%%%
%%% discard ~comment  ~ line ~=~ { <class> } { <start-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_discardline_new:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnnenn { codehl / lang } { syntax err }
              { lang26a }
              \l__codehl_alias_lang_tl
              { discard ~comment  ~line ~=~ #5 }
              { discard ~comment  ~line ~=~ { <class> } { <start-pattern> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #3 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              {
                  { 0 } %% 'class'  -- ignored in this case
                  {
                    %%%   <nestable><tag case>      . <incmt:0><col at:0> . <case:6>
                    { \l__codehl_lang_opt_nestkey_tl
                      \l__codehl_lang_opt_tagkey_tl . 00                  . 6 }
                    { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                    { }                                 %% 1st char (mark end)
                    { { } { } }                                 %% { regex } { end patt }
                    { }                                 %%% "escape char" provision OR column (at col)
                  }
              }

          }
      }
      { % err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang26b }
          \l__codehl_alias_lang_tl
          { discard ~comment  ~line ~=~ #5 }
          { discard ~comment  ~line ~=~ { <class> } { <start-pattern> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_discardline_at_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_discardline_at_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang36c }
            \l__codehl_alias_lang_tl
            { discard ~comment  ~line ~ at ~ =~ #1 }
            { discard ~comment  ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
      }
  }

%%%%%%%
%%% discard ~comment  ~ line ~=~ { <class> } { <start-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_discardline_at_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnnenn { codehl / lang } { syntax err }
              { lang36a }
              \l__codehl_alias_lang_tl
              { discard ~comment  ~line ~ at ~ =~ #6 }
              { discard ~comment  ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
          }
          {
            \__codehl_lang_options:n { #4 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \__codehl_lang_pattern_add:oee
              \l__codehl_def_lang_tl
              {
                \exp_not:o \l__codehl_tmpab_tl
              }
              {
                  { 0 } %% 'class'  -- ignored in this case
                  {
                    %%%   <nestable><tag case>      . <incmt:0><col at:1> . <case:6>
                    { \l__codehl_lang_opt_nestkey_tl
                      \l__codehl_lang_opt_tagkey_tl . 01                  . 6 }
                    { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                    { }                                 %% 1st char (mark end)
                    { { } { } }                                 %% { regex } { end patt }
                    { \exp_not:n { #3 } }               %%% column (at col)
                  }
              }

          }
      }
      { % err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang36b }
          \l__codehl_alias_lang_tl
          { discard ~comment  ~line ~ at ~ =~ #6 }
          { discard ~comment  ~line ~ at ~ =~ { <class> } { <start-pattern> } { <column> } { <options> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_string_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_string_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang14d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <pattern> } { <escape-char> }  }
      }
  }

%%%
%%%  single delimited string + escape char.
%%%
%%%%%%%
%%% string ~=~ { <class> } { <pattern> } { <escape-char> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_string_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang14a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <pattern> } { <escape-char> }  }
          }
          {
            \__codehl_lang_options:n { #4 }

            \__codehl_lang_get_dlimit:nNNN
              { #2 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \tl_if_empty:nTF { #3 }
              {
                    \__codehl_lang_pattern_add:oee
                      \l__codehl_def_lang_tl
                      {
                        \exp_not:o \l__codehl_tmpab_tl
                      }
                      {
                          { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                          {
                            %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:4>
                            { \l__codehl_lang_opt_nestkey_tl
                              \l__codehl_lang_opt_tagkey_tl . 10                  . 4 }
                            { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                            {
                              { \exp_not:o \l__codehl_tmpb_tl }
                              { \exp_not:o \l__codehl_tmpab_tl }
                            }   %% { regex } { start patt }
                            { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark end)
                            {
                              { \exp_not:o \l__codehl_tmpb_tl }
                              { \exp_not:o \l__codehl_tmpab_tl }
                            }   %% { regex } { end patt }
                            {  }   %%% "escape char"
                          }
                      }
              }
              {
                \__codehl_lang_get_dlimit:nNTF
                  { #3 }
                  \l__codehl_tmpe_tl
                  { %ok...
                    \__codehl_lang_pattern_add:oee
                      \l__codehl_def_lang_tl
                      {
                        \exp_not:o \l__codehl_tmpab_tl
                      }
                      {
                          { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                          {
                            %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:4>
                            { \l__codehl_lang_opt_nestkey_tl
                              \l__codehl_lang_opt_tagkey_tl . 10                  . 4 }
                            { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                            {
                              { \exp_not:o \l__codehl_tmpb_tl }
                              { \exp_not:o \l__codehl_tmpab_tl }
                            }   %% { regex } { start patt }
                            { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark end)
                            {
                              { \exp_not:o \l__codehl_tmpb_tl }
                              { \exp_not:o \l__codehl_tmpab_tl }
                            }   %% { regex } { end patt }
                            { \exp_not:o \l__codehl_tmpe_tl }   %%% "escape char"
                          }
                      }

                  }
                  { %err, more than one char
                    \msg_error:nnneee { codehl / lang } { syntax err }
                      { lang14b }
                      \l__codehl_alias_lang_tl
                      { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
                      { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <pattern> } { <escape-char> }  }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang14c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <pattern> } { <escape-char> }  }
      }
  }

\cs_new_protected:Npn \__codehl_lang_stringdlimit_new:n #1
  {
    \__codehl_test_v:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_string_new:nnnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang64ie }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> }  }
      }
  }

%%%%%%%
%%% delimited ~string ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_string_new:nnnnnwn #1#2#3#4#5 #6 \q_stop #7
  {
    \quark_if_nil:nTF { #6 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang64ia }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #7 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> }  }
          }
          {
            \tl_if_blank:nTF { #3 }
              { % nothing giving... => msg_error
                \msg_error:nnneee { codehl / lang } { syntax err }
                  { lang64ib }
                  \l__codehl_alias_lang_tl
                  { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #7 } }
                  { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> }  }
              }
              {
                \__codehl_lang_options:n { #5 }

                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl
                \__codehl_lang_get_dlimit:nNNN
                  { #3 }
                  \l__codehl_tmpcd_tl
                  \l__codehl_tmpc_tl \l__codehl_tmpd_tl

                \tl_if_empty:nTF { #4 }
                {
                      \__codehl_lang_pattern_add:oee
                        \l__codehl_def_lang_tl
                        {
                          \exp_not:o \l__codehl_tmpab_tl
                        }
                        {
                            { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                            {
                              %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:4>
                              { \l__codehl_lang_opt_nestkey_tl
                                \l__codehl_lang_opt_tagkey_tl . 10                  . 4 }
                              { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                          {
                            { \exp_not:o \l__codehl_tmpb_tl }
                            { \exp_not:o \l__codehl_tmpab_tl }
                          }   %% { regex } { start patt }
                              { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                          {
                            { \exp_not:o \l__codehl_tmpd_tl }
                            { \exp_not:o \l__codehl_tmpcd_tl }
                          }   %% { regex } { end patt }
                              {  }   %%% "escape char"
                            }
                        }
                }
                {
                  \__codehl_lang_get_dlimit:nNTF
                    { #4 }
                    \l__codehl_tmpe_tl
                    { %ok...
                      \__codehl_lang_pattern_add:oee
                        \l__codehl_def_lang_tl
                        {
                          \exp_not:o \l__codehl_tmpab_tl
                        }
                        {
                            { \exp_not:N \__codehl_class_remap:n { \exp_not:n { #1 } } } %% 'class'
                            {
                              %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:4>
                              { \l__codehl_lang_opt_nestkey_tl
                                \l__codehl_lang_opt_tagkey_tl . 10                  . 4 }
                              { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                          {
                            { \exp_not:o \l__codehl_tmpb_tl }
                            { \exp_not:o \l__codehl_tmpab_tl }
                          }   %% { regex } { start patt }
                              { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                          {
                            { \exp_not:o \l__codehl_tmpd_tl }
                            { \exp_not:o \l__codehl_tmpcd_tl }
                          }   %% { regex } { end patt }
                              { \exp_not:o \l__codehl_tmpe_tl }   %%% "escape char"
                            }
                        }
                    }
                    { %err, more than one char
                      \msg_error:nnneee { codehl / lang } { syntax err }
                        { lang64ic }
                        \l__codehl_alias_lang_tl
                        { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #7 } }
                        { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> }  }
                    }
                }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang64id }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #7 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <class> } { <start-pattern> } { <end-pattern> } { <escape-char> }  }
      }
  }

\cs_new_protected:Npn \__codehl_lang_ident_new:n #1
  {
    \__codehl_test_iii:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_ident_new:nnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang17d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <id-name> } { <char> } }
      }
  }

%%%%%%%
%%% identifier ~=~ { <id-name> } { <char> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_ident_new:nnnwn #1#2#3 #4 \q_stop #5
  {
    \quark_if_nil:nTF { #4 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang17a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #5 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <id-name> } { <char> } }
          }
          {
            \__codehl_lang_options:n { #3 }

                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl

                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:n { #1 } }                 %% 'class' not affected by remap
                      {
                        %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:7>
                        { \l__codehl_lang_opt_nestkey_tl
                          \l__codehl_lang_opt_tagkey_tl . 10                  . 7 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { }                                 %% 1st char (mark end)
                        { { } { } }                                 %% { regex } { end patt }
                        { }                                 %%% "escape char" provision OR column (at col)
                      }
                  }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang17c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #5 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <id-name> } { <char> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_identdlimit_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_ident_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnnenn { codehl / lang } { syntax err }
          { lang17d }
          \l__codehl_alias_lang_tl
          { identifier ~=~ #1 }
          { identifier ~=~ { <id-name> } { <char> } }
      }
  }

%%%%%%% TODO: will that be allowed?? implemented? ('easy' just another fully delimitted one.. but questionable)
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_ident_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {   % TOBE DONE... including tok-state
  }

\cs_new_protected:Npn \__codehl_lang_tagged_new:n #1
  {
    \__codehl_test_iv:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_tagged_new:nnnnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang18d }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } }
      }
  }

%%%%%%%
%%% comment ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_tagged_new:nnnnwn #1#2#3#4 #5 \q_stop #6
  {
    \quark_if_nil:nTF { #5 }
      {
        \tl_if_blank:nTF { #2 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang18a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } }
          }
          {
            \tl_if_blank:nTF { #3 }
              { % nothing giving... => msg_error
                \msg_error:nnneee { codehl / lang } { syntax err }
                  { lang18b }
                  \l__codehl_alias_lang_tl
                  { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
                  { \l__codehl_lang_opt_key_tl ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } }
              }
              {
                \__codehl_lang_options:n { #4 }

                \__codehl_lang_get_dlimit:nNNN
                  { #2 }
                  \l__codehl_tmpab_tl
                  \l__codehl_tmpa_tl \l__codehl_tmpb_tl

                \__codehl_lang_get_dlimit:nNNN
                  { #3 }
                  \l__codehl_tmpcd_tl
                  \l__codehl_tmpc_tl \l__codehl_tmpd_tl

                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:n { #1 } }                 %% 'class' not affected by remap
                      {
                        %%% ????
                        %%%   <nestable><tag case>      . <instr:1><col at:0> . <case:8>
                        { \l__codehl_lang_opt_nestkey_tl
                          \l__codehl_lang_opt_tagkey_tl . 10                  . 8 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:o \l__codehl_tmpc_tl }   %% 1st char (mark end)
                        {
                          { \exp_not:o \l__codehl_tmpd_tl }
                          { \exp_not:o \l__codehl_tmpcd_tl }
                        }   %% { regex } { end patt }
                        { }                                 %%% "escape char" provision OR column (at col)
                      }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang18c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #6 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } }
      }
  }

\cs_new_protected:Npn \__codehl_lang_tr_new:n #1
  {
    \__codehl_test_ii:nwTF #1 \q_nil \q_stop
      { %ok so far
        \__codehl_lang_tr_new:nnwn #1 \q_nil \q_stop { #1 }
      }
      { %err
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang19c }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #1 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <org-str> } { <replacement> } }
      }
  }

%%%%%%%
%%% comment ~=~ { <tagged-ident> } { <start-pattern> } { <end-pattern> } \q_nil \q_stop { <key-val> }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_tr_new:nnwn #1#2 #3 \q_stop #4
  {
    \quark_if_nil:nTF { #3 }
      {
        \tl_if_blank:nTF { #1 }
          { % nothing giving... => msg_error
            \msg_error:nnneee { codehl / lang } { syntax err }
              { lang19a }
              \l__codehl_alias_lang_tl
              { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #4 } }
              { \l__codehl_lang_opt_key_tl ~=~ { <org-str> } { <replacement> } }
          }
          {
            \__codehl_lang_get_dlimit:nNNN
              { #1 }
              \l__codehl_tmpab_tl
              \l__codehl_tmpa_tl \l__codehl_tmpb_tl

            \bool_if:NTF \l__codehl_lang_opt_tr_bool
              {
                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:n { replace } }                 %% 'class' not affected by remap
                      {
                        %%%   <nestable><tr case>      . <instr:1><col at:0> . <case:9>
                        { 03                            . 00                  . 9 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:n { #2 } }   %% replaced code
                        {
                          {  }
                          {  }
                        }   %% { regex } { end patt }
                        { }                                 %%% "escape char" provision OR column (at col)
                      }
                  }
              }
              {
                \__codehl_lang_pattern_add:oee
                  \l__codehl_def_lang_tl
                  {
                    \exp_not:o \l__codehl_tmpab_tl
                  }
                  {
                      { \exp_not:n { replace* } }                 %% 'class' not affected by remap
                      {
                        %%%   <nestable><tag case>      . <inboth:2><col at:0> . <case:9>
                        { 10                            . 20                  . 9 }
                        { \exp_not:o \l__codehl_tmpa_tl }   %% 1st char (mark start)
                        {
                          { \exp_not:o \l__codehl_tmpb_tl }
                          { \exp_not:o \l__codehl_tmpab_tl }
                        }   %% { regex } { start patt }
                        { \exp_not:n { #2 } }   %% replaced code
                        {
                          {  }
                          {  }
                        }   %% { regex } { end patt }
                        { }                                 %%% "escape char" provision OR column (at col)
                      }
                  }
              }
          }
      }
      {
        \msg_error:nnneee { codehl / lang } { syntax err }
          { lang19b }
          \l__codehl_alias_lang_tl
          { \l__codehl_lang_opt_key_tl ~=~ \exp_not:n { #4 } }
          { \l__codehl_lang_opt_key_tl ~=~ { <org-str> } { <replacement> } }
      }
  }

%%%%%%%
%%% those are all characters that have an special (regex) meaning
%%%%%%%
\regex_const:Nn \c__codehl_tr_regex { ( [ \_ \| \. \+ \* \? \! \, \^ \$ \:  \[ \] \{ \} \( \) \\ ] ) }
\cs_new_protected:Npn \__codehl_regex_sanitize:N
  {
    \regex_replace_all:NnN
      \c__codehl_tr_regex { \\ \1 }
  }

\regex_const:Nn \c__codehl_escape_regex { \\(.) }

%%%
%%% This 'saves' the pattern pre-sanitizing it
%%%
\cs_new_protected:Npn \__codehl_lang_get_dlimit:nNNN #1#2
  {
    \str_set:Nn #2 { #1 }
    \tl_remove_all:Nn #2 { ~ }
    \regex_replace_all:NnN
      \c__codehl_escape_regex {\1} #2
    \exp_last_unbraced:No \__codehl_lang_get_dlimit:wNN #2 \q_stop
  }

\cs_new_protected:Npn \__codehl_lang_get_dlimit:wNN #1#2 \q_stop #3#4
  {
    \tl_set:Nn #3 { #1 }
    \tl_if_blank:nTF { #2 }
      { \tl_clear:N #4 }
      {
        \tl_set:Nn #4 { #2 }
        \__codehl_regex_sanitize:N #4
      }
  }

\prg_new_protected_conditional:Npnn \__codehl_lang_get_dlimit:nN #1#2 { TF }
  {
    \str_set:Nn \l__codehl_tmpa_str { #1 }
    \tl_remove_all:Nn \l__codehl_tmpa_str { ~ }
    \regex_replace_all:NnN
      \c__codehl_escape_regex {\1} \l__codehl_tmpa_str
    \exp_last_unbraced:No \__codehl_lang_get_dlimit:wN \l__codehl_tmpa_str \q_stop #2
  }

\cs_new_protected:Npn \__codehl_lang_get_dlimit:wN #1#2 \q_stop #3
  {
    \tl_set:Nn #3 { #1 }
    \tl_if_blank:nTF { #2 }
      \prg_return_true:
      \prg_return_false:
  }

%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Using low level if's since it will process whatever code, a token (byte) at a time.
%%%
%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% 1st: nestable
%%% 2nd: 0:default, 1:tag only, 2:base only, 3:tr case
%%% 3rd: type 0:comment, 1:string, 2:both  <if nestable>
%%% 4th: col at
%%% 5th: case
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_case_split:w #1#2.#3#4.#5
  {
    \int_if_zero:nTF { #1 }
      {
        \bool_set_false:N \l__codehl_lang_case_incmt_bool
        \bool_set_false:N \l__codehl_lang_case_instr_bool
        \bool_set_false:N \l__codehl_lang_case_nestable_bool
      }
      {
        \bool_set_true:N \l__codehl_lang_case_nestable_bool
        \if_case:w #3
            \bool_set_true:N  \l__codehl_lang_case_incmt_bool
            \bool_set_false:N \l__codehl_lang_case_instr_bool
          \or:
            \bool_set_false:N \l__codehl_lang_case_incmt_bool
            \bool_set_true:N  \l__codehl_lang_case_instr_bool
          \or:
            \bool_set_true:N  \l__codehl_lang_case_incmt_bool
            \bool_set_true:N  \l__codehl_lang_case_instr_bool
        \fi:
      }

    \if_case:w #2
        \bool_set_true:N   \l__codehl_lang_case_inbase_bool
        \bool_set_true:N   \l__codehl_lang_case_intag_bool
        \bool_set_false:N  \l__codehl_lang_case_intr_bool
      \or:
        \bool_set_false:N  \l__codehl_lang_case_inbase_bool
        \bool_set_true:N   \l__codehl_lang_case_intag_bool
        \bool_set_false:N  \l__codehl_lang_case_intr_bool
      \or:
        \bool_set_true:N   \l__codehl_lang_case_inbase_bool
        \bool_set_false:N  \l__codehl_lang_case_intag_bool
        \bool_set_false:N  \l__codehl_lang_case_intr_bool
      \or:
        \bool_set_false:N  \l__codehl_lang_case_inbase_bool
        \bool_set_false:N  \l__codehl_lang_case_intag_bool
        \bool_set_true:N   \l__codehl_lang_case_intr_bool
    \fi:

    \int_if_zero:nTF { #4 }
      { \bool_set_false:N \l__codehl_lang_case_colat_bool }
      { \bool_set_true:N  \l__codehl_lang_case_colat_bool }
    \tl_set:Nn \l__codehl_lang_case_case_tl  { #5 }
  }

\cs_new_protected:Npn \__codehl_lang_case_getx:w #1#2.#3#4.#5
  {
      \int_if_zero:nTF { #4 }
      { \bool_set_false:N \l__codehl_lang_case_colat_bool }
      { \bool_set_true:N  \l__codehl_lang_case_colat_bool }
    \tl_set:Nn \l__codehl_lang_case_case_tl  { #5 }
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     building _scan: commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% { end 1st char } { end-rest } { class } { comment/string }  { case } { \...prop }
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_set_dlimit_end:nn #1#2
  {
    %%% dlimit end pattern (1st char)
    %%%
    \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end: }
      {
        \exp_not:N \if_charcode:w
          \exp_not:N \exp_not:o  \exp_not:N \l__codehl_tok_curr_token_tl
          \exp_not:N \exp_not:N \exp_not:n { #1 }
          \exp_not:N \cs_set:Npn
            \exp_not:N \__codehl_tok_proc:N
              {
                \exp_not:c
                  {
                    __codehl_lang_ \l__codehl_def_lang_tl _
                    \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                    \l__codehl_lang_build_postfix_tl _peek_end:N
                  }
              }
          \exp_not:N \__codehl_tok_scan_stop:w
        \exp_not:N \fi:
      }

    \tl_put_right:Nn \l__codehl_peek_build_endscanT_tl
      {
        \tl_clear:N \l__codehl_tok_build_dlimit_tl
         \__codehl_nested_pop:
         \__codehl_tok_proc:N
      }

    %%% dlimit end pattern (peeking)
    %%%
    \tl_if_empty:nTF { #2 }
      {
        \cs_set:cpe  {  __codehl_lang_ \l__codehl_def_lang_tl _
                        \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                        \l__codehl_lang_build_postfix_tl _peek_end:N }
          { \exp_not:o \l__codehl_peek_build_endscanT_tl }
      }
      {
        \regex_set:cn
          { l__codehl_lang_ \l__codehl_def_lang_tl _  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int \l__codehl_lang_build_postfix_tl _end_regex }
          { #2 }
        \cs_set:cpe  {  __codehl_lang_ \l__codehl_def_lang_tl _
                        \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                        \l__codehl_lang_build_postfix_tl _peek_end:N }
          {
            \exp_not:N \peek_regex_remove_once:NTF
              \exp_not:c {  l__codehl_lang_ \l__codehl_def_lang_tl _
                            \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                            \l__codehl_lang_build_postfix_tl _end_regex }
              { \exp_not:o \l__codehl_peek_build_endscanT_tl }
              { \exp_not:o \l__codehl_peek_build_endscanF_tl }
          }
      }
  }
\cs_generate_variant:Nn \__codehl_lang_set_dlimit_end:nn { no }

\cs_new_protected:Npn \__codehl_lang_init_eol:
  {
    \tl_clear:N \l__codehl_stack_eol_tl
    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_eol_tl
      { \l__codehl_tok_upto_eol_bool  }
  }

\cs_new_protected:Npn \__codehl_lang_stack_if_eol:
  {
    \bool_if:NTF \l__codehl_tok_upto_eol_bool
      {
        \__codehl_nested_stack_add:o
          \l__codehl_stack_eol_tl
        \bool_set_false:N \l__codehl_tok_upto_eol_bool
      }
      { }

  }

%%%%%%%
%%% case 0
%%% multi-line comment
%%% can be nested into another one
%%% can hold a nested one
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_comment:
  {
    \tl_clear:N \l__codehl_stack_cmt_tl

    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_cmt_tl
      { \l__codehl_tok_upto_eol_bool  }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_cmt_tl
      { \__codehl_tok_end_scan: , \__codehl_tok_start:N , \__codehl_tok_keyfmt_eff:Ncoo , \__codehl_tok_nesting_keywd:N }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmt_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N

    \__codehl_stack_build_fmtsave:N
      \l__codehl_stack_cmt_tl
  }

\cs_new_protected:Npn \__codehl_lang_peek_comment:nnnN #1#2#3#4  %% #4 shall be the 'right' property _tagcmtX_prop or _basecmtX_prop
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \tl_set:Ne \l__codehl_peek_build_endscanT_tl
      {
        \exp_not:N \__codehl_tok_fmt:on
          \exp_not:N \l__codehl_tok_build_dlimit_tl
          { \exp_not:o \l__codehl_peek_end_patt_tl \exp_not:N \__codehl_penalty: }
        \exp_not:N \tl_clear:N
          \exp_not:N \l__codehl_tok_build_dlimit_tl
      }

    \prop_get:NnNTF #4
      { #1 } \l__codehl_peek_endscan_caseB_tl
      {
        \tl_set:Ne \l__codehl_peek_build_endscanF_tl
          {
            \exp_not:N \cs_set:Npn
              \exp_not:N \__codehl_tok_proc:N
              { \exp_not:o \l__codehl_peek_endscan_caseB_tl }
            \exp_not:N \__codehl_tok_proc:N
          }
      }
      {
        %%% STILL TODO: verify, but all those _put_right:No might be wrong (missing \penalty 0)
        \tl_set:Nn \l__codehl_peek_build_endscanF_tl
          {
            \tl_put_right:No \l__codehl_tok_build_dlimit_tl \l__codehl_tok_curr_token_tl
            \cs_set:Npn \__codehl_tok_proc:N
              { \__codehl_tok_dlimit:N }
            \__codehl_tok_proc:N
          }
      }

    \__codehl_lang_set_dlimit_end:no { #1 } \l__codehl_peek_end_regex_tl

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \__codehl_nested_stack:o
          \exp_not:N \l__codehl_stack_cmt_tl

        \exp_not:N \bool_set_false:N
          \exp_not:N \l__codehl_tok_upto_eol_bool

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \__codehl_tok_set_fmt:c
          { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ comment _ \exp_not:n { #3 } _tl }

        \exp_not:N \cs_set:Npn \exp_not:N \__codehl_tok_keyfmt_eff:Ncoo
          { \exp_not:N \__codehl_tok_keyfmt_less:Ncoo }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_start:N
            { \exp_not:N \__codehl_tok_dlimit:N }
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_nesting_keywd:N
            { \exp_not:N \__codehl_tok_keywd_dlimit:N }

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_start:N

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_end_scan:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end:
                }
            }

      }
  }

%%%%%%%
%%% case 1
%%% multi-line active comment...
%%% can be nested into another one
%%%%%%%
%%% Already stack
\cs_new_protected:Npn \__codehl_lang_init_comment_tex:
  {
    \tl_clear:N \l__codehl_stack_cmttex_tl

    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_cmttex_tl
      { \l__codehl_tok_upto_eol_bool  }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_cmttex_tl
      { \__codehl_tok_end_scan: , \__codehl_tok_start:N }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmttex_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N

    \__codehl_stack_build_fmtsave:N
      \l__codehl_stack_cmttex_tl
  }
\cs_new_protected:Npn \__codehl_lang_peek_comment_tex:nnn #1#2#3
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \tl_set:Nn \l__codehl_peek_build_endscanT_tl
      {
        \__codehl_tok_fmt_retoken:o
          \l__codehl_tok_build_dlimit_tl

        \tl_clear:N
          \l__codehl_tok_build_dlimit_tl
      }
    \tl_set:Nn \l__codehl_peek_build_endscanF_tl
      {
        \tl_put_right:No \l__codehl_tok_build_dlimit_tl \l__codehl_tok_curr_token_tl
        \cs_set:Npn \__codehl_tok_proc:N
          { \__codehl_tok_dlimit_tex:N }
        \__codehl_tok_proc:N
      }

    \__codehl_lang_set_dlimit_end:no { #1 } \l__codehl_peek_end_regex_tl

    %%%
    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \__codehl_nested_stack:o
          \exp_not:N \l__codehl_stack_cmttex_tl

        \exp_not:N \bool_set_false:N
          \exp_not:N \l__codehl_tok_upto_eol_bool

        \exp_not:N \__codehl_tok_set_fmt:c
          { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ active _ \exp_not:n { #3 } _tl }
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_start:N
            { \exp_not:N \__codehl_tok_dlimit_tex:N }
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_current_base:N
            { \exp_not:N \__codehl_tok_dlimit_tex:N }
        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_start:N

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_end_scan:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end:
                }
            }
      }
  }

%%%%%%%
%%% case 2
%%% single-line comment
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_comment_line:
  {
    \tl_clear:N \l__codehl_stack_cmtline_tl

    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_cmtline_tl
      { \l__codehl_tok_upto_eol_bool  }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_cmtline_tl
      { \__codehl_tok_keyfmt_eff:Ncoo , \__codehl_tok_nesting_keywd:N }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmtline_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N

    \__codehl_stack_build_fmtsave:N
      \l__codehl_stack_cmtline_tl
  }
\cs_new_protected:Npn \__codehl_lang_peek_comment_line:n #1
  {
    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \bool_if:NTF \exp_not:N \l__codehl_tok_upto_eol_bool
          {
            \exp_not:N \__codehl_nested_stack_add:o
              \exp_not:N \l__codehl_stack_cmtline_tl
          }
          {
            \exp_not:N \__codehl_nested_stack:o
              \exp_not:N \l__codehl_stack_cmtline_tl
            \exp_not:N \bool_set_true:N \exp_not:N \l__codehl_tok_upto_eol_bool
          }

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \cs_set:Npn \exp_not:N \__codehl_tok_keyfmt_eff:Ncoo
          { \exp_not:N \__codehl_tok_keyfmt_less:Ncoo }

        \exp_not:N \__codehl_tok_set_fmt:c
          { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ comment _ \exp_not:n { #1 } _tl }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_proc:N
            { \exp_not:N \__codehl_tok_dlimit_line:N }  % single line comment
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_nesting_keywd:N
            { \exp_not:N \__codehl_tok_keywd_dlimit_line:N }
      }
  }

%%%%%%%
%%% case 3 => no format
%%% single-line 'active' (TeX) comment
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_comment_line_tex:
  {
    \tl_clear:N \l__codehl_stack_cmttexline_tl
    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_cmttexline_tl
      { \l__codehl_tok_upto_eol_bool  }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmttexline_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N

    \__codehl_stack_build_fmtsave:N
      \l__codehl_stack_cmttexline_tl

  }
\cs_new_protected:Npn \__codehl_lang_peek_comment_line_tex:n #1
  {

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \bool_if:NTF \exp_not:N \l__codehl_tok_upto_eol_bool
          {
            \exp_not:N \__codehl_nested_stack_add:o
              \exp_not:N \l__codehl_stack_cmttexline_tl
          }
          {
            \exp_not:N \__codehl_nested_stack:o
              \exp_not:N \l__codehl_stack_cmttexline_tl
            \exp_not:N \bool_set_true:N \exp_not:N \l__codehl_tok_upto_eol_bool
          }

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \__codehl_tok_set_fmt:c
          { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ active _ \exp_not:n { #1 } _tl }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_proc:N
            { \exp_not:N \__codehl_tok_dlimit_texline:w }  % single active (latex code) line comment
      }
  }

%%%%%%%
%%% case 4 => class formating: string
%%% multi-line string (same single/multi char delimiter) with/without escape char
%%% can be nested into another one
%%% can hold a nested one
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_string:
  {
    \tl_clear:N \l__codehl_stack_string_tl

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_string_tl
      { \__codehl_tok_end_scan: , \__codehl_tok_test_escape: , \__codehl_tok_start:N , \__codehl_tok_keyfmt_eff:Ncoo , \__codehl_tok_nesting_keywd:N }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_string_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N

    \__codehl_stack_build_fmtsave:N
      \l__codehl_stack_string_tl

  }
\cs_new_protected:Npn \__codehl_lang_peek_string:nnnnN #1#2#3#4#5
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \tl_set:Ne \l__codehl_peek_build_endscanT_tl
      {
        \exp_not:N \__codehl_tok_fmt:on
          \exp_not:N \l__codehl_tok_build_dlimit_tl
          { \exp_not:o \l__codehl_peek_end_patt_tl \exp_not:N \__codehl_penalty: }
        \exp_not:N \tl_clear:N
          \exp_not:N \l__codehl_tok_build_dlimit_tl
      }

    \prop_get:NnNTF #5
      { #1 } \l__codehl_peek_endscan_caseB_tl
      {
        \tl_set:Ne \l__codehl_peek_build_endscanF_tl
          {
                \exp_not:N \cs_set:Npn
                  \exp_not:N \__codehl_tok_proc:N
                  { \exp_not:o \l__codehl_peek_endscan_caseB_tl }
                \exp_not:N \__codehl_tok_proc:N
          }
      }
      {
        %%% STILL TODO: verify, but all those _put_right:No might be wrong (missing \penalty 0)
        \tl_set:Nn \l__codehl_peek_build_endscanF_tl
          {
            \tl_put_right:No \l__codehl_tok_build_dlimit_tl \l__codehl_tok_curr_token_tl
            \cs_set:Npn \__codehl_tok_proc:N
              { \__codehl_tok_string:N }
            \__codehl_tok_proc:N
          }
      }

    \__codehl_lang_set_dlimit_end:no { #1 } \l__codehl_peek_end_regex_tl

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \__codehl_nested_stack:o
          \exp_not:N \l__codehl_stack_string_tl

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_keyfmt_eff:Ncoo
          \exp_not:N \__codehl_tok_keyfmt_nested:Ncoo

        \exp_not:N \__codehl_tok_set_fmt:c
          { l__codehl_hlset_ \exp_not:N \l__codehl_tok_activ_hlset_tl _ string _ \exp_not:n { #4 } _tl }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_start:N
            { \exp_not:N \__codehl_tok_string:N }
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_nesting_keywd:N
            { \exp_not:N \__codehl_tok_keywd_string:N }

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_start:N

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_end_scan:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end:
                }
            }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_test_escape:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_escape:
                }
            }
      }

    %%% #3 -> escape char
    \tl_if_blank:nTF { #3 }
      {
        \cs_set_eq:cN
          { __codehl_lang_ \l__codehl_def_lang_tl _
            \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
            \l__codehl_lang_build_postfix_tl _scan_escape: }
          \prg_do_nothing:
      }
      {
        \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                      \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                      \l__codehl_lang_build_postfix_tl _scan_escape: }
          {
            \exp_not:N \if_charcode:w
              \exp_not:N \exp_not:o \exp_not:N \l__codehl_tok_curr_token_tl
              \exp_not:N \exp_not:N \exp_not:n { #3 }
              \exp_not:N \tl_put_right:No
                \exp_not:N \l__codehl_tok_build_dlimit_tl
                { \exp_not:n { #3 } }
              \exp_not:N \cs_set:Npn
                \exp_not:N \__codehl_tok_test_escape:
                  {
                    \exp_not:c
                      {
                        __codehl_lang_ \l__codehl_def_lang_tl _
                        \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                        \l__codehl_lang_build_postfix_tl _escape_done:
                      }
                  }
              \exp_not:N \__codehl_tok_scan_stop:w
            \exp_not:N \fi:
          }
        \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                      \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                      \l__codehl_lang_build_postfix_tl _escape_done: }
          {
            \exp_not:N \if_true:  %%% so that \__...scan_stop:w can be used...
              \exp_not:N \tl_put_right:No
                \exp_not:N \l__codehl_tok_build_dlimit_tl
                \exp_not:N \l__codehl_tok_curr_token_tl

              \exp_not:N \cs_set:Npn
                \exp_not:N \__codehl_tok_test_escape:
                  {
                    \exp_not:c
                      {
                        __codehl_lang_ \l__codehl_def_lang_tl _
                        \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                        \l__codehl_lang_build_postfix_tl _scan_escape:
                      }
                  }

              \exp_not:N \__codehl_tok_scan_stop:w
            \exp_not:N \fi:
          }
      }
  }

%%%%%%%
%%% case 5 =>
%%% multi-line discard comment
%%% can be nested into another one
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_discard:
  {
    \tl_clear:N \l__codehl_stack_cmtdisc_tl
    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_cmtdisc_tl
      { \l__codehl_tok_upto_eol_bool  }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_cmtdisc_tl
      { \__codehl_tok_end_scan: , \__codehl_tok_start:N , \__codehl_tok_disp_line:}

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmtdisc_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N
  }
\cs_new_protected:Npn \__codehl_lang_peek_discard:nnn #1#2#3
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \tl_set:Nn \l__codehl_peek_build_endscanT_tl
      { \tl_clear:N \l__codehl_tok_build_dlimit_tl }

    \tl_set:Nn \l__codehl_peek_build_endscanF_tl
      {
        %%% TODO: this should (?!) be just \tl_clear:N ... <discard>
        \tl_put_right:No \l__codehl_tok_build_dlimit_tl \l__codehl_tok_curr_token_tl
        \cs_set:Npn \__codehl_tok_proc:N
          { \__codehl_tok_dlimit_discard:N }
        \__codehl_tok_proc:N
      }

    \__codehl_lang_set_dlimit_end:no { #1 } \l__codehl_peek_end_regex_tl

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \__codehl_nested_stack:o
          \exp_not:N \l__codehl_stack_cmtdisc_tl

        \exp_not:N \bool_set_false:N
          \exp_not:N \l__codehl_tok_upto_eol_bool

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \cs_set:Npn \exp_not:N \__codehl_tok_disp_line:
          { \exp_not:N \__codehl_tok_discard_line: }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_start:N
            { \exp_not:N \__codehl_tok_dlimit_discard:N }
        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_start:N

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_end_scan:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end:
                }
            }
      }
  }

%%%%%%%
%%% case 6 =>
%%% single line discard 'comment'
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_discard_line:
  {
    \tl_clear:N \l__codehl_stack_cmtdiscline_tl

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_cmtdiscline_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N
  }
\cs_new_protected:Npn \__codehl_lang_peek_discard_line:
  {
    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \bool_if:NTF \exp_not:N \l__codehl_tok_upto_eol_bool
          {
           \exp_not:N \__codehl_nested_stack_add:o
             \exp_not:N \l__codehl_stack_cmtdiscline_tl
          }
          {
           \exp_not:N \__codehl_nested_stack:o
             \exp_not:N \l__codehl_stack_cmtdiscline_tl
          }

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_proc:N
            { \exp_not:N \__codehl_tok_discard_line:w } % single line discard
      }
  }

%%%%%%%
%%% case 7 =>
%%% "identifiers"  ( like $var  or \cs )
%%% can be nested into strings
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_ident:
  {
    \tl_clear:N \l__codehl_stack_ident_tl
    \__codehl_stack_build_tl:Nn
      \l__codehl_stack_ident_tl
      { \l__codehl_tok_curr_ident_tl }

    \__codehl_stack_build_bool:Nn
      \l__codehl_stack_ident_tl
      { \l__codehl_tok_ident_bool }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_ident_tl
      { \__codehl_tok_keyfmt_eff:Ncoo }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_ident_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N
  }
\cs_new_protected:Npn \__codehl_lang_peek_identifier:nnn #1#2#3
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_beg_regex_tl \l__codehl_peek_beg_patt_tl

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
       \exp_not:N \__codehl_nested_stack:o
         \exp_not:N \l__codehl_stack_ident_tl

        \exp_not:N \bool_set_true:N
          \exp_not:N \l__codehl_tok_ident_bool

        \exp_not:N \tl_set:Nn
          \exp_not:N \l__codehl_tok_build_prekeywd_tl
          { \exp_not:o \l__codehl_peek_beg_patt_tl }
        \exp_not:N \tl_set:Nn
          \exp_not:N \l__codehl_tok_curr_ident_tl
            { \exp_not:n { #3 } }

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_nesting_keywd:N

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_keyfmt_eff:Ncoo
          \exp_not:N \__codehl_tok_keyfmt_base:Ncoo
      }
  }

%%%%%%%
%%% case 8
%%% multi-line tagged area
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_init_tagged:
  {
    \tl_clear:N \l__codehl_stack_tagged_tl
    \__codehl_stack_build_tl:Nn
      \l__codehl_stack_tagged_tl
      { \l__codehl_tok_curr_tag_tl }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_tagged_tl
      { \__codehl_tok_end_scan: , \__codehl_tok_start:N , \__codehl_tok_keyfmt_eff:Ncoo , \__codehl_tok_nesting_keywd:N }

    \__codehl_stack_build_cs:Nn
      \l__codehl_stack_tagged_tl
      { \__codehl_tok_other_scan: , \__codehl_tok_cmt_scan: , \__codehl_tok_str_scan: }

    \__codehl_stack_build_cs:NNN
      \l__codehl_stack_tagged_tl
      \__codehl_tok_proc:N
      \__codehl_tok_start:N
  }

\cs_new_protected:Npn \__codehl_lang_peek_tagged:nnnN #1#2#3#4
  {
    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \tl_set:Ne \l__codehl_peek_build_endscanT_tl
      {
        \exp_not:N \__codehl_tok_fmt:on
          \exp_not:N \l__codehl_tok_build_dlimit_tl
          { \exp_not:o \l__codehl_peek_end_patt_tl \exp_not:N \__codehl_penalty: }

        \exp_not:N \tl_clear:N
          \exp_not:N \l__codehl_tok_build_dlimit_tl
      }

    \prop_get:NnNTF #4
      { #1 } \l__codehl_peek_endscan_caseB_tl
      {
        \tl_set:Ne \l__codehl_peek_build_endscanF_tl
          {
            \exp_not:N \cs_set:Npn
              \exp_not:N \__codehl_tok_proc:N
              { \exp_not:o \l__codehl_peek_endscan_caseB_tl }
            \exp_not:N \__codehl_tok_proc:N
          }
      }
      {
        \tl_set:Nn \l__codehl_peek_build_endscanF_tl
          {
            \tl_put_right:No \l__codehl_tok_build_dlimit_tl \l__codehl_tok_curr_token_tl
            \cs_set:Npn \__codehl_tok_proc:N
              { \__codehl_tok_tagged:N }
            \__codehl_tok_proc:N
          }
      }

    \__codehl_lang_set_dlimit_end:no { #1 } \l__codehl_peek_end_regex_tl

    \tl_set:Ne \l__codehl_peek_build_scanT_tl
      {
        \exp_not:N \__codehl_nested_stack:o
          \exp_not:N \l__codehl_stack_tagged_tl

        \exp_not:o \l__codehl_peek_build_scanTpre_tl

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_other_scan:
          \exp_not:N \__codehl_tok_intag:
        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_cmt_scan:
          \exp_not:N \__codehl_tok_intagcmt:
        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_str_scan:
          \exp_not:N \__codehl_tok_intagstr:

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_keyfmt_eff:Ncoo
          \exp_not:N \__codehl_tok_keyfmt_base:Ncoo

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_start:N
            { \exp_not:N \__codehl_tok_tagged:N }
        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_nesting_keywd:N
            { \exp_not:N \__codehl_tok_keywd_tagged:N }

        \exp_not:N \cs_set_eq:NN
          \exp_not:N \__codehl_tok_proc:N
          \exp_not:N \__codehl_tok_start:N

        \exp_not:N \tl_set:Nn
          \exp_not:N \l__codehl_tok_curr_tag_tl
          { #3 }

        \exp_not:N \cs_set:Npn
          \exp_not:N \__codehl_tok_end_scan:
            {
              \exp_not:c
                {
                  __codehl_lang_ \l__codehl_def_lang_tl _
                  \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                  \l__codehl_lang_build_postfix_tl _scan_dlimit_end:
                }
            }

      }
  }

%%%%%%%
%%% case 9
%%% replace
%%%%%%%
\cs_new_protected:Npn \__codehl_lang_peek_tr:n #1
  {
    \tl_set:Nn \l__codehl_peek_build_scanT_tl
      {
       \__codehl_tok_fmt:o
         \l__codehl_tok_build_dlimit_tl
       \tl_clear:N
         \l__codehl_tok_build_dlimit_tl
       \__codehl_tok_fmt:n
        { #1 }
       \cs_set_eq:NN
         \__codehl_tok_proc:N
         \__codehl_tok_start:N
      }
  }

\cs_new_protected:Npn \__codehl_lang_mark_get:nnNN #1#2#3#4
  {
    \tl_set:Nn #3 { #1 }
    \tl_set:Nn #4 { #2 }
  }

%%%%%%%
%%% {start 1st char}{start-rest} {end 1st char}{end-rest} {escape} {class} { case }
%%%%%%%
%%% #2 -> {regex}{tex pattern}
%%% #4 -> {regex}{tex pattern}
\cs_new_protected:Npn \__codehl_lang_peek_build:nnnnnnnNN #1#2#3#4#5#6#7#8#9  %%% #8 cmtX_prop #9 strX_prop
  {
    \__codehl_lang_case_getx:w #7

    \__codehl_lang_mark_get:nnNN #2
      \l__codehl_peek_beg_regex_tl \l__codehl_peek_beg_patt_tl

    \tl_set:Ne \l__codehl_peek_build_scanF_tl
      {
        \exp_not:c {  __codehl_lang_ \l__codehl_def_lang_tl _
                      \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                      \l__codehl_lang_build_postfix_tl _scan_dlimit: }
      }

    \int_if_zero:nT { \l__codehl_lang_dlimit_cntB_int }
      {
            \cs_set:cpn { __codehl_lang_ \l__codehl_def_lang_tl _
                          \int_use:N \l__codehl_lang_dlimit_cntA_int .0
                          \l__codehl_lang_build_postfix_tl _scan_dlimit: }
              {
                \cs_set_eq:NN
                  \__codehl_tok_proc:N
                  \__codehl_tok_start:N

                \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { #1 \__codehl_penalty: }
                \__codehl_tok_proc:N
              }
      }

    \int_incr:N \l__codehl_lang_dlimit_cntB_int

    \tl_set:Ne \l__codehl_peek_build_scanTpre_tl
      {
        \exp_not:N \__codehl_tok_fmt:o
          \exp_not:N \l__codehl_tok_build_dlimit_tl

        \exp_not:N \tl_set:Nn
          \exp_not:N \l__codehl_tok_build_dlimit_tl
          { \exp_not:o \l__codehl_peek_beg_patt_tl }
      }

    \if_case:w " \l__codehl_lang_case_case_tl
        %%% case 0
        %%% shall receive a _basecmtX_prop or _tagcmtX_prop
        \__codehl_lang_peek_comment:nnnN { #3 }{ #4 }{ #6 }  #8
      \or:
        %%% case 1
        \__codehl_lang_peek_comment_tex:nnn { #3 }{ #4 }{ #6 }
      \or:
        %%% case 2
        \__codehl_lang_peek_comment_line:n { #6 }
      \or:
        %%% case 3
        \__codehl_lang_peek_comment_line_tex:n { #6 }
      \or:
        %%% case 4
        %%% shall receive a _basestrX_prop or _tagstrX_prop
        \__codehl_lang_peek_string:nnnnN  { #3 }{ #4 }{ #5 }{ #6 }  #9
      \or:
        %%% case 5
        \__codehl_lang_peek_discard:nnn  { #3 }{ #4 }{ #6 }
      \or:
        %%% case 6
        \__codehl_lang_peek_discard_line:
      \or:
        %%% case 7
        \__codehl_lang_peek_identifier:nnn { #1 }{ #2 }{ #6 }
      \or:
        %%% case 8
        \bool_set_true:N \l__codehl_lang_BUILD_tagged_bool
        \__codehl_lang_peek_tagged:nnnN { #3 }{ #4 }{ #6 }  \l__codehl_lang_BUILD_tagX_prop

      \or:
        %%% case 9
        \__codehl_lang_peek_tr:n { #3 }

%      \or:
%        %%% case A => "... formating"
%        %%% reserved
%      \or:
%        %%% case B => "... formating"
%        %%% reserved
    \fi:

    \tl_if_empty:NTF \l__codehl_peek_beg_regex_tl
      {
            \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                          \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                          \l__codehl_lang_build_postfix_tl _scan_dlimit: }
              {
                \exp_not:o \l__codehl_peek_build_scanT_tl
                \exp_not:N \__codehl_tok_proc:N
              }
      }
      {
        \regex_set:ce { l__codehl_lang_ \l__codehl_def_lang_tl _
            \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
            \l__codehl_lang_build_postfix_tl _scan_regex }
          { \exp_not:o \l__codehl_peek_beg_regex_tl }
        \bool_if:NTF \l__codehl_lang_case_colat_bool
          {
            \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                          \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                          \l__codehl_lang_build_postfix_tl _scan_dlimit: }
              {
                \exp_not:N \int_compare:nNnTF { \exp_not:N \l__codehl_tok_col_int } = { \exp_not:n { #5 } }
                  {
                    \exp_not:N \peek_regex_remove_once:NTF
                      \exp_not:c {  l__codehl_lang_ \l__codehl_def_lang_tl _
                                    \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                                    \l__codehl_lang_build_postfix_tl _scan_regex }
                      {
                        \exp_not:o \l__codehl_peek_build_scanT_tl
                        \exp_not:N \__codehl_tok_proc:N
                      }
                      {
                        \exp_not:o \l__codehl_peek_build_scanF_tl
                      }
                  }
                  {
                    \exp_not:o \l__codehl_peek_build_scanF_tl
                  }
              }
          }
          {
                \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl _
                              \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                              \l__codehl_lang_build_postfix_tl _scan_dlimit: }
                  {
                    \exp_not:N \peek_regex_remove_once:NTF
                      \exp_not:c {  l__codehl_lang_ \l__codehl_def_lang_tl _
                                    \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                                    \l__codehl_lang_build_postfix_tl _scan_regex }
                      {
                        \exp_not:o \l__codehl_peek_build_scanT_tl
                        \exp_not:N \__codehl_tok_proc:N
                      }
                      {
                        \exp_not:o \l__codehl_peek_build_scanF_tl
                      }
                  }
          }
      }
  }

\cs_new_protected:Npn \__codehl_lang_build_cmd:nn #1#2
  {
    \seq_map_inline:cn { l__codehl_lang_ #2 _pattern_seq }
      {
        \prop_if_in:cnTF { l__codehl_lang_ #1 _pattern_prop } { ##1 }
          { }
          {
            \seq_put_right:cn { l__codehl_lang_ #1 _pattern_seq } { ##1 }
          }
        \prop_get:cnN { l__codehl_lang_ #2 _pattern_prop }
          { ##1 }
          \l__codehl_pattern_tmp_tl
        \exp_last_unbraced:Nno
          \__codehl_lang_build_aux:cenn
            { l__codehl_lang_ #1 _pattern_prop }
            \l__codehl_pattern_tmp_tl
            { ##1 }
      }

    \prop_concat:ccc
      { l__codehl_lang_  #1 _keys_prop }
      { l__codehl_lang_  #1 _keys_prop }
      { l__codehl_lang_  #2 _keys_prop }
    \prop_concat:ccc
      { l__codehl_lang_  #1 _bool_keys_prop }
      { l__codehl_lang_  #1 _bool_keys_prop }
      { l__codehl_lang_  #2 _bool_keys_prop }

  }

\cs_new_protected:Npn \__codehl_lang_build_aux:Nnnn #1#2#3#4
  {
    \tl_if_empty:nTF { #3 }
      {
        \prop_put:Nnn #1 { #4 }
          { }
      }
      {
        \prop_put:Nnn #1 { #4 }
          {
            \__codehl_lang_dlimit_add:nnnnnnn
              { #2 }
              #3
          }
      }
  }
\cs_generate_variant:Nn \__codehl_lang_build_aux:Nnnn { ce }

\cs_new_protected:Npn \__codehl_lang_build:NNN #1#2#3
  {
    \tl_clear:N \l__codehl_tmpa_tl
    \int_zero:N \l__codehl_lang_dlimit_cntA_int  %% per "1st char"

    \prop_map_inline:Nn #1
      {
        \int_incr:N \l__codehl_lang_dlimit_cntA_int
        \int_zero:N \l__codehl_lang_dlimit_cntB_int

        \seq_map_inline:Nn ##2
          {
            \__codehl_lang_peek_build:nnnnnnnNN ####1 #2 #3
          }
        \tl_put_right:Ne \l__codehl_tmpa_tl
          {
            \exp_not:N \if_charcode:w
              \exp_not:N \exp_not:o \exp_not:N \l__codehl_tok_curr_token_tl
              \exp_not:N \exp_not:N \exp_not:n { ##1 }
              \exp_not:N \cs_set:Npn
                \exp_not:N \__codehl_tok_proc:N
                  {
                    \exp_not:c
                      {
                        __codehl_lang_ \l__codehl_def_lang_tl _
                        \int_use:N \l__codehl_lang_dlimit_cntA_int . \int_use:N \l__codehl_lang_dlimit_cntB_int
                        \l__codehl_lang_build_postfix_tl _scan_dlimit:
                      }
                  }

              \exp_not:N \__codehl_tok_scan_stop:w
            \exp_not:N \fi:
          }
      }

    \cs_set:cpe { __codehl_lang_ \l__codehl_def_lang_tl  \l__codehl_lang_build_postfix_tl _scan_dlimit: }
      { \exp_not:o \l__codehl_tmpa_tl }

  }

\cs_new_protected:Npn \__codehl_lang_build_indX:NNn #1#2#3
  {
    \int_zero:N \l__codehl_lang_dlimit_cntA_int
    \prop_if_empty:NTF #1
      { }
      {
        \prop_map_inline:Nn #1
          {
            \int_incr:N \l__codehl_lang_dlimit_cntA_int
            \prop_put:Nne #2
              { ##1 }
              { \exp_not:c { __codehl_lang_ \l__codehl_def_lang_tl _ \int_use:N \l__codehl_lang_dlimit_cntA_int . \seq_count:N ##2 #3 _scan_dlimit: } }
          }
      }
  }

\cs_new_protected:Npn \__codehl_lang_build_digits_scan:Nnn #1#2#3
  {
    \bool_if:NTF #1
      {
        \tl_if_empty:nTF { #2#3 }
          {
            \cs_set:cpn  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_digits:N } ##1
              { }
          }
          {
            %%% TODO: sanitize this !!!
            \regex_set:cn
              { l__codehl_lang_ \l__codehl_def_lang_tl _digits_regex }
              { [ #2#3 ] }
            \cs_set:cpe  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_digits:N } ##1
              {
                \exp_not:N \if_true:
                \exp_not:N \regex_if_match:NnTF \exp_not:c { l__codehl_lang_ \l__codehl_def_lang_tl _digits_regex } { ##1 }
                  {
                    \exp_not:N \tl_put_right:Nn \exp_not:N \l__codehl_tok_build_keywd_tl ##1
                    \exp_not:N \__codehl_tok_scan_stop:w % jumping to \scan_stop:
                  }
                  { }
                \exp_not:N \fi:
              }
          }
        \tl_if_empty:nTF { #3 }
          {
            \cs_set:cpn  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_oletter:N } ##1
              { }
          }
          {
            %%% TODO: sanitize this !!!
            \regex_set:cn
              { l__codehl_lang_ \l__codehl_def_lang_tl _oletter_regex }
              { [ #3 ] }
            \cs_set:cpe  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_oletter:N } ##1
              {
                \exp_not:N \regex_if_match:NnTF \exp_not:c { l__codehl_lang_ \l__codehl_def_lang_tl _oletter_regex } { ##1 }
                  {
                    \exp_not:N \tl_set:Nn \exp_not:N \l__codehl_tok_build_keywd_tl ##1
                    \exp_not:N \cs_set_eq:NN \exp_not:N \__codehl_tok_proc:n \exp_not:N \__codehl_tok_nesting_keywd:N
                    \exp_not:N \tl_set_eq:NN \exp_not:N \l__codehl_tok_curr_ident_tl \exp_not:N \l__codehl_tok_curr_tag_tl
                    \exp_not:N \__codehl_tok_scan_stop:w % jumping to \scan_stop:
                  }
                  { }
              }
          }
      }
      {
        \cs_set:cpn  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_digits:N } ##1
          { }
        \cs_set:cpn  {  __codehl_lang_ \l__codehl_def_lang_tl _scan_oletter:N } ##1
          { }
      }
  }

\cs_generate_variant:Nn \__codehl_lang_build_digits_scan:Nnn { Noo }

\cs_new_protected:Npn \__codehl_lang_build:n #1
  {
    \bool_set_true:c { l__codehl_lang_ #1 _build_bool }
    \tl_set:Nn \l__codehl_def_lang_tl { #1 }

    \prop_clear:c { l__codehl_lang_ #1 _build _pattern_prop }
    \seq_clear:c  { l__codehl_lang_ #1 _build _pattern_seq }

    \prop_set_eq:cN { l__codehl_lang_ #1 _build_keys_prop } \c__codehl_lang_base_keys_prop
    \prop_set_eq:cN { l__codehl_lang_ #1 _build_bool_keys_prop } \c__codehl_lang_base_bool_keys_prop

  %%%
  %%% assembling _build_  !!!  remapping ...
  %%%
    \int_zero:N   \l__codehl_remapcount_int
    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_n:n
    \cs_set_eq:NN \__codehl_build_cmd:nn  \__codehl_lang_build_cmd:nn
    \__codehl_build_remap:nnnnn { lang } { #1 _build } { 0 } { 0 } { #1 }
    \cs_set_eq:NN \__codehl_class_remap:n \__codehl_class_remap_default:n

  %%%
  %%% single cases (for now)
  %%%
    \prop_get:cnN { l__codehl_lang_ #1 _build_keys_prop }
      { digits }
      \l__codehl_tmpa_tl
    \prop_get:cnN { l__codehl_lang_ #1 _build_keys_prop }
      { oletter }
      \l__codehl_tmpb_tl
    \prop_get:cnN { l__codehl_lang_ #1 _build_bool_keys_prop }
      { alpha }
      \l__codehl_tmpc_tl

    \exp_args:No
    \__codehl_lang_build_digits_scan:Noo
      \l__codehl_tmpc_tl
      \l__codehl_tmpa_tl
      \l__codehl_tmpb_tl

  %%%
    \int_zero:N \l__codehl_lang_base_int
    \int_zero:N \l__codehl_lang_basecmt_int
    \int_zero:N \l__codehl_lang_basestr_int
    \int_zero:N \l__codehl_lang_tag_int
    \int_zero:N \l__codehl_lang_tagcmt_int
    \int_zero:N \l__codehl_lang_tagstr_int

    \prop_clear:N \l__codehl_lang_BUILD_base_prop
    \prop_clear:N \l__codehl_lang_BUILD_basecmt_prop
    \prop_clear:N \l__codehl_lang_BUILD_basecmtX_prop
    \prop_clear:N \l__codehl_lang_BUILD_basestr_prop
    \prop_clear:N \l__codehl_lang_BUILD_basestrX_prop

    \prop_clear:N \l__codehl_lang_BUILD_tag_prop
    \prop_clear:N \l__codehl_lang_BUILD_tagX_prop
    \prop_clear:N \l__codehl_lang_BUILD_tagcmt_prop
    \prop_clear:N \l__codehl_lang_BUILD_tagcmtX_prop
    \prop_clear:N \l__codehl_lang_BUILD_tagstr_prop
    \prop_clear:N \l__codehl_lang_BUILD_tagstrX_prop

  %%%
  %%% 'executing' _build_ from assembling ==> executing
  %%%                 \__codehl_lang_dlimit_add:nnnnnnn (if not suppressed)
  %%%
    \bool_set_false:N \l__codehl_lang_BUILD_tr_bool
    \seq_map_inline:cn { l__codehl_lang_ #1 _build _pattern_seq }
      { \prop_item:cn { l__codehl_lang_ #1 _build _pattern_prop } { ##1 } }

  %%%%%%%
  %%% mapping _scan_ functions
  %%% this is 'almost' not needed... trouble is the 'end_scan' commands need those beforehand.
  %%%%%%%
    \bool_set_false:N \l__codehl_lang_BUILD_tagged_bool

    \__codehl_lang_build_indX:NNn
      \l__codehl_lang_BUILD_basecmt_prop
      \l__codehl_lang_BUILD_basecmtX_prop
      { _basecmt }

    \__codehl_lang_build_indX:NNn
      \l__codehl_lang_BUILD_basestr_prop
      \l__codehl_lang_BUILD_basestrX_prop
      { _basestr }

    \tl_set:Nn \l__codehl_lang_build_postfix_tl { _base }
    \__codehl_lang_build:NNN
      \l__codehl_lang_BUILD_base_prop
      \l__codehl_lang_BUILD_basecmtX_prop
      \l__codehl_lang_BUILD_basestrX_prop

    \tl_set:Nn \l__codehl_lang_build_postfix_tl { _basecmt }
    \__codehl_lang_build:NNN
      \l__codehl_lang_BUILD_basecmt_prop
      \l__codehl_lang_BUILD_basecmtX_prop
      \l__codehl_lang_BUILD_basestrX_prop

    \tl_set:Nn \l__codehl_lang_build_postfix_tl { _basestr }
    \__codehl_lang_build:NNN
      \l__codehl_lang_BUILD_basestr_prop
      \l__codehl_lang_BUILD_basecmtX_prop
      \l__codehl_lang_BUILD_basestrX_prop

    \bool_if:NTF \l__codehl_lang_BUILD_tagged_bool
      {
        \__codehl_lang_build_indX:NNn
          \l__codehl_lang_BUILD_tag_prop
          \l__codehl_lang_BUILD_tagX_prop
          { _tag }

        \__codehl_lang_build_indX:NNn
          \l__codehl_lang_BUILD_tagcmt_prop
          \l__codehl_lang_BUILD_tagcmtX_prop
          { _tagcmt }

        \__codehl_lang_build_indX:NNn
          \l__codehl_lang_BUILD_tagstr_prop
          \l__codehl_lang_BUILD_tagstrX_prop
          { _tagstr }

        \tl_set:Nn \l__codehl_lang_build_postfix_tl { _tag }
        \__codehl_lang_build:NNN
          \l__codehl_lang_BUILD_tag_prop
          \l__codehl_lang_BUILD_tagcmtX_prop
          \l__codehl_lang_BUILD_tagstrX_prop

        \tl_set:Nn \l__codehl_lang_build_postfix_tl { _tagcmt }
        \__codehl_lang_build:NNN
          \l__codehl_lang_BUILD_tagcmt_prop
          \l__codehl_lang_BUILD_tagcmtX_prop
          \l__codehl_lang_BUILD_tagstrX_prop

        \tl_set:Nn \l__codehl_lang_build_postfix_tl { _tagstr }
        \__codehl_lang_build:NNN
          \l__codehl_lang_BUILD_tagstr_prop
          \l__codehl_lang_BUILD_tagcmtX_prop
          \l__codehl_lang_BUILD_tagstrX_prop
      }
      {
        \cs_set:cpn { __codehl_lang_ \l__codehl_def_lang_tl  _tag _scan_dlimit: }
          { }
        \cs_set:cpn { __codehl_lang_ \l__codehl_def_lang_tl  _tagcmt _scan_dlimit: }
          { }
        \cs_set:cpn { __codehl_lang_ \l__codehl_def_lang_tl  _tagstr _scan_dlimit: }
          { }
      }
    \bool_if:NTF \l__codehl_lang_BUILD_tr_bool
      {
        \tl_set:Nn \l__codehl_lang_build_postfix_tl { _tr }
        \__codehl_lang_build:NNN
          \l__codehl_lang_BUILD_tr_prop
          \c_empty_prop
          \c_empty_prop
      }
      {
        \cs_set:cpn { __codehl_lang_ \l__codehl_def_lang_tl  _tr _scan_dlimit: }
          { }
      }

  }

%%% This assumes it exists!
\cs_new_protected:Npn \__codehl_lang_build_ifnot:n #1
  {
    \bool_if:cF { l__codehl_lang_ #1 _build_bool }
      { \__codehl_lang_build:n { #1 } }
  }
\cs_generate_variant:Nn \__codehl_lang_build_ifnot:n { o }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     show commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\cs_new_protected:Npn \codehl_settings_show:n #1
  { 
    \__codehl_settings_if_def:nNTF
      { #1 } \l__codehl_def_settings_tl
      {
        \group_begin:
          \tl_clear:N \l__codehl_tmpa_tl
          \prop_map_inline:cn { l__codehl_settings_  \l__codehl_def_settings_tl _prop }
            {
              \tl_put_right:Nn \l__codehl_tmpa_tl     
                { \exp_not:n { ~~ } \exp_not:n { ~~ } }
              \tl_put_right:Ne \l__codehl_tmpa_tl 
                { { \prop_item:Nn \c__codehl_settings_keys_name_prop { ##1 } } }
              \tl_put_right:Nn \l__codehl_tmpa_tl     
                {  ~ =>~ { \exp_not:n { ##2 } } \iow_newline: }
            }
            \msg_show:nnne { codehl / settings } { struct info }
              { #1 } \l__codehl_tmpa_tl
        \group_end:
      }
      {
        \tl_if_blank:nTF { #1 }
          {
            \group_begin:
              \tl_set:Ne \l__codehl_tmpa_tl
                {
                  \exp_not:n { ~~ } \exp_not:n { ~~ }  Active ~ language: ~      { \l__codehl_tok_activ_lang_tl }
                  \exp_not:N \iow_newline:
                  \exp_not:n { ~~ } \exp_not:n { ~~ }  Active ~ hl ~ set: ~      { \l__codehl_tok_activ_hlset_tl }
                  \exp_not:N \iow_newline:
                  \exp_not:n { ~~ } \exp_not:n { ~~ }  Active ~ keywd ~ set: ~   { \l__codehl_tok_activ_keyset_tl }
                  \exp_not:N \iow_newline:
                  \exp_not:n { ~~ } \exp_not:n { ~~ }  Active ~ base ~ format: ~ { \l__codehl_tok_activ_basefmt_tl }
                }
                \msg_show:nne { codehl / settings } { active }
                  \l__codehl_tmpa_tl
            \group_end:
            
          }
          {
            \msg_error:nnnn { codehl / settings } { non existant }
              { settings01a } { #1 }
          }
      }
  }
  
\cs_new_protected:Npn \hlSettingsShow #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_settings_show:n
  }

\cs_new_protected:Npn \codehl_basefmt_show:n #1
  {
    \__codehl_basefmt_if_def:nNTF
      { #1 } \l__codehl_def_basefmt_tl
      {
          \__codehl_basefmt_build_ifnot:on \l__codehl_def_basefmt_tl { }
        \group_begin:
          \tl_clear:N \l__codehl_tmpa_tl

          \tl_put_right:Nn \l__codehl_tmpa_tl
            { \exp_not:n { ~~ } Booleans: \iow_newline: }
          \prop_map_inline:cn { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_bool_keys_prop }
            {
              \prop_get:NnNTF \c__codehl_basefmt_keys_name_prop { ##1 } \l__codehl_tmpb_tl
                {
                  \tl_put_right:Nn \l__codehl_tmpa_tl     { \exp_not:n { ~~ } \exp_not:n { ~~ } }
                  \tl_put_right:Ne \l__codehl_tmpa_tl     { { \l__codehl_tmpb_tl } }

                  \bool_if:nTF { ##2 }
                    { \tl_put_right:Nn \l__codehl_tmpa_tl { ~ =>~ {true}  \iow_newline: } }
                    { \tl_put_right:Nn \l__codehl_tmpa_tl { ~ =>~ {false} \iow_newline: } }
                }
                {  }

            }

          \tl_put_right:Nn \l__codehl_tmpa_tl
            { \exp_not:n { ~~ } Values: \iow_newline: }
          \prop_map_inline:cn { l__codehl_basefmt_  \l__codehl_def_basefmt_tl _build_keys_prop }
            {
              \prop_get:NnNTF \c__codehl_basefmt_keys_name_prop { ##1 } \l__codehl_tmpb_tl
                {
                  \tl_put_right:Nn \l__codehl_tmpa_tl     { \exp_not:n { ~~ } \exp_not:n { ~~ } }
                  \tl_put_right:Ne \l__codehl_tmpa_tl     { { \l__codehl_tmpb_tl } }
                  \tl_put_right:Nn \l__codehl_tmpa_tl     {  ~ =>~ { \exp_not:n { ##2 } } \iow_newline: }
                }
                {  }

            }
          \msg_show:nnne { codehl / basefmt } { struct info }
            { #1 } \l__codehl_tmpa_tl
        \group_end:
      }
      {
        \msg_error:nnnn { codehl / basefmt } { non existant }
          { basefmt01a } { #1 }
      }
  }
\cs_new_protected:Npn \hlBasefmtShow #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_basefmt_show:n
  }

\cs_new_protected:Npn \codehl_hlset_show:n #1
  {
    \prop_get:NnNTF \l__codehl_sets_hlset_prop
      { #1 } \l__codehl_def_hlset_tl
      {
        \__codehl_hlset_build_ifnot:o \l__codehl_def_hlset_tl

        \group_begin:
          \tl_clear:N \l__codehl_tmpa_tl

          \seq_map_inline:cn { l__codehl_hlset_ \l__codehl_def_hlset_tl _build_seq }
            {
              \tl_put_right:Nn \l__codehl_tmpa_tl
                { \iow_newline: ~~group:~{ ##1 }  \iow_newline: }
              \prop_map_inline:cn { l__codehl_hlset_ \l__codehl_def_hlset_tl _ ##1 _build_prop }
                {
                  \tl_put_right:Nn \l__codehl_tmpa_tl
                    {
                      \exp_not:n { ~~ } \exp_not:n { ~~ } class:~{ \exp_not:n { ####1 } } ~ =>~ { \exp_not:n { ####2 } } \iow_newline:
                    }
                }
            }

          \msg_show:nnnx { codehl / hlset } { struct info }
            { #1 } \l__codehl_tmpa_tl
        \group_end:
      }
      {
        \msg_error:nnnn { codehl / hlset } { non existant }
          { hlset01a } { #1 }
      }
  }
  
\cs_new_protected:Npn \hlHLsetShow #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_hlset_show:n
  }

\cs_new_protected:Npn \codehl_keyset_show:n #1
  {
    \__codehl_keyset_if_def:nNTF
      { #1 } \l__codehl_def_keyset_tl
      {
        \__codehl_keyset_build_ifnot:o \l__codehl_def_keyset_tl

        \group_begin:
          \tl_clear:N \l__codehl_tmpa_tl

          \prop_map_inline:cn { l__codehl_keyset_ \l__codehl_def_keyset_tl _build_prop }
            {
              \seq_clear:N \l__codehl_tmpi_seq
              \tl_clear:N \l__codehl_tmpb_tl

              \prop_map_inline:Nn ##2
                {
                  \clist_if_exist:cTF { l__codehl_keyset_tmpshow_ ####2 _clist }
                    { }
                    {
                      \clist_set_eq:cN { l__codehl_keyset_tmpshow_ ####2 _clist } \c_empty_clist
                      \seq_put_right:Nn \l__codehl_tmpi_seq { ####2 }
                      \tl_put_right:Nn \l__codehl_tmpb_tl
                        { \cs_undefine:c { l__codehl_keyset_tmpshow_ ####2 _clist } }
                    }
                  \clist_put_right:cn
                    { l__codehl_keyset_tmpshow_ ####2 _clist }
                    { ####1 }
                }
              \tl_put_right:Nn \l__codehl_tmpa_tl
                { \iow_newline: ~~group:~{ ##1 }  \iow_newline: }

              \seq_map_inline:Nn \l__codehl_tmpi_seq
                {
                  \tl_put_right:Ne \l__codehl_tmpa_tl
                    {
                      \exp_not:n {~~} \exp_not:n {~~~ class:~{ ####1 } ~ => ~ }
                      { \clist_use:c { l__codehl_keyset_tmpshow_ ####1 _clist } }
                      \exp_not:N \iow_newline:
                    }
                }
              \l__codehl_tmpb_tl
            }

          \msg_show:nnnx { codehl / keyset } { struct info }
            { #1 } \l__codehl_tmpa_tl
        \group_end:
      }
      {
        \msg_error:nnnn { codehl / keyset } { non existant }
          { keyset01a } { #1 }
      }
  }
\cs_new_protected:Npn \hlKeysetShow #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_keyset_show:n
  }

\cs_new_protected:Npn \__codehl_lang_show:nnnnnnn #1#2#3#4#5#6#7
  {
    \__codehl_lang_case_split:w #2

    \__codehl_lang_mark_get:nnNN #4
      \l__codehl_peek_beg_regex_tl \l__codehl_peek_beg_patt_tl
    \__codehl_lang_mark_get:nnNN #6
      \l__codehl_peek_end_regex_tl \l__codehl_peek_end_patt_tl

    \if_case:w " \l__codehl_lang_case_case_tl
        % 0
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~comment ~=> ~ class:~{ #1 }  ~start: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~end:~{ \exp_not:o \l__codehl_peek_end_patt_tl }
              }

      \or: % 1
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~active ~comment ~=> ~ class:~{ #1 }  ~start: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~end:~{ \exp_not:o \l__codehl_peek_end_patt_tl }
              }

      \or: % 2
        \bool_if:NTF \l__codehl_lang_case_colat_bool
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~comment ~line ~ at ~ => ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl } ~ at ~ col: ~{ \exp_not:n { #7 } }
              }
          }
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~comment ~line ~=> ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl }
              }
          }

      \or: % 3
        \tl_put_right:Ne \l__codehl_tmpa_tl
          {
            \exp_not:n { ~active ~comment ~line ~=> ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl }
          }

      \or: % 4
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~string ~=> ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl }  ~end:~{ \exp_not:o \l__codehl_peek_end_patt_tl }  ~escape:~{ \exp_not:n { #7 } }
              }

      \or: % 5
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~discard ~comment ~=> ~ class:~{ #1 }  ~start: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~end:~{ \exp_not:o \l__codehl_peek_end_patt_tl }
              }

      \or: % 6
        \bool_if:NTF \l__codehl_lang_case_colat_bool
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~discad ~comment ~line ~ at ~ => ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl } ~ at ~ col: ~{ \exp_not:n { #7 } }
              }
          }
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~discad ~comment ~line ~=> ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl }
              }
          }

      \or: % 7
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~~~~identifier ~=> ~ class:~{ #1 }  } ~ start: ~{ \exp_not:o \l__codehl_peek_beg_patt_tl }
              }

      \or: % 8
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~tagged ~ area ~=> ~ class:~{ #1 }  ~start: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~end:~{ \exp_not:o \l__codehl_peek_end_patt_tl }
              }

      \or: % 9
        \bool_if:NTF \l__codehl_lang_case_intr_bool
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~replace ~=> ~ org: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~replacement:~{ \exp_not:n { #5 } }
              }
          }
          {
            \tl_put_right:Ne \l__codehl_tmpa_tl
              {
                \exp_not:n { ~replace* ~=> ~ org: } ~ { \exp_not:o \l__codehl_peek_beg_patt_tl }  ~replacement:~{ \exp_not:n { #5 } }
              }
          }
      \or: % 10
      \or: % 11

    \fi:
    \bool_if:NTF \l__codehl_lang_case_nestable_bool
      {
        \int_compare:nNnTF { " \l__codehl_lang_case_case_tl } = { 9 }
          { }
          {
            \tl_put_right:Nn \l__codehl_tmpa_tl
              { ~ { nestable } ~ }
          }
      } { }
    \bool_if:NTF \l__codehl_lang_case_inbase_bool
      {
        \bool_if:NTF \l__codehl_lang_case_intag_bool
          { }
          {
            \tl_put_right:Nn \l__codehl_tmpa_tl
              { ~ { non ~ tagged } ~ }
          }
      }
      {
        \bool_if:NTF \l__codehl_lang_case_intr_bool
          { }
          {
            \tl_put_right:Nn \l__codehl_tmpa_tl
              { ~ { tagged } ~ }
          }
      }
    \tl_put_right:Nn  \l__codehl_tmpa_tl { \iow_newline: }
  }

\cs_new_protected:Npn \codehl_lang_show:n #1
  {
    \__codehl_lang_if_def:nNTF
      { #1 } \l__codehl_def_lang_tl
      {
        \__codehl_lang_build_ifnot:o \l__codehl_def_lang_tl

        \group_begin:
          \tl_clear:N \l__codehl_tmpa_tl

          \tl_put_right:Nn \l__codehl_tmpa_tl
            { \exp_not:n { ~~ } Booleans: \iow_newline: }
          \prop_map_inline:cn { l__codehl_lang_  \l__codehl_def_lang_tl _build_bool_keys_prop }
            {
              \prop_get:NnNTF \c__codehl_lang_keys_name_prop { ##1 } \l__codehl_tmpb_tl
                {
                  \tl_put_right:Nn \l__codehl_tmpa_tl     { \exp_not:n { ~~ } \exp_not:n { ~~ } }
                  \tl_put_right:Ne \l__codehl_tmpa_tl     { { \l__codehl_tmpb_tl } }

                  \bool_if:nTF { ##2 }
                    { \tl_put_right:Nn \l__codehl_tmpa_tl { ~ =>~ {true}  \iow_newline: } }
                    { \tl_put_right:Nn \l__codehl_tmpa_tl { ~ =>~ {false} \iow_newline: } }
                }
                {  }

            }

          \tl_put_right:Nn \l__codehl_tmpa_tl
            { \exp_not:n { ~~ } Values: \iow_newline: }
          \prop_map_inline:cn { l__codehl_lang_  \l__codehl_def_lang_tl _build_keys_prop }
            {
              \prop_get:NnNTF \c__codehl_lang_keys_name_prop { ##1 } \l__codehl_tmpb_tl
                {
                      \tl_put_right:Nn \l__codehl_tmpa_tl     { \exp_not:n { ~~ } \exp_not:n { ~~ } }
                      \tl_put_right:Ne \l__codehl_tmpa_tl     { { \l__codehl_tmpb_tl } }
                  \str_compare:nNnTF { ##1 } = { case }
                    {
                      \if_case:w ##2
                        \tl_put_right:Nn \l__codehl_tmpa_tl     {  ~ =>~ true \iow_newline: }
                      \or:
                        \tl_put_right:Nn \l__codehl_tmpa_tl     {  ~ =>~ false ~ (lower ~ case) \iow_newline: }
                      \or:
                        \tl_put_right:Nn \l__codehl_tmpa_tl     {  ~ =>~ false ~ (upper ~ case) \iow_newline: }
                      \fi:
                    }
                    {
                      \tl_put_right:Nn \l__codehl_tmpa_tl     {  ~ =>~ { \exp_not:n { ##2 } } \iow_newline: }
                    }
                }
                {  }

            }
          \tl_put_right:Nn \l__codehl_tmpa_tl
            { \exp_not:n { ~~ } Patterns: \iow_newline: }

          \cs_set_eq:NN \__codehl_lang_dlimit_add:nnnnnnn \__codehl_lang_show:nnnnnnn
          \seq_map_inline:cn { l__codehl_lang_ \l__codehl_def_lang_tl _build_pattern_seq }
            {
              \prop_get:cnN { l__codehl_lang_ \l__codehl_def_lang_tl _build_pattern_prop }
                { ##1 }
                \l__codehl_tmpb_tl
              \l__codehl_tmpb_tl
            }

          \msg_show:nnnx { codehl / lang } { struct info }
             { #1 } \l__codehl_tmpa_tl
        \group_end:
      }
      {
        \msg_error:nnnn { codehl / lang } { non existant }
          { lang01a } { #1 }
      }

  }
  
\cs_new_protected:Npn \hlLangShow #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_lang_show:n
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     main (full) highlight command
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\cs_new_protected:Npn \__codehl_settings_lang:n #1
  {
        \__codehl_lang_if_def:nNTF
          { #1 } \l__codehl_tok_tmpb_tl
          {
            \str_compare:oNoTF \l__codehl_tok_tmpb_tl = \l__codehl_tok_activ_lang_tl
              {  }
              { 
                \tl_set_eq:NN  \l__codehl_tok_activ_lang_tl \l__codehl_tok_tmpb_tl
                \bool_set_true:N \l__codehl_activ_lang_change_bool
              }
            \__codehl_lang_build_ifnot:o \l__codehl_tok_activ_lang_tl
          }
          { 
            \tl_if_empty:NTF \l__codehl_tok_activ_lang_tl
              {  }
              { \bool_set_true:N \l__codehl_activ_lang_change_bool }

            \tl_clear:N \l__codehl_tok_activ_lang_tl
            \tl_if_empty:nTF { #1 }
              {  }
              {
                \msg_error:nnnn { codehl / lang } { non existant }
                  { lang01 } { #1 }
              }
          }
  }
  
\cs_new_protected:Npn \__codehl_settings_hlset:n #1
  {
        \__codehl_hlset_if_def:nNTF
          { #1 } \l__codehl_tok_tmpb_tl
          {
            \str_compare:oNoTF \l__codehl_tok_tmpb_tl = \l__codehl_tok_activ_hlset_tl
              {  }
              { 
                \tl_set_eq:NN  \l__codehl_tok_activ_hlset_tl \l__codehl_tok_tmpb_tl
                \bool_set_true:N \l__codehl_activ_hlset_change_bool
              }
            \__codehl_hlset_build_ifnot:o \l__codehl_tok_activ_hlset_tl
          }
          {
            \tl_if_empty:NTF \l__codehl_tok_activ_hlset_tl
              {  }
              { 
              \bool_set_true:N \l__codehl_activ_hlset_change_bool }
            \tl_clear:N \l__codehl_tok_activ_hlset_tl
            \tl_if_empty:nTF { #1 }
              { }
              {
                \msg_error:nnnn { codehl /  hlset } { non existant }
                  { hlset01 } { #1 }
              }
          }
  }
    
\cs_new_protected:Npn \__codehl_settings_keyset:n #1
  {
        \__codehl_keyset_if_def:nNTF
          { #1 } \l__codehl_tok_tmpb_tl
          {
            \str_compare:oNoTF \l__codehl_tok_tmpb_tl = \l__codehl_tok_activ_keyset_tl
              {  }
              { 
                \tl_set_eq:NN  \l__codehl_tok_activ_keyset_tl \l__codehl_tok_tmpb_tl
                \bool_set_true:N \l__codehl_activ_keyset_change_bool
              }
            \__codehl_keyset_build_ifnot:o \l__codehl_tok_activ_keyset_tl
          }
          {
            \tl_if_empty:NTF \l__codehl_tok_activ_keyset_tl
              {  }
              { \bool_set_true:N \l__codehl_activ_keyset_change_bool }
            \tl_clear:N \l__codehl_tok_activ_keyset_tl
            \tl_if_empty:nTF { #1 }
              { }
              {
                \msg_error:nnnn { codehl /  keyset } { non existant }
                  { keyset01 } { #1 }
              }
          }
  }
    
\cs_new_protected:Npn \__codehl_settings_basefmt:n #1
  {
        \tl_if_empty:nTF { #1 }
          { \tl_set:Nn \l__codehl_tok_tmpa_tl { std-basefmt } }
          { \tl_set:Nn \l__codehl_tok_tmpa_tl { #1 } }

        \__codehl_basefmt_if_def:oNTF
          \l__codehl_tok_tmpa_tl \l__codehl_tok_tmpb_tl
          {
            \str_compare:oNoTF \l__codehl_tok_tmpb_tl = \l__codehl_tok_activ_basefmt_tl
              {  }
              { 
                \tl_set_eq:NN  \l__codehl_tok_activ_basefmt_tl \l__codehl_tok_tmpb_tl
                \bool_set_true:N \l__codehl_activ_basefmt_change_bool
              }
            \__codehl_basefmt_build_ifnot:on \l__codehl_tok_activ_basefmt_tl { }
          }
          {
            \msg_error:nnnn { codehl /  base fmt } { non existant }
              { keyset01 } { #1 }

            \str_compare:nNoTF { std-basefmt } = \l__codehl_tok_activ_basefmt_tl
              {  }
              { \bool_set_true:N \l__codehl_activ_basefmt_change_bool }

            %%% so that, there is a default...
            \tl_set:Nn \l__codehl_tok_activ_basefmt_tl { std-basefmt }
%            \bool_set_true:N \l__codehl_activ_basefmt_change_bool
            \__codehl_basefmt_build_ifnot:on \l__codehl_tok_activ_basefmt_tl { }
          }
  }
      
\keys_define:nn { codehl / settings }
  {
    language        .code:n   =
      {
        \tl_trim_spaces_apply:nN { #1 } \__codehl_settings_lang:n
      } ,
    language        .default:n = { } ,

    hl ~ set        .code:n   =
      {
        \tl_trim_spaces_apply:nN { #1 } \__codehl_settings_hlset:n
      } ,
    hl ~ set        .default:n = { } ,

    keywd ~ set  .code:n   =
      {
        \tl_trim_spaces_apply:nN { #1 } \__codehl_settings_keyset:n
      } ,
    keywd ~ set  .default:n = { } ,

    base ~format    .code:n   =
      {
        \tl_trim_spaces_apply:nN { #1 } \__codehl_settings_basefmt:n
      } ,
    base ~format    .default:n = { } ,
  }

\keys_define:nn { codehl / settings UT }
  {
    language        .code:n   =
      {
        \__codehl_settings_lang:n { #1 }
      } ,
    language        .default:n = { } ,

    hl ~ set        .code:n   =
      {
        \__codehl_settings_hlset:n { #1 }
      } ,
    hl ~ set        .default:n = { } ,

    keywd ~ set  .code:n   =
      {
        \__codehl_settings_keyset:n { #1 }
      } ,
    keywd ~ set  .default:n = { } ,

    base ~format    .code:n   =
      {
        \__codehl_settings_basefmt:n { #1 }
      } ,
    base ~format    .default:n = { } ,
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     main (full) highlight command
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\keys_define:nn { }
  { codehl / display .inherit:n = codehl / base fmt }
\keys_define:nn { codehl / display }
  {
    %%% to extend an HL set
    hl ~ set    .code:n =
      {
        \tl_if_empty:NTF \l__codehl_tok_activ_hlset_tl
          { %%% err: can't expand this
            \msg_error:nnnn { codehl / display } { undef }
              {disp01} { hl~set }
          }
          { \keys_set:nn { codehl / hlset } { #1 } }
      } ,

    %%% to extend a keywd set
    keywd ~ set    .code:n =
      {
        \tl_if_empty:NTF \l__codehl_tok_activ_keyset_tl
          { %%% err: can't expand this
            \msg_error:nnnn { codehl / display } { undef }
              {disp02} { keywd~set }
          }
          { \keys_set:nn { codehl / keyset } { #1 } }
      } ,
  }

\cs_new_protected:Npn \__codehl_settings:nn #1#2
  {
    \bool_set_false:N \l__codehl_activ_basefmt_change_bool
    \bool_set_false:N \l__codehl_activ_keyset_change_bool
    \bool_set_false:N \l__codehl_activ_hlset_change_bool
    \bool_set_false:N \l__codehl_activ_lang_change_bool
    
    \keys_set:nn { #1 } { #2 }

    \bool_if:NTF \l__codehl_activ_basefmt_change_bool
      { \__codehl_basefmt_set_style: }
      { }
      
    \bool_if:NTF \l__codehl_activ_lang_change_bool
      { \__codehl_lang_tok_settings: }
      {  }

    \bool_lazy_or:nnTF { \tl_if_empty_p:N \l__codehl_tok_activ_keyset_tl } { \tl_if_empty_p:N \l__codehl_tok_activ_hlset_tl }
      {
        \cs_set:Npn \__codehl_tok_keyfmt_base:Ncoo
          { \__codehl_tok_keyfmt_less:Ncoo }
        \cs_set:Npn \__codehl_tok_keyfmt_nested:Ncoo
          { \__codehl_tok_keyfmt_less:Ncoo }
      }
      {
        \cs_set:Npn \__codehl_tok_keyfmt_base:Ncoo
          { \__codehl_tok_keyfmt:Ncoo }
      }
  }

\cs_new_protected:Npn \codehl_settings:n
  {
    \__codehl_settings:nn { codehl / settings UT }
  }  
\cs_generate_variant:Nn \codehl_settings:n { e }  

\cs_new_protected:Npn \hlSettings
  {
    \__codehl_settings:nn { codehl / settings }
  }  

%%%%%%%
%%% That's the base/default format
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_settings_base_keys_prop
  {
    lang         = { }          ,
    keyset       = { }          ,
    hlset        = { }          ,
    basefmt      = { std-basefmt }  ,
  }

%%%%%%%
%%% <keys> internal => external labels
%%% The ones 'not defined here' won't show at \codehl_settings_show:n
%%% (hidden properties)
%%%%%%%
\prop_const_linked_from_keyval:Nn \c__codehl_settings_keys_name_prop
  {
    lang         = based ~ on ~ language       ,
    keyset       = based ~ on ~ keywd ~set     ,
    hlset        = based ~ on ~ hl ~set        ,
    basefmt      = based ~ on ~ base ~ format  ,
  }

\tl_new:N \l__codehl_settings_tmp_tl

\cs_new_protected:Npn \__codehl_settings_set:nnn #1#2#3
  {
    \tl_if_blank:nTF { #1 }
      {
        \prop_put:cnn { l__codehl_settings_  \l__codehl_def_settings_tl _prop }
          { #2 } { #3 }
      }
      {
        \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #1 }
        \int_compare:nNnTF { \seq_count:N \l__codehl_tmpa_seq } = { 1 }
          {
            \seq_get_left:NN \l__codehl_tmpa_seq \l__codehl_settings_tmp_tl
            \use:c { __codehl_ #2 _if_def:oNTF }
              \l__codehl_settings_tmp_tl \l__codehl_tmpa_tl
              {
                \prop_put:cnn { l__codehl_settings_  \l__codehl_def_settings_tl _prop }
                  { #2 } { #1 }
              }
              {
                \msg_error:nnne { codehl / #2 } { non existant }
                  { settings03 } \l__codehl_settings_tmp_tl
              }
          }
          {
            \prop_put:cne { l__codehl_settings_  \l__codehl_def_settings_tl _prop }
              { #2 } { \l__codehl_def_settings_tl _ #2 }
            \use:c { codehl_ #2 _def:en } { \l__codehl_def_settings_tl _ #2 }
              { based ~ on = { #1 }  }
          }
      }
  }

\keys_define:nn { codehl / settings def }
  {
    based ~ on ~ language        .code:n   =
      {
        \__codehl_settings_set:nnn { #1 } { lang } { } 
      } ,
    based ~ on ~ language        .default:n = { } ,

    based ~ on ~ hl ~ set        .code:n   =
      {
        \__codehl_settings_set:nnn { #1 } { hlset } { }
      } ,
    based ~ on ~ hl ~ set        .default:n = { } ,

    based ~ on ~ keywd ~ set  .code:n   =
      {
        \__codehl_settings_set:nnn { #1 } { keyset } { }
      } ,
    based ~ on ~ keywd ~ set  .default:n = { } ,

    based ~ on ~ base ~format    .code:n   =
      {
        \__codehl_settings_set:nnn { #1 } { basefmt } { std-basefmt } 
      } ,
    based ~ on ~ base ~format    .default:n = { } ,
  }

\prg_new_conditional:Npnn \__codehl_settings_if_def:nN #1#2 { TF }
  {
    \prop_get:NnNTF \l__codehl_sets_settings_prop
      { #1 } #2
      { \prg_return_true: }
      {
        \__codehl_settings_load_if_predef:nTF { #1 }
          {
            \prop_get:NnNTF \l__codehl_sets_settings_prop
              { #1 } #2
              { \prg_return_true: }
              { \prg_return_false: } %%% it shouldn't be the case
          }
          { \prg_return_false: }
      }
  }
\prg_generate_conditional_variant:Nnn \__codehl_settings_if_def:nN { o } { TF }

\prg_new_conditional:Npnn \__codehl_settings_alias:n #1 { TF }
  {
    \__codehl_settings_if_def:nNTF
      { #1 } \l__codehl_def_settings_tl
      {
        \str_if_eq:noTF { #1 } \l__codehl_def_settings_tl
          { \prg_return_false: }
          { \prg_return_true: }
      }
      { \prg_return_true: }
  }

\cs_new_protected:Npn \codehl_settings_alias:nn #1#2
  {
    \__codehl_settings_alias:nTF { #1 }
      {
        %%% OK... new or redefining an alias
        \__codehl_settings_if_def:nNTF
          { #2 } \l__codehl_def_settings_tl
          {
            \prop_put:Nno \l__codehl_sets_settings_prop
              { #1 }
              \l__codehl_def_settings_tl

            \__codehl_note:nnnnen { codehl / settings } { info note }
              { settings02c }
              { #1 }
              { \g_file_curr_name_str \g_file_curr_ext_str }
              { Alias ~ definition: ~ { #1 } ~ => ~ { #2 } }
          }
          {
            \msg_error:nnnn { codehl / settings } { non existant }
              { settings02a } { #2 }
          }
      }
      {
        %%% Err... it's a 'settings definition'
        \msg_error:nnnn { codehl / settings } { alias err }
          { settings02b } { #1 }
      }
  }
\cs_generate_variant:Nn \codehl_settings_alias:nn { ee }

\cs_new_protected:Npn \hlSettingsAlias #1#2
  {
    \__codehl_settings_alias:ee 
      { \tl_trim_spaces:n { #1 } }
      { \tl_trim_spaces:n { #2 } }
  }

\cs_new_protected:Npn \codehl_settings_def:nn #1#2
  {
    \__codehl_settings_if_def:nNTF
      { #1 } \l__codehl_def_settings_tl
      { }
      {
        \tl_set:Nn \l__codehl_def_settings_tl { #1 }

        \prop_put:Nnn \l__codehl_sets_settings_prop
          { #1 }
          { #1 }
          
        \prop_new_linked:c { l__codehl_settings_  #1 _prop }
        \prop_set_eq:cN    { l__codehl_settings_  #1 _prop } 
          \c__codehl_settings_base_keys_prop
      }
          
    \keys_set:nn { codehl / settings def }
      { #2 }
  }
\cs_generate_variant:Nn \codehl_settings_def:nn { e }

\cs_new_protected:Npn \hlSettingsDef #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_settings_def:nn 
  }
  

\cs_new_protected:Npn   \codehl_settings_select:nn #1
  {
    \__codehl_settings_if_def:nNTF
      { #1 } \l__codehl_def_settings_tl
      { 
        \prop_map_inline:cn { l__codehl_settings_  \l__codehl_def_settings_tl _prop }
          { \tl_set:cn { l__codehl_settings_  ##1 _ tl } { ##2 } }
        \codehl_settings:e 
          {
            language      = \exp_not:o \l__codehl_settings_lang_tl  ,
            keywd ~ set   = \exp_not:o \l__codehl_settings_keyset_tl  ,
            hl ~ set      = \exp_not:o \l__codehl_settings_hlset_tl  ,
            base ~ format = \exp_not:o \l__codehl_settings_basefmt_tl 
          }
      }
      { 
        \msg_error:nnnn { codehl / settings } { non existant }
          { settings01 } { #1 }
      }
    
  }
\cs_new_protected:Npn \hlSettingsSelect #1
  { 
    \tl_trim_spaces_apply:nN { #1 } \codehl_settings_select:nn 
  }
  
  
%%% TODO: test first if it has changed
%%%  
\cs_new_protected:Npn \__codehl_lang_tok_settings:
  {
    \tl_if_empty:NTF \l__codehl_tok_activ_lang_tl
      {
        \cs_set_eq:NN \__codehl_tok_inbase:    \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_inbasecmt: \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_inbasestr: \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_intag:     \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_intagcmt:  \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_intagstr:  \prg_do_nothing:
        \cs_set_eq:NN \__codehl_tok_intr:      \prg_do_nothing:

        \cs_set:Npn \__codehl_tok_scan_digits:N ##1
          { }
        \cs_set:Npn \__codehl_tok_scan_oletter:N ##1
          { }
        \cs_set:Npn \__codehl_tok_keywd_case:N
          { \__codehl_tok_keywd_casesensitive:N }
        \cs_set:Npn \__codehl_tok_keyfmt_nested:Ncoo
          { \__codehl_tok_keyfmt_less:Ncoo }
      }
      {
        \cs_set:Npe  \__codehl_tok_inbase:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _base_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_inbasecmt:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _basecmt_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_inbasestr:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _basestr_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_intag:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _tag_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_intagcmt:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _tagcmt_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_intagstr:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _tagstr_scan_dlimit: } }
        \cs_set:Npe  \__codehl_tok_intr:
          { \exp_not:c { __codehl_lang_ \l__codehl_tok_activ_lang_tl _tr_scan_dlimit: } }

        \prop_map_inline:cn { l__codehl_lang_ \l__codehl_tok_activ_lang_tl _build_keys_prop }
          {
            \tl_set:cn { l__codehl_tok_lang_style_ ##1 _tl } { ##2 }
          }
        \prop_map_inline:cn { l__codehl_lang_ \l__codehl_tok_activ_lang_tl _build_bool_keys_prop }
          {
            \bool_set_eq:cN { l__codehl_tok_lang_style_ ##1 _bool } ##2
          }

        \cs_set:Npe
          \__codehl_tok_scan_digits:N
          { \exp_not:c {  __codehl_lang_ \l__codehl_tok_activ_lang_tl _scan_digits:N } }
        \cs_set:Npe
          \__codehl_tok_scan_oletter:N
          { \exp_not:c {  __codehl_lang_ \l__codehl_tok_activ_lang_tl _scan_oletter:N } }

        \if_case:w \l__codehl_tok_lang_style_case_tl
          \cs_set:Npn \__codehl_tok_keywd_case:N
            { \__codehl_tok_keywd_casesensitive:N }
        \or:
          \cs_set:Npn \__codehl_tok_keywd_case:N
            { \__codehl_tok_keywd_caseless_lc:N }
        \or:
          \cs_set:Npn \__codehl_tok_keywd_case:N
            { \__codehl_tok_keywd_caseless_uc:N }
        \fi:

        \bool_if:NTF \l__codehl_tok_lang_style_keywd_bool
          {
            \cs_set:Npn \__codehl_tok_keyfmt_nested:Ncoo
              { \__codehl_tok_keyfmt:Ncoo }
          }
          {
            \cs_set:Npn \__codehl_tok_keyfmt_nested:Ncoo
              { \__codehl_tok_keyfmt_less:Ncoo }
          }

      }

    \cs_set_eq:NN
      \__codehl_tok_other_scan:
      \__codehl_tok_inbase:
    \cs_set_eq:NN
      \__codehl_tok_cmt_scan:
      \__codehl_tok_inbasecmt:
    \cs_set_eq:NN
      \__codehl_tok_str_scan:
      \__codehl_tok_inbasestr:
    \cs_set_eq:NN
      \__codehl_tok_tr_scan:
      \__codehl_tok_intr:
  }

\cs_new_protected:Npn \__codehl_basefmt_set_style:
  {
    \prop_map_inline:cn { l__codehl_basefmt_ \l__codehl_tok_activ_basefmt_tl _build_keys_prop }
      {
        \tl_set:cn { l__codehl_tok_style_ ##1 _tl } { ##2 }
      }
    \prop_map_inline:cn { l__codehl_basefmt_ \l__codehl_tok_activ_basefmt_tl _build_bool_keys_prop }
      {
        \bool_set_eq:cN { l__codehl_tok_style_ ##1 _bool } ##2
      }

    %%% this will cicle throughout all of them
    %%%
    \prop_map_inline:Nn \l__codehl_basefmt_cmds_prop
      { ##2 }
  }

%%%%%%%
%%% for long codes... this is meaningless,
%%% might be relevant for lots of small inline code (short verbatim)
%%%%%%%
\cs_new_protected:Npn \__codehl_tok_start_invariants:
  {
          \cs_set:Npn \__codehl_tok_disp_line:
            { \__codehl_tok_set_line: }
          \cs_set:Npn \__codehl_tok_col_count:
            { \__codehl_tok_col_counting: }

          \cs_set:Npn \__codehl_tok_start:N
            { \__codehl_tok_other:N  } %% it will (shall) handle just one token (byte) a time
          \cs_set:Npn \__codehl_tok_nesting_keywd:N
              { \__codehl_tok_keywd_other:N }
          \tl_set:Nn \l__codehl_tok_curr_tag_tl
            { keywd }
  }

\__codehl_tok_start_invariants:

\cs_new_protected:Npn \codehl_display:nn #1#2
  {
    \tl_if_blank:nTF { #2 }
      { }
      {
        %%% verifying if all sets are really pre-build... :/
        %%% might have changed after the last \codehl_settings:n
        %%% at least, _activ_ variables should be safe.
        %%%
        \tl_if_empty:NF \l__codehl_tok_activ_lang_tl
          { \__codehl_lang_build_ifnot:o \l__codehl_tok_activ_lang_tl }
        \tl_if_empty:NF \l__codehl_tok_activ_hlset_tl
          { \__codehl_hlset_build_ifnot:o \l__codehl_tok_activ_hlset_tl }
        \tl_if_empty:NF \l__codehl_tok_activ_keyset_tl
          { \__codehl_keyset_build_ifnot:o \l__codehl_tok_activ_keyset_tl }

        \__codehl_basefmt_build_ifnot:on \l__codehl_tok_activ_basefmt_tl
          { \__codehl_basefmt_set_style: }

        \group_begin:

          \cs_set_eq:NN \__codehl_basefmt_display_set:nn
            \__codehl_basefmt_display_set_tok_style:nn
          \cs_set_eq:NN \__codehl_basefmt_display_bool_set:nn
            \__codehl_basefmt_display_set_tok_bool_style:nn

          \tl_set_eq:NN \l__codehl_def_hlset_tl    \l__codehl_tok_activ_hlset_tl
          \tl_set_eq:NN \l__codehl_def_keyset_tl   \l__codehl_tok_activ_keyset_tl

          \bool_set_true:N  \l__codehl_display_bool

          \keys_set:nn { codehl / display }
            { #1 }

          \bool_if:NTF \l__codehl_tok_style_inline_bool
            {
              \cs_set_eq:NN \__codehl_tok_set_line:    \__codehl_tok_inline_set:
              \cs_set_eq:NN \__codehl_tok_next_line:w  \__codehl_tok_inline_proc:w
              \tl_clear:N \l__codehl_tok_inline_aux_tl
            }
            {
              \__codehl_basefmt_set_dims:

              %%%%%%%
              %%% TODO: review the fixed spacing here...
              %%%%%%%
              \skip_vertical:n { 1ex }

              \cs_set_eq:NN \__codehl_tok_set_line:     \__codehl_tok_coffin_set_line:
              \cs_set_eq:NN \__codehl_tok_next_line:w   \__codehl_tok_coffin_line_proc:w
            }

          \int_zero:N \l__codehl_tok_line_int

          \cs_set_eq:NN
            \__codehl_tok_proc:N
            \__codehl_tok_start:N
          \cs_set_eq:NN
            \__codehl_tok_keyfmt_eff:Ncoo
            \__codehl_tok_keyfmt_base:Ncoo

          \l__codehl_tok_style_basefmt_tl

          \bool_if:NTF \l__codehl_tok_style_Sverb_bool
            {
              \__codehl_tok_next_line:w #2 ^^J \q_nil ^^J
            }
            {
              \__codehl_tok_next_line:w #2 \q_nil ^^J 
            }

        \group_end:
      }
  }
\cs_generate_variant:Nn \codehl_display:nn { no }

\NewDocumentCommand{\hlDisplay}{O{}m}
  { \codehl_display:nn { #1 } { #2 } }

\NewDocumentCommand{\hlDisplayV}{O{}m}
  { \codehl_display:no { #1 } #2 }

\cs_new_protected:Npn \__codehl_tok_gobble_true:
  {
    \int_set_eq:NN \l__codehl_tok_gbbl_cnt_int \l__codehl_tok_gbbl_int
    \cs_set:Npn \__codehl_tok_proc:N
      { \__codehl_tok_gobble:N }
  }

\cs_new_protected:Npn \__codehl_tok_gobble_false:
  {
    \cs_set_eq:NN \__codehl_tok_proc:N  \__codehl_tok_start:N
  }

\cs_new_protected:Npn \__codehl_tok_discard_line:
  {
    \tl_if_empty:NTF \l__codehl_tok_build_line_tl
      { }
      { \__codehl_tok_set_line: }
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     <state> and <state> related commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%
%%% from tokglobalstack
%%%%%%%
\globalstack_csnew:n    { __codehl_nested }
\cs_generate_variant:Nn  \__codehl_nested_gpush:n { e }
\cs_generate_variant:Nn  \__codehl_nested_gput_right:n { e }
\cs_generate_variant:Nn  \__codehl_nested_gput_left:n { e }

\cs_new_protected:Npn \__codehl_stack_build_tl:Nn #1#2
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #2 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \tl_put_right:Nn #1
          {
            \exp_not:N \tl_set:Nn \exp_not:N ##1
              { \exp_not:o ##1 }
          }
      }
  }

\cs_new_protected:Npn \__codehl_stack_build_cs:Nn #1#2
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #2 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \tl_put_right:Nn #1
          {
            \exp_not:N \cs_set_nopar:Npn \exp_not:N ##1
              { \exp_not:o ##1 }
          }
      }
  }

\cs_new_protected:Npn \__codehl_stack_build_cs:NNN #1#2#3
  {
    \tl_put_right:Nn #1
      {
        \exp_not:N \cs_set:Npn \exp_not:N #2
          { \exp_not:o #3 }
      }
  }

\cs_new_protected:Npn \__codehl_stack_build_bool:Nn #1#2
  {
    \seq_set_from_clist:Nn \l__codehl_tmpa_seq { #2 }
    \seq_map_inline:Nn \l__codehl_tmpa_seq
      {
        \tl_put_right:Nn #1
          {
            \bool_if:NTF ##1
              { \exp_not:N \bool_set_true:N \exp_not:N ##1 }
              { \exp_not:N \bool_set_false:N \exp_not:N ##1 }
          }
      }
  }

\cs_new_protected:Npn \__codehl_stack_build_fmtsave:N #1
  {
    \__codehl_stack_build_tl:Nn
      #1
      { \l__codehl_tok_fmtcmd_tl }
    \__codehl_stack_build_cs:Nn
      #1
      { \l__codehl_tok_fmtcmd_seq }
  }

\__codehl_lang_init_comment:
\__codehl_lang_init_comment_tex:
\__codehl_lang_init_comment_line:
\__codehl_lang_init_comment_line_tex:
\__codehl_lang_init_string:
\__codehl_lang_init_discard:
\__codehl_lang_init_discard_line:
\__codehl_lang_init_ident:
\__codehl_lang_init_tagged:

\cs_new_protected:Npn \__codehl_nested_stack:n #1
  {
    \__codehl_nested_gpush:e { #1 }
  }
\cs_generate_variant:Nn \__codehl_nested_stack:n { o }

\cs_new_protected:Npn \__codehl_nested_stack_add:n #1
  {
    \__codehl_nested_gput_left:e { #1 }
  }
\cs_generate_variant:Nn \__codehl_nested_stack_add:n { o }

\cs_new:Npn \__codehl_nested_pop:
  {
    \__codehl_nested_gpop:
  }

%%%%%%%
%%% jumps to 'scan stop' (from inside a single primitive \if )
%%%%%%%
\cs_new:Npn \__codehl_tok_scan_stop:w #1 \scan_stop:
  { \fi: }

%%%%%%%
%%% NEW 'main' tok format into _build_line_tl
%%%%%%%

\seq_new:N \l__codehl_tok_fmtcmd_seq
\tl_new:N  \l__codehl_tok_fmtcmd_tl
\tl_set:Nn \l__codehl_tok_fmtcmd_tl { { \exp_not:o \l__codehl_tok_fmtcmd_tmpa_tl } }
\tl_new:N  \l__codehl_tok_fmtcmd_tmpa_tl

\cs_new_protected:Npn \__codehl_tok_set_fmt:N #1
  {
    \tl_if_exist:NTF #1
      {
        \tl_set:Nn \l__codehl_tok_fmtcmd_tl
          { { \exp_not:N #1 { \exp_not:o \l__codehl_tok_fmtcmd_tmpa_tl } } }
        \seq_map_inline:Nn \l__codehl_tok_fmtcmd_seq
          {
            \tl_set:Ne \l__codehl_tok_fmtcmd_tl
              { { \exp_not:N \exp_not:N \exp_not:N ##1 \exp_not:o \l__codehl_tok_fmtcmd_tl } }
          }
        \seq_put_left:Nn \l__codehl_tok_fmtcmd_seq { #1 }
      } {}
  }
\cs_generate_variant:Nn \__codehl_tok_set_fmt:N { c }

\cs_new_protected:Npn \__codehl_tok_fmt:n #1
  {
    \tl_set:Nn \l__codehl_tok_fmtcmd_tmpa_tl { #1 }
    \tl_put_right:Ne \l__codehl_tok_build_line_tl
      { \l__codehl_tok_fmtcmd_tl }
  }
\cs_generate_variant:Nn \__codehl_tok_fmt:n { o }

\cs_new_protected:Npn \__codehl_tok_fmt:Nn #1#2
  {
    \tl_set:Nn \l__codehl_tok_fmtcmd_tmpa_tl { #2 }
    \tl_put_right:Ne #1
      \l__codehl_tok_fmtcmd_tl
  }
\cs_generate_variant:Nn \__codehl_tok_fmt:Nn { No }

\cs_new_protected:Npn \__codehl_tok_fmt:nn #1#2
  {
    \tl_set:Nn \l__codehl_tok_fmtcmd_tmpa_tl { #1#2 }
    \tl_put_right:Ne \l__codehl_tok_build_line_tl
      \l__codehl_tok_fmtcmd_tl
  }
\cs_generate_variant:Nn \__codehl_tok_fmt:nn { o }

\cs_new_protected:Npn \__codehl_tok_fmt:Nnn #1#2#3
  {
    \tl_set:Nn \l__codehl_tok_fmtcmd_tmpa_tl { #2#3 }
    \tl_put_right:Ne #1
      \l__codehl_tok_fmtcmd_tl
  }
\cs_generate_variant:Nn \__codehl_tok_fmt:Nnn { No , Noo }

\cs_new_protected:Npn \__codehl_tok_fmt_retoken:n #1
  {
    \tl_set:Nn \l__codehl_tok_fmtcmd_tmpa_tl
      { \tl_retokenize:n { #1 } }
    \tl_put_right:Ne \l__codehl_tok_build_line_tl
      { \l__codehl_tok_fmtcmd_tl }
  }
\cs_generate_variant:Nn \__codehl_tok_fmt_retoken:n { o }

\cs_new:Npn \__codehl_tok_keywd_caseless:N #1
  { \str_lowercase:f #1 }

\cs_new:Npn \__codehl_tok_keywd_caseless_lc:N #1
  { \str_lowercase:f #1 }

\cs_new:Npn \__codehl_tok_keywd_caseless_uc:N #1
  { \str_uppercase:f #1 }

\cs_new:Npn \__codehl_tok_keywd_casesensitive:N
  { }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cs_new_protected:Npn \__codehl_tok_keyfmt:NNnn #1 #2#3#4
  {
    \tl_if_exist:NTF #2
      { \tl_put_right:Nn #1 { { #2 { #3#4 } } } }
      { \tl_put_right:Nn #1 { #3#4 } }
  }
\cs_generate_variant:Nn \__codehl_tok_keyfmt:NNnn { Ncoo }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cs_new_protected:Npn \__codehl_tok_keyfmt_less:NNnn #1 #2#3#4
  { \tl_put_right:Nn #1 { #3#4 } }
\cs_generate_variant:Nn \__codehl_tok_keyfmt_less:NNnn { Ncoo }

%%%%%%%
%%% this will be used in an expansion context (retokenized)
%%% using \relax to be latex2e safe
%%%%%%%
\cs_new:Npn \__codehl_penalty:
  { \penalty 0 \relax }
%\cs_new:Npn \__codehl_penalty:
%  { \penalty 0 \scan_stop: }

%%%%%%%
%%% columns counting (if needed)
%%%%%%%
\cs_new:Npn \__codehl_tok_col_counting:
  { \int_incr:N \l__codehl_tok_col_int }

\cs_new:Npn \__codehl_tok_col_nocount:
  { }

%%%%%%%
%%% space handling, no <state> change
%%%%%%%
\cs_new:Npn \__codehl_tok_space:
  {
    \exp_last_unbraced:NNo
    \if_int_compare:w ` \l__codehl_tok_curr_token_tl = 32
      \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { { \use:n { ~ } } \__codehl_penalty: }
      \__codehl_tok_scan_stop:w % jumping to \scan_stop:
    \fi:
  }

\cs_new:Npn \__codehl_tok_show_space:
  { }

%%%%%%%
%%% <gobble> state ... bytes are gobble regardless of what follows.
%%% it's ok for the intended use: de-indent ( normally just spaces, ASCII chars, like % )
%%% it fails miserably with utf-8, and others multi-byte encodings.
%%%%%%%
\cs_new:Npn \__codehl_tok_gobble:N #1
  {
    \if_meaning:w \q_nil #1
      \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:
    \else:
      \int_decr:N \l__codehl_tok_gbbl_cnt_int
      \if_int_compare:w \l__codehl_tok_gbbl_cnt_int = 0
        \cs_set_eq:NN \__codehl_tok_proc:N  \__codehl_tok_start:N
      \fi:
    \fi:
    \__codehl_tok_proc:N
  }

%%%%%%%
%%% <discard-line> state  (up to line end...)
%%%%%%%
\cs_new:Npn \__codehl_tok_discard_line:w #1 \q_nil
  {
    \tl_clear:N \l__codehl_tok_build_dlimit_tl
    \__codehl_nested_pop:
  }

%%%%%%%
%%% <tex-line> state  (up to line end... LaTeX retokenized)
%%%%%%%
\cs_new:Npn \__codehl_tok_dlimit_texline:w #1 \q_nil
  {
    \__codehl_tok_fmt_retoken:n
      { #1 }

    \tl_clear:N \l__codehl_tok_build_dlimit_tl
    \__codehl_nested_pop:
  }

%%%%%%%
%%% states factory without keywd state
%%%%%%%

%%%%%%%
%%% #1 => \__codehl_tok_utf_<name>:
%%% #2 => \__codehl_tok_utf_<name>:
%%% #3 => eol building code
%%% #4 => base code
%%%%%%%
\cs_new_protected:Npn \__codehl_tok_gen:NNnn #1#2 #3#4
  {
    %%%
    %%% This is  __codehl_tok_utf_  <name> :
    %%%
    \cs_new:Npn #1 ##1
      {
        \if_meaning:w \q_nil ##1

          \tl_put_right:NV \l__codehl_tok_build_dlimit_tl \l__codehl_tok_build_utf_tl
          #3

          \bool_if:NTF \l__codehl_tok_upto_eol_bool
            {
              \__codehl_nested_pop:
            } { }
          \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:

        \else:
          \if_int_compare:w ` ##1 > 127
            \tl_put_right:Nn \l__codehl_tok_build_utf_tl { ##1 }
            \if_int_compare:w ` ##1 > 191
              \__codehl_tok_col_count:
            \fi:
          \else:
            \tl_put_right:NV \l__codehl_tok_build_dlimit_tl \l__codehl_tok_build_utf_tl

            \cs_set:Npn
              \__codehl_tok_proc:N
              { #2 }

            \tl_set:Nn
              \l__codehl_tok_curr_token_tl
              { ##1 }
            \__codehl_tok_col_count:

            #4 % 'end' code

            \scan_stop:
          \fi:
        \fi:
        \__codehl_tok_proc:N
      }

    %%%
    %%% This is  __codehl_tok_  <name> :
    %%%
    \cs_new:Npn #2 ##1
      {
        \if_meaning:w \q_nil ##1

          #3

          \bool_if:NTF \l__codehl_tok_upto_eol_bool
            {
              \__codehl_nested_pop:
            } { }
          \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:

        \else:
            \tl_set:Nn \l__codehl_tok_curr_token_tl { ##1 }
            \__codehl_tok_col_count:

            %%% utf test
            %%%
            \if_int_compare:w ` ##1 > 127
              \tl_set_eq:NN \l__codehl_tok_build_utf_tl \l__codehl_tok_curr_token_tl
              \cs_set:Npn \__codehl_tok_proc:N  { #1 }

              \__codehl_tok_scan_stop:w % jumping to \_codehl_scan_stop:
            \fi:

            #4 % 'end' code

            \scan_stop:
        \fi:
        \__codehl_tok_proc:N
      }
  }
\cs_generate_variant:Nn \__codehl_tok_gen:NNnn { cc }

%%%%%%%
%%% gen without keywd
%%% { base <state> } { eol code } { base }
%%%%%%%
\cs_new_protected:Npn \__codehl_tok_gen:nnn #1
  {
    \__codehl_tok_gen:ccnn
      { __codehl_tok_utf_ #1 :N }
      { __codehl_tok_ #1 :N }
  }

%%%%%%%
%%% <states> factory with keywd state
%%%%%%%

%%%%%%%
%%% #1 => \__codehl_tok_utf_<name>:
%%% #2 => \__codehl_tok_<name>:
%%% #3 => \__codehl_tok_keywd_<name>:
%%% #4 => eol building code
%%% #5 => base code
%%%%%%%
\cs_new_protected:Npn \__codehl_tok_keygen:NNNnn #1#2#3 #4#5
  {
    %%%
    %%% This is  __codehl_tok_utf_  <name> :
    %%%
    \cs_new:Npn #1 ##1
      {
        \if_meaning:w \q_nil ##1

          \tl_put_right:NV \l__codehl_tok_build_dlimit_tl \l__codehl_tok_build_utf_tl
          #4

          \bool_if:NTF \l__codehl_tok_upto_eol_bool
            {
              \__codehl_nested_pop:
            } { }
          \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:

        \else:
          \if_int_compare:w ` ##1 > 127
            \tl_put_right:Nn \l__codehl_tok_build_utf_tl { ##1 }
            \if_int_compare:w ` ##1 > 191
              \__codehl_tok_col_count:
            \fi:
          \else:
            \tl_put_right:NV \l__codehl_tok_build_dlimit_tl \l__codehl_tok_build_utf_tl
            \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { \__codehl_penalty: }
            \cs_set:Npn \__codehl_tok_proc:N  { #2 }

            \tl_set:Nn \l__codehl_tok_curr_token_tl { ##1 }
            \__codehl_tok_col_count:

            #5 % 'end' code

            \if_catcode:w \exp_not:N ##1 \c_catcode_letter_token
              \tl_set:Nn    \l__codehl_tok_build_keywd_tl ##1
              \tl_set_eq:NN \l__codehl_tok_curr_ident_tl \l__codehl_tok_curr_tag_tl
              \cs_set:Npn \__codehl_tok_proc:N  { #3 }

            \else:
              \__codehl_tok_scan_oletter:N ##1

              \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { ##1 \__codehl_penalty: }
            \fi:

            \scan_stop:
          \fi:
        \fi:

        \__codehl_tok_proc:N
      }

    %%%
    %%% This is  __codehl_tok_  <name> :
    %%%
    \cs_new:Npn #2 ##1
      {
        \if_meaning:w \q_nil ##1

          #4

          \bool_if:NTF \l__codehl_tok_upto_eol_bool
            {
              \__codehl_nested_pop:
            }
            { }
          \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:

        \else:
            \tl_set:Nn \l__codehl_tok_curr_token_tl { ##1 }
            \__codehl_tok_col_count:

            %%% utf test
            %%%
            \if_int_compare:w ` ##1 > 127
              \tl_set_eq:NN \l__codehl_tok_build_utf_tl \l__codehl_tok_curr_token_tl
              \cs_set:Npn \__codehl_tok_proc:N
                { #1 }

              \__codehl_tok_scan_stop:w % jumping to \scan_stop:
            \fi:

            #5 % 'end' code

            \if_catcode:w \exp_not:N ##1 \c_catcode_letter_token
              \tl_set:Nn    \l__codehl_tok_build_keywd_tl ##1
              \tl_set_eq:NN \l__codehl_tok_curr_ident_tl \l__codehl_tok_curr_tag_tl
              \cs_set:Npn \__codehl_tok_proc:N  { #3 }
            \else:
              \__codehl_tok_scan_oletter:N ##1
              \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { ##1 \__codehl_penalty: }
            \fi:

            \scan_stop:
        \fi:
        \__codehl_tok_proc:N
      }

    %%%
    %%% This is  __codehl_tok_keywd_  <name> :
    %%%
    \cs_new:Npn #3 ##1
      {
        \if_meaning:w \q_nil ##1

          \__codehl_tok_keyfmt_eff:Ncoo
            \l__codehl_tok_build_dlimit_tl
            { l__codehl_keyset_ \l__codehl_tok_activ_keyset_tl  _  \l__codehl_tok_curr_ident_tl _ \__codehl_tok_keywd_case:N \l__codehl_tok_build_keywd_tl _tl }
            \l__codehl_tok_build_prekeywd_tl
            \l__codehl_tok_build_keywd_tl
          \tl_clear:N \l__codehl_tok_build_keywd_tl
          \tl_clear:N \l__codehl_tok_build_prekeywd_tl

          #4

          \bool_if:NTF \l__codehl_tok_ident_bool
            {
              \__codehl_nested_pop:
              \bool_set_false:N \l__codehl_tok_ident_bool
            } { }

          \bool_if:NTF \l__codehl_tok_upto_eol_bool
            {
              \__codehl_nested_pop:
            } { }

          \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:

        \else:

          \__codehl_tok_col_count:
          \if_catcode:w \exp_not:N ##1 \c_catcode_letter_token
            \tl_put_right:Nn \l__codehl_tok_build_keywd_tl ##1
          \else:

            \__codehl_tok_scan_digits:N ##1

            \__codehl_tok_keyfmt_eff:Ncoo
              \l__codehl_tok_build_dlimit_tl
              { l__codehl_keyset_ \l__codehl_tok_activ_keyset_tl  _  \l__codehl_tok_curr_ident_tl _ \__codehl_tok_keywd_case:N \l__codehl_tok_build_keywd_tl _tl }
              \l__codehl_tok_build_prekeywd_tl
              \l__codehl_tok_build_keywd_tl
            \tl_clear:N \l__codehl_tok_build_prekeywd_tl
            \tl_clear:N \l__codehl_tok_build_keywd_tl

            \cs_set:Npn \__codehl_tok_proc:N  { #2 }

            \bool_if:NTF \l__codehl_tok_ident_bool
              {
                \__codehl_nested_pop:
                \bool_set_false:N \l__codehl_tok_ident_bool
              } { }

            \tl_set:Nn \l__codehl_tok_curr_token_tl { ##1 }

            %%% utf test
            %%%
            \if_int_compare:w ` ##1 > 127
              \tl_set_eq:NN \l__codehl_tok_build_utf_tl \l__codehl_tok_curr_token_tl
              \cs_set:Npn \__codehl_tok_proc:N  { #1 }
              \__codehl_tok_scan_stop:w % jumping to \scan_stop:
            \fi:

            #5

            \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { ##1 \__codehl_penalty: }  %%% ARGH! look above (...if_catcode... last assigment...)
            \scan_stop:
          \fi:
        \fi:
        \__codehl_tok_proc:N
      }
  }
\cs_generate_variant:Nn \__codehl_tok_keygen:NNNnn { ccc }

%%%%%%%
%%% gen with keywd
%%% { base <state> } { <build-var> } { eol code } { base }
%%%%%%%
\cs_new_protected:Npn \__codehl_tok_keygen:nnn #1
  {
    \__codehl_tok_keygen:cccnn
      { __codehl_tok_utf_ #1 :N }
      { __codehl_tok_ #1 :N }
      { __codehl_tok_keywd_ #1 :N }
  }

%%%%%%%
%%% \__codehl_tok_utf_other:N
%%% \__codehl_tok_other:N
%%% \__codehl_tok_keywd_other:N
%%%%%%%
\__codehl_tok_keygen:nnn
  { other }
  {
    \tl_put_right:No \l__codehl_tok_build_line_tl
      \l__codehl_tok_build_dlimit_tl
    \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_test_space:
      \__codehl_tok_other_scan:
      \__codehl_tok_tr_scan:
  }

%%%%%%%
%%% \__codehl_tok_utf_tagged:N
%%% \__codehl_tok_tagged:N
%%% \__codehl_tok_keywd_tagged:N
%%%%%%%
\__codehl_tok_keygen:nnn
  { tagged }
  {
      \__codehl_tok_fmt:o
        \l__codehl_tok_build_dlimit_tl
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_test_space:
      \__codehl_tok_end_scan:
      \__codehl_tok_other_scan:
      \__codehl_tok_tr_scan:
  }

%%%%%%%
%%% \__codehl_tok_utf_dlimit:N
%%% \__codehl_tok_dlimit:N
%%% \__codehl_tok_keywd_dlimit:N
%%%%%%%
\__codehl_tok_keygen:nnn
  { dlimit }
  {
      \__codehl_tok_fmt:o
        \l__codehl_tok_build_dlimit_tl
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_test_space:
      \__codehl_tok_end_scan:
      \__codehl_tok_cmt_scan:
      \__codehl_tok_tr_scan:
  }

%%%%%%%
%%% \__codehl_tok_utf_string:N
%%% \__codehl_tok_string:N
%%% \__codehl_tok_keywd_string:N
%%%%%%%
\__codehl_tok_keygen:nnn
  { string }
  {
      \__codehl_tok_fmt:o
        \l__codehl_tok_build_dlimit_tl
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_test_space:
      \__codehl_tok_test_escape:
      \__codehl_tok_end_scan:
      \__codehl_tok_str_scan:
      \__codehl_tok_tr_scan:
  }

%%%%%%%
%%% \__codehl_tok_utf_dlimit_line:N
%%% \__codehl_tok_dlimit_line:N
%%% \__codehl_tok_keywd_dlimit_line:N
%%%%%%%
\__codehl_tok_keygen:nnn
  { dlimit_line }
  {
      \__codehl_tok_fmt:o
        \l__codehl_tok_build_dlimit_tl
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_test_space:
      \__codehl_tok_cmt_scan:
      \__codehl_tok_tr_scan:
  }

%%%%%%%
%%% \__codehl_tok_utf_dlimit_tex:N
%%% \__codehl_tok_dlimit_tex:N
%%%%%%%
\__codehl_tok_gen:nnn
  { dlimit_tex }
  {
      \__codehl_tok_fmt_retoken:o
        \l__codehl_tok_build_dlimit_tl
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
  }
  {
      \__codehl_tok_end_scan:
            %%% no \penalty here... tex coding
      \tl_put_right:Nn \l__codehl_tok_build_dlimit_tl { #1 }
  }

%%%%%%%
%%% \__codehl_tok_utf_dlimit_discard:N
%%% \__codehl_tok_dlimit_discard:N
%%%%%%%
%%%%%%%
%%% Functionaly OK... but quite a few unnecessary assigments.
%%%%%%%
\__codehl_tok_gen:nnn
  { dlimit_discard }
  { }
  {
      \__codehl_tok_end_scan:
  }

%%%%%%%
%%% ==> re-defining __codehl_tok_utf_dlimit_discard:N to remove the unnecessary steps/assigments !
%%% in case of discard... there is no need to build up the line (which will be discarded anyway)
%%% breaking the factory pattern.
%%%%%%%
%%% why not just 'discard' everything?
%%% utf8 chars might be active (and the \peek_ahead commands will fail)
%%%
\cs_set:Npn  \__codehl_tok_utf_dlimit_discard:N #1
  {

    \if_meaning:w \q_nil #1
      \cs_set_eq:NN \__codehl_tok_proc:N \prg_do_nothing:
      \tl_clear:N \l__codehl_tok_build_dlimit_tl
    \else:
      \if_int_compare:w ` #1 > 127
      \else:
        \cs_set:Npn \__codehl_tok_proc:N
          { \__codehl_tok_dlimit_discard:N }

        \tl_set:Nn \l__codehl_tok_curr_token_tl { #1 }

        \__codehl_tok_end_scan:
        \scan_stop:
      \fi:
    \fi:
    \__codehl_tok_proc:N
  }

%%%%%%%
%%% standard sets
%%%
%%%%%%%
\codehl_basefmt_def:nn { std-basefmt }
  { }

\codehl_hlset_def:nn { std-hlset }
  {
    comment  =   {1}{ \itshape } ,
    comment  =   {2}{ \itshape } ,
    comment  =   {3}{ \itshape } ,
    comment  =   {4}{ \itshape } ,
    string    =   {1}{ \slshape } ,
    string    =   {2}{ \slshape } ,
    string    =   {3}{ \slshape } ,
    string    =   {4}{ \slshape } ,
    keywd     =   {1}{ \bfseries } ,
    keywd     =   {2}{ \bfseries } ,
    keywd     =   {3}{ \bfseries } ,
    keywd     =   {4}{ \bfseries } ,
    texcs     =   {1}{ \bfseries } ,
    texcs     =   {2}{ \bfseries } ,
    texcs     =   {3}{ \bfseries } ,
    texcs     =   {4}{ \bfseries } ,

    attrib    =   {1}{ \bfseries } ,
    pragma    =   {1}{ \bfseries } ,
    html      =   {1}{ \bfseries } ,
    html      =   {2}{ \bfseries } ,
    html      =   {3}{ \bfseries } ,
    html      =   {4}{ \bfseries } ,
    php       =   {1}{ \bfseries } ,
    php       =   {2}{ \bfseries } ,
    php       =   {3}{ \bfseries } ,
    annotation=   {1}{ \bfseries } ,
  }

%%%
%%% this is just to trigger a 'configuration change' in \codehl_settings:n
%%% and make sure all _tok_.._scan:N commands have a reliable definition
%%%
\tl_set:Nn \l__codehl_tok_activ_keyset_tl  { some-other }
\tl_set:Nn \l__codehl_tok_activ_hlset_tl   { some-other }
\tl_set:Nn \l__codehl_tok_activ_lang_tl    { some-other }
\tl_set:Nn \l__codehl_tok_activ_basefmt_tl { some-other }
\codehl_settings:n
  {
    language = {} ,
    keywd ~ set = {} ,
    hl ~ set = std-hlset ,
    base ~ format = std-basefmt
  }

%% some ideas for <mark> <char><regex>
%% problem \peek_regex_replace_once: has to _tok_something:N that processes {n} then _tok_proc:N => _tok_start:N
%% this completely brakes the pattern
%
%%%\cs_new:Npn \__codehl_tst:n #1
%%%  {
%%%    \tl_set:Nn \l_tmpa_tl { #1 }
%%%    this:~(\l_tmpa_tl)\par
%%%  }
%%%
%%%\tl_clear:N \l_tmpa_tl
%%%\regex_const:Nn \l__codehl_tst_regex {ab|AB}
%%%\peek_regex_replace_once:NnTF \l__codehl_tst_regex { { \0 } }
%%%  {
%%%   got~it\par
%%%   \__codehl_tst:n
%%%  }
%%%  {
%%%  not~them\par
%%%  }
%%%ab
%%%\par
%%%\cs_show:N \l_tmpa_tl
%%%that:<<\l_tmpa_tl>>\par


