trxl 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -3382,7 +3382,7 @@ module Trxl
3382
3382
  def eval(env = Environment.new)
3383
3383
  # left associative evaluation
3384
3384
  multitives(env).inject(exponential.eval(env)) do |operand, next_op|
3385
- op = (next_op[0].text_value == '/' ? operand.to_f : operand)
3385
+ op = (next_op[0].text_value == '/' ? (operand ? operand.to_f : nil) : operand)
3386
3386
  next_op[0].apply(op, next_op[1])
3387
3387
  end
3388
3388
  end
@@ -518,7 +518,7 @@ grammar Trxl
518
518
  def eval(env = Environment.new)
519
519
  # left associative evaluation
520
520
  multitives(env).inject(exponential.eval(env)) do |operand, next_op|
521
- op = (next_op[0].text_value == '/' ? operand.to_f : operand)
521
+ op = (next_op[0].text_value == '/' ? (operand ? operand.to_f : nil) : operand)
522
522
  next_op[0].apply(op, next_op[1])
523
523
  end
524
524
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  Infinity = 1.0 / 0
4
4
 
5
5
  describe "When evaluating addition expressions, the language" do
6
-
6
+
7
7
  include Trxl::SpecHelper
8
8
 
9
9
  before(:each) do
10
10
  @parser = Trxl::Calculator.new
11
11
  end
12
-
12
+
13
13
  it "should allow integers as operands" do
14
14
  eval("0+0").should == 0 + 0
15
15
  eval("0+1").should == 0 + 1
@@ -18,7 +18,7 @@ describe "When evaluating addition expressions, the language" do
18
18
  eval("2+2").should == 2 + 2
19
19
  eval("2+-2").should == 2 + -2
20
20
  end
21
-
21
+
22
22
  it "should allow floats as operands" do
23
23
  eval("0.0+0.0").should == 0.0 + 0.0
24
24
  eval("0.1+1").should == 0.1 + 1
@@ -28,6 +28,14 @@ describe "When evaluating addition expressions, the language" do
28
28
  eval("2.0+-2.01").should == 2.0 + -2.01
29
29
  end
30
30
 
31
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
32
+ expect { eval("NULL + 1") }.to raise_error(Trxl::InvalidArgumentException)
33
+ end
34
+
35
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
36
+ expect { eval("1 + NULL") }.to raise_error(Trxl::InvalidArgumentException)
37
+ end
38
+
31
39
  it "should allow arbitrary spacing" do
32
40
  eval("4 + 2").should == 4 + 2
33
41
  eval("4 +2").should == 4 + 2
@@ -36,23 +44,23 @@ describe "When evaluating addition expressions, the language" do
36
44
  eval("4 + 2 ").should == 4 + 2
37
45
  eval(" 4 + 2 ").should == 4 + 2
38
46
  end
39
-
47
+
40
48
  it "should allow chained expressions" do
41
49
  eval("1 + 1 + 1").should == 1 + 1 + 1
42
50
  eval("1 + 1 + 1 + 1").should == 1 + 1 + 1 + 1
43
51
  end
44
-
52
+
45
53
  end
46
54
 
47
55
 
48
56
  describe "When evaluating subtraction expressions, the language" do
49
-
57
+
50
58
  include Trxl::SpecHelper
51
59
 
52
60
  before(:each) do
53
61
  @parser = Trxl::Calculator.new
54
62
  end
55
-
63
+
56
64
  it "should allow integers as operands" do
57
65
  eval("0-0").should == 0 - 0
58
66
  eval("0-2").should == 0 - 2
@@ -61,7 +69,7 @@ describe "When evaluating subtraction expressions, the language" do
61
69
  eval("5--2").should == 5--2
62
70
  end
63
71
 
64
-
72
+
65
73
  it "should allow floats as operands" do
66
74
  eval("0.0-0.0").should == 0.0 - 0.0
67
75
  eval("0.1-2.34").should == 0.1 - 2.34
