diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-03-20 22:59:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-03-20 22:59:00 +0100 |
commit | 28351dce705d3546bc4a67b554ee474d2f3cce4a (patch) | |
tree | d47aa92d59770d1b4da0b01337158a5791e0b0de /tex/context/base/l-dimen.lua | |
parent | 66a814af45f6ebe7ff0210238b2b9eba7dd3a499 (diff) | |
download | context-28351dce705d3546bc4a67b554ee474d2f3cce4a.tar.gz |
beta 2010.03.20 22:59
Diffstat (limited to 'tex/context/base/l-dimen.lua')
-rw-r--r-- | tex/context/base/l-dimen.lua | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/tex/context/base/l-dimen.lua b/tex/context/base/l-dimen.lua index 52ef06dcb..a8faa270b 100644 --- a/tex/context/base/l-dimen.lua +++ b/tex/context/base/l-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 { } @@ -125,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 @@ -148,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> |