summaryrefslogtreecommitdiff
path: root/luaextra-dimen.lua
diff options
context:
space:
mode:
Diffstat (limited to 'luaextra-dimen.lua')
-rw-r--r--luaextra-dimen.lua20
1 files changed, 15 insertions, 5 deletions
diff --git a/luaextra-dimen.lua b/luaextra-dimen.lua
index e15e294..a8faa27 100644
--- a/luaextra-dimen.lua
+++ b/luaextra-dimen.lua
@@ -16,7 +16,7 @@ table.</p>
--ldx]]--
local format, match, gsub, type, setmetatable = string.format, string.match, string.gsub, type, setmetatable
-local lpegmatch = lpeg.match
+local P, S, R, Cc, lpegmatch = lpeg.P, lpeg.S, lpeg.R, lpeg.Cc, lpeg.match
number = number or { }
@@ -100,6 +100,7 @@ end
<p>We collect a bunch of converters in the <type>number</type> namespace.</p>
--ldx]]--
+number.maxdimen = 1073741823
number.todimen = todimen
number.dimenfactors = dimenfactors
@@ -124,10 +125,12 @@ a number and optionally a unit. When no unit is given a constant
capture takes place.</p>
--ldx]]--
-local amount = (lpeg.S("+-")^0 * lpeg.R("09")^0 * lpeg.P(".")^0 * lpeg.R("09")^0) + lpeg.Cc("0")
-local unit = lpeg.R("az")^1
+local amount = (S("+-")^0 * R("09")^0 * P(".")^0 * R("09")^0) + Cc("0")
+local unit = R("az")^1
-local pattern = amount/tonumber * (unit^1/dimenfactors + lpeg.Cc(1)) -- tonumber is new
+local pattern = amount/tonumber * (unit^1/dimenfactors + Cc(1)) -- tonumber is new
+
+lpeg.patterns.dimenpair = pattern
--[[ldx--
<p>We use a metatable to intercept errors. When no key is found in
@@ -147,11 +150,18 @@ function string:todimen()
return self
else
local value, unit = lpegmatch(pattern,self)
- print(value,unit)
return value/unit
end
end
+local amount = S("+-")^0 * R("09")^0 * S(".,")^0 * R("09")^0
+local unit = P("pt") + P("cm") + P("mm") + P("sp") + P("bp") + P("in") +
+ P("pc") + P("dd") + P("cc") + P("nd") + P("nc")
+
+local pattern = amount * unit
+
+lpeg.patterns.validdimen = pattern
+
--[[ldx--
<p>This converter accepts calls like:</p>