sexpr 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,16 @@
1
+ # 0.5.1 / 2012-03-13
2
+
3
+ * Minor enhancements
4
+
5
+ * Modules and Classes are now recognized for terminals in the same way as Regexp, true,
6
+ false and nil. As there are quite a few bugs in Psych/Sick to put class names in .yaml
7
+ files, Sexpr recognizes them also as strings starting with '::' (e.g. ::Symbol).
8
+
9
+ * Bug fixes
10
+
11
+ * Use `reference.const_get(name, *false*)` when looking for tagging modules to avoid
12
+ finding ruby classes such as Array when tagging sexpr such as [:array, ...].
13
+
1
14
  # 0.5.0 / 2012-02-25
2
15
 
3
16
  * Major enhancements
@@ -36,7 +36,9 @@ module Sexpr
36
36
  case arg
37
37
  when Matcher
38
38
  arg
39
- when Regexp, TrueClass, FalseClass, NilClass
39
+ when Regexp, Module
40
+ Matcher::Terminal.new arg
41
+ when TrueClass, FalseClass, NilClass
40
42
  Matcher::Terminal.new arg
41
43
  when lambda{|x| x.is_a?(Array) && x.size == 1 && x.first.is_a?(Array)}
42
44
  Matcher::Sequence.new arg.first.map{|s| compile_rule_defn(s) }