@@ -69,7 +77,15 @@ describe "When evaluating subtraction expressions, the language" do
69
77
  eval("5.45678-2.456789").should == 5.45678 - 2.456789
70
78
  eval("5.45678--2.456789").should == 5.45678 - -2.456789
71
79
  end
72
-
80
+
81
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
82
+ expect { eval("NULL - 1") }.to raise_error(Trxl::InvalidArgumentException)
83
+ end
84
+
85
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
86
+ expect { eval("1 - NULL") }.to raise_error(Trxl::InvalidArgumentException)
87
+ end
88
+
73
89
  it "should allow arbitrary spacing" do
74
90
  eval("4 - 2").should == 4 - 2
75
91
  eval("4 -2").should == 4 - 2
@@ -78,12 +94,12 @@ describe "When evaluating subtraction expressions, the language" do
78
94
  eval("4 - 2 ").should == 4 - 2
79
95
  eval(" 4 - 2 ").should == 4 - 2
80
96
  end
81
-
97
+
82
98
  it "should perform left associative evaluation in chained expressions" do
83
99
  eval("16 - 4 - 2").should == (16 - 4 - 2)
84
100
  eval("16 - 4 - 2 - 2").should == (16 - 4 - 2 - 2)
85
101
  end
86
-
102
+
87
103
  it "should allow to override operator precedence with parentheses" do
88
104
  eval("(16 - 4) - 2").should == (16 - 4) - 2
89
105
  eval("16 - (4 - 2)").should == 16 - (4 - 2)
@@ -91,17 +107,17 @@ describe "When evaluating subtraction expressions, the language" do
91
107
  eval("16 - (4 - 2) - 2").should == 16 - (4 - 2) - 2
92
108
  end
93
109
 
94
- end
110
+ end
95
111
 
96
112
 
97
113
  describe "When evaluating multiplication expressions, the language" do
98
-
114
+
99
115
  include Trxl::SpecHelper
100
116
 
101
117
  before(:each) do
102
118
  @parser = Trxl::Calculator.new
103
119
  end
104
-
120
+
105
121
  it "should allow integers as operands" do
106
122
  eval("0*0").should == 0 * 0
107
123
  eval("0*1").should == 0 * 1
@@ -112,7 +128,7 @@ describe "When evaluating multiplication expressions, the language" do
112
128
  eval("3*-4").should == 3 * -4
113
129
  end
114
130
 
115
-
131
+
116
132
  it "should allow floats as operands" do
117
133
  eval("0.0*0.0").should == 0.0 * 0.0
118
134
  eval("0.1*1.0").should == 0.1 * 1.0
@@ -123,6 +139,14 @@ describe "When evaluating multiplication expressions, the language" do
123
139
  eval("3.45*-4.45").should == 3.45 * -4.45
124
140
  end
125
141
 
142
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
143
+ expect { eval("NULL * 1") }.to raise_error(Trxl::InvalidArgumentException)
144
+ end
145
+
146
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
147
+ expect { eval("1 * NULL") }.to raise_error(Trxl::InvalidArgumentException)
148
+ end
149
+
126
150
  it "should allow arbitrary spacing" do
127
151
  eval("4 * 2").should == 4 * 2
128
152
  eval("4 *2").should == 4 * 2
@@ -131,23 +155,23 @@ describe "When evaluating multiplication expressions, the language" do
131
155
  eval("4 * 2 ").should == 4 * 2
132
156
  eval(" 4 * 2 ").should == 4 * 2
133
157
  end
134
-
158
+
135
159
  it "should allow chained expressions" do
136
160
  eval("1 * 2 * 3").should == 1 * 2 * 3
137
161
  eval("1 * 2 * 3 * 4").should == 1 * 2 * 3 * 4
138
162
  end
139
-
163
+
140
164
  end
141
165
 
142
166
 
143
167
  describe "When evaluating division expressions, the language" do
144
-
168
+
145
169
  include Trxl::SpecHelper
146
170
 
147
171
  before(:each) do
148
172
  @parser = Trxl::Calculator.new
149
173
  end
