-
Notifications
You must be signed in to change notification settings - Fork 203
/
def.t
65 lines (62 loc) · 1.97 KB
/
def.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
return {
name = "def";
entrypoints = {"def"};
keywords = {};
expression = function(self,lex)
lex:expect("def")
lex:expect("(")
local formal = lex:expect(lex.name).value
lex:expect(")")
local expfn = lex:luaexpr()
return function(environment_function)
--return our result, a single argument lua function
return function(actual)
local env = environment_function()
--bind the formal argument to the actual one in our environment
env[formal] = actual
--evaluate our expression in the environment
return expfn(env)
end
end
end;
--normally these functions would be refactored to prevent code duplication,
--we leave the duplication here to allow you to examine each individiually
statement = function(self,lex)
lex:expect("def")
local fname = lex:expect(lex.name).value
lex:expect("(")
local formal = lex:expect(lex.name).value
lex:expect(")")
local expfn = lex:luaexpr()
local ctor = function(environment_function)
--return our result, a single argument lua function
return function(actual)
local env = environment_function()
--bind the formal argument to the actual one in our environment
env[formal] = actual
--evaluate our expression in the environment
return expfn(env)
end
end
return ctor, { fname } -- create the statement: name = ctor(environment_function))
end;
localstatement = function(self,lex)
lex:expect("def")
local fname = lex:expect(lex.name).value
lex:expect("(")
local formal = lex:expect(lex.name).value
lex:expect(")")
local expfn = lex:luaexpr()
local ctor = function(environment_function)
--return our result, a single argument lua function
return function(actual)
local env = environment_function()
--bind the formal argument to the actual one in our environment
env[formal] = actual
--evaluate our expression in the environment
return expfn(env)
end
end
return ctor, { fname } -- create the statement: local name = ctor(environment_function))
end;
}