expressive 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 614bf71a221bed50450541c737809d5951209c70
4
- data.tar.gz: 85fab60313e884f5dd227c2438b8752be81d8143
5
- SHA512:
6
- metadata.gz: 4d07ec60fe5faefd39c010ab324bae26a10ff1a9fe35afe405d19aae8c2409ba060f42e974c08834bd48464def180f210a6a2b62a8394bac79071db062e01fa5
7
- data.tar.gz: 772d3269dead9864011ac6c58a469aff99d138794860d82a6e9ea4ccb9faba32cae43bad0767f93e0ee14ce5721951182d12c974e04f8e5064a3753430909e19
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDMxNjY5ZWVlYTc3ZTM3NDk3ZjBkYzVlNzdmZjljYmI3MWQ5ZmZlOQ==
5
+ data.tar.gz: !binary |-
6
+ NTRlNDVlYjRhOGYxM2VhM2JiMmJkNTgxNjgxMjk3MzhmMDA1ODQ0NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmQ3ZmMzZDAxMWIxZDNjZmZlZjNhODZlYTU4NDM2YmM5MzVkM2E3OWNmODRl
10
+ OTNjZjhlMjUyNjk1MDRjNWExNzUwMGMwYWIzMGRmZDE3YTc3M2Q0ZjhmZWY3
11
+ OWMxZDQ0Y2E1YTQwNDYwZjViN2IyMDhhNTIzMWI1NWFiYzg4MzE=
12
+ data.tar.gz: !binary |-
13
+ MTgyZGNjNWQxYzExM2Y1MTZjNjg1MzcyMGRjYjI2ZjEwYjQ2NjczZTM5OGIz
14
+ MDJiZTJiZDFjNDJiN2U0ZDdjZGRkMzNhMjRkOWViNDQ0YWZmNTllMzFlMDRj
15
+ ODc1ZDhlNGUyM2Q0MTIwMzI3YTI0NTRkMWM2ZTA1NDZiZDg2NTA=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expressive (0.0.32)
4
+ expressive (0.0.33)
5
5
  awesome_print (~> 1.0.2)
6
6
  json
7
7
  polyglot (~> 0.3.3)
@@ -0,0 +1,5 @@
1
+ module Expressive
2
+ class ParseError < StandardError
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Expressive
2
+ class RunError < StandardError
3
+
4
+ end
5
+ end
data/lib/expressive.rb CHANGED
@@ -5,22 +5,37 @@ require 'rest_client'
5
5
  require File.join(File.dirname(__FILE__), 'scope')
6
6
  require File.join(File.dirname(__FILE__), 'extended_value')
7
7
  require File.join(File.dirname(__FILE__), 'webhook')
8
+ require File.join(File.dirname(__FILE__), 'errors/parse_error')
9
+ require File.join(File.dirname(__FILE__), 'errors/run_error')
8
10
 
9
11
  Treetop.load File.join(File.dirname(__FILE__), 'expressive_grammar.treetop')
10
12
 
11
13
  module Expressive
12
14
  def self.run(source_code, scope = TopLevel.new )
13
15
  program = parse(source_code)
14
- program.eval(scope)
16
+ begin
17
+ program.eval(scope)
18
+ rescue Exception => e
19
+ raise RunError, "Error running '#{source_code}': #{$!}", $!.backtrace
20
+ end
15
21
  end
16
22
 
17
23
  def self.parse(expressions)
18
24
  @parser ||= ::ExpressiveParser.new
19
- @parser.parse(expressions)
25
+ begin
26
+ @parser.parse(expressions)
27
+ rescue Exception => e
28
+ if expressions.nil?
29
+ message = "Error parsing nil expression: #{$!}"
30
+ else
31
+ message = "Error parsing '#{expressions}': #{$!}"
32
+ end
33
+ raise ParseError, message, $!.backtrace
34
+ end
20
35
  end
21
36
 
22
37
  def self.all_symbols
23
- %w(+ - * / = set sum $sub post >= > < <= and or if date datetime get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id $hash $concat $split $sms $hval $index $random $join)
38
+ %w(+ - * / = set sum $sub post >= > < <= and or if date datetime get put lookup $lookup $head $tail $reverse round $round $days_ago $hours_ago $minutes_ago $append $id $hash $concat $split $sms $hval $index $random $join $not)
24
39
  end
25
40
 
26
41
  module Boolean
@@ -1,3 +1,3 @@
1
1
  module Expressive
2
- VERSION = "0.0.32"
2
+ VERSION = "0.0.33"
3
3
  end
data/lib/scope.rb CHANGED
@@ -189,6 +189,7 @@ module Expressive
189
189
  define('$head'){|*args| args.flatten.first }
190
190
  define('$tail'){|*args| args.flatten[1..-1] }
191
191
  define('$reverse'){|*args| args.flatten.reverse }
192
+ define('$not'){|*args| not args.first }
192
193
 
193
194
  define('$round'){|*args| perform_round(args) }
194
195
  define('round'){|*args| perform_round(args) }
@@ -6,7 +6,7 @@ describe "Expressive" do
6
6
  end
7
7
 
8
8
  describe "all_symbols" do
9
- it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join) }
9
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join $not) }
10
10
  end
