skeem 0.2.20 → 0.2.22

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +33 -298
  3. data/CHANGELOG.md +17 -2
  4. data/LICENSE.txt +1 -1
  5. data/lib/skeem/grammar.rb +14 -15
  6. data/lib/skeem/interpreter.rb +1 -1
  7. data/lib/skeem/parser.rb +1 -1
  8. data/lib/skeem/primitive/primitive_builder.rb +4 -2
  9. data/lib/skeem/primitive/primitive_procedure.rb +1 -1
  10. data/lib/skeem/runtime.rb +3 -1
  11. data/lib/skeem/s_expr_builder.rb +7 -7
  12. data/lib/skeem/s_expr_nodes.rb +5 -3
  13. data/lib/skeem/skm_simple_datum.rb +2 -2
  14. data/lib/skeem/tokenizer.rb +18 -23
  15. data/lib/skeem/version.rb +1 -1
  16. data/lib/skeem.rb +2 -2
  17. data/skeem.gemspec +8 -5
  18. data/spec/skeem/datum_dsl_spec.rb +50 -50
  19. data/spec/skeem/element_visitor_spec.rb +108 -108
  20. data/spec/skeem/interpreter_spec.rb +171 -169
  21. data/spec/skeem/lambda_spec.rb +27 -27
  22. data/spec/skeem/parser_spec.rb +27 -25
  23. data/spec/skeem/primitive/primitive_builder_spec.rb +127 -131
  24. data/spec/skeem/primitive/primitive_procedure_spec.rb +28 -28
  25. data/spec/skeem/runtime_spec.rb +52 -51
  26. data/spec/skeem/s_expr_nodes_spec.rb +31 -31
  27. data/spec/skeem/skm_compound_datum_spec.rb +36 -35
  28. data/spec/skeem/skm_element_spec.rb +35 -34
  29. data/spec/skeem/skm_empty_list_spec.rb +19 -19
  30. data/spec/skeem/skm_frame_spec.rb +49 -46
  31. data/spec/skeem/skm_pair_spec.rb +93 -93
  32. data/spec/skeem/skm_procedure_exec_spec.rb +11 -11
  33. data/spec/skeem/skm_simple_datum_spec.rb +104 -95
  34. data/spec/skeem/skm_unary_expression_spec.rb +60 -61
  35. data/spec/skeem/tokenizer_spec.rb +52 -52
  36. data/spec/skeem_spec.rb +1 -1
  37. data/spec/spec_helper.rb +0 -2
  38. metadata +61 -17
@@ -19,19 +19,19 @@ module Skeem
19
19
  end
20
20
 
21
21
  # Default instantiation rule
22
- subject { SkmElementVisitor.new(simple_datum) }
22
+ subject(:visitor) { described_class.new(simple_datum) }
23
23
 
24
24
  context 'Standard creation & initialization:' do
25
- it 'should be initialized with a parse tree argument' do
26
- expect { SkmElementVisitor.new(simple_datum) }.not_to raise_error
25
+ it 'is initialized with a parse tree argument' do
26
+ expect { described_class.new(simple_datum) }.not_to raise_error
27
27
  end
28
28
 
29
- it 'should know the parse tree to visit' do
30
- expect(subject.root).to eq(simple_datum)
29
+ it 'knows the parse tree to visit' do
30
+ expect(visitor.root).to eq(simple_datum)
31
31
  end
32
32
 
33
- it "shouldn't have subscribers at start" do
34
- expect(subject.subscribers).to be_empty
33
+ it "doesn't have subscribers at start" do
34
+ expect(visitor.subscribers).to be_empty
35
35
  end
36
36
  end # context
37
37
 
@@ -39,137 +39,137 @@ module Skeem
39
39
  let(:listener1) { double('fake-subscriber1') }
40
40
  let(:listener2) { double('fake-subscriber2') }
41
41
 
42
- it 'should allow subscriptions' do
43
- subject.subscribe(listener1)
44
- expect(subject.subscribers.size).to eq(1)
45
- expect(subject.subscribers).to eq([listener1])
42
+ it 'allows subscriptions' do
43
+ visitor.subscribe(listener1)
44
+ expect(visitor.subscribers.size).to eq(1)
45
+ expect(visitor.subscribers).to eq([listener1])
46
46
 
