From fffd05cae905f23ad2300395a5ead86d7c0253cd Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 29 Nov 2021 21:13:12 +0000
Subject: babel (29nov21)

git-svn-id: svn://tug.org/texlive/trunk@61186 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/generic/babel/luababel.def | 111 +++++++++++------------
 1 file changed, 53 insertions(+), 58 deletions(-)

(limited to 'Master/texmf-dist/tex/generic/babel/luababel.def')

diff --git a/Master/texmf-dist/tex/generic/babel/luababel.def b/Master/texmf-dist/tex/generic/babel/luababel.def
index b99ff979189..d5c8c17511b 100644
--- a/Master/texmf-dist/tex/generic/babel/luababel.def
+++ b/Master/texmf-dist/tex/generic/babel/luababel.def
@@ -1138,13 +1138,21 @@ end
 \catcode`\~=12
 \catcode`\%=12
 \catcode`\&=14
-\gdef\babelposthyphenation#1#2#3{&%
-  \bbl@activateposthyphen
+\gdef\babelprehyphenation{&%
+  \@ifnextchar[{\bbl@settransform{0}}{\bbl@settransform{0}[]}}
+\gdef\babelposthyphenation{&%
+  \@ifnextchar[{\bbl@settransform{1}}{\bbl@settransform{1}[]}}
+\gdef\bbl@settransform#1[#2]#3#4#5{&%
+  \ifcase#1
+    \bbl@activateprehyphen
+  \else
+    \bbl@activateposthyphen
+  \fi
   \begingroup
     \def\babeltempa{\bbl@add@list\babeltempb}&%
     \let\babeltempb\@empty
-    \def\bbl@tempa{#3}&% TODO. Ugly trick to preserve {}:
-    \bbl@replace\bbl@tempa{,}{ ,}&%
+    \def\bbl@tempa{#5}&%
+    \bbl@replace\bbl@tempa{,}{ ,}&% TODO. Ugly trick to preserve {}
     \expandafter\bbl@foreach\expandafter{\bbl@tempa}{&%
       \bbl@ifsamestring{##1}{remove}&%
         {\bbl@add@list\babeltempb{nil}}&%
@@ -1152,69 +1160,55 @@ end
            local rep = [=[##1]=]
            rep = rep:gsub('^%s*(remove)%s*$', 'remove = true')
            rep = rep:gsub('^%s*(insert)%s*,', 'insert = true, ')
-           rep = rep:gsub(    '(no)%s*=%s*([^%s,]*)', Babel.capture_func)
-           rep = rep:gsub(   '(pre)%s*=%s*([^%s,]*)', Babel.capture_func)
-           rep = rep:gsub(  '(post)%s*=%s*([^%s,]*)', Babel.capture_func)
            rep = rep:gsub('(string)%s*=%s*([^%s,]*)', Babel.capture_func)
+           if #1 == 0 then
+             rep = rep:gsub('(space)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
+               'space = {' .. '%2, %3, %4' .. '}')
+             rep = rep:gsub('(spacefactor)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
+               'spacefactor = {' .. '%2, %3, %4' .. '}')
+             rep = rep:gsub('(kashida)%s*=%s*([^%s,]*)', Babel.capture_kashida)
+           else
+             rep = rep:gsub(    '(no)%s*=%s*([^%s,]*)', Babel.capture_func)
+             rep = rep:gsub(   '(pre)%s*=%s*([^%s,]*)', Babel.capture_func)
+             rep = rep:gsub(  '(post)%s*=%s*([^%s,]*)', Babel.capture_func)
+           end
            tex.print([[\string\babeltempa{{]] .. rep .. [[}}]])
          }}}&%
+    \let\bbl@kv@attribute\relax
+    \let\bbl@kv@label\relax
+    \bbl@forkv{#2}{\bbl@csarg\edef{kv@##1}{##2}}&%
+    \ifx\bbl@kv@attribute\relax\else
+      \edef\bbl@kv@attribute{\expandafter\bbl@stripslash\bbl@kv@attribute}&%
+    \fi
     \directlua{
-      local lbkr = Babel.linebreaking.replacements[1]
+      local lbkr = Babel.linebreaking.replacements[#1]
       local u = unicode.utf8
-      local id = \the\csname l@#1\endcsname
-      &% Convert pattern:
-      local patt = string.gsub([==[#2]==], '%s', '')
-      if not u.find(patt, '()', nil, true) then
-        patt = '()' .. patt .. '()'
+      local id, attr, label
+      if #1 == 0 then
+        id = \the\csname bbl@id@@#3\endcsname\space
+      else
+        id = \the\csname l@#3\endcsname\space
       end
-      patt = string.gsub(patt, '%(%)%^', '^()')
-      patt = string.gsub(patt, '%$%(%)', '()$')
-      patt = u.gsub(patt, '{(.)}',
-             function (n)
-               return '%' .. (tonumber(n) and (tonumber(n)+1) or n)
-             end)
-      patt = u.gsub(patt, '{(%x%x%x%x+)}',
-             function (n)
-               return u.gsub(u.char(tonumber(n, 16)), '(%p)', '%%%1')
-             end)
-      lbkr[id] = lbkr[id] or {}
-      table.insert(lbkr[id], { pattern = patt, replace = { \babeltempb } })
-    }&%
-  \endgroup}
-\gdef\babelprehyphenation#1#2#3{&%
-  \bbl@activateprehyphen
-  \begingroup
-    \def\babeltempa{\bbl@add@list\babeltempb}&%
-    \let\babeltempb\@empty
-    \def\bbl@tempa{#3}&% TODO. Ugly trick to preserve {}:
-    \bbl@replace\bbl@tempa{,}{ ,}&%
-    \expandafter\bbl@foreach\expandafter{\bbl@tempa}{&%
-      \bbl@ifsamestring{##1}{remove}&%
-        {\bbl@add@list\babeltempb{nil}}&%
-        {\directlua{
-           local rep = [=[##1]=]
-           rep = rep:gsub('^%s*(remove)%s*$', 'remove = true')
-           rep = rep:gsub('^%s*(insert)%s*,', 'insert = true, ')
-           rep = rep:gsub('(string)%s*=%s*([^%s,]*)', Babel.capture_func)
-           rep = rep:gsub('(space)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
-             'space = {' .. '%2, %3, %4' .. '}')
-           rep = rep:gsub('(spacefactor)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
-             'spacefactor = {' .. '%2, %3, %4' .. '}')
-           rep = rep:gsub('(kashida)%s*=%s*([^%s,]*)', Babel.capture_kashida)
-           tex.print([[\string\babeltempa{{]] .. rep .. [[}}]])
-         }}}&%
-    \directlua{
-      local lbkr = Babel.linebreaking.replacements[0]
-      local u = unicode.utf8
-      local id = \the\csname bbl@id@@#1\endcsname
+      \ifx\bbl@kv@attribute\relax
+        attr = -1
+      \else
+        attr = luatexbase.registernumber'\bbl@kv@attribute'
+      \fi
+      \ifx\bbl@kv@label\relax\else  &% Same refs:
+        label = [==[\bbl@kv@label]==]
+      \fi
       &% Convert pattern:
-      local patt = string.gsub([==[#2]==], '%s', '')
-      local patt = string.gsub(patt, '|', ' ')
+      local patt = string.gsub([==[#4]==], '%s', '')
+      if #1 == 0 then
+        patt = string.gsub(patt, '|', ' ')
+      end
       if not u.find(patt, '()', nil, true) then
         patt = '()' .. patt .. '()'
       end
-      &% patt = string.gsub(patt, '%(%)%^', '^()')
-      &% patt = string.gsub(patt, '([^%%])%$%(%)', '%1()$')
+      if #1 == 1 then
+        patt = string.gsub(patt, '%(%)%^', '^()')
+        patt = string.gsub(patt, '%$%(%)', '()$')
+      end
       patt = u.gsub(patt, '{(.)}',
              function (n)
                return '%' .. (tonumber(n) and (tonumber(n)+1) or n)
@@ -1224,7 +1218,8 @@ end
                return u.gsub(u.char(tonumber(n, 16)), '(%p)', '%%%1')
              end)
       lbkr[id] = lbkr[id] or {}
-      table.insert(lbkr[id], { pattern = patt, replace = { \babeltempb } })
+      table.insert(lbkr[id],
+        { label=label, attr=attr, pattern=patt, replace={\babeltempb} })
     }&%
   \endgroup}
 \endgroup
-- 
cgit v1.2.3

