diff options
author | Karl Berry <karl@freefriends.org> | 2017-04-19 23:04:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-04-19 23:04:15 +0000 |
commit | f74161ca4e7eb3c5af9afcbe92522ae3b58987c1 (patch) | |
tree | 3c30a13df5ac7968195c85070a2b074578e669d2 /Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua | |
parent | 1d5a55ac8f5506a7ae9cfca52f4b588182e199d4 (diff) |
context beta/cont-tmf.zip (Apr 16 12:55)
git-svn-id: svn://tug.org/texlive/trunk@43931 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua | 210 |
1 files changed, 175 insertions, 35 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua b/Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua index 98b92cef3b3..34e5c4e887f 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/syst-aux.lua @@ -121,6 +121,7 @@ implement { -- \gdef\setpercentdimen#1#2% -- {#1=\ctxcommand{percentageof("#2",\number#1)}\relax} +local space = P(" ") / "" local spaces = P(" ")^0 / "" local nohash = 1 - P("#") local digit = R("09") @@ -130,27 +131,147 @@ local sentinel = spaces * (nohash^1 / "\\%0") local sargument = (single * digit)^1 local dargument = (double * digit)^1 -local usespaces = nil -local texpreamble = nil - -local pattern = Cs( -- ^-1 - ( P("spaces") / function() usespaces = true return "" end )^0 - * spaces - * ( P("nospaces") / function() usespaces = false return "" end )^0 - * spaces - * ( P("global") / "\\global" )^0 - * spaces - * ( P("unexpanded") / "\\unexpanded" )^0 - * spaces - * Cc("\\expandafter\\") - * spaces - * ( P("expanded") / "e" )^0 - * spaces - * ( P((1-S(" #"))^1) / "def\\csname %0\\endcsname" ) - * spaces - * ( - -- (double * digit)^1 * sentinel^-1 * double^-1 - -- + (single * digit)^1 * sentinel^-1 * single^-1 +-- first variant: +-- +-- local texpreamble = nil +-- local usespaces = nil +-- +-- local pattern = Cs( -- ^-1 +-- ( P("spaces") / function() usespaces = true return "" end )^0 +-- * spaces +-- * ( P("nospaces") / function() usespaces = false return "" end )^0 +-- * spaces +-- * ( P("global") / "\\global" )^0 +-- * spaces +-- * ( P("unexpanded") / "\\unexpanded" )^0 +-- * spaces +-- * Cc("\\expandafter\\") +-- * spaces +-- * ( P("expanded") / "e" )^0 +-- * spaces +-- * ( P((1-S(" #"))^1) / "def\\csname %0\\endcsname" ) +-- * spaces +-- * ( +-- -- (double * digit)^1 * sentinel^-1 * double^-1 +-- -- + (single * digit)^1 * sentinel^-1 * single^-1 +-- ( P("[") * dargument * P("]") + dargument)^1 * sentinel^-1 * double^-1 +-- + ( P("[") * sargument * P("]") + sargument)^1 * sentinel^-1 * single^-1 +-- + sentinel^-1 * (double+single)^-1 +-- ) +-- ) +-- +-- local ctx_dostarttexdefinition = context.dostarttexdefinition +-- +-- local function texdefinition_one(str) +-- usespaces = nil +-- texpreamble = lpegmatch(pattern,str) +-- if usespaces == true then +-- setcatcode(32,10) -- space +-- setcatcode(13, 5) -- endofline +-- elseif usespaces == false then +-- setcatcode(32, 9) -- ignore +-- setcatcode(13, 9) -- ignore +-- else +-- -- this is default +-- -- setcatcode(32,10) -- space +-- -- setcatcode(13, 9) -- ignore +-- end +-- ctx_dostarttexdefinition() +-- end +-- +-- local function texdefinition_two() +-- context(texpreamble) +-- end + +-- second variant: +-- +-- -- default: +-- -- +-- -- setcatcode(32,10) -- space +-- -- setcatcode(13, 9) -- ignore +-- +-- local function catcodes_s() +-- setcatcode(32,10) -- space +-- setcatcode(13, 5) -- endofline +-- return "" +-- end +-- +-- local function catcodes_n() +-- setcatcode(32, 9) -- ignore +-- setcatcode(13, 9) -- ignore +-- return "" +-- end +-- +-- local pattern = Cs( -- ^-1 +-- ( P("spaces") * space / catcodes_s )^0 +-- * spaces * ( P("nospaces") * space / catcodes_n )^0 +-- * spaces * ( P("global") * space / "\\global" )^0 +-- * spaces * ( P("unexpanded") * space / "\\unexpanded" )^0 +-- * spaces * Cc("\\expandafter\\") +-- * spaces * ( P("expanded") / "e" )^0 +-- * spaces * ( P((1-S(" #["))^1) / "def\\csname %0\\endcsname" ) +-- * spaces * ( +-- -- (double * digit)^1 * sentinel^-1 * double^-1 +-- -- + (single * digit)^1 * sentinel^-1 * single^-1 +-- ( P("[") * dargument * P("]") + dargument)^1 * sentinel^-1 * double^-1 +-- + ( P("[") * sargument * P("]") + sargument)^1 * sentinel^-1 * single^-1 +-- + sentinel^-1 * (double+single)^-1 +-- ) +-- ) +-- +-- local texpreamble = nil +-- +-- local ctx_dostarttexdefinition = context.dostarttexdefinition +-- +-- local function texdefinition_one(str) +-- texpreamble = lpegmatch(pattern,str) +-- ctx_dostarttexdefinition() +-- end +-- +-- local function texdefinition_two() +-- context(texpreamble) +-- end + +-- third variant: + +local global = nil +local unexpanded = nil +local expanded = nil +local optional = nil +local csname = nil +local rest = nil + +local function catcodes_s() + setcatcode(32,10) -- space + setcatcode(13, 5) -- endofline +end + +local function catcodes_n() + setcatcode(32, 9) -- ignore + setcatcode(13, 9) -- ignore +end + +local space = P(" ") +local spaces = space^0 + +local option = ( + P("single") + + P("double") + + P("triple") + + P("quadruple") + + P("quintuple") + + P("sixtuple") + ) * (P("empty") + P("argument")) + +local pattern = ( + ( P("spaces") * space / catcodes_s )^0 + * spaces * ( P("nospaces") * space / catcodes_n )^0 + * spaces * ( P("global") * space * Cc(true) + Cc(false) ) + * spaces * ( P("unexpanded") * space * Cc(true) + Cc(false) ) + * spaces * ( P("expanded") * space * Cc(true) + Cc(false) ) + * spaces * ( C(option) * space + Cc(false) ) + * spaces * ( C((1-S(" #["))^1) ) + * spaces * Cs( ( P("[") * dargument * P("]") + dargument)^1 * sentinel^-1 * double^-1 + ( P("[") * sargument * P("]") + sargument)^1 * sentinel^-1 * single^-1 + sentinel^-1 * (double+single)^-1 @@ -160,24 +281,43 @@ local pattern = Cs( -- ^-1 local ctx_dostarttexdefinition = context.dostarttexdefinition local function texdefinition_one(str) - usespaces = nil - texpreamble = lpegmatch(pattern,str) - if usespaces == true then - setcatcode(32,10) -- space - setcatcode(13, 5) -- endofline - elseif usespaces == false then - setcatcode(32, 9) -- ignore - setcatcode(13, 9) -- ignore - else - -- this is default - -- setcatcode(32,10) -- space - -- setcatcode(13, 9) -- ignore - end + global, unexpanded, expanded, optional, csname, rest = lpegmatch(pattern,str) ctx_dostarttexdefinition() end local function texdefinition_two() - context(texpreamble) + if optional then + context ( + [[\unexpanded\expandafter]] .. + (global and [[\xdef]] or [[\edef]]) .. + [[\csname ]] .. + csname .. + [[\endcsname{\expandafter\noexpand\expandafter\do]] .. + optional .. + [[\csname _do_]] .. + csname .. + -- [[_\endcsname}\unexpanded\expandafter]] .. + [[_\endcsname}\expandafter]] .. + (global and [[\gdef]] or [[\edef]]) .. + [[\csname _do_]] .. + csname .. + [[_\endcsname ]] .. + rest + ) + else + context ( + [[\unexpanded\expandafter]] .. + ( global and ( + expanded and [[\xdef]] or [[\gdef]] + ) or ( + expanded and [[\edef]] or [[\def]] + ) ) .. + [[\csname ]] .. + csname .. + [[\endcsname ]] .. + rest + ) + end end implement { name = "texdefinition_one", actions = texdefinition_one, scope = "private", arguments = "string" } |