47
- subject.subscribe(listener2)
48
- expect(subject.subscribers.size).to eq(2)
49
- expect(subject.subscribers).to eq([listener1, listener2])
47
+ visitor.subscribe(listener2)
48
+ expect(visitor.subscribers.size).to eq(2)
49
+ expect(visitor.subscribers).to eq([listener1, listener2])
50
50
  end
51
51
 
52
- it 'should allow un-subcriptions' do
53
- subject.subscribe(listener1)
54
- subject.subscribe(listener2)
55
- subject.unsubscribe(listener2)
56
- expect(subject.subscribers.size).to eq(1)
57
- expect(subject.subscribers).to eq([listener1])
58
- subject.unsubscribe(listener1)
59
- expect(subject.subscribers).to be_empty
52
+ it 'allows un-subcriptions' do
53
+ visitor.subscribe(listener1)
54
+ visitor.subscribe(listener2)
55
+ visitor.unsubscribe(listener2)
56
+ expect(visitor.subscribers.size).to eq(1)
57
+ expect(visitor.subscribers).to eq([listener1])
58
+ visitor.unsubscribe(listener1)
59
+ expect(visitor.subscribers).to be_empty
60
60
  end
61
61
  end # context
62
62
 
63
63
  context 'Visiting simple datum:' do
64
64
  let(:runtime) { double('fake-runtime') }
65
65
 
66
- it 'should allow the visit of simple datum object' do
67
- subject.subscribe(listener)
68
- expect(listener).to receive(:before_simple_datum).with(runtime, simple_datum)
69
- expect(listener).to receive(:after_simple_datum).with(runtime, simple_datum)
70
- subject.start(runtime)
71
- expect(subject.runtime).to eq(runtime)
66
+ it 'allows the visit of simple datum object' do
67
+ visitor.subscribe(listener)
68
+ allow(listener).to receive(:before_simple_datum).with(runtime, simple_datum)
69
+ allow(listener).to receive(:after_simple_datum).with(runtime, simple_datum)
70
+ visitor.start(runtime)
71
+ expect(visitor.runtime).to eq(runtime)
72
72
  end
73
73
  end # context
74
74
 
75
75
  context 'Visiting compound datum:' do
76
76
  let(:runtime) { double('fake-runtime') }
77
77
 
78
- it 'should allow the visit of a flat list' do
78
+ it 'allows the visit of a flat list' do
79
79
  ls = list ['#false', 3, 'foo']
80
- instance = SkmElementVisitor.new(ls)
80
+ instance = described_class.new(ls)
81
81
  instance.subscribe(listener)
