aniero-tire_swing 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- == 1.0.4 / 2008-11-17
1
+ == 0.0.5 / 2008-11-26
2
+
3
+ * 2 minor enhancements
4
+ * Switched dependency on ActiveSupport out for the lighter-weight Extlib
5
+ * Updated array_of to remove recursive flag and add support for extracting more than one kind of node
6
+
7
+ == 0.0.4 / 2008-11-17
2
8
 
3
9
  * 4 minor enhancements
4
10
  * Updated array traversal code to be recursive by default
@@ -7,7 +13,7 @@
7
13
  * Added clone method for deep copy of AST
8
14
  * Updated node building to set node parents for easier traversal of the AST
9
15
 
10
- == 1.0.0 / 2008-06-29
16
+ == 0.0.1 / 2008-06-29
11
17
 
12
18
  * 1 major enhancement
13
19
  * Birthday!
data/Rakefile CHANGED
@@ -22,4 +22,4 @@ PROJ.spec.opts << '--color --format specdoc'
22
22
 
23
23
  depend_on "treetop"
24
24
  depend_on "attributes"
25
- depend_on "activesupport", ">= 2.0.2"
25
+ depend_on "extlib", "~> 0.9.8"
data/lib/tire_swing.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module TireSwing
2
2
 
3
3
  # :stopdoc:
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -44,9 +44,9 @@ module TireSwing
44
44
  end # module TireSwing
45
45
 
46
46
  require "rubygems"
47
- gem "activesupport"
47
+ gem "extlib"
48
48
  gem "attributes"
49
49
 
50
- %w(active_support/core_ext/string attributes treetop).each { |lib| require lib }
50
+ %w(extlib/inflection extlib/string attributes treetop).each { |lib| require lib }
51
51
 
52
52
  TireSwing.require_all_libs_relative_to __FILE__
@@ -31,7 +31,7 @@ module TireSwing::NodeDefinition
31
31
  #
32
32
  # <AST.create_node(:variable)>
33
33
  #
34
- # and when you're using the parser extension, tell the parser about the namespace
34
+ # but when you're using the parser extension, tell the parser about the namespace
35
35
  #
36
36
  # TireSwing.parses_grammar(Grammar, AST)
37
37
  #
@@ -39,10 +39,10 @@ module TireSwing::NodeDefinition
39
39
  #
40
40
  # <node(...)>
41
41
  #
42
- # which is an instance method wrapper for the create_node class method.
42
+ # which is an instance method wrapper for this create_node module method.
43
43
  #
44
44
  def create_node(name)
45
- TireSwing::NodeCreator.new(name, const_get(name.to_s.camelize))
45
+ TireSwing::NodeCreator.new(name, const_get(name.to_s.camel_case))
46
46
  end
47
47
 
48
48
  # Define a node.
@@ -114,7 +114,7 @@ module TireSwing::NodeDefinition
114
114
  #
115
115
  def node(name, *attribute_names, &blk)
116
116
  klass = TireSwing::Node.create *attribute_names
117
- const_set name.to_s.camelize, klass
117
+ const_set name.to_s.camel_case, klass
118
118
  klass.class_eval &blk if block_given?
119
119
  end
120
120
 
@@ -131,15 +131,14 @@ module TireSwing::NodeDefinition
131
131
  #
132
132
  # [assignment, [assignment, [assignment]]]
133
133
  #
134
- # If you specify that the array is recursive, it will retrieve all nested child nodes, no matter how deep, which
135
- # provide the kind of node you want.
134
+ # array_of(:assignment) will retrieve all of the assignment nodes from that recursive tree.
136
135
  #
137
- # If you provide a block, the filtered result will be yielded to the block and returned as the final result.
136
+ # If you provide a block, the filtered syntax node will be yielded to the block and returned as the final result.
138
137
  #
139
- def array_of(kind, recursive = true, &blk)
138
+ def array_of(*kinds, &block)
140
139
  lambda do |node|
141
- result = NodeFilters.filter(node, kind, recursive)
142
- blk ? result.map(&blk) : result
140
+ result = NodeFilters.filter(node, kinds)
141
+ block ? result.map(&block) : result
143
142
  end
144
143
  end
145
144
 
@@ -176,15 +175,11 @@ module TireSwing::NodeDefinition
176
175
 
177
176
  module NodeFilters
178
177
 
179
- def self.filter(node, kind, recursive)
178
+ def self.filter(node, kinds)
180
179
  nodes = []
181
180
  children = node.respond_to?(:elements) ? (node.elements || []) : []
182
- if recursive
183
- nodes << node if node.respond_to?(:node_to_build) && node.node_to_build == kind
184
- children.each { |child| nodes.push *filter(child, kind, true) }
185
- else
186
- nodes = ([node] + children).select { |n| n.respond_to?(:node_to_build) && n.node_to_build == kind }
187
- end
181
+ nodes << node if node.respond_to?(:node_to_build) && kinds.include?(node.node_to_build)
182
+ children.each { |child| nodes.push *filter(child, kinds) }
188
183
  nodes
189
184
  end
190
185
 
