delorean_lang 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitlab-ci.yml +1 -2
- data/.rubocop.yml +45 -5
- data/.rubocop_todo.yml +1 -634
- data/Gemfile +3 -1
- data/README.md +22 -0
- data/Rakefile +3 -1
- data/delorean.gemspec +18 -17
- data/lib/delorean/abstract_container.rb +4 -2
- data/lib/delorean/base.rb +30 -27
- data/lib/delorean/cache.rb +2 -0
- data/lib/delorean/cache/adapters.rb +2 -0
- data/lib/delorean/cache/adapters/base.rb +2 -0
- data/lib/delorean/cache/adapters/ruby_cache.rb +5 -0
- data/lib/delorean/const.rb +5 -3
- data/lib/delorean/debug.rb +6 -5
- data/lib/delorean/delorean.rb +466 -147
- data/lib/delorean/delorean.treetop +13 -1
- data/lib/delorean/engine.rb +61 -50
- data/lib/delorean/error.rb +2 -1
- data/lib/delorean/model.rb +12 -9
- data/lib/delorean/nodes.rb +130 -67
- data/lib/delorean/ruby.rb +2 -0
- data/lib/delorean/ruby/whitelists.rb +2 -0
- data/lib/delorean/ruby/whitelists/base.rb +7 -3
- data/lib/delorean/ruby/whitelists/default.rb +6 -6
- data/lib/delorean/ruby/whitelists/empty.rb +3 -2
- data/lib/delorean/ruby/whitelists/matchers.rb +2 -0
- data/lib/delorean/ruby/whitelists/matchers/arguments.rb +2 -0
- data/lib/delorean/ruby/whitelists/matchers/method.rb +5 -2
- data/lib/delorean/ruby/whitelists/whitelist_error.rb +2 -0
- data/lib/delorean/version.rb +3 -1
- data/lib/delorean_lang.rb +3 -1
- data/spec/cache_spec.rb +4 -2
- data/spec/dev_spec.rb +68 -69
- data/spec/eval_spec.rb +824 -729
- data/spec/func_spec.rb +172 -176
- data/spec/parse_spec.rb +516 -522
- data/spec/ruby/whitelist_spec.rb +6 -3
- data/spec/spec_helper.rb +26 -23
- metadata +27 -27
data/spec/ruby/whitelist_spec.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../spec_helper'
|
2
4
|
require 'delorean/ruby/whitelists/empty'
|
3
5
|
|
4
|
-
describe
|
6
|
+
describe 'Delorean Ruby whitelisting' do
|
5
7
|
it 'allows to override whitelist with an empty one' do
|
6
8
|
::Delorean::Ruby.whitelist = whitelist
|
7
9
|
expect(whitelist.matchers).to be_empty
|
@@ -12,7 +14,7 @@ describe "Delorean Ruby whitelisting" do
|
|
12
14
|
|
13
15
|
let(:whitelist) { ::Delorean::Ruby::Whitelists::Empty.new }
|
14
16
|
|
15
|
-
describe
|
17
|
+
describe 'methods' do
|
16
18
|
before do
|
17
19
|
whitelist.add_method :testmethod do |method|
|
18
20
|
method.called_on Dummy
|
@@ -47,7 +49,8 @@ describe "Delorean Ruby whitelisting" do
|
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'raises error if arguments list is too long' do
|
50
|
-
expect do
|
52
|
+
expect do
|
53
|
+
matcher.match!(klass: Dummy, args: [1])
|
51
54
|
end.to raise_error('too many args to testmethod')
|
52
55
|
end
|
53
56
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
5
|
|
@@ -8,10 +10,9 @@ require 'pry'
|
|
8
10
|
|
9
11
|
# Requires supporting files with custom matchers and macros, etc,
|
10
12
|
# in ./support/ and its subdirectories.
|
11
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
14
|
|
13
15
|
RSpec.configure do |config|
|
14
|
-
|
15
16
|
end
|
16
17
|
|
17
18
|
def defn(*l)
|
@@ -21,7 +22,7 @@ end
|
|
21
22
|
######################################################################
|
22
23
|
# ActiveRecord related
|
23
24
|
|
24
|
-
ActiveRecord::Base.establish_connection adapter:
|
25
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
25
26
|
|
26
27
|
ActiveRecord::Migration.create_table :dummies do |t|
|
27
28
|
t.string :name
|
@@ -39,40 +40,38 @@ class Dummy < ActiveRecord::Base
|
|
39
40
|
Dummy.new(name: name, number: number)
|
40
41
|
end
|
41
42
|
|
42
|
-
I_JUST_MET_YOU_SIG = [1, 2]
|
43
|
+
I_JUST_MET_YOU_SIG = [1, 2].freeze
|
43
44
|
|
44
45
|
def self.call_me_maybe(*a)
|
45
46
|
a.inject(0, :+)
|
46
47
|
end
|
47
48
|
|
48
|
-
CALL_ME_MAYBE_SIG = [0, Float::INFINITY]
|
49
|
+
CALL_ME_MAYBE_SIG = [0, Float::INFINITY].freeze
|
49
50
|
|
50
|
-
def self.this_is_crazy
|
51
|
-
end
|
51
|
+
def self.this_is_crazy; end
|
52
52
|
|
53
53
|
def self.miss_you_so_bad
|
54
|
-
d = Dummy.create(name:
|
55
|
-
|
54
|
+
d = Dummy.create(name: 'hello', number: 123)
|
55
|
+
Dummy.new(name: 'jello', number: 456, dummy: d)
|
56
56
|
end
|
57
57
|
|
58
|
-
MISS_YOU_SO_BAD_SIG = [0, 0]
|
58
|
+
MISS_YOU_SO_BAD_SIG = [0, 0].freeze
|
59
59
|
|
60
60
|
delorean_fn :all_of_me, sig: 0 do
|
61
|
-
[
|
61
|
+
[{ 'name' => 'hello', 'foo' => 'bar' }]
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.i_threw_a_hash_in_the_well
|
65
|
-
{a: 123,
|
65
|
+
{ a: 123, 'a' => 456, b: 789 }
|
66
66
|
end
|
67
67
|
|
68
|
-
I_THREW_A_HASH_IN_THE_WELL_SIG = [0, 0]
|
68
|
+
I_THREW_A_HASH_IN_THE_WELL_SIG = [0, 0].freeze
|
69
69
|
|
70
70
|
def name2
|
71
71
|
"#{name}-#{number.round(4)}"
|
72
72
|
end
|
73
73
|
|
74
|
-
delorean_fn :one_or_two, sig: [1, 2] do
|
75
|
-
|*args|
|
74
|
+
delorean_fn :one_or_two, sig: [1, 2] do |*args|
|
76
75
|
# FIXME: |a,b| will not work properly with delorean_fn
|
77
76
|
a, b = args
|
78
77
|
|
@@ -85,33 +84,37 @@ class Dummy < ActiveRecord::Base
|
|
85
84
|
end
|
86
85
|
|
87
86
|
delorean_fn :returns_openstruct, sig: 0 do
|
88
|
-
OpenStruct.new(
|
87
|
+
OpenStruct.new('abc' => 'def')
|
89
88
|
end
|
90
89
|
|
91
90
|
cached_delorean_fn :returns_cached_openstruct, sig: 2 do |first, last|
|
92
|
-
OpenStruct.new(
|
91
|
+
OpenStruct.new(first.to_s => last)
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
95
|
class DummyChild < Dummy
|
97
96
|
def self.hello
|
98
|
-
DummyChild.new(name:
|
97
|
+
DummyChild.new(name: 'child', number: 99_999)
|
99
98
|
end
|
100
|
-
HELLO_SIG = [0, 0]
|
99
|
+
HELLO_SIG = [0, 0].freeze
|
101
100
|
end
|
102
101
|
|
103
102
|
module M
|
104
103
|
class LittleDummy
|
105
104
|
include Delorean::Model
|
106
105
|
|
107
|
-
delorean_fn(:heres_my_number, sig: [0, Float::INFINITY]) do
|
108
|
-
|*a|
|
106
|
+
delorean_fn(:heres_my_number, sig: [0, Float::INFINITY]) do |*a|
|
109
107
|
a.inject(0, :+)
|
110
108
|
end
|
111
109
|
def self.sup
|
112
110
|
LittleDummy.new
|
113
111
|
end
|
114
|
-
SUP_SIG = [0, 0]
|
112
|
+
SUP_SIG = [0, 0].freeze
|
113
|
+
end
|
114
|
+
|
115
|
+
module N
|
116
|
+
class NestedDummy < ::M::LittleDummy
|
117
|
+
end
|
115
118
|
end
|
116
119
|
end
|
117
120
|
|
@@ -122,7 +125,7 @@ end
|
|
122
125
|
######################################################################
|
123
126
|
|
124
127
|
class TestContainer < Delorean::AbstractContainer
|
125
|
-
def initialize(scripts={})
|
128
|
+
def initialize(scripts = {})
|
126
129
|
super()
|
127
130
|
@scripts = scripts
|
128
131
|
@engines = {}
|
metadata
CHANGED
@@ -1,73 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean_lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: treetop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1
|
61
|
+
version: '2.1'
|
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: 1
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.3.10
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.3.10
|
97
97
|
description: A "compiler" for the Delorean programming language
|
98
98
|
email:
|
99
99
|
- arman.bostani@pnmac.com
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.7.8
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Delorean compiler
|