delorean_lang 0.3.17 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/delorean.gemspec +1 -1
- data/lib/delorean/base.rb +9 -1
- data/lib/delorean/model.rb +8 -0
- data/lib/delorean/version.rb +1 -1
- data/spec/eval_spec.rb +16 -0
- data/spec/func_spec.rb +9 -0
- data/spec/parse_spec.rb +32 -30
- data/spec/spec_helper.rb +9 -3
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 64ec010131114928fd9951e07d2cce771d282e78
|
|
4
|
+
data.tar.gz: b0bd5b2d897bc11db6f1716e8597a17f07102d26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ae4acf562ffc9fb7786229ffd1b83c2a5c02fa745dacb9112bd39b1b2095f3ab895e4a90d9693408d2b5f698624e490996f0d67541e0e3cd80a842d82830949
|
|
7
|
+
data.tar.gz: 81c1481f224a236eeba19c0f2f431e48d5990093809233ad5d1ba73fc63bc86f960565d213bf209d93ad2fafd5f9bebed19bd4b21a07de02ddfde7f3a630fddd
|
data/.rubocop.yml
ADDED
data/delorean.gemspec
CHANGED
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |gem|
|
|
|
19
19
|
gem.add_dependency "treetop", "~> 1.5"
|
|
20
20
|
gem.add_dependency "activerecord", ">= 3.2"
|
|
21
21
|
gem.add_development_dependency "rspec", '~> 2.1'
|
|
22
|
-
gem.add_development_dependency "sqlite3", '~> 1.3'
|
|
22
|
+
gem.add_development_dependency "sqlite3", '~> 1.3.10'
|
|
23
23
|
end
|
data/lib/delorean/base.rb
CHANGED
|
@@ -8,6 +8,8 @@ module Delorean
|
|
|
8
8
|
# hash. The whole whitelist mechanism should be eventually
|
|
9
9
|
# rethought.
|
|
10
10
|
RUBY_WHITELIST = {
|
|
11
|
+
between?: [[Numeric, String],[Numeric, String],[Numeric, String]],
|
|
12
|
+
between: "between?",
|
|
11
13
|
compact: [Array],
|
|
12
14
|
to_set: [Array],
|
|
13
15
|
flatten: [Array, [Fixnum, nil]],
|
|
@@ -227,7 +229,13 @@ module Delorean
|
|
|
227
229
|
return obj.send(msg, *args)
|
|
228
230
|
end
|
|
229
231
|
|
|
230
|
-
sig =
|
|
232
|
+
sig = begin
|
|
233
|
+
obj.class.delorean_instance_methods[msg]
|
|
234
|
+
rescue NoMethodError
|
|
235
|
+
nil
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
sig = RUBY_WHITELIST[msg] unless sig
|
|
231
239
|
|
|
232
240
|
raise "no such method #{method}" unless sig
|
|
233
241
|
|
data/lib/delorean/model.rb
CHANGED
|
@@ -22,6 +22,14 @@ module Delorean
|
|
|
22
22
|
self.const_set(name.to_s.upcase+Delorean::SIG, sig)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
+
|
|
26
|
+
def delorean_instance_method(name, sig = nil)
|
|
27
|
+
delorean_instance_methods[name.to_sym] = [self, *sig].compact
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def delorean_instance_methods
|
|
31
|
+
@@delorean_instance_methods ||= {}
|
|
32
|
+
end
|
|
25
33
|
end
|
|
26
34
|
end
|
|
27
35
|
end
|
data/lib/delorean/version.rb
CHANGED
data/spec/eval_spec.rb
CHANGED
|
@@ -308,6 +308,14 @@ describe "Delorean" do
|
|
|
308
308
|
r.should == "CRJ-1.234"
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
+
it "should be able to access delorean_instance_method fns using .x syntax" do
|
|
312
|
+
engine.parse defn("A:",
|
|
313
|
+
' b = Dummy.i_just_met_you("I Really Like You", 1.234).name3("Run Away with Me")',
|
|
314
|
+
)
|
|
315
|
+
r = engine.evaluate("A", "b")
|
|
316
|
+
r.should == "I Really Like You-1.234-Run Away with Me"
|
|
317
|
+
end
|
|
318
|
+
|
|
311
319
|
it "should be able to get attr on Hash objects using a.b syntax" do
|
|
312
320
|
engine.parse defn("A:",
|
|
313
321
|
' b = Dummy.i_threw_a_hash_in_the_well()',
|
|
@@ -592,6 +600,14 @@ eof
|
|
|
592
600
|
engine.evaluate("A", "b").should == [-1, 10]
|
|
593
601
|
end
|
|
594
602
|
|
|
603
|
+
it "should handle list comprehension with conditions using loop var" do
|
|
604
|
+
skip "need to fix"
|
|
605
|
+
engine.parse defn("A:",
|
|
606
|
+
" b = [n for n in {'pt' : 1} if n[1]+1]",
|
|
607
|
+
)
|
|
608
|
+
engine.evaluate("A", "b").should == [['pt', 1]]
|
|
609
|
+
end
|
|
610
|
+
|
|
595
611
|
it "should eval hashes" do
|
|
596
612
|
engine.parse defn("A:",
|
|
597
613
|
" b = {}",
|
data/spec/func_spec.rb
CHANGED
|
@@ -197,4 +197,13 @@ describe "Delorean" do
|
|
|
197
197
|
engine.evaluate("A", "res").should == [true, true, true, false, false, false]
|
|
198
198
|
end
|
|
199
199
|
|
|
200
|
+
it "should handle BETWEEN" do
|
|
201
|
+
engine.parse defn("A:",
|
|
202
|
+
" a = 1.23",
|
|
203
|
+
" b = [a.between(10,20), a.between(1,3)]",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
expect(engine.evaluate("A", "b")).to eq([false, true])
|
|
207
|
+
end
|
|
208
|
+
|
|
200
209
|
end
|
data/spec/parse_spec.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "Delorean" do
|
|
4
|
-
|
|
5
4
|
let(:sset) {
|
|
6
|
-
TestContainer.new(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
TestContainer.new(
|
|
6
|
+
"AAA" =>
|
|
7
|
+
defn("X:",
|
|
8
|
+
" a = 123",
|
|
9
|
+
" b = a",
|
|
10
|
+
)
|
|
11
|
+
)
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
let(:engine) {
|
|
@@ -315,21 +314,25 @@ describe "Delorean" do
|
|
|
315
314
|
engine.reset
|
|
316
315
|
|
|
317
316
|
lambda {
|
|
318
|
-
engine.parse defn("
|
|
319
|
-
"
|
|
320
|
-
"
|
|
321
|
-
" nil_1 = false_1",
|
|
317
|
+
engine.parse defn("E:",
|
|
318
|
+
" a = 1",
|
|
319
|
+
" return=a",
|
|
322
320
|
)
|
|
323
321
|
}.should_not raise_error
|
|
324
322
|
|
|
325
323
|
engine.reset
|
|
326
324
|
|
|
325
|
+
skip "need to fix"
|
|
326
|
+
|
|
327
327
|
lambda {
|
|
328
|
-
engine.parse defn("
|
|
329
|
-
"
|
|
330
|
-
"
|
|
328
|
+
engine.parse defn("D:",
|
|
329
|
+
" true_1 = false",
|
|
330
|
+
" false_1 = true_1",
|
|
331
|
+
" nil_1 = false_1",
|
|
331
332
|
)
|
|
332
333
|
}.should_not raise_error
|
|
334
|
+
|
|
335
|
+
engine.reset
|
|
333
336
|
end
|
|
334
337
|
|
|
335
338
|
it "should parse calls followed by getattr" do
|
|
@@ -732,7 +735,7 @@ describe "Delorean" do
|
|
|
732
735
|
" 3];",
|
|
733
736
|
" b = 456",
|
|
734
737
|
)
|
|
735
|
-
|
|
738
|
+
fail
|
|
736
739
|
rescue Delorean::ParseError => exc
|
|
737
740
|
exc.line.should == 2
|
|
738
741
|
end
|
|
@@ -745,7 +748,7 @@ describe "Delorean" do
|
|
|
745
748
|
" a = 1 +",
|
|
746
749
|
" 2 +",
|
|
747
750
|
)
|
|
748
|
-
|
|
751
|
+
fail
|
|
749
752
|
rescue Delorean::ParseError => exc
|
|
750
753
|
exc.line.should == 3
|
|
751
754
|
end
|
|
@@ -759,7 +762,7 @@ describe "Delorean" do
|
|
|
759
762
|
" for a in [1,2,3]",
|
|
760
763
|
"B:",
|
|
761
764
|
)
|
|
762
|
-
|
|
765
|
+
fail
|
|
763
766
|
rescue Delorean::ParseError => exc
|
|
764
767
|
exc.line.should == 3
|
|
765
768
|
end
|
|
@@ -772,7 +775,7 @@ describe "Delorean" do
|
|
|
772
775
|
" 2]",
|
|
773
776
|
" b = 456",
|
|
774
777
|
)
|
|
775
|
-
|
|
778
|
+
fail
|
|
776
779
|
rescue Delorean::ParseError => exc
|
|
777
780
|
exc.line.should == 2
|
|
778
781
|
end
|
|
@@ -784,7 +787,7 @@ describe "Delorean" do
|
|
|
784
787
|
engine.parse defn("A:",
|
|
785
788
|
' d = "#{this is a test}"',
|
|
786
789
|
)
|
|
787
|
-
|
|
790
|
+
fail
|
|
788
791
|
rescue Delorean::ParseError => exc
|
|
789
792
|
exc.line.should == 2
|
|
790
793
|
end
|
|
@@ -800,16 +803,15 @@ describe "Delorean" do
|
|
|
800
803
|
|
|
801
804
|
it "should disallow import loops" do
|
|
802
805
|
skip 'not implemented yet'
|
|
803
|
-
sset.merge(
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
806
|
+
sset.merge(
|
|
807
|
+
"BBB" =>
|
|
808
|
+
defn("import AAA",
|
|
809
|
+
"import CCC",
|
|
810
|
+
),
|
|
811
|
+
"CCC" =>
|
|
812
|
+
defn("import BBB",
|
|
813
|
+
),
|
|
814
|
+
)
|
|
812
815
|
sset.get_engine("CCC")
|
|
813
816
|
end
|
|
814
|
-
|
|
815
817
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -77,6 +77,12 @@ class Dummy < ActiveRecord::Base
|
|
|
77
77
|
|
|
78
78
|
[a, b]
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
def name3 other_name
|
|
82
|
+
"#{name}-#{number.round(4)}-#{other_name}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
delorean_instance_method :name3, String
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
module M
|
|
@@ -91,9 +97,9 @@ module M
|
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
Delorean::RUBY_WHITELIST.
|
|
94
|
-
merge!(
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
merge!(
|
|
101
|
+
name2: [Dummy],
|
|
102
|
+
)
|
|
97
103
|
|
|
98
104
|
######################################################################
|
|
99
105
|
|
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.19
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arman Bostani
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: treetop
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 1.3.10
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
68
|
+
version: 1.3.10
|
|
69
69
|
description: A "compiler" for the Delorean programming language
|
|
70
70
|
email:
|
|
71
71
|
- arman.bostani@pnmac.com
|
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
|
75
75
|
files:
|
|
76
76
|
- ".gitignore"
|
|
77
77
|
- ".rspec"
|
|
78
|
+
- ".rubocop.yml"
|
|
78
79
|
- Gemfile
|
|
79
80
|
- LICENSE
|
|
80
81
|
- README.md
|
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
116
117
|
version: '0'
|
|
117
118
|
requirements: []
|
|
118
119
|
rubyforge_project:
|
|
119
|
-
rubygems_version: 2.
|
|
120
|
+
rubygems_version: 2.4.3
|
|
120
121
|
signing_key:
|
|
121
122
|
specification_version: 4
|
|
122
123
|
summary: Delorean compiler
|
|
@@ -126,4 +127,3 @@ test_files:
|
|
|
126
127
|
- spec/func_spec.rb
|
|
127
128
|
- spec/parse_spec.rb
|
|
128
129
|
- spec/spec_helper.rb
|
|
129
|
-
has_rdoc:
|