150
-
174
+
151
175
  it "should allow integers as operands" do
152
176
  eval("1/1").should == 1.0 / 1
153
177
  eval("0/1").should == 0.0 / 1
@@ -167,10 +191,18 @@ describe "When evaluating division expressions, the language" do
167
191
  eval("4.2345678/2").should == 4.2345678 / 2
168
192
  eval("3/2.123456").should == 3 / 2.123456
169
193
  eval("3/-2.123456").should == 3 / -2.123456
170
-
194
+
171
195
  # TODO think about DivisonByZero vs. Infinity
172
196
  end
173
-
197
+
198
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
199
+ expect { eval("NULL / 1") }.to raise_error(Trxl::InvalidArgumentException)
200
+ end
201
+
202
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
203
+ expect { eval("1 / NULL") }.to raise_error(Trxl::InvalidArgumentException)
204
+ end
205
+
174
206
  it "should allow arbitrary spacing" do
175
207
  eval("4 / 2").should == 4 / 2
176
208
  eval("4 /2").should == 4 / 2
@@ -179,7 +211,7 @@ describe "When evaluating division expressions, the language" do
179
211
  eval("4 / 2 ").should == 4 / 2
180
212
  eval(" 4 / 2 ").should == 4 / 2
181
213
  end
182
-
214
+
183
215
  it "should perform left associative evaluation in chained expressions" do
184
216
  eval("16 / 4 / 2").should == (16 / 4 / 2)
185
217
  eval("16 / 4 / 2 / 2").should == (16 / 4 / 2 / 2)
@@ -191,38 +223,46 @@ describe "When evaluating division expressions, the language" do
191
223
  eval("(16 / 4) / (2 / 2)").should == (16 / 4) / (2 / 2)
192
224
  eval("16 / (4 / 2) / 2").should == 16 / (4 / 2) / 2
193
225
  end
194
-
226
+
195
227
  end
196
228
 
197
229
 
198
230
  describe "When evaluating modulo expressions, the language" do
199
-
231
+
200
232
  include Trxl::SpecHelper
201
233
 
202
234
  before(:each) do
203
235
  @parser = Trxl::Calculator.new
204
236
  end
205
-
237
+
206
238
  it "should allow integers as operands" do
207
239
  eval("1%1").should == 1 % 1
208
240
  eval("4%2").should == 4 % 2
209
241
  eval("8%3").should == 8 % 3
210
242
  eval("8%-3").should == 8 % -3
211
-
243
+
212
244
  # test division by zero
213
245
  lambda { eval("1%0") }.should raise_error(Trxl::DivisionByZeroError)
214
246
  end
215
-
247
+
216
248
 
217
249
  it "should allow floats as operands" do
218
250
  eval("1.0%1.0").should == 1.0 % 1.0
219
251
  eval("4.0%2.0").should == 4.0 % 2.0
220
252
  eval("8.0%3.2").should == 8.0 % 3.2
221
253
  eval("8.0%-3.2").should == 8.0 % -3.2
222
-
254
+
223
255
  # TODO think about DivisonByZero vs. Infinity
224
256
  end
225
-
257
+
258
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
259
+ expect { eval("NULL % 1") }.to raise_error(Trxl::InvalidArgumentException)
260
+ end
261
+
262
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
263
+ expect { eval("1 % NULL") }.to raise_error(Trxl::InvalidArgumentException)
264
+ end
265
+
226
266
  it "should allow arbitrary spacing" do
227
267
  eval("4 % 2").should == 4 % 2
228
268
  eval("4 %2").should == 4 % 2
@@ -231,7 +271,7 @@ describe "When evaluating modulo expressions, the language" do
231
271
  eval("4 % 2 ").should == 4 % 2
232
272
  eval(" 4 % 2 ").should == 4 % 2
233
273
  end
234
-
274
+
235
275
  it "should perform left associative evaluation in chained expressions" do
236
276
  eval("15 % 5 % 3").should == (15 % 5 % 3)