82
- expect(listener).to receive(:before_pair).with(runtime, ls).ordered
83
- expect(listener).to receive(:before_car).with(runtime, ls, ls.car).ordered
84
- expect(listener).to receive(:before_simple_datum).with(runtime, ls.car).ordered
85
- expect(listener).to receive(:after_simple_datum).with(runtime, ls.car).ordered
86
- expect(listener).to receive(:after_car).with(runtime, ls, ls.car).ordered
87
- expect(listener).to receive(:before_cdr).with(runtime, ls, ls.cdr).ordered
88
- expect(listener).to receive(:before_pair).with(runtime, ls.cdr).ordered
89
- expect(listener).to receive(:before_car).with(runtime, ls.cdr, ls.cdr.car).ordered
90
- expect(listener).to receive(:before_simple_datum).with(runtime, ls.cdr.car).ordered
91
- expect(listener).to receive(:after_simple_datum).with(runtime, ls.cdr.car).ordered
92
- expect(listener).to receive(:after_car).with(runtime, ls.cdr, ls.cdr.car).ordered
93
- expect(listener).to receive(:before_cdr).with(runtime, ls.cdr, ls.cdr.cdr).ordered
94
- expect(listener).to receive(:before_pair).with(runtime, ls.cdr.cdr).ordered
95
- expect(listener).to receive(:before_car).with(runtime, ls.cdr.cdr, ls.cdr.cdr.car).ordered
96
- expect(listener).to receive(:before_simple_datum).with(runtime, ls.cdr.cdr.car).ordered
97
- expect(listener).to receive(:after_simple_datum).with(runtime, ls.cdr.cdr.car).ordered
98
- expect(listener).to receive(:after_car).with(runtime, ls.cdr.cdr, ls.cdr.cdr.car).ordered
99
- expect(listener).to receive(:before_cdr).with(runtime, ls.cdr.cdr, ls.cdr.cdr.cdr).ordered
100
- expect(listener).to receive(:before_empty_list).with(runtime, ls.cdr.cdr.cdr).ordered
101
- expect(listener).to receive(:after_empty_list).with(runtime, ls.cdr.cdr.cdr).ordered
102
- expect(listener).to receive(:after_cdr).with(runtime, ls.cdr.cdr, ls.cdr.cdr.cdr).ordered
103
- expect(listener).to receive(:after_pair).with(runtime, ls.cdr.cdr).ordered
104
- expect(listener).to receive(:after_cdr).with(runtime, ls.cdr, ls.cdr.cdr).ordered
105
- expect(listener).to receive(:after_pair).with(runtime, ls.cdr).ordered
106
- expect(listener).to receive(:after_cdr).with(runtime, ls, ls.cdr).ordered
107
- expect(listener).to receive(:after_pair).with(runtime, ls).ordered
82
+ allow(listener).to receive(:before_pair).with(runtime, ls)
83
+ allow(listener).to receive(:before_car).with(runtime, ls, ls.car)
84
+ allow(listener).to receive(:before_simple_datum).with(runtime, ls.car)
85
+ allow(listener).to receive(:after_simple_datum).with(runtime, ls.car)
86
+ allow(listener).to receive(:after_car).with(runtime, ls, ls.car)
87
+ allow(listener).to receive(:before_cdr).with(runtime, ls, ls.cdr)
88
+ allow(listener).to receive(:before_pair).with(runtime, ls.cdr)
89
+ allow(listener).to receive(:before_car).with(runtime, ls.cdr, ls.cdr.car)
90
+ allow(listener).to receive(:before_simple_datum).with(runtime, ls.cdr.car)
91
+ allow(listener).to receive(:after_simple_datum).with(runtime, ls.cdr.car)
92
+ allow(listener).to receive(:after_car).with(runtime, ls.cdr, ls.cdr.car)
93
+ allow(listener).to receive(:before_cdr).with(runtime, ls.cdr, ls.cdr.cdr)
94
+ allow(listener).to receive(:before_pair).with(runtime, ls.cdr.cdr)
95
+ allow(listener).to receive(:before_car).with(runtime, ls.cdr.cdr, ls.cdr.cdr.car)
96
+ allow(listener).to receive(:before_simple_datum).with(runtime, ls.cdr.cdr.car)
97
+ allow(listener).to receive(:after_simple_datum).with(runtime, ls.cdr.cdr.car)
98
+ allow(listener).to receive(:after_car).with(runtime, ls.cdr.cdr, ls.cdr.cdr.car)
99
+ allow(listener).to receive(:before_cdr).with(runtime, ls.cdr.cdr, ls.cdr.cdr.cdr)
100
+ allow(listener).to receive(:before_empty_list).with(runtime, ls.cdr.cdr.cdr)
101
+ allow(listener).to receive(:after_empty_list).with(runtime, ls.cdr.cdr.cdr)
102
+ allow(listener).to receive(:after_cdr).with(runtime, ls.cdr.cdr, ls.cdr.cdr.cdr)
103
+ allow(listener).to receive(:after_pair).with(runtime, ls.cdr.cdr)
104
+ allow(listener).to receive(:after_cdr).with(runtime, ls.cdr, ls.cdr.cdr)
105
+ allow(listener).to receive(:after_pair).with(runtime, ls.cdr)
106
+ allow(listener).to receive(:after_cdr).with(runtime, ls, ls.cdr)
107
+ allow(listener).to receive(:after_pair).with(runtime, ls)
108
108
  instance.start(runtime)
109
109
  end
110
110
 
111
- it 'should allow the visit of a flat vector' do
111
+ it 'allows the visit of a flat vector' do
112
112
  vec = vector ['#false', 3, 'foo']
