diff options
author | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2010-03-28 14:34:44 +0200 |
---|---|---|
committer | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2010-03-28 14:34:44 +0200 |
commit | 0bb6d1e8d28f914398d3b3de15cf5317f480d02a (patch) | |
tree | a222ca028b0f3bec9f4057424623323602174c29 /luaextra-dimen.lua | |
parent | 7047b46b6fe6dead388c8427a7510710f920b617 (diff) | |
parent | 22fa4cc9381179fdd43ca8a251cb49dd2703079d (diff) | |
download | lualibs-0bb6d1e8d28f914398d3b3de15cf5317f480d02a.tar.gz |
Merge remote branch 'github/master'
Diffstat (limited to 'luaextra-dimen.lua')
-rw-r--r-- | luaextra-dimen.lua | 20 |
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> |