delorean_lang 0.3.29 → 0.3.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/delorean/engine.rb +12 -12
- data/lib/delorean/version.rb +1 -1
- data/spec/eval_spec.rb +41 -41
- data/spec/func_spec.rb +8 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6533974257ae71867de5f7237d671a74c5df653c
|
4
|
+
data.tar.gz: 0be5b0053ac67c03e22b4d79f8ff6ca6699edbfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61f051c79ce4219de27151c228ef8f997f6caffe5a30af7f53e7e3ace82e92803b6221a34bd5eb13677a697d63d7ff7e5b12df8da96c32e9979709b02042cb8b
|
7
|
+
data.tar.gz: 6e1e789f69566b2c526b6a7f84da419588963e419664ead313a5cfcad8c9bd8edaf5e56417df46dc6f988e743b83adcd1f6c00401cc623f52dbba1d022565f3c
|
data/README.md
CHANGED
data/lib/delorean/engine.rb
CHANGED
@@ -346,18 +346,9 @@ module Delorean
|
|
346
346
|
# Runtime
|
347
347
|
######################################################################
|
348
348
|
|
349
|
-
def evaluate(node,
|
350
|
-
evaluate_attrs(node, [attr], params)[0]
|
351
|
-
end
|
352
|
-
|
353
|
-
def eval_to_hash(node, attrs, params={})
|
354
|
-
res = evaluate_attrs(node, attrs, params)
|
355
|
-
Hash[* attrs.zip(res).flatten(1)]
|
356
|
-
end
|
357
|
-
|
358
|
-
def evaluate_attrs(node, attrs, params={})
|
349
|
+
def evaluate(node, attrs, params={})
|
359
350
|
raise "bad params" unless params.is_a?(Hash)
|
360
|
-
|
351
|
+
|
361
352
|
if node.is_a?(Class)
|
362
353
|
klass = node
|
363
354
|
else
|
@@ -372,10 +363,19 @@ module Delorean
|
|
372
363
|
|
373
364
|
params[:_engine] = self
|
374
365
|
|
375
|
-
attrs.
|
366
|
+
type_arr = attrs.is_a?(Array)
|
367
|
+
attrs = [attrs] unless type_arr
|
368
|
+
|
369
|
+
res = attrs.map { |attr|
|
376
370
|
raise "bad attribute '#{attr}'" unless attr =~ /^[a-z][A-Za-z0-9_]*$/
|
377
371
|
klass.send("#{attr}#{POST}".to_sym, params)
|
378
372
|
}
|
373
|
+
type_arr ? res : res[0]
|
374
|
+
end
|
375
|
+
|
376
|
+
def eval_to_hash(node, attrs, params={})
|
377
|
+
res = evaluate(node, attrs, params)
|
378
|
+
Hash[* attrs.zip(res).flatten(1)]
|
379
379
|
end
|
380
380
|
|
381
381
|
def self.grok_runtime_exception(exc)
|
data/lib/delorean/version.rb
CHANGED
data/spec/eval_spec.rb
CHANGED
@@ -25,9 +25,9 @@ describe "Delorean" do
|
|
25
25
|
" d = a ** 3 - 10*0.2",
|
26
26
|
)
|
27
27
|
|
28
|
-
engine.
|
28
|
+
engine.evaluate("A", ["a"]).should == [123]
|
29
29
|
|
30
|
-
r = engine.
|
30
|
+
r = engine.evaluate("A", ["x", "b"])
|
31
31
|
r.should == [-246, -124]
|
32
32
|
|
33
33
|
expect(engine.evaluate("A", "d")).to eq 1860865.0
|
@@ -57,7 +57,7 @@ describe "Delorean" do
|
|
57
57
|
" a = {'x':123, 'y':456, 'z':789}",
|
58
58
|
" b = A.a.x * A.a.y - A.a.z",
|
59
59
|
)
|
60
|
-
engine.
|
60
|
+
engine.evaluate("A", ["b"]).should == [123*456-789]
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should handle numeric getattr" do
|
@@ -65,7 +65,7 @@ describe "Delorean" do
|
|
65
65
|
" a = {1:123, 0:456, 'z':789, 2: {'a':444}}",
|
66
66
|
" b = A.a.1 * A.a.0 - A.a.z - A.a.2.a",
|
67
67
|
)
|
68
|
-
engine.
|
68
|
+
engine.evaluate("A", ["b"]).should == [123*456-789-444]
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should be able to evaluate multiple node attrs" do
|
@@ -76,7 +76,7 @@ describe "Delorean" do
|
|
76
76
|
)
|
77
77
|
|
78
78
|
h = {"a" => 16}
|
79
|
-
r = engine.
|
79
|
+
r = engine.evaluate("A", ["c", "b"], h)
|
80
80
|
r.should == [4, 5]
|
81
81
|
end
|
82
82
|
|
@@ -117,8 +117,8 @@ describe "Delorean" do
|
|
117
117
|
" a =? 2",
|
118
118
|
" c = A.a",
|
119
119
|
)
|
120
|
-
engine.
|
121
|
-
engine.
|
120
|
+
engine.evaluate("B", %w{c a}).should == [1, 2]
|
121
|
+
engine.evaluate("B", %w{a c}).should == [2, 1]
|
122
122
|
end
|
123
123
|
|
124
124
|
it "params should behave properly with inheritance" do
|
@@ -131,9 +131,9 @@ describe "Delorean" do
|
|
131
131
|
" b = B.a",
|
132
132
|
" c = A.a",
|
133
133
|
)
|
134
|
-
engine.
|
135
|
-
engine.
|
136
|
-
engine.
|
134
|
+
engine.evaluate("C", %w{a b c}).should == [3, 2, 1]
|
135
|
+
engine.evaluate("C", %w{a b c}, {"a" => 4}).should == [4, 4, 4]
|
136
|
+
engine.evaluate("C", %w{c b a}).should == [1, 2, 3]
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should give error when param is undefined for eval" do
|
@@ -273,7 +273,7 @@ describe "Delorean" do
|
|
273
273
|
" c = Dummy.call_me_maybe()",
|
274
274
|
" d = Dummy.call_me_maybe(5) + b + c",
|
275
275
|
)
|
276
|
-
r = engine.
|
276
|
+
r = engine.evaluate("A", ["b", "c", "d"])
|
277
277
|
r.should == [10, 0, 15]
|
278
278
|
end
|
279
279
|
|
@@ -326,7 +326,7 @@ describe "Delorean" do
|
|
326
326
|
" d = b.b",
|
327
327
|
" e = b.this_is_crazy",
|
328
328
|
)
|
329
|
-
engine.
|
329
|
+
engine.evaluate("A", %w{c d e}).should == [456, 789, nil]
|
330
330
|
end
|
331
331
|
|
332
332
|
it "get attr on nil should return nil" do
|
@@ -335,7 +335,7 @@ describe "Delorean" do
|
|
335
335
|
' c = b.gaga',
|
336
336
|
' d = b.gaga || 55',
|
337
337
|
)
|
338
|
-
r = engine.
|
338
|
+
r = engine.evaluate("A", ["b", "c", "d"])
|
339
339
|
r.should == [nil, nil, 55]
|
340
340
|
end
|
341
341
|
|
@@ -354,7 +354,7 @@ describe "Delorean" do
|
|
354
354
|
" b = A",
|
355
355
|
" c = b.a * 2",
|
356
356
|
)
|
357
|
-
engine.
|
357
|
+
engine.evaluate("A", %w{a c}).should == [123, 123*2]
|
358
358
|
end
|
359
359
|
|
360
360
|
getattr_code = <<eoc
|
@@ -496,11 +496,11 @@ eof
|
|
496
496
|
" d = 111",
|
497
497
|
)
|
498
498
|
|
499
|
-
engine.
|
500
|
-
engin2.
|
499
|
+
engine.evaluate("A", ["a", "b"]).should == [123, 123*3]
|
500
|
+
engin2.evaluate("A", ["a", "b"]).should == [222.0, 222.0/5]
|
501
501
|
|
502
|
-
engine.
|
503
|
-
engin2.
|
502
|
+
engine.evaluate("B", ["a", "b", "c"]).should == [123, 123*3, 123*3*2]
|
503
|
+
engin2.evaluate("B", ["a", "b", "c"]).should ==
|
504
504
|
[222.0, 222.0/5, 222.0/5*3]
|
505
505
|
|
506
506
|
engin2.evaluate("C", "d").should == 111
|
@@ -523,7 +523,7 @@ eof
|
|
523
523
|
" e = [1, 1+1, 1+1+1, 1*2*4]",
|
524
524
|
)
|
525
525
|
|
526
|
-
engine.
|
526
|
+
engine.evaluate("A", %w{b c d e}).should ==
|
527
527
|
[[],
|
528
528
|
[1, 2, 3],
|
529
529
|
[[], [1, 2, 3], [], [1, 2, 3], 1, 2, "123", 1.1, -1.23],
|
@@ -538,7 +538,7 @@ eof
|
|
538
538
|
" d = c*2",
|
539
539
|
)
|
540
540
|
|
541
|
-
engine.
|
541
|
+
engine.evaluate("A", %w{b c d}).should ==
|
542
542
|
[[],
|
543
543
|
[1, 2, 3],
|
544
544
|
[1, 2, 3]*2,
|
@@ -551,7 +551,7 @@ eof
|
|
551
551
|
" b = {i*5 for i in {1,2,3}}",
|
552
552
|
" c = {1,2,3} | {4,5}",
|
553
553
|
)
|
554
|
-
engine.
|
554
|
+
engine.evaluate("A", ["a", "b", "c"]).should ==
|
555
555
|
[Set[], Set[5,10,15], Set[1,2,3,4,5]]
|
556
556
|
end
|
557
557
|
|
@@ -621,7 +621,7 @@ eof
|
|
621
621
|
" g = {b:b, [b]:[1,23], []:345}",
|
622
622
|
)
|
623
623
|
|
624
|
-
engine.
|
624
|
+
engine.evaluate("A", %w{b c d e f g}).should ==
|
625
625
|
[{},
|
626
626
|
{"a"=>1, "b"=>2, "c"=>3},
|
627
627
|
{123*2=>-123, "b_b"=>2},
|
@@ -682,7 +682,7 @@ eof
|
|
682
682
|
" f = e.d / e.a",
|
683
683
|
)
|
684
684
|
|
685
|
-
engine.
|
685
|
+
engine.evaluate("A", ["d", "f"]).should == [26, 2]
|
686
686
|
end
|
687
687
|
|
688
688
|
it "should eval multi-var hash comprehension" do
|
@@ -706,7 +706,7 @@ eof
|
|
706
706
|
" j = d(a=6).aa",
|
707
707
|
)
|
708
708
|
|
709
|
-
engine.
|
709
|
+
engine.evaluate("A", ["g", "h", "j"]).should ==
|
710
710
|
[3*2 + 4*2, 5*2, 6*2]
|
711
711
|
end
|
712
712
|
|
@@ -717,7 +717,7 @@ eof
|
|
717
717
|
" e = [d.a, d(a=4).a]",
|
718
718
|
)
|
719
719
|
|
720
|
-
engine.
|
720
|
+
engine.evaluate("A", ["e"]).should == [[3,4]]
|
721
721
|
end
|
722
722
|
|
723
723
|
it "should eval module calls 1" do
|
@@ -727,7 +727,7 @@ eof
|
|
727
727
|
" d = n().a",
|
728
728
|
)
|
729
729
|
|
730
|
-
engine.
|
730
|
+
engine.evaluate("A", %w{d}).should == [123]
|
731
731
|
end
|
732
732
|
|
733
733
|
it "should eval module calls 2" do
|
@@ -740,7 +740,7 @@ eof
|
|
740
740
|
" e = nil() % ['b']",
|
741
741
|
)
|
742
742
|
|
743
|
-
engine.
|
743
|
+
engine.evaluate("A", %w{n c d e}).should ==
|
744
744
|
["A", {"a"=>123, "b"=>579}, {"a"=>123, "b"=>579}, {"b"=>579}]
|
745
745
|
end
|
746
746
|
|
@@ -752,7 +752,7 @@ eof
|
|
752
752
|
" d = n().a",
|
753
753
|
)
|
754
754
|
|
755
|
-
engine.
|
755
|
+
engine.evaluate("B", %w{d}).should == [123]
|
756
756
|
end
|
757
757
|
|
758
758
|
it "should be possible to implement recursive calls" do
|
@@ -796,7 +796,7 @@ eof
|
|
796
796
|
" ) % ['b']",
|
797
797
|
)
|
798
798
|
|
799
|
-
engine.
|
799
|
+
engine.evaluate("A", %w{n c d e}).should ==
|
800
800
|
["A", {"a"=>123, "b"=>579}, {"a"=>123, "b"=>579}, {"b"=>579}]
|
801
801
|
end
|
802
802
|
|
@@ -809,7 +809,7 @@ eof
|
|
809
809
|
" d = [i*2 for i in s if i in a]",
|
810
810
|
)
|
811
811
|
|
812
|
-
engine.
|
812
|
+
engine.evaluate("A", %w{b c d}).should ==
|
813
813
|
[false, true, [66, 88]]
|
814
814
|
end
|
815
815
|
|
@@ -821,7 +821,7 @@ eof
|
|
821
821
|
" a = 111",
|
822
822
|
" c = AAA::X(a=456).b",
|
823
823
|
)
|
824
|
-
engine.
|
824
|
+
engine.evaluate("B", ["a", "b", "c"], {}).should ==
|
825
825
|
[111, 222, 456*2]
|
826
826
|
end
|
827
827
|
|
@@ -846,7 +846,7 @@ eof
|
|
846
846
|
|
847
847
|
e2 = sset.get_engine("BBB")
|
848
848
|
|
849
|
-
e2.
|
849
|
+
e2.evaluate("B", ["a", "b", "c", "d"]).should ==
|
850
850
|
[111, 222, -2, 222]
|
851
851
|
|
852
852
|
engine.parse defn("import BBB",
|
@@ -854,15 +854,15 @@ eof
|
|
854
854
|
" e = d + 3",
|
855
855
|
)
|
856
856
|
|
857
|
-
engine.
|
857
|
+
engine.evaluate("B", ["a", "b", "c", "d", "e"]).should ==
|
858
858
|
[111, 222, -2, 222, 225]
|
859
859
|
|
860
860
|
e4 = sset.get_engine("CCC")
|
861
861
|
|
862
|
-
e4.
|
862
|
+
e4.evaluate("B", ["a", "b", "c", "d", "e"]).should ==
|
863
863
|
[111, 222, -2, 222, 666]
|
864
864
|
|
865
|
-
e4.
|
865
|
+
e4.evaluate("C", ["a", "b", "d"]).should == [123, 123*2, 123*3*2]
|
866
866
|
end
|
867
867
|
|
868
868
|
it "should eval imports (3)" do
|
@@ -890,7 +890,7 @@ eof
|
|
890
890
|
" e = d['b']",
|
891
891
|
" f = a[1,2]",
|
892
892
|
)
|
893
|
-
r = engine.
|
893
|
+
r = engine.evaluate("A", ["b", "c", "e", "f"])
|
894
894
|
r.should == [2, 3, 456, [2,3]]
|
895
895
|
end
|
896
896
|
|
@@ -901,7 +901,7 @@ eof
|
|
901
901
|
" c = A() % ['a', 'b']",
|
902
902
|
" d = c['b'].x * c['a'] - c['b'].y",
|
903
903
|
)
|
904
|
-
r = engine.
|
904
|
+
r = engine.evaluate("A", ["a", "b", "c", "d"])
|
905
905
|
r.should ==
|
906
906
|
[1, {"x"=>123, "y"=>456}, {"a"=>1, "b"=>{"x"=>123, "y"=>456}}, -333]
|
907
907
|
end
|
@@ -915,15 +915,15 @@ eof
|
|
915
915
|
" d = A() / ['a', 'e']",
|
916
916
|
" f = A() / 'a'",
|
917
917
|
)
|
918
|
-
r = engine.
|
918
|
+
r = engine.evaluate("A", ["a", "b", "c"])
|
919
919
|
r.should ==
|
920
920
|
[1, {"x"=>123, "y"=>456}, {"a"=>1, "b"=>{"x"=>123, "y"=>456}}]
|
921
921
|
|
922
|
-
r = engine.
|
922
|
+
r = engine.evaluate("A", ["a", "d"])
|
923
923
|
r.should ==
|
924
924
|
[1, {"error"=>"hello", "backtrace"=>[["XXX", 4, "e"], ["XXX", 6, "d"]]}]
|
925
925
|
|
926
|
-
r = engine.
|
926
|
+
r = engine.evaluate("A", ["f"])
|
927
927
|
r.should == [1]
|
928
928
|
end
|
929
929
|
|
@@ -977,7 +977,7 @@ eof
|
|
977
977
|
" z = B(10, 20, a=3, b=7).x",
|
978
978
|
" y = B('x', 'y').y",
|
979
979
|
)
|
980
|
-
engine.
|
980
|
+
engine.evaluate("A", ["a", "z", "y"], {0 => 123, 1 => 456}).should ==
|
981
981
|
[123-456, 40, ["x", "y", nil]]
|
982
982
|
end
|
983
983
|
|
data/spec/func_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe "Delorean" do
|
|
31
31
|
" c = 12.3456.round()",
|
32
32
|
)
|
33
33
|
|
34
|
-
r = engine.
|
34
|
+
r = engine.evaluate("A", ["a", "b", "c"])
|
35
35
|
r.should == [12.35, 12.3, 12]
|
36
36
|
end
|
37
37
|
|
@@ -42,7 +42,7 @@ describe "Delorean" do
|
|
42
42
|
" c = '12'.to_f()",
|
43
43
|
)
|
44
44
|
|
45
|
-
r = engine.
|
45
|
+
r = engine.evaluate("A", ["a", "b", "c"])
|
46
46
|
r.should == [12.3456, 12.3456, 12]
|
47
47
|
end
|
48
48
|
|
@@ -54,7 +54,7 @@ describe "Delorean" do
|
|
54
54
|
" d = 0.abs()",
|
55
55
|
)
|
56
56
|
|
57
|
-
r = engine.
|
57
|
+
r = engine.evaluate("A", ["a", "b", "c", "d"])
|
58
58
|
r.should == [123, 1.1, 2.3, 0]
|
59
59
|
end
|
60
60
|
|
@@ -65,7 +65,7 @@ describe "Delorean" do
|
|
65
65
|
" c = [1,2,3].to_s()",
|
66
66
|
)
|
67
67
|
|
68
|
-
r = engine.
|
68
|
+
r = engine.evaluate("A", ["a", "b", "c"])
|
69
69
|
r.should == ["hello", '12.3456', [1,2,3].to_s]
|
70
70
|
end
|
71
71
|
|
@@ -81,11 +81,11 @@ describe "Delorean" do
|
|
81
81
|
|
82
82
|
p = Time.now
|
83
83
|
params = {"p" => p}
|
84
|
-
r = engine.
|
84
|
+
r = engine.evaluate("A", %w{h m s d e}, params)
|
85
85
|
r.should == [p.hour, p.min, p.sec, p.to_date, p.to_date]
|
86
86
|
|
87
87
|
# Non time argument should raise an error
|
88
|
-
expect { engine.
|
88
|
+
expect { engine.evaluate("A", ["m"], {"p" => 123}) }.to raise_error
|
89
89
|
|
90
90
|
end
|
91
91
|
|
@@ -98,12 +98,12 @@ describe "Delorean" do
|
|
98
98
|
)
|
99
99
|
|
100
100
|
p = Date.today
|
101
|
-
r = engine.
|
101
|
+
r = engine.evaluate("A", ["y", "d", "m"], {"p" => p})
|
102
102
|
r.should == [p.year, p.day, p.month]
|
103
103
|
|
104
104
|
# Non date argument should raise an error
|
105
105
|
expect {
|
106
|
-
engine.
|
106
|
+
engine.evaluate("A", ["y", "d", "m"], {"p" => 123})
|
107
107
|
}.to raise_error
|
108
108
|
end
|
109
109
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean_lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.13
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Delorean compiler
|