113
- instance = SkmElementVisitor.new(vec)
113
+ instance = described_class.new(vec)
114
114
  instance.subscribe(listener)
115
- expect(listener).to receive(:before_compound_datum).with(runtime, vec).ordered
116
- expect(listener).to receive(:before_children).with(runtime, vec, vec.members).ordered
117
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[0]).ordered
118
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[0]).ordered
119
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[1]).ordered
120
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[1]).ordered
121
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[2]).ordered
122
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[2]).ordered
123
- expect(listener).to receive(:after_children).with(runtime, vec, vec.members).ordered
124
- expect(listener).to receive(:after_compound_datum).with(runtime, vec).ordered
115
+ allow(listener).to receive(:before_compound_datum).with(runtime, vec)
116
+ allow(listener).to receive(:before_children).with(runtime, vec, vec.members)
117
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[0])
118
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[0])
119
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[1])
120
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[1])
121
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[2])
122
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[2])
123
+ allow(listener).to receive(:after_children).with(runtime, vec, vec.members)
124
+ allow(listener).to receive(:after_compound_datum).with(runtime, vec)
125
125
  instance.start(runtime)
126
126
  end
127
127
 
128
- it 'should allow the visit of a nested compound datum' do
128
+ it 'allows the visit of a nested compound datum' do
129
129
  nested_list = list %w[uno twei three']
130
130
  vec = vector ['#false', 3, nested_list, 'foo']
131
- instance = SkmElementVisitor.new(vec)
131
+ instance = described_class.new(vec)
132
132
  instance.subscribe(listener)
133
- expect(listener).to receive(:before_compound_datum).with(runtime, vec).ordered
134
- expect(listener).to receive(:before_children).with(runtime, vec, vec.members).ordered
135
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[0]).ordered
136
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[0]).ordered
137
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[1]).ordered
138
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[1]).ordered
139
-
140
- expect(listener).to receive(:before_pair).with(runtime, nested_list).ordered
141
- expect(listener).to receive(:before_car).with(runtime, nested_list, nested_list.car).ordered
133
+ allow(listener).to receive(:before_compound_datum).with(runtime, vec)
134
+ allow(listener).to receive(:before_children).with(runtime, vec, vec.members)
135
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[0])
136
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[0])
137
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[1])
138
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[1])
139
+
140
+ allow(listener).to receive(:before_pair).with(runtime, nested_list)
141
+ allow(listener).to receive(:before_car).with(runtime, nested_list, nested_list.car)
142
142
  expect(nested_list.car).to eq('uno')