@@ -29,7 +29,7 @@ module TireSwing
29
29
  #
30
30
  # You can specify an alternate module which contains the AST if desired.
31
31
  def self.parses_grammar(grammar, ast=nil)
32
- parser = (grammar.to_s + "Parser").constantize
32
+ parser = Extlib::Inflection.constantize(grammar.to_s + "Parser")
33
33
  ast ||= grammar
34
34
  parser.module_eval do
35
35
  extend ParserExtension
@@ -45,7 +45,7 @@ module TireSwing::VisitorDefinition
45
45
  #
46
46
  def visitor(name, &blk)
47
47
  klass = Class.new(TireSwing::Visitor)
48
- const_set name.to_s.camelize, klass
48
+ const_set name.to_s.camel_case, klass
49
49
  klass.class_eval &blk if block_given?
50
50
  end
51
51
  end
@@ -28,7 +28,7 @@ module Lists
28
28
  module AST
29
29
  include TireSwing::NodeDefinition
30
30
  node :lists, :elements, :lists => extract(:list)
31
- node :list, :elements, :numbers => array_of(:number, true) { |num| num.text_value.to_i }
31
+ node :list, :elements, :numbers => array_of(:number) { |num| num.text_value.to_i }
32
32
  node :number # placeholder
33
33
  end
34
34
 
@@ -76,20 +76,18 @@ describe TireSwing::NodeDefinition do
76
76
  TestNodes.array_of(:foo).call(node).should == [node]
77
77
  end
78
78
 
79
- it "filters recursively by default" do
79
+ it "filters recursively" do
80
80
  b = mock_syntax_node("b", :elements => ["stuff", "whatever"], :node_to_build => :foo)
81
81
  a = mock_syntax_node("a", :elements => ["jkl", b], :node_to_build => :foo)
82
82
  top = mock_syntax_node("top", :elements => ["asdf", a], :node_to_build => :foo)
83
- TestNodes.array_of(:foo, true).call(top).should == [top, a, b]
83
+ TestNodes.array_of(:foo).call(top).should == [top, a, b]
84
84
  end
85
85
 
86
- describe "with the recursive flag set to false" do
87
- it "returns a lambda that does not filter recursively" do
88
- b = mock_syntax_node("b", :elements => ["stuff", "whatever"], :node_to_build => :foo)
89
- a = mock_syntax_node("a", :elements => ["jkl", b], :node_to_build => :foo)
90
- top = mock_syntax_node("top", :elements => ["asdf", a], :node_to_build => :foo)
91
- TestNodes.array_of(:foo, false).call(top).should == [top, a]
92
- end
86
+ it "filters for more than one kind of node" do
87
+ c = mock_syntax_node("c", :elements => [], :node_to_build => :foo)
88
+ b = mock_syntax_node("b", :elements => [c], :node_to_build => :bar)
89
+ a = mock_syntax_node("a", :elements => [b], :node_to_build => :foo)
90
+ TestNodes.array_of(:foo, :bar).call(a).should == [a, b, c]
93
91
  end
94
92
 
95
93
  describe "with a block provided" do
data/tire_swing.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tire_swing}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nathan Witmer"]
9
- s.date = %q{2008-11-17}
9
+ s.date = %q{2008-11-26}
10
10
  s.description = %q{Simple node and visitor definitions for Treetop grammars.}
11
11
  s.email = %q{nwitmer at gmail dot com}
12
12
  s.extra_rdoc_files = ["History.txt", "README.txt", "spec/fixtures/assignments.txt"]
@@ -26,15 +26,15 @@ Gem::Specification.new do |s|
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
27
  s.add_runtime_dependency(%q<treetop>, [">= 1.2.4"])
28
28
  s.add_runtime_dependency(%q<attributes>, [">= 5.0.1"])
29
- s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
29
+ s.add_runtime_dependency(%q<extlib>, ["~> 0.9.8"])
30
30
  else
31
31
  s.add_dependency(%q<treetop>, [">= 1.2.4"])
32
32
  s.add_dependency(%q<attributes>, [">= 5.0.1"])
33
- s.add_dependency(%q<activesupport>, [">= 2.0.2"])
33
+ s.add_dependency(%q<extlib>, ["~> 0.9.8"])
34
34
  end
35
35
  else
36
36
  s.add_dependency(%q<treetop>, [">= 1.2.4"])
37
37
  s.add_dependency(%q<attributes>, [">= 5.0.1"])
38
- s.add_dependency(%q<activesupport>, [">= 2.0.2"])
38
+ s.add_dependency(%q<extlib>, ["~> 0.9.8"])
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aniero-tire_swing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Witmer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-17 00:00:00 -08:00
12
+ date: 2008-11-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,13 +31,13 @@ dependencies:
31
31
  version: 5.0.1
32
32
  version:
33
33
  - !ruby/object:Gem::Dependency
34
- name: activesupport
34
+ name: extlib
35
35
  version_requirement:
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.2
40
+ version: 0.9.8
41
41
  version:
42
42
  description: Simple node and visitor definitions for Treetop grammars.
43
43
  email: nwitmer at gmail dot com