@@ -46,6 +48,9 @@ module Sexpr
46
48
  Matcher::Many.new compile_rule_defn($`), $1
47
49
  when /^[a-z][a-z_]+$/
48
50
  Matcher::Reference.new arg.to_sym, grammar
51
+ when /^::([A-Z][a-z]*.*)$/
52
+ found = $1.split('::').inject(Kernel){|cl,n| cl.const_get(n)}
53
+ Matcher::Terminal.new found
49
54
  else
50
55
  raise ArgumentError, "Invalid rule definition: #{arg.inspect}", caller
51
56
  end
@@ -56,7 +56,7 @@ module Sexpr
56
56
  if ref = tagging_reference
57
57
  rulename = sexpr.first
58
58
  modname = rule2modname(rulename)
59
- tag = ref.const_get(modname) rescue default_tagging_module
59
+ tag = ref.const_get(modname, false) rescue default_tagging_module
60
60
  sexpr.extend(tag) if tag
61
61
  elsif tag = default_tagging_module
62
62
  sexpr.extend(tag)
@@ -25,7 +25,7 @@ module Sexpr
25
25
 
26
26
  def terminal_match?(term)
27
27
  case @value
28
- when Regexp
28
+ when Regexp, Module
29
29
  @value === term rescue false
30
30
  when TrueClass, FalseClass, NilClass
31
31
  @value == term
@@ -3,7 +3,7 @@ module Sexpr
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
@@ -9,7 +9,7 @@ variables:
9
9
  upper:
10
10
  Sexpr
11
11
  version:
12
- 0.5.0
12
+ 0.5.1
13
13
  summary: |-
14
14
  A compilation framework around s-expressions
15
15
  description: |-
@@ -41,6 +41,30 @@ module Sexpr
41
41
  end
42
42
  end
43
43
 
44
+ context "with a Module/Class" do
45
+ let(:arg){ Symbol }
46
+ it 'gives it the class' do
47
+ subject.should be_a(Matcher::Terminal)
48
+ subject.value.should eq(Symbol)
49
+ end
50
+ end
51
+
52
+ context "with a single Module/Class name" do
53
+ let(:arg){ '::Symbol' }
54
+ it 'gives it the class' do
55
+ subject.should be_a(Matcher::Terminal)
56
+ subject.value.should eq(Symbol)
57
+ end
58
+ end
59
+
60
+ context "with a qualified Module/Class name" do
61
+ let(:arg){ '::Sexpr::Node' }
62
+ it 'gives it the class' do
63
+ subject.should be_a(Matcher::Terminal)
64
+ subject.value.should eq(Sexpr::Node)
65
+ end
66
+ end
67
+
44
68
  context 'with an alternative array' do
45
69
  let(:arg){ [true, false, nil] }
46
70
  it 'factors an Alternative' do
@@ -26,6 +26,10 @@ module Sexpr::Grammar
26
26
  tag([:or]).should be_a(TaggingReference::Node)
27
27
  end
28
28
 
29
+ it 'does not try to tag with a ruby class' do
30
+ tag([:array]).should be_a(TaggingReference::Node)
31
+ end
32
+
29
33
  end
30
34
 
31
35
  context 'when a tagging reference is provided' do
@@ -47,6 +51,10 @@ module Sexpr::Grammar
47
51
  it 'tags with the default tagging module when no match' do
48
52
  res = tag([:or]).should be_a(TaggingReference::Node)
49
53
  end
54
+
55
+ it 'does not try to tag with a ruby class' do
56
+ tag([:array]).should be_a(TaggingReference::Node)
57
+ end
50
58
  end
51
59
 
52
60
  end
@@ -85,5 +85,24 @@ module Sexpr::Matcher
85
85
  end
86
86
  end
87
87
 
88
+ context "with a Class" do
89
+ let(:arg){ Symbol }
90
+
91
+ it 'matches a symbol' do
92
+ terminal.terminal_match?(:hello).should be_true
93
+ end
94
+
95
+ it 'does not match a string' do
96
+ terminal.terminal_match?("hello").should be_false
97
+ end
98
+
99
+ it 'does not match anything else' do
100
+ terminal.terminal_match?(nil).should be_false
101
+ terminal.terminal_match?([]).should be_false
102
+ terminal.terminal_match?([:sexp]).should be_false
103
+ terminal.terminal_match?("nil").should be_false
104
+ end
105
+ end
106
+
88
107
  end
89
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sexpr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-25 00:00:00.000000000Z
12
+ date: 2012-03-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: epath
16
- requirement: &81881430 !ruby/object:Gem::Requirement
16
+ requirement: &70208258266200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *81881430
24
+ version_requirements: *70208258266200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: citrus
27
- requirement: &81881110 !ruby/object:Gem::Requirement
27
+ requirement: &70208258265600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.4'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *81881110
35
+ version_requirements: *70208258265600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &81880830 !ruby/object:Gem::Requirement
38
+ requirement: &70208258265040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *81880830
46
+ version_requirements: *70208258265040
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &81880580 !ruby/object:Gem::Requirement
49
+ requirement: &70208258264540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.8'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *81880580
57
+ version_requirements: *70208258264540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: wlang
60
- requirement: &81880280 !ruby/object:Gem::Requirement
60
+ requirement: &70208258263980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.10.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81880280
68
+ version_requirements: *70208258263980
69
69
  description: Sexpr helps manipulating s-expressions in ruby.
70
70
  email:
71
71
  - blambeau@gmail.com
@@ -81,99 +81,98 @@ files:
81
81
  - CHANGELOG.md
82
82
  - Gemfile
83
83
  - Gemfile.lock
84
- - examples/bool_expr/bool_expr.rb
85
84
  - examples/bool_expr/bool_expr.citrus
85
+ - examples/bool_expr/bool_expr.rb
86
86
  - examples/bool_expr/bool_expr.sexp.yml
87
- - lib/sexpr.rb
88
- - lib/sexpr/matcher/terminal.rb
89
- - lib/sexpr/matcher/rule.rb
87
+ - lib/sexpr/errors.rb
88
+ - lib/sexpr/grammar/matching.rb
89
+ - lib/sexpr/grammar/options.rb
90
+ - lib/sexpr/grammar/parsing.rb
91
+ - lib/sexpr/grammar/tagging.rb
92
+ - lib/sexpr/grammar.rb
93
+ - lib/sexpr/loader.rb
90
94
  - lib/sexpr/matcher/alternative.rb
91
- - lib/sexpr/matcher/sequence.rb
92
- - lib/sexpr/matcher/reference.rb
93
95
  - lib/sexpr/matcher/many.rb
94
- - lib/sexpr/rewriter.rb
95
- - lib/sexpr/grammar.rb
96
+ - lib/sexpr/matcher/reference.rb
97
+ - lib/sexpr/matcher/rule.rb
98
+ - lib/sexpr/matcher/sequence.rb
99
+ - lib/sexpr/matcher/terminal.rb
100
+ - lib/sexpr/matcher.rb
96
101
  - lib/sexpr/node.rb
97
- - lib/sexpr/processor/sexpr_coercions.rb
98
- - lib/sexpr/processor/helper.rb
99
- - lib/sexpr/processor/null_helper.rb
100
- - lib/sexpr/processor.rb
101
102
  - lib/sexpr/parser/citrus.rb
102
103
  - lib/sexpr/parser/ext.rb
103
- - lib/sexpr/errors.rb
104
- - lib/sexpr/loader.rb
105
- - lib/sexpr/grammar/parsing.rb
106
- - lib/sexpr/grammar/tagging.rb
107
- - lib/sexpr/grammar/options.rb
108
- - lib/sexpr/grammar/matching.rb
109
104
  - lib/sexpr/parser.rb
110
- - lib/sexpr/matcher.rb
105
+ - lib/sexpr/processor/helper.rb
106
+ - lib/sexpr/processor/null_helper.rb
107
+ - lib/sexpr/processor/sexpr_coercions.rb
108
+ - lib/sexpr/processor.rb
109
+ - lib/sexpr/rewriter.rb
111
110
  - lib/sexpr/version.rb
111
+ - lib/sexpr.rb
112
112
  - LICENCE.md
113
113
  - Manifest.txt
114
114
  - Rakefile
115
115
  - README.md
116
- - spec/spec_helper.rb
116
+ - spec/fixtures/bar.rb
117
+ - spec/fixtures/foo.rb
118
+ - spec/fixtures/preprocessed.rb
119
+ - spec/fixtures/simple_processor.rb
120
+ - spec/grammar/matching/test_compile_rule.rb
121
+ - spec/grammar/matching/test_compile_rule_defn.rb
122
+ - spec/grammar/options/test_install_parser.rb
123
+ - spec/grammar/options/test_install_path.rb
124
+ - spec/grammar/options/test_install_root.rb
125
+ - spec/grammar/tagging/test_looks_a_sexpr.rb
126
+ - spec/grammar/tagging/test_mod2rulename.rb
127
+ - spec/grammar/tagging/test_rule2modname.rb
128
+ - spec/grammar/tagging/test_tag_sexpr.rb
129
+ - spec/grammar/test_new.rb
130
+ - spec/grammar/test_parse.rb
131
+ - spec/grammar/test_sexpr.rb
132
+ - spec/matcher/alternative/test_eat.rb
133
+ - spec/matcher/alternative/test_match_q.rb
134
+ - spec/matcher/many/test_eat.rb
135
+ - spec/matcher/many/test_initialize.rb
136
+ - spec/matcher/many/test_match_q.rb
117
137
  - spec/matcher/reference/test_eat.rb
118
138
  - spec/matcher/reference/test_match_q.rb
119
139
  - spec/matcher/rule/test_eat.rb
120
140
  - spec/matcher/rule/test_match_q.rb
121
- - spec/matcher/many/test_eat.rb
122
- - spec/matcher/many/test_initialize.rb
123
- - spec/matcher/many/test_match_q.rb
124
141
  - spec/matcher/sequence/test_eat.rb
125
142
  - spec/matcher/sequence/test_match_q.rb
126
143
  - spec/matcher/terminal/test_eat.rb
127
- - spec/matcher/terminal/test_terminal_match.rb
128
144
  - spec/matcher/terminal/test_match_q.rb
129
- - spec/matcher/alternative/test_eat.rb
130
- - spec/matcher/alternative/test_match_q.rb
131
- - spec/rewriter/test_copy_and_apply.rb
132
- - spec/processor/test_helper.rb
133
- - spec/processor/test_sexpr_coercions.rb
134
- - spec/processor/test_build_helper_chain.rb
135
- - spec/processor/test_use.rb
136
- - spec/processor/test_apply.rb
137
- - spec/processor/test_call.rb
138
- - spec/processor/helper/test_call.rb
139
- - spec/test_rewriter.rb
140
- - spec/grammar.yml
145
+ - spec/matcher/terminal/test_terminal_match.rb
146
+ - spec/node/test_sexpr_body.rb
147
+ - spec/node/test_sexpr_copy.rb
148
+ - spec/node/test_sexpr_type.rb
149
+ - spec/node/test_tracking_markers.rb
141
150
  - spec/parser/citrus/test_new.rb
142
- - spec/parser/citrus/test_registration.rb
143
151
  - spec/parser/citrus/test_parse.rb
144
- - spec/parser/citrus/test_to_sexpr.rb
145
152
  - spec/parser/citrus/test_recognize.rb
153
+ - spec/parser/citrus/test_registration.rb
154
+ - spec/parser/citrus/test_to_sexpr.rb
146
155
  - spec/parser/test_factor.rb
147
156
  - spec/parser/test_input_text.rb
148
- - spec/test_sexpr.rb
157
+ - spec/processor/helper/test_call.rb
158
+ - spec/processor/test_apply.rb
159
+ - spec/processor/test_build_helper_chain.rb
160
+ - spec/processor/test_call.rb
161
+ - spec/processor/test_helper.rb
162
+ - spec/processor/test_sexpr_coercions.rb
163
+ - spec/processor/test_use.rb
164
+ - spec/rewriter/test_copy_and_apply.rb
165
+ - spec/spec_helper.rb
149
166
  - spec/test_load.rb
150
- - spec/grammar/test_new.rb
151
- - spec/grammar/tagging/test_mod2rulename.rb
152
- - spec/grammar/tagging/test_rule2modname.rb
153
- - spec/grammar/tagging/test_looks_a_sexpr.rb
154
- - spec/grammar/tagging/test_tag_sexpr.rb
155
- - spec/grammar/test_sexpr.rb
156
- - spec/grammar/options/test_install_root.rb
157
- - spec/grammar/options/test_install_parser.rb
158
- - spec/grammar/options/test_install_path.rb
159
- - spec/grammar/test_parse.rb
160
- - spec/grammar/matching/test_compile_rule.rb
161
- - spec/grammar/matching/test_compile_rule_defn.rb
162
- - spec/node/test_tracking_markers.rb
163
- - spec/node/test_sexpr_copy.rb
164
- - spec/node/test_sexpr_body.rb
165
- - spec/node/test_sexpr_type.rb
166
167
  - spec/test_readme_examples.rb
167
- - spec/fixtures/preprocessed.rb
168
- - spec/fixtures/simple_processor.rb
169
- - spec/fixtures/bar.rb
170
- - spec/fixtures/foo.rb
168
+ - spec/test_rewriter.rb
169
+ - spec/test_sexpr.rb
171
170
  - tasks/debug_mail.rake
172
- - tasks/yard.rake
171
+ - tasks/debug_mail.txt
173
172
  - tasks/gem.rake
174
173
  - tasks/spec_test.rake
175
174
  - tasks/unit_test.rake
176
- - tasks/debug_mail.txt
175
+ - tasks/yard.rake
177
176
  homepage: https://github.com/blambeau/sexp
178
177
  licenses: []
179
178
  post_install_message:
@@ -194,63 +193,62 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
193
  version: '0'
195
194
  requirements: []
196
195
  rubyforge_project:
197
- rubygems_version: 1.8.15
196
+ rubygems_version: 1.8.10
198
197
  signing_key:
199
198
  specification_version: 3
200
199
  summary: A compilation framework around s-expressions
201
200
  test_files:
202
- - spec/spec_helper.rb
201
+ - spec/fixtures/bar.rb
202
+ - spec/fixtures/foo.rb
203
+ - spec/fixtures/preprocessed.rb
204
+ - spec/fixtures/simple_processor.rb
205
+ - spec/grammar/matching/test_compile_rule.rb
206
+ - spec/grammar/matching/test_compile_rule_defn.rb
207
+ - spec/grammar/options/test_install_parser.rb
208
+ - spec/grammar/options/test_install_path.rb
209
+ - spec/grammar/options/test_install_root.rb
210
+ - spec/grammar/tagging/test_looks_a_sexpr.rb
211
+ - spec/grammar/tagging/test_mod2rulename.rb
212
+ - spec/grammar/tagging/test_rule2modname.rb
213
+ - spec/grammar/tagging/test_tag_sexpr.rb
214
+ - spec/grammar/test_new.rb
215
+ - spec/grammar/test_parse.rb
216
+ - spec/grammar/test_sexpr.rb
217
+ - spec/matcher/alternative/test_eat.rb
218
+ - spec/matcher/alternative/test_match_q.rb
219
+ - spec/matcher/many/test_eat.rb
220
+ - spec/matcher/many/test_initialize.rb
221
+ - spec/matcher/many/test_match_q.rb
203
222
  - spec/matcher/reference/test_eat.rb
204
223
  - spec/matcher/reference/test_match_q.rb
205
224
  - spec/matcher/rule/test_eat.rb
206
225
  - spec/matcher/rule/test_match_q.rb
207
- - spec/matcher/many/test_eat.rb
208
- - spec/matcher/many/test_initialize.rb
209
- - spec/matcher/many/test_match_q.rb
210
226
  - spec/matcher/sequence/test_eat.rb
211
227
  - spec/matcher/sequence/test_match_q.rb
212
228
  - spec/matcher/terminal/test_eat.rb
213
- - spec/matcher/terminal/test_terminal_match.rb
214
229
  - spec/matcher/terminal/test_match_q.rb
215
- - spec/matcher/alternative/test_eat.rb
216
- - spec/matcher/alternative/test_match_q.rb
217
- - spec/rewriter/test_copy_and_apply.rb
218
- - spec/processor/test_helper.rb
219
- - spec/processor/test_sexpr_coercions.rb
220
- - spec/processor/test_build_helper_chain.rb
221
- - spec/processor/test_use.rb
222
- - spec/processor/test_apply.rb
223
- - spec/processor/test_call.rb
224
- - spec/processor/helper/test_call.rb
225
- - spec/test_rewriter.rb
226
- - spec/grammar.yml
230
+ - spec/matcher/terminal/test_terminal_match.rb
231
+ - spec/node/test_sexpr_body.rb
232
+ - spec/node/test_sexpr_copy.rb
233
+ - spec/node/test_sexpr_type.rb
234
+ - spec/node/test_tracking_markers.rb
227
235
  - spec/parser/citrus/test_new.rb
228
- - spec/parser/citrus/test_registration.rb
229
236
  - spec/parser/citrus/test_parse.rb
230
- - spec/parser/citrus/test_to_sexpr.rb
231
237
  - spec/parser/citrus/test_recognize.rb
238
+ - spec/parser/citrus/test_registration.rb
239
+ - spec/parser/citrus/test_to_sexpr.rb
232
240
  - spec/parser/test_factor.rb
233
241
  - spec/parser/test_input_text.rb
234
- - spec/test_sexpr.rb
242
+ - spec/processor/helper/test_call.rb
243
+ - spec/processor/test_apply.rb
244
+ - spec/processor/test_build_helper_chain.rb
245
+ - spec/processor/test_call.rb
246
+ - spec/processor/test_helper.rb
247
+ - spec/processor/test_sexpr_coercions.rb
248
+ - spec/processor/test_use.rb
249
+ - spec/rewriter/test_copy_and_apply.rb
250
+ - spec/spec_helper.rb
235
251
  - spec/test_load.rb
236
- - spec/grammar/test_new.rb
237
- - spec/grammar/tagging/test_mod2rulename.rb
238
- - spec/grammar/tagging/test_rule2modname.rb
239
- - spec/grammar/tagging/test_looks_a_sexpr.rb
240
- - spec/grammar/tagging/test_tag_sexpr.rb
241
- - spec/grammar/test_sexpr.rb
242
- - spec/grammar/options/test_install_root.rb
243
- - spec/grammar/options/test_install_parser.rb
244
- - spec/grammar/options/test_install_path.rb
245
- - spec/grammar/test_parse.rb
246
- - spec/grammar/matching/test_compile_rule.rb
247
- - spec/grammar/matching/test_compile_rule_defn.rb
248
- - spec/node/test_tracking_markers.rb
249
- - spec/node/test_sexpr_copy.rb
250
- - spec/node/test_sexpr_body.rb
251
- - spec/node/test_sexpr_type.rb
252
252
  - spec/test_readme_examples.rb
253
- - spec/fixtures/preprocessed.rb
254
- - spec/fixtures/simple_processor.rb
255
- - spec/fixtures/bar.rb
256
- - spec/fixtures/foo.rb
253
+ - spec/test_rewriter.rb
254
+ - spec/test_sexpr.rb
@@ -1,24 +0,0 @@
1
- rule:
2
- - non_terminal
3
- - terminal
4
- non_terminal:
5
- - [ a_rule ]
6
- - [ a_rule+ ]
7
- - [ a_rule* ]
8
- - [ "a_rule?" ]
9
- - [ a_rule, a_rule, a_rule ]
10
- a_rule:
11
- - [ terminal, non_terminal ]
12
- terminal:
13
- - regexp_nt
14
- - true_nt
15
- - false_nt
16
- - nil_nt
17
- regexp_nt:
18
- !ruby/regexp /^[a-z]+$/
19
- true_nt:
20
- true
21
- false_nt:
22
- false
23
- nil_nt:
24
- ~