11
11
 
12
12
  describe "understands booleans" do
@@ -287,6 +287,26 @@ EOH
287
287
  it { Expressive.run('(or nil_value true)', @scope).should eql true }
288
288
  it { Expressive.run('(or nil_value false)', @scope).should eql false }
289
289
  end
290
+
291
+ context "not - negate a boolean" do
292
+ before(:each) do
293
+ @scope["key1"] = "value1"
294
+ @scope["key2"] = "value2"
295
+ @scope["key3"] = "value1"
296
+ @scope["key4"] = nil
297
+ end
298
+ it { Expressive.run('($not true)', @scope).should eql false }
299
+ it { Expressive.run('($not false)', @scope).should eql true }
300
+ it { Expressive.run('($not (= 1 2))', @scope).should eql true}
301
+ it { Expressive.run('($not (= 1 1))', @scope).should eql false}
302
+ it { Expressive.run('($not (= key1 key2))', @scope).should eql true}
303
+ it { Expressive.run('($not (= key1 key3))', @scope).should eql false}
304
+ it { Expressive.run("($not (= key1 ''))", @scope).should eql true}
305
+ it { Expressive.run('($not (= key1 "value1"))', @scope).should eql false}
306
+ it { Expressive.run('($not (= key4 "value2"))', @scope).should eql true}
307
+ it { Expressive.run('($not (= key4 ''))', @scope).should eql false}
308
+
309
+ end
290
310
  end
291
311
 
292
312
  describe "generates random values" do
@@ -728,4 +748,14 @@ EOH
728
748
  end
729
749
  end
730
750
  end
751
+
752
+ describe "parse error handling" do
753
+ it "should raise parse exceptions" do
754
+ expect{ Expressive.run(nil) }.to raise_error Expressive::ParseError, "Error parsing nil expression: undefined method `length' for nil:NilClass"
755
+ end
756
+ it "should raise runtime exceptions" do
757
+ expect{ Expressive.run('( 1 2') }.to raise_error Expressive::RunError, "Error running '( 1 2': private method `eval' called for nil:NilClass"
758
+ end
759
+ end
760
+
731
761
  end
metadata CHANGED
@@ -1,223 +1,223 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ijonas Kisselbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_gntp
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.3.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.11.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.11.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.12'
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
54
  version: '3.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
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
68
  version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.3.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.3.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.2.1
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
96
  version: 1.2.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.8.11
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.8.11
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: 0.9.10
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.9.10
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: timecop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: 0.5.3
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.5.3
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - ! '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - ! '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: polyglot
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ~>
158
158
  - !ruby/object:Gem::Version
159
159
  version: 0.3.3
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ~>
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.3.3
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: json
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - ! '>='
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - ! '>='
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: treetop
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - "~>"
185
+ - - ~>
186
186
  - !ruby/object:Gem::Version
187
187
  version: 1.4.10
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - "~>"
192
+ - - ~>
193
193
  - !ruby/object:Gem::Version
194
194
  version: 1.4.10
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: awesome_print
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - "~>"
199
+ - - ~>
200
200
  - !ruby/object:Gem::Version
201
201
  version: 1.0.2
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - "~>"
206
+ - - ~>
207
207
  - !ruby/object:Gem::Version
208
208
  version: 1.0.2
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rest-client
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - "~>"
213
+ - - ~>
214
214
  - !ruby/object:Gem::Version
215
215
  version: 1.6.7
216
216
  type: :runtime
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - "~>"
220
+ - - ~>
221
221
  - !ruby/object:Gem::Version
222
222
  version: 1.6.7
223
223
  description: Scheme-like language for manipulating CaseBlocks cases
@@ -227,9 +227,9 @@ executables: []
227
227
  extensions: []
228
228
  extra_rdoc_files: []
229
229
  files:
230
- - ".document"
231
- - ".gitignore"
232
- - ".rspec"
230
+ - .document
231
+ - .gitignore
232
+ - .rspec
233
233
  - Gemfile
234
234
  - Gemfile.lock
235
235
  - Guardfile
@@ -239,6 +239,8 @@ files:
239
239
  - README.rdoc
240
240
  - Rakefile
241
241
  - expressive.gemspec
242
+ - lib/errors/parse_error.rb
243
+ - lib/errors/run_error.rb
242
244
  - lib/expressive.rb
243
245
  - lib/expressive/version.rb
244
246
  - lib/expressive_grammar.treetop
@@ -258,17 +260,17 @@ require_paths:
258
260
  - lib
259
261
  required_ruby_version: !ruby/object:Gem::Requirement
260
262
  requirements:
261
- - - ">="
263
+ - - ! '>='
262
264
  - !ruby/object:Gem::Version
263
265
  version: '0'
264
266
  required_rubygems_version: !ruby/object:Gem::Requirement
265
267
  requirements:
266
- - - ">="
268
+ - - ! '>='
267
269
  - !ruby/object:Gem::Version
268
270
  version: '0'
269
271
  requirements: []
270
272
  rubyforge_project:
271
- rubygems_version: 2.2.2
273
+ rubygems_version: 2.0.3
272
274
  signing_key:
273
275
  specification_version: 4
274
276
  summary: Scheme-like language for manipulating CaseBlocks cases