diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-10-10 13:36:53 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-10-10 13:36:53 +0200 |
commit | d47ee9fc195ba82eef5e4be132b1d88b7f009a9c (patch) | |
tree | 45964c47b2242f6ff9bf6a881639146be1edd201 /tex/context/base/mkiv/mlib-lua.lua | |
parent | edaa6851d5c096acba2ad5817f70d3eb7cec46e6 (diff) | |
download | context-d47ee9fc195ba82eef5e4be132b1d88b7f009a9c.tar.gz |
2017-10-10 12:06:00
Diffstat (limited to 'tex/context/base/mkiv/mlib-lua.lua')
-rw-r--r-- | tex/context/base/mkiv/mlib-lua.lua | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/tex/context/base/mkiv/mlib-lua.lua b/tex/context/base/mkiv/mlib-lua.lua index 9831efc20..3406d05db 100644 --- a/tex/context/base/mkiv/mlib-lua.lua +++ b/tex/context/base/mkiv/mlib-lua.lua @@ -13,9 +13,10 @@ if not modules then modules = { } end modules ['mlib-lua'] = { local type, tostring, select, loadstring = type, tostring, select, loadstring local find, match, gsub, gmatch = string.find, string.match, string.gsub, string.gmatch -local formatters = string.formatters -local concat = table.concat -local lpegmatch = lpeg.match +local formatters = string.formatters +local concat = table.concat +local lpegmatch = lpeg.match +local lpegpatterns = lpeg.patterns local P, S, Ct = lpeg.P, lpeg.S, lpeg.Ct @@ -230,8 +231,8 @@ function mp.n(t) return type(t) == "table" and #t or 0 end -local whitespace = lpeg.patterns.whitespace -local newline = lpeg.patterns.newline +local whitespace = lpegpatterns.whitespace +local newline = lpegpatterns.newline local setsep = newline^2 local comment = (S("#%") + P("--")) * (1-newline)^0 * (whitespace - setsep)^0 local value = (1-whitespace)^1 / tonumber @@ -479,13 +480,15 @@ function mp.prefix(str) mpquoted(match(str,"^(.-)[%d%[]") or str) end -function mp.dimensions(str) - local n = 0 - for s in gmatch(str,"%[?%-?%d+%]?") do --todo: lpeg - n = n + 1 - end - mpprint(n) -end +-- function mp.dimension(str) +-- local n = 0 +-- for s in gmatch(str,"%[?%-?%d+%]?") do --todo: lpeg +-- n = n + 1 +-- end +-- mpprint(n) +-- end + +mp.dimension = lpeg.counter(P("[") * lpegpatterns.integer * P("]") + lpegpatterns.integer,mpprint) -- faster and okay as we don't have many variables but probably only -- basename makes sense and even then it's not called that often |