143
- expect(listener).to receive(:before_simple_datum).with(runtime, nested_list.car).ordered
144
- expect(listener).to receive(:after_simple_datum).with(runtime, nested_list.car).ordered
145
- expect(listener).to receive(:after_car).with(runtime, nested_list, nested_list.car).ordered
146
- expect(listener).to receive(:before_cdr).with(runtime, nested_list, nested_list.cdr).ordered
147
- expect(listener).to receive(:before_pair).with(runtime, nested_list.cdr).ordered
148
- expect(listener).to receive(:before_car).with(runtime, nested_list.cdr, nested_list.cdr.car).ordered
149
- expect(listener).to receive(:before_simple_datum).with(runtime, nested_list.cdr.car).ordered
150
- expect(listener).to receive(:after_simple_datum).with(runtime, nested_list.cdr.car).ordered
151
- expect(listener).to receive(:after_car).with(runtime, nested_list.cdr, nested_list.cdr.car).ordered
152
- expect(listener).to receive(:before_cdr).with(runtime, nested_list.cdr, nested_list.cdr.cdr).ordered
153
- expect(listener).to receive(:before_pair).with(runtime, nested_list.cdr.cdr).ordered
154
- expect(listener).to receive(:before_car).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.car).ordered
155
- expect(listener).to receive(:before_simple_datum).with(runtime, nested_list.cdr.cdr.car).ordered
156
- expect(listener).to receive(:after_simple_datum).with(runtime, nested_list.cdr.cdr.car).ordered
157
- expect(listener).to receive(:after_car).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.car).ordered
158
- expect(listener).to receive(:before_cdr).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.cdr).ordered
159
- expect(listener).to receive(:before_empty_list).with(runtime, nested_list.cdr.cdr.cdr).ordered
160
- expect(listener).to receive(:after_empty_list).with(runtime, nested_list.cdr.cdr.cdr).ordered
161
- expect(listener).to receive(:after_cdr).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.cdr).ordered
162
- expect(listener).to receive(:after_pair).with(runtime, nested_list.cdr.cdr).ordered
163
- expect(listener).to receive(:after_cdr).with(runtime, nested_list.cdr, nested_list.cdr.cdr).ordered
164
- expect(listener).to receive(:after_pair).with(runtime, nested_list.cdr).ordered
165
- expect(listener).to receive(:after_cdr).with(runtime, nested_list, nested_list.cdr).ordered
166
- expect(listener).to receive(:after_pair).with(runtime, nested_list).ordered
167
- expect(listener).to receive(:before_simple_datum).with(runtime, vec.members[3]).ordered
168
- expect(listener).to receive(:after_simple_datum).with(runtime, vec.members[3]).ordered
169
- expect(listener).to receive(:after_children).with(runtime, vec, vec.members).ordered
170
- expect(listener).to receive(:after_compound_datum).with(runtime, vec).ordered
143
+ allow(listener).to receive(:before_simple_datum).with(runtime, nested_list.car)
144
+ allow(listener).to receive(:after_simple_datum).with(runtime, nested_list.car)
145
+ allow(listener).to receive(:after_car).with(runtime, nested_list, nested_list.car)
146
+ allow(listener).to receive(:before_cdr).with(runtime, nested_list, nested_list.cdr)
147
+ allow(listener).to receive(:before_pair).with(runtime, nested_list.cdr)
148
+ allow(listener).to receive(:before_car).with(runtime, nested_list.cdr, nested_list.cdr.car)
149
+ allow(listener).to receive(:before_simple_datum).with(runtime, nested_list.cdr.car)
150
+ allow(listener).to receive(:after_simple_datum).with(runtime, nested_list.cdr.car)
151
+ allow(listener).to receive(:after_car).with(runtime, nested_list.cdr, nested_list.cdr.car)
152
+ allow(listener).to receive(:before_cdr).with(runtime, nested_list.cdr, nested_list.cdr.cdr)
153
+ allow(listener).to receive(:before_pair).with(runtime, nested_list.cdr.cdr)
154
+ allow(listener).to receive(:before_car).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.car)
155
+ allow(listener).to receive(:before_simple_datum).with(runtime, nested_list.cdr.cdr.car)
156
+ allow(listener).to receive(:after_simple_datum).with(runtime, nested_list.cdr.cdr.car)
157
+ allow(listener).to receive(:after_car).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.car)
158
+ allow(listener).to receive(:before_cdr).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.cdr)
159
+ allow(listener).to receive(:before_empty_list).with(runtime, nested_list.cdr.cdr.cdr)
160
+ allow(listener).to receive(:after_empty_list).with(runtime, nested_list.cdr.cdr.cdr)
161
+ allow(listener).to receive(:after_cdr).with(runtime, nested_list.cdr.cdr, nested_list.cdr.cdr.cdr)
162
+ allow(listener).to receive(:after_pair).with(runtime, nested_list.cdr.cdr)
163
+ allow(listener).to receive(:after_cdr).with(runtime, nested_list.cdr, nested_list.cdr.cdr)
164
+ allow(listener).to receive(:after_pair).with(runtime, nested_list.cdr)
165
+ allow(listener).to receive(:after_cdr).with(runtime, nested_list, nested_list.cdr)
166
+ allow(listener).to receive(:after_pair).with(runtime, nested_list)
167
+ allow(listener).to receive(:before_simple_datum).with(runtime, vec.members[3])
168
+ allow(listener).to receive(:after_simple_datum).with(runtime, vec.members[3])
169
+ allow(listener).to receive(:after_children).with(runtime, vec, vec.members)
170
+ allow(listener).to receive(:after_compound_datum).with(runtime, vec)
171
171
  instance.start(runtime)
172
172
  end
173
173
  end # context
174
174
  end # describe
175
- end # module
175
+ end # modulecls