delorean_lang 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/delorean/delorean.rb +83 -50
- data/lib/delorean/delorean.treetop +21 -16
- data/lib/delorean/error.rb +4 -0
- data/lib/delorean/version.rb +1 -1
- data/spec/dev_spec.rb +29 -29
- data/spec/eval_spec.rb +181 -181
- data/spec/func_spec.rb +41 -41
- data/spec/parse_spec.rb +142 -142
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjQ5M2EzMTc3OGJlMmFhYTY0YmY1YTE5ODg5MTZiYjk2NmFjNDk1OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTVhYzM1MGQxNmNkNjM1YWQ4Zjc3ZjU2MDQzOGJjNzA5MjczNmNmNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjA2NWM5NmQ0Zjg1NjkxYTI1YjBmZTEzYTdkNzJiODRkMzI2YTQ1NWNlZjA1
|
10
|
+
ODgyZjkzODAxYWViOTBmNDI0ODViNzBmMWE0NjRjZjE2NzI4ZWZjMmMzZDYw
|
11
|
+
YzhjMDQ5MjQyNzVhYjYyN2ZhYTMzODcyNzNkYTg4Y2Q5OWVmZWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzQ5YTJmODYwNTdkMjYyM2I1NzZiYjU2MjIyZmMzNzk1MTU4YTJmNDBlMzE4
|
14
|
+
MzlmYzU0ZmRmNmNmMThiYzA5ODdkNThhZjQ5MzAzZDI5MTVkMjk3MTE4ZjFl
|
15
|
+
ZjAyYjkzOTA5YmJlMmYxYTk5YjcwOWMxYWJjMTJhNWJmY2U2MDI=
|
data/lib/delorean/delorean.rb
CHANGED
@@ -98,7 +98,7 @@ module Delorean
|
|
98
98
|
end
|
99
99
|
|
100
100
|
module Formula0
|
101
|
-
def
|
101
|
+
def sp4
|
102
102
|
elements[0]
|
103
103
|
end
|
104
104
|
|
@@ -112,7 +112,7 @@ module Delorean
|
|
112
112
|
end
|
113
113
|
|
114
114
|
module Formula1
|
115
|
-
def
|
115
|
+
def sp4
|
116
116
|
elements[0]
|
117
117
|
end
|
118
118
|
|
@@ -123,7 +123,7 @@ module Delorean
|
|
123
123
|
end
|
124
124
|
|
125
125
|
module Formula2
|
126
|
-
def
|
126
|
+
def sp4
|
127
127
|
elements[0]
|
128
128
|
end
|
129
129
|
|
@@ -187,7 +187,7 @@ module Delorean
|
|
187
187
|
|
188
188
|
i0 = index
|
189
189
|
i1, s1 = index, []
|
190
|
-
r2 =
|
190
|
+
r2 = _nt_sp4
|
191
191
|
s1 << r2
|
192
192
|
if r2
|
193
193
|
r3 = _nt_identifier
|
@@ -236,7 +236,7 @@ module Delorean
|
|
236
236
|
r0 = r1
|
237
237
|
else
|
238
238
|
i10, s10 = index, []
|
239
|
-
r11 =
|
239
|
+
r11 = _nt_sp4
|
240
240
|
s10 << r11
|
241
241
|
if r11
|
242
242
|
r12 = _nt_identifier
|
@@ -272,7 +272,7 @@ module Delorean
|
|
272
272
|
r0 = r10
|
273
273
|
else
|
274
274
|
i16, s16 = index, []
|
275
|
-
r17 =
|
275
|
+
r17 = _nt_sp4
|
276
276
|
s16 << r17
|
277
277
|
if r17
|
278
278
|
r18 = _nt_identifier
|
@@ -2697,22 +2697,31 @@ module Delorean
|
|
2697
2697
|
r3 = _nt_identifier
|
2698
2698
|
s2 << r3
|
2699
2699
|
if r3
|
2700
|
-
|
2701
|
-
|
2702
|
-
|
2700
|
+
r5 = _nt_sp
|
2701
|
+
if r5
|
2702
|
+
r4 = r5
|
2703
2703
|
else
|
2704
|
-
|
2705
|
-
r4 = nil
|
2704
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
2706
2705
|
end
|
2707
2706
|
s2 << r4
|
2708
2707
|
if r4
|
2709
|
-
|
2710
|
-
|
2711
|
-
|
2708
|
+
if has_terminal?('=', false, index)
|
2709
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2710
|
+
@index += 1
|
2712
2711
|
else
|
2713
|
-
|
2712
|
+
terminal_parse_failure('=')
|
2713
|
+
r6 = nil
|
2714
|
+
end
|
2715
|
+
s2 << r6
|
2716
|
+
if r6
|
2717
|
+
r8 = _nt_sp
|
2718
|
+
if r8
|
2719
|
+
r7 = r8
|
2720
|
+
else
|
2721
|
+
r7 = instantiate_node(SyntaxNode,input, index...index)
|
2722
|
+
end
|
2723
|
+
s2 << r7
|
2714
2724
|
end
|
2715
|
-
s2 << r5
|
2716
2725
|
end
|
2717
2726
|
end
|
2718
2727
|
if s2.last
|
@@ -2729,58 +2738,58 @@ module Delorean
|
|
2729
2738
|
end
|
2730
2739
|
s0 << r1
|
2731
2740
|
if r1
|
2732
|
-
|
2733
|
-
s0 <<
|
2734
|
-
if
|
2735
|
-
|
2736
|
-
|
2737
|
-
if
|
2738
|
-
|
2741
|
+
r9 = _nt_expression
|
2742
|
+
s0 << r9
|
2743
|
+
if r9
|
2744
|
+
i11, s11 = index, []
|
2745
|
+
r13 = _nt_sp
|
2746
|
+
if r13
|
2747
|
+
r12 = r13
|
2739
2748
|
else
|
2740
|
-
|
2749
|
+
r12 = instantiate_node(SyntaxNode,input, index...index)
|
2741
2750
|
end
|
2742
|
-
|
2743
|
-
if
|
2751
|
+
s11 << r12
|
2752
|
+
if r12
|
2744
2753
|
if has_terminal?(',', false, index)
|
2745
|
-
|
2754
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2746
2755
|
@index += 1
|
2747
2756
|
else
|
2748
2757
|
terminal_parse_failure(',')
|
2749
|
-
|
2758
|
+
r14 = nil
|
2750
2759
|
end
|
2751
|
-
|
2752
|
-
if
|
2753
|
-
|
2754
|
-
if
|
2755
|
-
|
2760
|
+
s11 << r14
|
2761
|
+
if r14
|
2762
|
+
r16 = _nt_sp
|
2763
|
+
if r16
|
2764
|
+
r15 = r16
|
2756
2765
|
else
|
2757
|
-
|
2766
|
+
r15 = instantiate_node(SyntaxNode,input, index...index)
|
2758
2767
|
end
|
2759
|
-
|
2760
|
-
if
|
2761
|
-
|
2762
|
-
if
|
2763
|
-
|
2768
|
+
s11 << r15
|
2769
|
+
if r15
|
2770
|
+
r18 = _nt_kw_args
|
2771
|
+
if r18
|
2772
|
+
r17 = r18
|
2764
2773
|
else
|
2765
|
-
|
2774
|
+
r17 = instantiate_node(SyntaxNode,input, index...index)
|
2766
2775
|
end
|
2767
|
-
|
2776
|
+
s11 << r17
|
2768
2777
|
end
|
2769
2778
|
end
|
2770
2779
|
end
|
2771
|
-
if
|
2772
|
-
|
2773
|
-
|
2780
|
+
if s11.last
|
2781
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
2782
|
+
r11.extend(KwArgs1)
|
2774
2783
|
else
|
2775
|
-
@index =
|
2776
|
-
|
2784
|
+
@index = i11
|
2785
|
+
r11 = nil
|
2777
2786
|
end
|
2778
|
-
if
|
2779
|
-
|
2787
|
+
if r11
|
2788
|
+
r10 = r11
|
2780
2789
|
else
|
2781
|
-
|
2790
|
+
r10 = instantiate_node(SyntaxNode,input, index...index)
|
2782
2791
|
end
|
2783
|
-
s0 <<
|
2792
|
+
s0 << r10
|
2784
2793
|
end
|
2785
2794
|
end
|
2786
2795
|
if s0.last
|
@@ -3064,6 +3073,30 @@ module Delorean
|
|
3064
3073
|
r0
|
3065
3074
|
end
|
3066
3075
|
|
3076
|
+
def _nt_sp4
|
3077
|
+
start_index = index
|
3078
|
+
if node_cache[:sp4].has_key?(index)
|
3079
|
+
cached = node_cache[:sp4][index]
|
3080
|
+
if cached
|
3081
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
3082
|
+
@index = cached.interval.end
|
3083
|
+
end
|
3084
|
+
return cached
|
3085
|
+
end
|
3086
|
+
|
3087
|
+
if has_terminal?(' ', false, index)
|
3088
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
3089
|
+
@index += 4
|
3090
|
+
else
|
3091
|
+
terminal_parse_failure(' ')
|
3092
|
+
r0 = nil
|
3093
|
+
end
|
3094
|
+
|
3095
|
+
node_cache[:sp4][start_index] = r0
|
3096
|
+
|
3097
|
+
r0
|
3098
|
+
end
|
3099
|
+
|
3067
3100
|
def _nt_sp
|
3068
3101
|
start_index = index
|
3069
3102
|
if node_cache[:sp].has_key?(index)
|
@@ -4,11 +4,11 @@ grammar Delorean
|
|
4
4
|
end
|
5
5
|
|
6
6
|
rule formula
|
7
|
-
|
7
|
+
sp4 i:identifier sp? '=?' sp? e:expression <ParameterDefault>
|
8
8
|
/
|
9
|
-
|
9
|
+
sp4 i:identifier sp? '=?' <Parameter>
|
10
10
|
/
|
11
|
-
|
11
|
+
sp4 i:identifier sp? '=' sp? e:expression <Formula>
|
12
12
|
/
|
13
13
|
n:class_name ':' sp? mod:(m:class_name '::')? p:class_name <SubNode>
|
14
14
|
/
|
@@ -26,9 +26,9 @@ grammar Delorean
|
|
26
26
|
/
|
27
27
|
op:unary_op sp? e:expression <UnOp>
|
28
28
|
/
|
29
|
-
'if'
|
30
|
-
'then'
|
31
|
-
'else'
|
29
|
+
'if' sp? v:expression sp?
|
30
|
+
'then' sp? e1:expression sp?
|
31
|
+
'else' sp? e2:expression <IfElse>
|
32
32
|
/
|
33
33
|
v:getattr_exp sp? op:binary_op sp? e:expression <BinOp>
|
34
34
|
/
|
@@ -100,16 +100,16 @@ grammar Delorean
|
|
100
100
|
end
|
101
101
|
|
102
102
|
rule value
|
103
|
-
number
|
104
|
-
string
|
105
|
-
boolean
|
106
|
-
nil_val
|
107
|
-
identifier
|
108
|
-
list_expr
|
109
|
-
set_expr
|
110
|
-
hash_expr
|
103
|
+
number /
|
104
|
+
string /
|
105
|
+
boolean /
|
106
|
+
nil_val /
|
107
|
+
identifier /
|
108
|
+
list_expr /
|
109
|
+
set_expr /
|
110
|
+
hash_expr /
|
111
111
|
mod:(m:class_name '::')? c:class_name <NodeAsValue> /
|
112
|
-
'(' sp? e:expression sp? ')'
|
112
|
+
'(' sp? e:expression sp? ')' <Expr>
|
113
113
|
end
|
114
114
|
|
115
115
|
rule fn_args
|
@@ -121,7 +121,7 @@ grammar Delorean
|
|
121
121
|
end
|
122
122
|
|
123
123
|
rule kw_args
|
124
|
-
k:(i:identifier '
|
124
|
+
k:(i:identifier sp? '=' sp?)? arg0:expression args_rest:(sp? ',' sp? al:kw_args?)? <KwArgs>
|
125
125
|
end
|
126
126
|
|
127
127
|
rule number
|
@@ -148,6 +148,11 @@ grammar Delorean
|
|
148
148
|
'nil' <Literal>
|
149
149
|
end
|
150
150
|
|
151
|
+
# and you thought python was anal about spaces?
|
152
|
+
rule sp4
|
153
|
+
' '
|
154
|
+
end
|
155
|
+
|
151
156
|
rule sp
|
152
157
|
[\s]+
|
153
158
|
end
|
data/lib/delorean/error.rb
CHANGED
data/lib/delorean/version.rb
CHANGED
data/spec/dev_spec.rb
CHANGED
@@ -8,28 +8,28 @@ describe "Delorean" do
|
|
8
8
|
|
9
9
|
it "can enumerate nodes" do
|
10
10
|
engine.parse defn("X:",
|
11
|
-
"
|
12
|
-
"
|
11
|
+
" a = 123",
|
12
|
+
" b = a",
|
13
13
|
"Y: X",
|
14
14
|
"A:",
|
15
15
|
"XX: Y",
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
16
|
+
" a = 11",
|
17
|
+
" c =?",
|
18
|
+
" d = 456",
|
19
19
|
)
|
20
20
|
engine.enumerate_nodes.should == SortedSet.new(["A", "X", "XX", "Y"])
|
21
21
|
end
|
22
22
|
|
23
23
|
it "can enumerate all attrs" do
|
24
24
|
engine.parse defn("X:",
|
25
|
-
"
|
26
|
-
"
|
25
|
+
" a = 123",
|
26
|
+
" b = a",
|
27
27
|
"Y: X",
|
28
28
|
"Z:",
|
29
29
|
"XX: Y",
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
30
|
+
" a = 11",
|
31
|
+
" c =?",
|
32
|
+
" d = 456",
|
33
33
|
)
|
34
34
|
engine.enumerate_attrs.should == {
|
35
35
|
"X"=>["a", "b"],
|
@@ -41,14 +41,14 @@ describe "Delorean" do
|
|
41
41
|
|
42
42
|
it "can enumerate attrs by node" do
|
43
43
|
engine.parse defn("X:",
|
44
|
-
"
|
45
|
-
"
|
44
|
+
" a = 123",
|
45
|
+
" b = a",
|
46
46
|
"Y: X",
|
47
47
|
"Z:",
|
48
48
|
"XX: Y",
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
49
|
+
" a = 11",
|
50
|
+
" c =?",
|
51
|
+
" d = 456",
|
52
52
|
)
|
53
53
|
engine.enumerate_attrs_by_node("X").should == ["a", "b"]
|
54
54
|
engine.enumerate_attrs_by_node("Y").should == ["a", "b"]
|
@@ -58,17 +58,17 @@ describe "Delorean" do
|
|
58
58
|
|
59
59
|
it "can enumerate params" do
|
60
60
|
engine.parse defn("X:",
|
61
|
-
"
|
62
|
-
"
|
61
|
+
" a =? 123",
|
62
|
+
" b = a",
|
63
63
|
"Y: X",
|
64
64
|
"Z:",
|
65
65
|
"XX: Y",
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
66
|
+
" a = 11",
|
67
|
+
" c =?",
|
68
|
+
" d = 123",
|
69
69
|
"YY: XX",
|
70
|
-
"
|
71
|
-
"
|
70
|
+
" c =? 22",
|
71
|
+
" e =? 11",
|
72
72
|
)
|
73
73
|
|
74
74
|
engine.enumerate_params.should == Set.new(["a", "c", "e"])
|
@@ -76,17 +76,17 @@ describe "Delorean" do
|
|
76
76
|
|
77
77
|
it "can enumerate params by node" do
|
78
78
|
engine.parse defn("X:",
|
79
|
-
"
|
80
|
-
"
|
79
|
+
" a =? 123",
|
80
|
+
" b = a",
|
81
81
|
"Y: X",
|
82
82
|
"Z:",
|
83
83
|
"XX: Y",
|
84
|
-
"
|
85
|
-
"
|
86
|
-
"
|
84
|
+
" a = 11",
|
85
|
+
" c =?",
|
86
|
+
" d = 123",
|
87
87
|
"YY: XX",
|
88
|
-
"
|
89
|
-
"
|
88
|
+
" c =? 22",
|
89
|
+
" e =? 11",
|
90
90
|
)
|
91
91
|
engine.enumerate_params_by_node("X").should == Set.new(["a"])
|
92
92
|
engine.enumerate_params_by_node("XX").should == Set.new(["a", "c"])
|
data/spec/eval_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe "Delorean" do
|
|
6
6
|
TestContainer.new({
|
7
7
|
"AAA" =>
|
8
8
|
defn("X:",
|
9
|
-
"
|
10
|
-
"
|
9
|
+
" a =? 123",
|
10
|
+
" b = a*2",
|
11
11
|
)
|
12
12
|
})
|
13
13
|
}
|
@@ -18,10 +18,10 @@ describe "Delorean" do
|
|
18
18
|
|
19
19
|
it "evaluate simple expressions" do
|
20
20
|
engine.parse defn("A:",
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
21
|
+
" a = 123",
|
22
|
+
" x = -(a * 2)",
|
23
|
+
" b = -(a + 1)",
|
24
|
+
" c = -a + 1",
|
25
25
|
)
|
26
26
|
|
27
27
|
engine.evaluate_attrs("A", ["a"]).should == [123]
|
@@ -32,8 +32,8 @@ describe "Delorean" do
|
|
32
32
|
|
33
33
|
it "proper unary expression evaluation" do
|
34
34
|
engine.parse defn("A:",
|
35
|
-
"
|
36
|
-
"
|
35
|
+
" a = 123",
|
36
|
+
" c = -a + 1",
|
37
37
|
)
|
38
38
|
|
39
39
|
r = engine.evaluate("A", "c")
|
@@ -42,17 +42,17 @@ describe "Delorean" do
|
|
42
42
|
|
43
43
|
it "should handle getattr in expressions" do
|
44
44
|
engine.parse defn("A:",
|
45
|
-
"
|
46
|
-
"
|
45
|
+
" a = {'x':123, 'y':456, 'z':789}",
|
46
|
+
" b = A.a.x * A.a.y - A.a.z",
|
47
47
|
)
|
48
48
|
engine.evaluate_attrs("A", ["b"]).should == [123*456-789]
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should be able to evaluate multiple node attrs" do
|
52
52
|
engine.parse defn("A:",
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
53
|
+
" a =? 123",
|
54
|
+
" b = a % 11",
|
55
|
+
" c = a / 4.0",
|
56
56
|
)
|
57
57
|
|
58
58
|
h = {"a" => 16}
|
@@ -62,8 +62,8 @@ describe "Delorean" do
|
|
62
62
|
|
63
63
|
it "should give error when accessing undefined attr" do
|
64
64
|
engine.parse defn("A:",
|
65
|
-
"
|
66
|
-
"
|
65
|
+
" a = 1",
|
66
|
+
" c = a.to_s",
|
67
67
|
)
|
68
68
|
|
69
69
|
lambda {
|
@@ -73,8 +73,8 @@ describe "Delorean" do
|
|
73
73
|
|
74
74
|
it "should handle default param values" do
|
75
75
|
engine.parse defn("A:",
|
76
|
-
"
|
77
|
-
"
|
76
|
+
" a =? 123",
|
77
|
+
" c = a / 123.0",
|
78
78
|
)
|
79
79
|
|
80
80
|
r = engine.evaluate("A", "c")
|
@@ -83,10 +83,10 @@ describe "Delorean" do
|
|
83
83
|
|
84
84
|
it "order of attr evaluation should not matter" do
|
85
85
|
engine.parse defn("A:",
|
86
|
-
"
|
86
|
+
" a =? 1",
|
87
87
|
"B:",
|
88
|
-
"
|
89
|
-
"
|
88
|
+
" a =? 2",
|
89
|
+
" c = A.a",
|
90
90
|
)
|
91
91
|
engine.evaluate_attrs("B", %w{c a}).should == [1, 2]
|
92
92
|
engine.evaluate_attrs("B", %w{a c}).should == [2, 1]
|
@@ -94,13 +94,13 @@ describe "Delorean" do
|
|
94
94
|
|
95
95
|
it "params should behave properly with inheritance" do
|
96
96
|
engine.parse defn("A:",
|
97
|
-
"
|
97
|
+
" a =? 1",
|
98
98
|
"B: A",
|
99
|
-
"
|
99
|
+
" a =? 2",
|
100
100
|
"C: B",
|
101
|
-
"
|
102
|
-
"
|
103
|
-
"
|
101
|
+
" a =? 3",
|
102
|
+
" b = B.a",
|
103
|
+
" c = A.a",
|
104
104
|
)
|
105
105
|
engine.evaluate_attrs("C", %w{a b c}).should == [3, 2, 1]
|
106
106
|
engine.evaluate_attrs("C", %w{a b c}, {"a" => 4}).should == [4, 4, 4]
|
@@ -109,8 +109,8 @@ describe "Delorean" do
|
|
109
109
|
|
110
110
|
it "should give error when param is undefined for eval" do
|
111
111
|
engine.parse defn("A:",
|
112
|
-
"
|
113
|
-
"
|
112
|
+
" a =?",
|
113
|
+
" c = a / 123.0",
|
114
114
|
)
|
115
115
|
|
116
116
|
lambda {
|
@@ -120,8 +120,8 @@ describe "Delorean" do
|
|
120
120
|
|
121
121
|
it "should handle simple param computation" do
|
122
122
|
engine.parse defn("A:",
|
123
|
-
"
|
124
|
-
"
|
123
|
+
" a =?",
|
124
|
+
" c = a / 123.0",
|
125
125
|
)
|
126
126
|
|
127
127
|
r = engine.evaluate("A", "c", {"a" => 123})
|
@@ -130,7 +130,7 @@ describe "Delorean" do
|
|
130
130
|
|
131
131
|
it "should give error on unknown node" do
|
132
132
|
engine.parse defn("A:",
|
133
|
-
"
|
133
|
+
" a = 1",
|
134
134
|
)
|
135
135
|
|
136
136
|
lambda {
|
@@ -140,8 +140,8 @@ describe "Delorean" do
|
|
140
140
|
|
141
141
|
it "should handle runtime errors and report module/line number" do
|
142
142
|
engine.parse defn("A:",
|
143
|
-
"
|
144
|
-
"
|
143
|
+
" a = 1/0",
|
144
|
+
" b = 10 * a",
|
145
145
|
)
|
146
146
|
|
147
147
|
begin
|
@@ -158,7 +158,7 @@ describe "Delorean" do
|
|
158
158
|
|
159
159
|
it "should handle runtime errors 2" do
|
160
160
|
engine.parse defn("A:",
|
161
|
-
"
|
161
|
+
" b = Dummy.call_me_maybe('a', 'b')",
|
162
162
|
)
|
163
163
|
|
164
164
|
begin
|
@@ -172,10 +172,10 @@ describe "Delorean" do
|
|
172
172
|
|
173
173
|
it "should handle operator precedence properly" do
|
174
174
|
engine.parse defn("A:",
|
175
|
-
"
|
176
|
-
"
|
177
|
-
"
|
178
|
-
"
|
175
|
+
" b = 3+2*4-1",
|
176
|
+
" c = b*3+5",
|
177
|
+
" d = b*2-c*2",
|
178
|
+
" e = if (d < -10) then -123-1 else -456+1",
|
179
179
|
)
|
180
180
|
|
181
181
|
r = engine.evaluate("A", "d")
|
@@ -187,8 +187,8 @@ describe "Delorean" do
|
|
187
187
|
|
188
188
|
it "should handle if/else" do
|
189
189
|
text = defn("A:",
|
190
|
-
"
|
191
|
-
'
|
190
|
+
" d =? -10",
|
191
|
+
' e = if d < -10 then "gungam"+"style" else "korea"'
|
192
192
|
)
|
193
193
|
|
194
194
|
engine.parse text
|
@@ -201,13 +201,13 @@ describe "Delorean" do
|
|
201
201
|
|
202
202
|
it "should be able to access specific node attrs " do
|
203
203
|
engine.parse defn("A:",
|
204
|
-
"
|
205
|
-
"
|
204
|
+
" b = 123",
|
205
|
+
" c =?",
|
206
206
|
"B: A",
|
207
|
-
"
|
208
|
-
"
|
207
|
+
" b = 111",
|
208
|
+
" c = A.b * 123",
|
209
209
|
"C:",
|
210
|
-
"
|
210
|
+
" c = A.c + B.c",
|
211
211
|
)
|
212
212
|
|
213
213
|
r = engine.evaluate("B", "c")
|
@@ -218,9 +218,9 @@ describe "Delorean" do
|
|
218
218
|
|
219
219
|
it "should be able to call class methods on ActiveRecord classes" do
|
220
220
|
engine.parse defn("A:",
|
221
|
-
"
|
222
|
-
"
|
223
|
-
"
|
221
|
+
" b = Dummy.call_me_maybe(1, 2, 3, 4)",
|
222
|
+
" c = Dummy.call_me_maybe()",
|
223
|
+
" d = Dummy.call_me_maybe(5) + b + c",
|
224
224
|
)
|
225
225
|
r = engine.evaluate_attrs("A", ["b", "c", "d"])
|
226
226
|
r.should == [10, 0, 15]
|
@@ -228,10 +228,10 @@ describe "Delorean" do
|
|
228
228
|
|
229
229
|
it "should be able to get attr on ActiveRecord objects using a.b syntax" do
|
230
230
|
engine.parse defn("A:",
|
231
|
-
'
|
232
|
-
"
|
233
|
-
"
|
234
|
-
"
|
231
|
+
' b = Dummy.i_just_met_you("this is crazy", 0.404)',
|
232
|
+
" c = b.number",
|
233
|
+
" d = b.name",
|
234
|
+
" e = b.foo",
|
235
235
|
)
|
236
236
|
r = engine.evaluate("A", "c")
|
237
237
|
r.should == 0.404
|
@@ -246,7 +246,7 @@ describe "Delorean" do
|
|
246
246
|
|
247
247
|
it "should be able to get attr on ActiveRecord objects using Class.method().attr syntax" do
|
248
248
|
engine.parse defn("A:",
|
249
|
-
'
|
249
|
+
' b = Dummy.i_just_met_you("CRJ", 1.234).name',
|
250
250
|
)
|
251
251
|
r = engine.evaluate("A", "b")
|
252
252
|
r.should == "CRJ"
|
@@ -254,19 +254,19 @@ describe "Delorean" do
|
|
254
254
|
|
255
255
|
it "should be able to get attr on Hash objects using a.b syntax" do
|
256
256
|
engine.parse defn("A:",
|
257
|
-
'
|
258
|
-
"
|
259
|
-
"
|
260
|
-
"
|
257
|
+
' b = Dummy.i_threw_a_hash_in_the_well()',
|
258
|
+
" c = b.a",
|
259
|
+
" d = b.b",
|
260
|
+
" e = b.this_is_crazy",
|
261
261
|
)
|
262
262
|
engine.evaluate_attrs("A", %w{c d e}).should == [456, 789, nil]
|
263
263
|
end
|
264
264
|
|
265
265
|
it "get attr on nil should return nil" do
|
266
266
|
engine.parse defn("A:",
|
267
|
-
'
|
268
|
-
'
|
269
|
-
'
|
267
|
+
' b = Dummy.i_just_met_you("CRJ", 1.234).dummy',
|
268
|
+
' c = b.gaga',
|
269
|
+
' d = b.gaga || 55',
|
270
270
|
)
|
271
271
|
r = engine.evaluate_attrs("A", ["b", "c", "d"])
|
272
272
|
r.should == [nil, nil, 55]
|
@@ -274,8 +274,8 @@ describe "Delorean" do
|
|
274
274
|
|
275
275
|
it "should be able to get assoc attr on ActiveRecord objects" do
|
276
276
|
engine.parse defn("A:",
|
277
|
-
'
|
278
|
-
'
|
277
|
+
' b = Dummy.miss_you_so_bad()',
|
278
|
+
' c = b.dummy',
|
279
279
|
)
|
280
280
|
r = engine.evaluate("A", "c")
|
281
281
|
r.name.should == "hello"
|
@@ -283,24 +283,24 @@ describe "Delorean" do
|
|
283
283
|
|
284
284
|
it "should be able to get attr on node" do
|
285
285
|
engine.parse defn("A:",
|
286
|
-
"
|
287
|
-
"
|
288
|
-
"
|
286
|
+
" a = 123",
|
287
|
+
" b = A",
|
288
|
+
" c = b.a * 2",
|
289
289
|
)
|
290
290
|
engine.evaluate_attrs("A", %w{a c}).should == [123, 123*2]
|
291
291
|
end
|
292
292
|
|
293
293
|
getattr_code = <<eoc
|
294
294
|
A:
|
295
|
-
|
295
|
+
x = 1
|
296
296
|
B:
|
297
|
-
|
297
|
+
x = 2
|
298
298
|
C:
|
299
|
-
|
299
|
+
x = 3
|
300
300
|
D:
|
301
|
-
|
301
|
+
xs = [A, B, C]
|
302
302
|
E:
|
303
|
-
|
303
|
+
xx = [n.x for n in D.xs]
|
304
304
|
eoc
|
305
305
|
|
306
306
|
it "should be able to get attr on node 2" do
|
@@ -310,7 +310,7 @@ eoc
|
|
310
310
|
|
311
311
|
it "should be able to call class methods on AR classes in modules" do
|
312
312
|
engine.parse defn("A:",
|
313
|
-
"
|
313
|
+
" b = M::LittleDummy.heres_my_number(867, 5309)",
|
314
314
|
)
|
315
315
|
r = engine.evaluate("A", "b")
|
316
316
|
r.should == 867 + 5309
|
@@ -318,7 +318,7 @@ eoc
|
|
318
318
|
|
319
319
|
it "should not eval inside strings" do
|
320
320
|
engine.parse defn("A:",
|
321
|
-
'
|
321
|
+
' d = "#{this is a test}"',
|
322
322
|
)
|
323
323
|
|
324
324
|
r = engine.evaluate("A", "d")
|
@@ -327,7 +327,7 @@ eoc
|
|
327
327
|
|
328
328
|
it "should ignore undeclared params sent to eval which match attr names" do
|
329
329
|
engine.parse defn("A:",
|
330
|
-
"
|
330
|
+
" d = 12",
|
331
331
|
)
|
332
332
|
r = engine.evaluate("A", "d", {"d" => 5, "e" => 6})
|
333
333
|
r.should == 12
|
@@ -335,12 +335,12 @@ eoc
|
|
335
335
|
|
336
336
|
it "should handle different param defaults on nodes" do
|
337
337
|
engine.parse defn("A:",
|
338
|
-
"
|
339
|
-
"
|
338
|
+
" p =? 1",
|
339
|
+
" c = p * 123",
|
340
340
|
"B: A",
|
341
|
-
"
|
341
|
+
" p =? 2",
|
342
342
|
"C: A",
|
343
|
-
"
|
343
|
+
" p =? 3",
|
344
344
|
)
|
345
345
|
|
346
346
|
r = engine.evaluate("C", "c", {"p" => 5})
|
@@ -361,10 +361,10 @@ eoc
|
|
361
361
|
|
362
362
|
it "should allow overriding of attrs as params" do
|
363
363
|
engine.parse defn("A:",
|
364
|
-
"
|
365
|
-
"
|
364
|
+
" a = 2",
|
365
|
+
" b = a*3",
|
366
366
|
"B: A",
|
367
|
-
"
|
367
|
+
" a =?",
|
368
368
|
)
|
369
369
|
|
370
370
|
r = engine.evaluate("A", "b", {"a" => 10})
|
@@ -381,16 +381,16 @@ eoc
|
|
381
381
|
|
382
382
|
sample_script = <<eof
|
383
383
|
A:
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
384
|
+
a = 2
|
385
|
+
p =?
|
386
|
+
c = a * 2
|
387
|
+
pc = p + c
|
388
388
|
|
389
389
|
C: A
|
390
390
|
p =? 3
|
391
391
|
|
392
392
|
B: A
|
393
|
-
|
393
|
+
p =? 5
|
394
394
|
eof
|
395
395
|
|
396
396
|
it "should allow overriding of attrs as params" do
|
@@ -414,19 +414,19 @@ eof
|
|
414
414
|
engin2 = Delorean::Engine.new(engine.module_name)
|
415
415
|
|
416
416
|
engine.parse defn("A:",
|
417
|
-
"
|
418
|
-
"
|
417
|
+
" a = 123",
|
418
|
+
" b = a*3",
|
419
419
|
"B: A",
|
420
|
-
"
|
420
|
+
" c = b*2",
|
421
421
|
)
|
422
422
|
|
423
423
|
engin2.parse defn("A:",
|
424
|
-
"
|
425
|
-
"
|
424
|
+
" a = 222.0",
|
425
|
+
" b = a/5",
|
426
426
|
"B: A",
|
427
|
-
"
|
427
|
+
" c = b*3",
|
428
428
|
"C:",
|
429
|
-
"
|
429
|
+
" d = 111",
|
430
430
|
)
|
431
431
|
|
432
432
|
engine.evaluate_attrs("A", ["a", "b"]).should == [123, 123*3]
|
@@ -450,10 +450,10 @@ eof
|
|
450
450
|
|
451
451
|
it "should eval lists" do
|
452
452
|
engine.parse defn("A:",
|
453
|
-
"
|
454
|
-
"
|
455
|
-
"
|
456
|
-
"
|
453
|
+
" b = []",
|
454
|
+
" c = [1,2,3]",
|
455
|
+
" d = [b, c, b, c, 1, 2, '123', 1.1, -1.23]",
|
456
|
+
" e = [1, 1+1, 1+1+1, 1*2*4]",
|
457
457
|
)
|
458
458
|
|
459
459
|
engine.evaluate_attrs("A", %w{b c d e}).should ==
|
@@ -466,9 +466,9 @@ eof
|
|
466
466
|
|
467
467
|
it "should eval list expressions" do
|
468
468
|
engine.parse defn("A:",
|
469
|
-
"
|
470
|
-
"
|
471
|
-
"
|
469
|
+
" b = []+[]",
|
470
|
+
" c = [1,2,3]+b",
|
471
|
+
" d = c*2",
|
472
472
|
)
|
473
473
|
|
474
474
|
engine.evaluate_attrs("A", %w{b c d}).should ==
|
@@ -480,9 +480,9 @@ eof
|
|
480
480
|
|
481
481
|
it "should eval sets and set comprehension" do
|
482
482
|
engine.parse defn("A:",
|
483
|
-
"
|
484
|
-
"
|
485
|
-
"
|
483
|
+
" a = {-}",
|
484
|
+
" b = {i*5 for i in {1,2,3}}",
|
485
|
+
" c = {1,2,3} | {4,5}",
|
486
486
|
)
|
487
487
|
engine.evaluate_attrs("A", ["a", "b", "c"]).should ==
|
488
488
|
[Set[], Set[5,10,15], Set[1,2,3,4,5]]
|
@@ -490,14 +490,14 @@ eof
|
|
490
490
|
|
491
491
|
it "should eval list comprehension" do
|
492
492
|
engine.parse defn("A:",
|
493
|
-
"
|
493
|
+
" b = [i*5 for i in [1,2,3]]",
|
494
494
|
)
|
495
495
|
engine.evaluate("A", "b").should == [5, 10, 15]
|
496
496
|
end
|
497
497
|
|
498
498
|
it "should eval nested list comprehension" do
|
499
499
|
engine.parse defn("A:",
|
500
|
-
"
|
500
|
+
" b = [[a+c for c in [4,5]] for a in [1,2,3]]",
|
501
501
|
)
|
502
502
|
engine.evaluate("A", "b").should == [[5, 6], [6, 7], [7, 8]]
|
503
503
|
|
@@ -505,23 +505,23 @@ eof
|
|
505
505
|
|
506
506
|
it "should eval list comprehension variable override" do
|
507
507
|
engine.parse defn("A:",
|
508
|
-
"
|
508
|
+
" b = [b/2.0 for b in [1,2,3]]",
|
509
509
|
)
|
510
510
|
engine.evaluate("A", "b").should == [0.5, 1.0, 1.5]
|
511
511
|
end
|
512
512
|
|
513
513
|
it "should eval list comprehension variable override (2)" do
|
514
514
|
engine.parse defn("A:",
|
515
|
-
"
|
516
|
-
"
|
515
|
+
" a = 1",
|
516
|
+
" b = [a+1 for a in [1,2,3]]",
|
517
517
|
)
|
518
518
|
engine.evaluate("A", "b").should == [2, 3, 4]
|
519
519
|
end
|
520
520
|
|
521
521
|
it "should eval conditional list comprehension" do
|
522
522
|
engine.parse defn("A:",
|
523
|
-
"
|
524
|
-
"
|
523
|
+
" b = [i*5 for i in [1,2,3,4,5] if i%2 == 1]",
|
524
|
+
" c = [i/10.0 for i in [1,2,3,4,5] if i>4]",
|
525
525
|
)
|
526
526
|
engine.evaluate("A", "b").should == [5, 15, 25]
|
527
527
|
engine.evaluate("A", "c").should == [0.5]
|
@@ -529,12 +529,12 @@ eof
|
|
529
529
|
|
530
530
|
it "should eval hashes" do
|
531
531
|
engine.parse defn("A:",
|
532
|
-
"
|
533
|
-
"
|
534
|
-
"
|
535
|
-
"
|
536
|
-
"
|
537
|
-
"
|
532
|
+
" b = {}",
|
533
|
+
" c = {'a':1, 'b': 2,'c':3}",
|
534
|
+
" d = {123*2: -123, 'b_b': 1+1}",
|
535
|
+
" e = {'x': 1, 'y': 1+1, 'z': 1+1+1, 'zz': 1*2*4}",
|
536
|
+
" f = {'a': nil, 'b': [1, nil, 2]}",
|
537
|
+
" g = {b:b, [b]:[1,23], []:345}",
|
538
538
|
)
|
539
539
|
|
540
540
|
engine.evaluate_attrs("A", %w{b c d e f g}).should ==
|
@@ -549,14 +549,14 @@ eof
|
|
549
549
|
|
550
550
|
it "should eval hash comprehension" do
|
551
551
|
engine.parse defn("A:",
|
552
|
-
"
|
552
|
+
" b = {i*5 :i for i in [1,2,3]}",
|
553
553
|
)
|
554
554
|
engine.evaluate("A", "b").should == {5=>1, 10=>2, 15=>3}
|
555
555
|
end
|
556
556
|
|
557
557
|
it "should eval nested hash comprehension" do
|
558
558
|
engine.parse defn("A:",
|
559
|
-
"
|
559
|
+
" b = { a:{a+c:a-c for c in [4,5]} for a in [1,2,3]}",
|
560
560
|
)
|
561
561
|
engine.evaluate("A", "b").should ==
|
562
562
|
{1=>{5=>-3, 6=>-4}, 2=>{6=>-2, 7=>-3}, 3=>{7=>-1, 8=>-2}}
|
@@ -564,8 +564,8 @@ eof
|
|
564
564
|
|
565
565
|
it "should eval conditional hash comprehension" do
|
566
566
|
engine.parse defn("A:",
|
567
|
-
"
|
568
|
-
"
|
567
|
+
" b = {i*5:i+5 for i in [1,2,3,4,5] if i%2 == 1}",
|
568
|
+
" c = {i/10.0:i*10 for i in [1,2,3,4,5] if i>4}",
|
569
569
|
)
|
570
570
|
engine.evaluate("A", "b").should == {5=>6, 15=>8, 25=>10}
|
571
571
|
engine.evaluate("A", "c").should == {0.5=>50}
|
@@ -573,10 +573,10 @@ eof
|
|
573
573
|
|
574
574
|
it "should eval node calls as intermediate results" do
|
575
575
|
engine.parse defn("A:",
|
576
|
-
"
|
577
|
-
"
|
578
|
-
"
|
579
|
-
"
|
576
|
+
" a =?",
|
577
|
+
" e = A(a=13)",
|
578
|
+
" d = e.a * 2",
|
579
|
+
" f = e.d / e.a",
|
580
580
|
)
|
581
581
|
|
582
582
|
engine.evaluate_attrs("A", ["d", "f"]).should == [26, 2]
|
@@ -584,9 +584,9 @@ eof
|
|
584
584
|
|
585
585
|
it "should eval module calls 1" do
|
586
586
|
engine.parse defn("A:",
|
587
|
-
"
|
588
|
-
"
|
589
|
-
"
|
587
|
+
" a = 123",
|
588
|
+
" n = A",
|
589
|
+
" d = n().a",
|
590
590
|
)
|
591
591
|
|
592
592
|
engine.evaluate_attrs("A", %w{d}).should == [123]
|
@@ -594,12 +594,12 @@ eof
|
|
594
594
|
|
595
595
|
it "should eval module calls 2" do
|
596
596
|
engine.parse defn("A:",
|
597
|
-
"
|
598
|
-
"
|
599
|
-
"
|
600
|
-
"
|
601
|
-
"
|
602
|
-
"
|
597
|
+
" a = 123",
|
598
|
+
" b = 456 + a",
|
599
|
+
" n = 'A'",
|
600
|
+
" c = nil(x = 123, y = 456) % ['a', 'b']",
|
601
|
+
" d = n(x = 123, y = 456) % ['a', 'b']",
|
602
|
+
" e = nil() % ['b']",
|
603
603
|
)
|
604
604
|
|
605
605
|
engine.evaluate_attrs("A", %w{n c d e}).should ==
|
@@ -608,10 +608,10 @@ eof
|
|
608
608
|
|
609
609
|
it "should eval module calls 3" do
|
610
610
|
engine.parse defn("A:",
|
611
|
-
"
|
611
|
+
" a = 123",
|
612
612
|
"B:",
|
613
|
-
"
|
614
|
-
"
|
613
|
+
" n = 'A'",
|
614
|
+
" d = n().a",
|
615
615
|
)
|
616
616
|
|
617
617
|
engine.evaluate_attrs("B", %w{d}).should == [123]
|
@@ -619,8 +619,8 @@ eof
|
|
619
619
|
|
620
620
|
it "should be possible to implement recursive calls" do
|
621
621
|
engine.parse defn("A:",
|
622
|
-
"
|
623
|
-
"
|
622
|
+
" n =?",
|
623
|
+
" fact = if n <= 1 then 1 else n * A(n=n-1).fact",
|
624
624
|
)
|
625
625
|
|
626
626
|
engine.evaluate("A", "fact", "n" => 10).should == 3628800
|
@@ -628,34 +628,34 @@ eof
|
|
628
628
|
|
629
629
|
it "should eval module calls by node name" do
|
630
630
|
engine.parse defn("A:",
|
631
|
-
"
|
632
|
-
"
|
631
|
+
" a = 123",
|
632
|
+
" b = A().a",
|
633
633
|
)
|
634
634
|
engine.evaluate("A", "b").should == 123
|
635
635
|
end
|
636
636
|
|
637
637
|
it "should eval multiline expressions" do
|
638
638
|
engine.parse defn("A:",
|
639
|
-
"
|
640
|
-
"
|
641
|
-
"
|
642
|
-
"
|
639
|
+
" a = 1",
|
640
|
+
" b = [a+1",
|
641
|
+
" for a in [1,2,3]",
|
642
|
+
" ]",
|
643
643
|
)
|
644
644
|
engine.evaluate("A", "b").should == [2, 3, 4]
|
645
645
|
end
|
646
646
|
|
647
647
|
it "should eval multiline expressions" do
|
648
648
|
engine.parse defn("A:",
|
649
|
-
"
|
650
|
-
"
|
651
|
-
"
|
652
|
-
"
|
653
|
-
"
|
654
|
-
"
|
655
|
-
"
|
656
|
-
"
|
657
|
-
"
|
658
|
-
"
|
649
|
+
" a = 123",
|
650
|
+
" b = 456 + ",
|
651
|
+
" a",
|
652
|
+
" n = 'A'",
|
653
|
+
" c = nil(x = 123,",
|
654
|
+
" y = 456) % ['a', 'b']",
|
655
|
+
" d = n(",
|
656
|
+
" x = 123, y = 456) % ['a', 'b']",
|
657
|
+
" e = nil(",
|
658
|
+
" ) % ['b']",
|
659
659
|
)
|
660
660
|
|
661
661
|
engine.evaluate_attrs("A", %w{n c d e}).should ==
|
@@ -665,10 +665,10 @@ eof
|
|
665
665
|
it "should eval imports" do
|
666
666
|
engine.parse defn("import AAA",
|
667
667
|
"A:",
|
668
|
-
"
|
668
|
+
" b = 456",
|
669
669
|
"B: AAA::X",
|
670
|
-
"
|
671
|
-
"
|
670
|
+
" a = 111",
|
671
|
+
" c = AAA::X(a=456).b",
|
672
672
|
)
|
673
673
|
engine.evaluate_attrs("B", ["a", "b", "c"], {}).should ==
|
674
674
|
[111, 222, 456*2]
|
@@ -676,20 +676,20 @@ eof
|
|
676
676
|
|
677
677
|
it "should eval imports (2)" do
|
678
678
|
sset.merge({
|
679
|
-
"BBB"
|
679
|
+
"BBB" =>
|
680
680
|
defn("import AAA",
|
681
681
|
"B: AAA::X",
|
682
|
-
"
|
683
|
-
"
|
684
|
-
"
|
682
|
+
" a = 111",
|
683
|
+
" c = AAA::X(a=-1).b",
|
684
|
+
" d = a * 2",
|
685
685
|
),
|
686
686
|
"CCC" =>
|
687
687
|
defn("import BBB",
|
688
688
|
"import AAA",
|
689
689
|
"B: BBB::B",
|
690
|
-
"
|
690
|
+
" e = d * 3",
|
691
691
|
"C: AAA::X",
|
692
|
-
"
|
692
|
+
" d = b * 3",
|
693
693
|
),
|
694
694
|
})
|
695
695
|
|
@@ -700,7 +700,7 @@ eof
|
|
700
700
|
|
701
701
|
engine.parse defn("import BBB",
|
702
702
|
"B: BBB::B",
|
703
|
-
"
|
703
|
+
" e = d + 3",
|
704
704
|
)
|
705
705
|
|
706
706
|
engine.evaluate_attrs("B", ["a", "b", "c", "d", "e"]).should ==
|
@@ -720,8 +720,8 @@ eof
|
|
720
720
|
"CCC" =>
|
721
721
|
defn("import BBB",
|
722
722
|
"X:",
|
723
|
-
"
|
724
|
-
"
|
723
|
+
" xx = [n.x for n in BBB::D().xs]",
|
724
|
+
" yy = [n.x for n in BBB::D.xs]",
|
725
725
|
),
|
726
726
|
})
|
727
727
|
|
@@ -732,12 +732,12 @@ eof
|
|
732
732
|
|
733
733
|
it "can eval indexing" do
|
734
734
|
engine.parse defn("A:",
|
735
|
-
"
|
736
|
-
"
|
737
|
-
"
|
738
|
-
"
|
739
|
-
"
|
740
|
-
"
|
735
|
+
" a = [1,2,3]",
|
736
|
+
" b = a[1]",
|
737
|
+
" c = a[-1]",
|
738
|
+
" d = {'a' : 123, 'b': 456}",
|
739
|
+
" e = d['b']",
|
740
|
+
" f = a[1,2]",
|
741
741
|
)
|
742
742
|
r = engine.evaluate_attrs("A", ["b", "c", "e", "f"])
|
743
743
|
r.should == [2, 3, 456, [2,3]]
|
@@ -745,10 +745,10 @@ eof
|
|
745
745
|
|
746
746
|
it "can eval indexing 2" do
|
747
747
|
engine.parse defn("A:",
|
748
|
-
"
|
749
|
-
"
|
750
|
-
"
|
751
|
-
"
|
748
|
+
" a = 1",
|
749
|
+
" b = {'x' : 123, 'y': 456}",
|
750
|
+
" c = A() % ['a', 'b']",
|
751
|
+
" d = c['b'].x * c['a'] - c['b'].y",
|
752
752
|
)
|
753
753
|
r = engine.evaluate_attrs("A", ["a", "b", "c", "d"])
|
754
754
|
r.should ==
|
@@ -757,14 +757,14 @@ eof
|
|
757
757
|
|
758
758
|
it "should properly eval overridden attrs" do
|
759
759
|
engine.parse defn("A:",
|
760
|
-
"
|
761
|
-
"
|
760
|
+
" a = 5",
|
761
|
+
" b = a",
|
762
762
|
"B: A",
|
763
|
-
"
|
764
|
-
"
|
765
|
-
"
|
766
|
-
"
|
767
|
-
"
|
763
|
+
" a = 2",
|
764
|
+
" x = A.b - B.b",
|
765
|
+
" k = [A.b, B.b]",
|
766
|
+
" l = [x.b for x in [A, B]]",
|
767
|
+
" m = [x().b for x in [A, B]]",
|
768
768
|
)
|
769
769
|
|
770
770
|
engine.evaluate("A", "b").should == 5
|