texlive[67674] Master/texmf-dist: yamlvars (19jul23)

commits+karl at tug.org commits+karl at tug.org
Wed Jul 19 22:48:55 CEST 2023


Revision: 67674
          http://tug.org/svn/texlive?view=revision&revision=67674
Author:   karl
Date:     2023-07-19 22:48:55 +0200 (Wed, 19 Jul 2023)
Log Message:
-----------
yamlvars (19jul23)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf
    trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex
    trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua
    trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex	2023-07-19 20:48:47 UTC (rev 67673)
+++ trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex	2023-07-19 20:48:55 UTC (rev 67674)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2022-11-06
+% 2023-07-18
 % Copyright (C) 2021-2022 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -53,8 +53,8 @@
 \date{\today}
 
 
-\usepackage[pl,extrasnoglobals]{penlight}
-\usepackage[overwritedefs]{YAMLvars}
+\usepackage[pl,extrasglobals]{penlight}
+\usepackage[overwritedefs]{yamlvars}
 \title{YAMLvars}
 \subtitle{a YAML variable parser for LuaLaTeX}
 
@@ -107,14 +107,10 @@
 \llcmd{overwritedefs}Danger! This will allow you to \cmd{gdef} commands with YAML. Caution should be taken to not set definitions like \cmd{begin}, \cmd{section}, etc.
 
 \section{Dependencies}
