aboutsummaryrefslogtreecommitdiff
path: root/relabel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'relabel.lua')
-rw-r--r--relabel.lua34
1 files changed, 20 insertions, 14 deletions
diff --git a/relabel.lua b/relabel.lua
index f668086..eb71dd0 100644
--- a/relabel.lua
+++ b/relabel.lua
@@ -1,4 +1,4 @@
1-- $Id: re.lua,v 1.44 2013/03/26 20:11:40 roberto Exp $ 1-- $Id: re.lua $
2 2
3-- imported functions and modules 3-- imported functions and modules
4local tonumber, type, print, error = tonumber, type, print, error 4local tonumber, type, print, error = tonumber, type, print, error
@@ -126,15 +126,6 @@ updatelocale()
126local I = m.P(function (s,i) print(i, s:sub(1, i-1)); return i end) 126local I = m.P(function (s,i) print(i, s:sub(1, i-1)); return i end)
127 127
128 128
129local function getdef (id, defs)
130 local c = defs and defs[id]
131 if not c then
132 error("undefined name: " .. id)
133 end
134 return c
135end
136
137
138local function mult (p, n) 129local function mult (p, n)
139 local np = mm.P(true) 130 local np = mm.P(true)
140 while n >= 1 do 131 while n >= 1 do
@@ -161,6 +152,20 @@ local arrow = S * "<-"
161-- a defined name only have meaning in a given environment 152-- a defined name only have meaning in a given environment
162local Def = name * m.Carg(1) 153local Def = name * m.Carg(1)
163 154
155
156local function getdef (id, defs)
157 local c = defs and defs[id]
158 if not c then error("undefined name: " .. id) end
159 return c
160end
161
162-- match a name and return a group of its corresponding definition
163-- and 'f' (to be folded in 'Suffix')
164local function defwithfunc (f)
165 return m.Cg(Def / getdef * m.Cc(f))
166end
167
168
164local num = m.C(m.R"09"^1) * S / tonumber 169local num = m.C(m.R"09"^1) * S / tonumber
165 170
166local String = "'" * m.C((any - "'" - m.P"\n")^0) * expect("'", "MisTerm1") 171local String = "'" * m.C((any - "'" - m.P"\n")^0) * expect("'", "MisTerm1")
@@ -177,7 +182,7 @@ end
177 182
178local Range = m.Cs(any * (m.P"-"/"") * (any - "]")) / mm.R 183local Range = m.Cs(any * (m.P"-"/"") * (any - "]")) / mm.R
179 184
180local item = defined + Range + m.C(any - m.P"\n") 185local item = (defined + Range + m.C(any - m.P"\n")) / m.P
181 186
182local Class = 187local Class =
183 "[" 188 "["
@@ -224,12 +229,13 @@ local exp = m.P{ "Exp",
224 "ExpNumName") 229 "ExpNumName")
225 + "->" * expect(S * ( m.Cg((String + num) * m.Cc(mt.__div)) 230 + "->" * expect(S * ( m.Cg((String + num) * m.Cc(mt.__div))
226 + m.P"{}" * m.Cc(nil, m.Ct) 231 + m.P"{}" * m.Cc(nil, m.Ct)
227 + m.Cg(Def / getdef * m.Cc(mt.__div)) 232 + defwithfunc(mt.__div)
228 ), 233 ),
229 "ExpCap") 234 "ExpCap")
230 + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), 235 + "=>" * expect(S * defwithfunc(m.Cmt),
231 "ExpName1") 236 "ExpName1")
232 ) 237 + "~>" * S * defwithfunc(m.Cf)
238 ) --* S
233 )^0, function (a,b,f) if f == "lab" then return a + mm.T(b) else return f(a,b) end end ); 239 )^0, function (a,b,f) if f == "lab" then return a + mm.T(b) else return f(a,b) end end );
234 Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") 240 Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1")
235 + String / mm.P 241 + String / mm.P