aniero-tire_swing 0.0.4 → 0.0.5
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.
- data/History.txt +8 -2
- data/Rakefile +1 -1
- data/lib/tire_swing.rb +3 -3
- data/lib/tire_swing/node_definition.rb +12 -17
- data/lib/tire_swing/parser_extension.rb +1 -1
- data/lib/tire_swing/visitor_definition.rb +1 -1
- data/spec/grammars/lists.rb +1 -1
- data/spec/node_definition_spec.rb +7 -9
- data/tire_swing.gemspec +5 -5
- metadata +5 -5
data/History.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
==
|
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
|
-
==
|
16
|
+
== 0.0.1 / 2008-06-29
|
11
17
|
|
12
18
|
* 1 major enhancement
|
13
19
|
* Birthday!
|
data/Rakefile
CHANGED
data/lib/tire_swing.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module TireSwing
|
2
2
|
|
3
3
|
# :stopdoc:
|
4
|
-
VERSION = "0.0.
|
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 "
|
47
|
+
gem "extlib"
|
48
48
|
gem "attributes"
|
49
49
|
|
50
|
-
%w(
|
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
|
-
#
|
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
|
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.
|
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.
|
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
|
-
#
|
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
|
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(
|
138
|
+
def array_of(*kinds, &block)
|
140
139
|
lambda do |node|
|
141
|
-
result = NodeFilters.filter(node,
|
142
|
-
|
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,
|
178
|
+
def self.filter(node, kinds)
|
180
179
|
nodes = []
|
181
180
|
children = node.respond_to?(:elements) ? (node.elements || []) : []
|
182
|
-
if
|
183
|
-
|
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")
|
32
|
+
parser = Extlib::Inflection.constantize(grammar.to_s + "Parser")
|
33
33
|
ast ||= grammar
|
34
34
|
parser.module_eval do
|
35
35
|
extend ParserExtension
|
data/spec/grammars/lists.rb
CHANGED
@@ -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
|
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
|
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
|
83
|
+
TestNodes.array_of(:foo).call(top).should == [top, a, b]
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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.
|
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-
|
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<
|
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<
|
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<
|
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
|
+
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-
|
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:
|
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:
|
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
|