237
277
  eval("16 % 9 % 4 % 2").should == (16 % 9 % 4 % 2)
@@ -243,24 +283,24 @@ describe "When evaluating modulo expressions, the language" do
243
283
  eval("(16 % 4) % (5 % 3)").should == (16 % 4) % (5 % 3)
244
284
  eval("16 % (5 % 3) % 2").should == 16 % (5 % 3) % 2
245
285
  end
246
-
286
+
247
287
  end
248
288
 
249
289
  describe "When evaluating exponential expressions, the language" do
250
-
290
+
251
291
  include Trxl::SpecHelper
252
292
 
253
293
  before(:each) do
254
294
  @parser = Trxl::Calculator.new
255
295
  end
256
-
296
+
257
297
  it "should allow integers as operands" do
258
298
  eval("1^1").should == 1 ** 1
259
299
  eval("4^2").should == 4 ** 2
260
300
  eval("8^3").should == 8 ** 3
261
301
  eval("8^-3").should == 8 ** -3
262
302
  end
263
-
303
+
264
304
 
265
305
  it "should allow floats as operands" do
266
306
  eval("1.0^1.0").should == 1.0 ** 1.0
@@ -268,7 +308,15 @@ describe "When evaluating exponential expressions, the language" do
268
308
  eval("8.0^3.2").should == 8.0 ** 3.2
269
309
  eval("8.0^-3.2").should == 8.0 ** -3.2
270
310
  end
271
-
311
+
312
+ it "should raise Trxl::InvalidArgumentException when the LHS is NULL" do
313
+ expect { eval("NULL ^ 1") }.to raise_error(Trxl::InvalidArgumentException)
314
+ end
315
+
316
+ it "should raise Trxl::InvalidArgumentException when the RHS is NULL" do
317
+ expect { eval("1 ^ NULL") }.to raise_error(Trxl::InvalidArgumentException)
318
+ end
319
+
272
320
  it "should allow arbitrary spacing" do
273
321
  eval("4 ^ 2").should == 4 ** 2
274
322
  eval("4 ^2").should == 4 ** 2
@@ -277,17 +325,17 @@ describe "When evaluating exponential expressions, the language" do
277
325
  eval("4 ^ 2 ").should == 4 ** 2
278
326
  eval(" 4 ^ 2 ").should == 4 ** 2
279
327
  end
280
-
328
+
281
329
  it "should perform left associative evaluation in chained expressions" do
282
330
  eval("2 ^ 2 ^ 2").should == (2 ** 2 ** 2)
283
331
  eval("2 ^ 2 ^ 2 ^ 2").should == (2 ** 2 ** 2 ** 2)
284
332
  end
285
-
333
+
286
334
  end
287
335
 
288
336
 
289
337
  describe "When evaluating arbitrary arithmetic expressions, the language" do
290
-
338
+
291
339
  include Trxl::SpecHelper
292
340
 
293
341
  before(:each) do
@@ -323,12 +371,12 @@ describe "When evaluating arbitrary arithmetic expressions, the language" do
323
371
  eval("4 + 2 - 2").should == 4 + 2 - 2
324
372
  eval("4 * 2 / 2").should == 4 * 2 / 2
325
373
  eval("4 * 2 % 2").should == 4 * 2 % 2
326
-
374
+
327
375
  eval("4 - 2 + 2").should == 4 - 2 + 2
328
376
  eval("4 / 2 * 2").should == 4 / 2 * 2
329
377
  eval("4 % 2 * 2").should == 4 % 2 * 2
330
378
  eval("4 ^ 2 * 2").should == 4 ** 2 * 2
331
-
379
+
332
380
  end
333
381
 
334
382
  it "should allow to override operator precedence using parentheses" do
@@ -349,7 +397,7 @@ describe "When evaluating arbitrary arithmetic expressions, the language" do
349
397
  eval("8 % (4 % 2 - 2)").should == 8 % (4 % 2 - 2)
350
398
  eval("2 ^ (2 ^ 2) - 2").should == 2 ** (2 ** 2) - 2