-%This package contains the \texttt{tinyyaml} Lua package.
-\llcmd{Note:}This package requires that the \cmd{markdown} (\url{https://ctan.org/pkg/markdown}) be installed. This package does not use the package in its entirety, but rather depends on the YAML interpreter it comes with: \cmd{markdown-tinyyaml.lua}. This dependency is chosen to avoid redundancy in your TeX installation and align development of the \cmd{tinyyaml} Lua package.
-If you want to use the YAML interpreter for other purposes, you can bring it into Lua by either:
-\begin{verbatim}
-\directlua{yaml = YAMLvars.yaml}           or
-\directlua{yaml = require'markdown-tinyyaml'}
-\end{verbatim}
+\llcmd{Note:}This package requires the \cmd{tinyyaml} package, available on CTAN.
+
 The distribution: \url{https://github.com/api7/lua-tinyyaml}\\
+\ \ \ \ \url{https://ctan.org/pkg/lua-tinyyaml}\\
 The YAML specification: \url{https://yaml.org/spec/}\\
 
 Many of the ``transform'' and ``processing'' functions built-in to this package rely on other packages,
@@ -393,5 +389,32 @@
 
 \lstinputlisting[linerange=113-296]{yamlvars.lua}
 
+%
+%\AllowUndeclaredYV
+%\luadirect{YAMLvars.xfmDefault={'lb2nl','addxspace'}}
+
+%
+%\luadirect{YAMLvars.debug = true}
+%\setYAMLvars{undeclared, xfm= lb2nl addxspace}
+%\begin{parseYAMLvars}
+%kale: |-
+%  kale
+%  eee
+%\end{parseYAMLvars}
+%
+%\kale ee
+%
+%\setYAMLvars{undeclared, xfm=list2items}
+%\begin{parseYAMLvars}
+%lllist:
+%  - one
+%  - two
+%  - three
+%\end{parseYAMLvars}
+%
+%\begin{itemize}
+%  \lllist
+%\end{itemize}
+
 \end{document}
 

Modified: trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua	2023-07-19 20:48:47 UTC (rev 67673)
+++ trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua	2023-07-19 20:48:55 UTC (rev 67674)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2022-11-06
+--% 2023-07-18
 --% Copyright (C) 2021-2022 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,64 +23,66 @@
 --% OR OTHER DEALINGS IN THE SOFTWARE.
 
 
--- tinyyaml license
---MIT License
---
---Copyright (c) 2017 peposso
---
---Permission is hereby granted, free of charge, to any person obtaining a copy
---of this software and associated documentation files (the "Software"), to deal
---in the Software without restriction, including without limitation the rights
---to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
---copies of the Software, and to permit persons to whom the Software is
---furnished to do so, subject to the following conditions:
---
---The above copyright notice and this permission notice shall be included in all
---copies or substantial portions of the Software.
---
---THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
---IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
---FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
---AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
---LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
---OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
---SOFTWARE.
 
 YAMLvars = {} -- self table
 
-YAMLvars.yaml = require'markdown-tinyyaml' -- note: YAMLvars.sty will have checked existence of this already
+YAMLvars.yaml = require'tinyyaml' -- note: YAMLvars.sty will have checked existence of this already
 
+local luakeys = require'luakeys'()  -- note: YAMLvars.sty will have checked existence of this already
+
 local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl
 if (__PL_EXTRAS__ == nil) or  (__PENLIGHT__ == nil) then
     tex.sprint('\\PackageError{yamlvars}{penlight package with extras (or extrasnoglobals) option must be loaded before this package}{}')
 end
 
+-- UI tables to extend functionality
 YAMLvars.xfm = {}
 YAMLvars.prc = {}
 YAMLvars.dec = {} -- table of declare function
 
+-- internal variables
 YAMLvars.varsvals = {}
 YAMLvars.varspecs = {}
 YAMLvars.varslowcase = pl.List()
 
-YAMLvars.xfmDefault = {}
-YAMLvars.prcDefault = 'gdef'
-YAMLvars.dftDefault = nil
-
-YAMLvars.allowUndeclared = false
-YAMLvars.overwritedefs = false
-YAMLvars.lowvasevarall = false
-
 YAMLvars.valTemp = ''
 YAMLvars.varTemp = ''
 
-YAMLvars.tabmidrule = 'hline'
 
 YAMLvars.debug = false
 
+YAMLvars.setts = {}
+YAMLvars.setts.undeclared = false
+YAMLvars.setts.overwrite = false
+YAMLvars.setts.lowercase = false
+YAMLvars.setts.tabmidrule = 'midrule'
+YAMLvars.setts.xfm = {}
+YAMLvars.setts.prc = 'gdef'
+YAMLvars.setts.dft = ''
 
+YAMLvars.settsdefault = pl.tablex.deepcopy(YAMLvars.setts)
 
+function YAMLvars.setts2default()
+    YAMLvars.setts = pl.tablex.deepcopy(YAMLvars.settsdefault)
+end
 
+function YAMLvars.updatesettskv(kv, res, def)
+    def = def or false
+    ss = 'setts' -- setts or settsdefault
+    if def then ss = 'settsdefault' end
+
+    if res == pl.tex._xTrue then
+        YAMLvars.setts2default()
+    end
+
+    local kv = luakeys.parse(kv)
+    if type(kv.xfm) == 'string' then
+        kv.xfm = pl.stringx.split(kv.xfm)
+    end
+
+    pl.tablex.update(YAMLvars[ss], kv)
+end
+
 function YAMLvars.debugtalk(s, ss)
     if YAMLvars.debug then
         pl.tex.help_wrt(s, ss)
@@ -93,12 +95,6 @@
 
 
 
-
--- todo need distinction beyyween table and penlight list ???
-    --val = pl.array2d.map_slice1(_1..'\\\\', val, 1,-2)
-    --return val:join('')
-    --return pl.tablex.reduce(_1.._2, val, '')
-
 function YAMLvars.xfm.markdown(var, val)
      --return '\\begin{markdown} '..val..'\n \\end{markdown}'
      pl.tex.help_wrt(val, md)
@@ -109,7 +105,6 @@
 
 
 
-
 -- xfm functions (transforms) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 function YAMLvars.xfm.addxspace(var, val)
     return val .. '\\xspace'
@@ -124,7 +119,7 @@
 end
 
 function YAMLvars.xfm.addrule2arr(var, val)
-     return pl.array2d.map_slice2(_1..'\\\\\\'.. YAMLvars.tabmidrule..' ', val, 1,-1,-2,-1)
+     return pl.array2d.map_slice2(_1..'\\\\\\'.. YAMLvars.setts.tabmidrule..' ', val, 1,-1,-2,-1)
 end
 
 function YAMLvars.xfm.arr2tabular(var, val)
@@ -296,19 +291,13 @@
 -- --
 
 
--- ??
---token.set_macro('yv--'..var, val, 'global') -- todo fix with csname hack?
-
-
-
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
 function YAMLvars.makecmd(cs, val) -- provide command via lua
-   if token.is_defined(cs) and (not YAMLvars.overwritedefs) then
+   if token.is_defined(cs) and (not YAMLvars.setts.overwrite) then
         YAMLvars.pkgerr('Variable '..cs..' already defined, could not declare')
     else
         pl.tex.defcmd(cs, val)
-        --token.set_macro(cs, val, 'global') -- issues if val contains undefined macro
     end
 end
 
@@ -334,15 +323,18 @@
     end
 end
 
+local function default_stuff()
+    return {xfm=YAMLvars.setts.xfm,prc=YAMLvars.setts.prc,dft=YAMLvars.setts.dft}
+end
 
 function YAMLvars.declareYAMLvarsStr(y)
     local t = YAMLvars.yaml.parse(y)
     for var, specs in pairs(t) do
-        if pl.hasval(specs['lowcasevar']) or YAMLvars.lowvasevarall then
+        if pl.hasval(specs['lowcasevar']) or YAMLvars.setts.lowercase then
             var = var:lower()
             YAMLvars.varslowcase:append(var)
         end
-        YAMLvars.varspecs[var] = {xfm=YAMLvars.xfmDefault,prc=YAMLvars.prcDefault,dft=YAMLvars.dftDefault}
+        YAMLvars.varspecs[var] = default_stuff()
         if type(specs) == 'string' then
             specs = {xfm={specs}}
         end
@@ -353,8 +345,6 @@
         end
         if YAMLvars.dec[YAMLvars.varspecs[var].prc] ~= nil then
             YAMLvars.dec[YAMLvars.varspecs[var].prc](var, YAMLvars.varspecs[var].dft)
-        --else -- actually don't a dec function for all
-        --    -- -- -- tex.print('\\PackageError{YAMLvars}{Declaration function for '..YAMLvarspecs[var].prc..'not found}{}')
         end
     end
     YAMLvars.debugtalk(YAMLvars.varspecs, 'declared YAML vars, varspecs')
@@ -367,21 +357,6 @@
 end
 
 
-local  function check_def(var, val)
-    if YAMLvars.allowUndeclared then
-        if YAMLvars.prcDefault == 'yvdef' then
-            YAMLvars.prc.yvdef(var, val)
-            YAMLvars.debugtalk(var..' = '..val,'yvdef made (undeclared)')
-        else
-            YAMLvars.makecmd(var, val)
-            YAMLvars.debugtalk(var..' = '..val,'gdef made (undeclared)')
-        end
-     else
-        --tex.print('\\PackageError{YAMLvars}{Variable "'..var..'" set but not declared}{}')
-        YAMLvars.pkgerr('Variable "'..var..'" set but not declared')
-    end
-end
-
 local function sub_lua_var(s, v1, v2)
     return s:gsub('([%A?%-?])('..v1..')([%W?%-?])', '%1'..v2..'%3') -- replace x variables
 end
@@ -399,15 +374,11 @@
     if c == 0 then
         return _YV_invalid_expression
     else
-        --pl.tex.help_wrt(s, var)
-        --pl.tex.help_wrt(val, var)
         YAMLvars.valTemp = val
         YAMLvars.varTemp = var
-        --pl.tex.help_wrt(s, var)
         s, c = s:gsub('\2', '') -- strip \2 that might have appeared if / was applied
         s = sub_lua_var(' '..s, 'x', 'YAMLvars.valTemp')
         s = sub_lua_var(s, 'v', 'YAMLvars.varTemp')
-        --pl.tex.help_wrt(s, var)
         local f, err = pcall(loadstring(s))
         if not f then
             --tex.print('\\PackageError{YAMLvars}{xfm with "= or /" error on var "'..var..'"}{}') --
@@ -439,12 +410,13 @@
     end
     f = YAMLvars.prc[YAMLvars.varspecs[var]['prc']]
     if f == nil then
-        --tex.print('\\PackageError{YAMLvars}{prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined}{}')
         YAMLvars.pkgerr('prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined')
     end
     f(var, val) -- prc the value of the variable
 end
 
+
+
 function YAMLvars.parseYAMLvarsStr(y)
     YAMLvars.varsvals = YAMLvars.yaml.parse(y)
     for var, val in pairs(YAMLvars.varsvals) do
@@ -451,12 +423,11 @@
         if YAMLvars.varslowcase:contains(var:lower()) then
             var = var:lower()
         end
-        if YAMLvars.varspecs[var] == nil then
-            check_def(var, val) -- if not declared
-            -- todo consider free form parse declaring
-            -- variable name: {xfm:, dec:, prc:, val: }
-            -- definitely doable here
-        else
+        if YAMLvars.varspecs[var] == nil and YAMLvars.setts.undeclared then
+            YAMLvars.debugtalk(YAMLvars.setts, 'XYZ')
+            YAMLvars.varspecs[var] = default_stuff()  -- if undeclared and allowing, add to varspec set to default xfm, prc, dft
+        end
+        if YAMLvars.varspecs[var] ~= nil then -- if specified, process
             transform_and_prc(var, val)
         end
     end
@@ -501,7 +472,6 @@
           end
       end
     end
-    --pl.tex.help_wrt(t)
     return t
  end
 
@@ -572,71 +542,8 @@
 
     end
 end
--- produce \Var[val[2]\\val[3].....\val[n]]{val[1]}
---function YAMLvars.prc.setdocvarOpt(var, val)
---       if type(val) ~= 'table' then
---            val = {val}
---        end
---        local s = '\\'..var..'{'..tostring(val[1])..'}'
---        s = s..'['..pl.List(v):map_slice1():join()..']' -- what does this do?
---        tex.print(s)
---end
---
---
---function YAMLvars.prc.setdocvarOpts(var, val)
---        if type(val) ~= 'table' then
---            val = {val}
---        end
---        local s = '\\'..var..'{'..tostring(val[1])..'}'
---        for k, v in pairs(val) do
---            if k > 1 then
---                s = s..'['..tostring(v)..']'
---            end
---        end
---        tex.print(s)
---end
 
-return YAMLvars
 
 
+return YAMLvars
 
-
-
-
-
-
-
-     --token.set_macro('@memoFr', k, 'global')
-        --token.set_macro('@memoFrAddr', v, 'global')
-        --token.set_macro('@memoTo', k, 'global')
-        --token.set_macro('@memoToAddr', v, 'global')
-        --help_wrt(var,val)
-        --        token.set_macro('@'..var, val, 'global')
-
---function YAMLvars.prc.title(var, val)
---        YAMLvars.prc.setdocvar('title', val)
---end
---
---
---function YAMLvars.prc.author(var, val)
---        YAMLvars.prc.setdocvar('author', val)
---end
---
---function YAMLvars.prc.date(var, val)
---        YAMLvars.prc.setdocvar('date', val)
---end
-
-
-  --clean = clean or true
-    --if clean then -- clean first part of yaml string
-    --    y = clean_tex_spaces(y)
-    --end
---local function clean_tex_spaces(s)
---    pl.tex.help_wrt(s)
---    if s:sub(1,2) == '%s' then
---        s, _ = s:gsub('%s+','',1)
---    end
---    s, _ = s:gsub('\\par ','\n\n')
---    return s
---end
-

Modified: trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty	2023-07-19 20:48:47 UTC (rev 67673)
+++ trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty	2023-07-19 20:48:55 UTC (rev 67674)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2022-11-06
+% 2023-07-18
 % Copyright (C) 2021-2022 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,43 +25,73 @@
 
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{yamlvars}[2022-11-06]
+\ProvidesPackage{yamlvars}[2023-07-18]
 
-\IfFileExists{markdown-tinyyaml.lua}{}{\PackageError{YAMLvars}{This package requires installation of the 'markdown' package, please install it and try again}{}}
-
 \RequirePackage{luacode}
 \RequirePackage{xspace}
 \RequirePackage{etoolbox}
+\RequirePackage{luakeys}
 \RequirePackage{penlight} % no option passed here, but extras must be used, error will be thrown if not
 
+%\IfFileExists{tinyyaml.lua}{}{\PackageError{yamlvars}{This package requires installation of the 'tinyyaml' package, please install it and try again}{}}
+
+
 \luadirect{YAMLvars = require('YAMLvars')}
 
 \DeclareOption{useyv}{
         \gdef\yv#1{\csname yv--#1\endcsname}
-        \luadirect{YAMLvars.prcDefault = 'yvdef'}
+        \luadirect{YAMLvars.setts.prc = 'yvdef'}
+        \luadirect{YAMLvars.settsdefault.prc = 'yvdef'}
 }
 \DeclareOption{parseCLI}{
       \AtBeginDocument{\luadirect{YAMLvars.doYAMLfiles(YAMLvars.getYAMLcli())}}
 }
+\DeclareOption{debug}{
+        \luadirect{YAMLvars.debug = true}
+}
+
+
+
+
+
+
+
+
+
+
+%% todo delete below
+\newcommand{\lowercasevarYVon}{\luadirect{YAMLvars.lowvasevarall = true}}
+\newcommand{\lowercasevarYVoff}{\luadirect{YAMLvars.lowvasevarall = false}}
+\newcommand{\AllowUndeclaredYV}{\luadirect{YAMLvars.setts.undeclared = true}}
+\newcommand{\ForbidUndeclaredYV}{\luadirect{YAMLvars.setts.undeclared = false}}
+\newcommand{\TextualYV}{\luadirect{
+YAMLvars.allowUndeclared = true
+YAMLvars.xfmDefault = {'lb2nl','addxspace'}
+}}
 \DeclareOption{allowundeclared}{
-        \luadirect{YAMLvars.allowUndeclared = true}
+        \luadirect{YAMLvars.settsdefault.undeclared = true}
 }
 \DeclareOption{overwritedefs}{
-        \luadirect{YAMLvars.overwritedefs = true}
+        \luadirect{YAMLvars.settsdefault.overwrite = true}
 }
-\DeclareOption{debug}{
-        \luadirect{YAMLvars.debug = true}
-}
+%%%%%%%%%%%%%%%%%%%%%%
 
-\newcommand{\AllowUndeclaredYV}{\luadirect{YAMLvars.allowUndeclared = true}}
-\newcommand{\ForbidUndeclaredYV}{\luadirect{YAMLvars.allowUndeclared = false}}
 
+
+
+
+
+
 \DeclareOption*{\PackageWarning{YAMLvars}{Unknown option: '\CurrentOption'}{}}
 \ProcessOptions\relax
 
+\luadirect{YAMLvars.setts2default()}
 
+
 \newcommand{\declareYAMLvarsFile}[1]{\luadirect{YAMLvars.declareYAMLvarsFile(\luastring{#1})}}
-\newcommand{\parseYAMLvarsFile}[1]{\luadirect{YAMLvars.parseYAMLvarsFile(\luastring{#1})}}
+\NewDocumentCommand{\parseYAMLvarsFile}{m}{\luadirect{
+  YAMLvars.parseYAMLvarsFile(\luastring{#1})
+}}
 
 
 \newenvironment{declareYAMLvars}{\luadirect{_G[__PENLIGHT__].tex.startrecording()}}{\luadirect{_G[__PENLIGHT__].tex.stoprecording()}
@@ -68,17 +98,21 @@
         \luadirect{YAMLvars.declareYAMLvarsStr(_G[__PENLIGHT__].tex.recordedbuf)}
 }
 
-\newenvironment{parseYAMLvars}{\luadirect{_G[__PENLIGHT__].tex.startrecording()}}{\luadirect{_G[__PENLIGHT__].tex.stoprecording()}
-}
+
+\NewDocumentEnvironment{parseYAMLvars}{}%
+{\luadirect{
+  _G[__PENLIGHT__].tex.startrecording()
+}}%
+{\luadirect{
+  _G[__PENLIGHT__].tex.stoprecording()
+}}
 \AfterEndEnvironment{parseYAMLvars}{\luadirect{YAMLvars.parseYAMLvarsStr(_G[__PENLIGHT__].tex.recordedbuf)}}
 % necessary hack to get rohead and lohead to work..
 % .. https://tex.stackexchange.com/questions/637018/setting-koma-heading-within-lua/637021?noredirect=1#comment1587387_637021
 
-\newcommand{\resetYAMLvarsspec}{\luadirect{YAMLvars.varspec = {}}}
 
 
-\newcommand{\lowercasevarYVon}{\luadirect{YAMLvars.lowvasevarall = true}}
-\newcommand{\lowercasevarYVoff}{\luadirect{YAMLvars.lowvasevarall = false}}
+\newcommand{\resetYAMLvarsspec}{\luadirect{YAMLvars.varspec = {}}}
 
 
 
@@ -89,3 +123,18 @@
   }
 }
 
+
+
+
+\NewDocumentCommand{\setYAMLvars}{s m }{\luadirect{
+  YAMLvars.updatesettskv(\luastring{#2}, \luastring{#1})
+}}
+
+\NewDocumentCommand{\setdefYAMLvars}{ m }{\luadirect{
+  YAMLvars.updatesettskv(pl.tex._xFalse, \luastring{#1}, true)
+}}
+
+%  \IfBooleanTF{#1}{\luadirect{YAMLvars.setts = pl.tablex.deepcopy(YAMLvars.settsdefault)}}{} % if * return to default first
+%  \luadirect{pl.tablex.update(YAMLvars.setts, luakeys.parse(\luastring{#2}))}
+%  \luadirect{YAMLvars.setts.xfm = {'lb2nl', 'addxspace'}}
+



More information about the tex-live-commits mailing list.