351
399
  eval("2 ^ (2 ^ 2 - 2)").should == 2 ** (2 ** 2 - 2)
352
-
400
+
353
401
  eval("2 * 4 * (2 - 2) * 3").should == 2 * 4 * (2 - 2) * 3
354
402
  eval("2 * 4 * (2 - 2 * 3)").should == 2 * 4 * (2 - 2 * 3)
355
403
  eval("8 / 4 / (2 - 4) / 2").should == 8.0 / 4 / (2 - 4) / 2
@@ -358,7 +406,7 @@ describe "When evaluating arbitrary arithmetic expressions, the language" do
358
406
  eval("8 % 4 % (2 - 6 % 3)").should == 8 % 4 % (2 - 6 % 3)
359
407
  eval("2 ^ 2 ^ (2 - 2) ^ 2").should == 2 ** 2 ** (2 - 2) ** 2
360
408
  eval("2 ^ 2 ^ (2 - 2 ^ 2)").should == 2 ** 2 ** (2 - 2 ** 2)
361
-
409
+
362
410
  eval("4 / (2 + 2 * 4) * (2 - 2) * 3").should == 4 / (2 + 2 * 4) * (2 - 2) * 3
363
411
  eval("2 * (2 + 8 / 4 / 2 - 4) / 2").should == 2 * (2 + 8 / 4 / 2 - 4) / 2
364
412
  eval("(2 + 4 + 8 % 4) % 2 - (5 % 3)").should == (2 + 4 + 8 % 4) % 2 - (5 % 3)
@@ -387,5 +435,5 @@ describe "When evaluating arbitrary arithmetic expressions, the language" do
387
435
  PROGRAM
388
436
  eval(program).should == 5
389
437
  end
390
-
391
- end
438
+
439
+ end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{trxl}
8
- s.version = "0.1.10"
7
+ s.name = "trxl"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Martin Gamsjaeger (snusnu)}, %q{Michael Aufreiter}]
12
- s.date = %q{2011-07-14}
13
- s.description = %q{A specced little language written with ruby and treetop. It has lambdas, recursion, conditionals, arrays, hashes, ranges, strings, arithmetics and some other stuff. It even has a small code import facility.}
14
- s.email = %q{gamsnjaga [at] gmail [dot] com}
11
+ s.authors = ["Martin Gamsjaeger (snusnu)", "Michael Aufreiter"]
12
+ s.date = "2012-05-08"
13
+ s.description = "A specced little language written with ruby and treetop. It has lambdas, recursion, conditionals, arrays, hashes, ranges, strings, arithmetics and some other stuff. It even has a small code import facility."
14
+ s.email = "gamsnjaga [at] gmail [dot] com"
15
15
  s.extra_rdoc_files = [
16
16
  "README"
17
17
  ]
@@ -44,10 +44,10 @@ Gem::Specification.new do |s|
44
44
  "spec/trxl/variables_spec.rb",
45
45
  "trxl.gemspec"
46
46
  ]
47
- s.homepage = %q{http://github.com/snusnu/trxl}
48
- s.require_paths = [%q{lib}]
49
- s.rubygems_version = %q{1.8.5}
50
- s.summary = %q{A specced little language written with ruby and treetop.}
47
+ s.homepage = "http://github.com/snusnu/trxl"
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = "1.8.17"
50
+ s.summary = "A specced little language written with ruby and treetop."
51
51
 
52
52
  if s.respond_to? :specification_version then
53
53
  s.specification_version = 3
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trxl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 10
10
- version: 0.1.10
9
+ - 11
10
+ version: 0.1.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Martin Gamsjaeger (snusnu)
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-14 00:00:00 Z
19
+ date: 2012-05-08 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: treetop
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements: []
115
115
 
116
116
  rubyforge_project:
117
- rubygems_version: 1.8.5
117
+ rubygems_version: 1.8.17
118
118
  signing_key:
119
119
  specification_version: 3
120
120
  summary: A specced little language written with ruby and treetop.