antlr3 1.8.0 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +35 -0
- data/Manifest.txt +73 -0
- data/README.txt +6 -13
- data/java/RubyTarget.java +43 -19
- data/java/antlr-full-3.2.1.jar +0 -0
- data/lib/antlr3/debug.rb +2 -0
- data/lib/antlr3/debug/event-hub.rb +55 -55
- data/lib/antlr3/debug/record-event-listener.rb +2 -2
- data/lib/antlr3/debug/rule-tracer.rb +14 -14
- data/lib/antlr3/debug/socket.rb +47 -47
- data/lib/antlr3/debug/trace-event-listener.rb +8 -8
- data/lib/antlr3/main.rb +29 -9
- data/lib/antlr3/modes/ast-builder.rb +7 -7
- data/lib/antlr3/modes/filter.rb +19 -17
- data/lib/antlr3/profile.rb +34 -6
- data/lib/antlr3/recognizers.rb +50 -1
- data/lib/antlr3/streams.rb +19 -15
- data/lib/antlr3/streams/rewrite.rb +241 -229
- data/lib/antlr3/template/group-file-lexer.rb +6 -8
- data/lib/antlr3/template/group-file-parser.rb +16 -16
- data/lib/antlr3/template/group-file.rb +1 -1
- data/lib/antlr3/test/call-stack.rb +13 -13
- data/lib/antlr3/test/core-extensions.rb +69 -69
- data/lib/antlr3/test/functional.rb +0 -4
- data/lib/antlr3/test/grammar.rb +70 -70
- data/lib/antlr3/token.rb +41 -17
- data/lib/antlr3/tree.rb +11 -14
- data/lib/antlr3/tree/debug.rb +53 -53
- data/lib/antlr3/tree/visitor.rb +11 -11
- data/lib/antlr3/tree/wizard.rb +35 -35
- data/lib/antlr3/util.rb +18 -0
- data/lib/antlr3/version.rb +1 -1
- data/rakefile +1 -0
- data/samples/ANTLRv3Grammar.g +3 -3
- data/samples/JavaScript.g +702 -0
- data/samples/standard/C/C.g +543 -0
- data/samples/standard/C/C.tokens +175 -0
- data/samples/standard/C/C__testrig.st +0 -0
- data/samples/standard/C/c.rb +12 -0
- data/samples/standard/C/input +3479 -0
- data/samples/standard/C/output +171 -0
- data/samples/standard/LL-star/LLStar.g +101 -0
- data/samples/standard/LL-star/input +12 -0
- data/samples/standard/LL-star/ll-star.rb +12 -0
- data/samples/standard/LL-star/output +2 -0
- data/samples/standard/calc/Calculator.g +47 -0
- data/samples/standard/calc/Calculator.py +16 -0
- data/samples/standard/calc/Calculator.rb +28 -0
- data/samples/standard/cminus/CMinus.g +141 -0
- data/samples/standard/cminus/bytecode.group +80 -0
- data/samples/standard/cminus/cminus.rb +16 -0
- data/samples/standard/cminus/input +9 -0
- data/samples/standard/cminus/java.group +91 -0
- data/samples/standard/cminus/output +11 -0
- data/samples/standard/cminus/python.group +48 -0
- data/samples/standard/dynamic-scope/DynamicScopes.g +50 -0
- data/samples/standard/dynamic-scope/dynamic-scopes.rb +12 -0
- data/samples/standard/dynamic-scope/input +7 -0
- data/samples/standard/dynamic-scope/output +4 -0
- data/samples/standard/fuzzy/FuzzyJava.g +89 -0
- data/samples/standard/fuzzy/fuzzy.py +11 -0
- data/samples/standard/fuzzy/fuzzy.rb +9 -0
- data/samples/standard/fuzzy/input +13 -0
- data/samples/standard/fuzzy/output +12 -0
- data/samples/standard/hoisted-predicates/HoistedPredicates.g +40 -0
- data/samples/standard/hoisted-predicates/hoisted-predicates.rb +13 -0
- data/samples/standard/hoisted-predicates/input +1 -0
- data/samples/standard/hoisted-predicates/output +1 -0
- data/samples/standard/island-grammar/Javadoc.g +46 -0
- data/samples/standard/island-grammar/Simple.g +104 -0
- data/samples/standard/island-grammar/input +11 -0
- data/samples/standard/island-grammar/island.rb +12 -0
- data/samples/standard/island-grammar/output +16 -0
- data/samples/standard/java/Java.g +827 -0
- data/samples/standard/java/input +80 -0
- data/samples/standard/java/java.rb +13 -0
- data/samples/standard/java/output +1 -0
- data/samples/standard/python/Python.g +718 -0
- data/samples/standard/python/PythonTokenSource.rb +107 -0
- data/samples/standard/python/input +210 -0
- data/samples/standard/python/output +24 -0
- data/samples/standard/python/python.rb +14 -0
- data/samples/standard/rakefile +18 -0
- data/samples/standard/scopes/SymbolTable.g +66 -0
- data/samples/standard/scopes/input +12 -0
- data/samples/standard/scopes/output +3 -0
- data/samples/standard/scopes/scopes.rb +12 -0
- data/samples/standard/simplecTreeParser/SimpleC.g +113 -0
- data/samples/standard/simplecTreeParser/SimpleCWalker.g +64 -0
- data/samples/standard/simplecTreeParser/input +12 -0
- data/samples/standard/simplecTreeParser/output +1 -0
- data/samples/standard/simplecTreeParser/simplec.rb +18 -0
- data/samples/standard/treeparser/Lang.g +24 -0
- data/samples/standard/treeparser/LangDumpDecl.g +17 -0
- data/samples/standard/treeparser/input +1 -0
- data/samples/standard/treeparser/output +2 -0
- data/samples/standard/treeparser/treeparser.rb +18 -0
- data/samples/standard/tweak/Tweak.g +68 -0
- data/samples/standard/tweak/input +9 -0
- data/samples/standard/tweak/output +16 -0
- data/samples/standard/tweak/tweak.rb +13 -0
- data/samples/standard/xml/README +16 -0
- data/samples/standard/xml/XML.g +123 -0
- data/samples/standard/xml/input +21 -0
- data/samples/standard/xml/output +39 -0
- data/samples/standard/xml/xml.rb +9 -0
- data/templates/Ruby.stg +4 -4
- data/test/functional/ast-output/auto-ast.rb +0 -5
- data/test/functional/ast-output/rewrites.rb +4 -4
- data/test/unit/test-scope.rb +45 -0
- metadata +96 -8
data/lib/antlr3/tree/debug.rb
CHANGED
@@ -11,53 +11,53 @@ Adds debugging event hooks to TreeAdaptor objects
|
|
11
11
|
module TreeAdaptor
|
12
12
|
|
13
13
|
def self.wrap( adaptor, debug_listener = nil )
|
14
|
-
adaptor.extend(self)
|
14
|
+
adaptor.extend( self )
|
15
15
|
adaptor.debug_listener = debug_listener
|
16
16
|
return( adaptor )
|
17
17
|
end
|
18
18
|
|
19
19
|
attr_accessor :debug_listener
|
20
20
|
|
21
|
-
def create_with_payload(payload)
|
21
|
+
def create_with_payload( payload )
|
22
22
|
node = super
|
23
|
-
@debug_listener.create_node(node, payload)
|
23
|
+
@debug_listener.create_node( node, payload )
|
24
24
|
return node
|
25
25
|
end
|
26
26
|
|
27
|
-
def create_from_token(token_type, from_token, text = nil)
|
27
|
+
def create_from_token( token_type, from_token, text = nil )
|
28
28
|
node = super
|
29
|
-
@debug_listener.create_node(node)
|
29
|
+
@debug_listener.create_node( node )
|
30
30
|
return node
|
31
31
|
end
|
32
32
|
|
33
|
-
def create_from_type(token_type, text)
|
33
|
+
def create_from_type( token_type, text )
|
34
34
|
node = super
|
35
|
-
@debug_listener.create_node(node)
|
35
|
+
@debug_listener.create_node( node )
|
36
36
|
return node
|
37
37
|
end
|
38
38
|
|
39
|
-
def create_error_node(input, start, stop, exc)
|
39
|
+
def create_error_node( input, start, stop, exc )
|
40
40
|
node = super
|
41
|
-
node.nil? or @debug_listener.error_node(node)
|
41
|
+
node.nil? or @debug_listener.error_node( node )
|
42
42
|
return node
|
43
43
|
end
|
44
44
|
|
45
|
-
def copy_tree(tree)
|
45
|
+
def copy_tree( tree )
|
46
46
|
t = super
|
47
|
-
simulate_tree_construction(t)
|
47
|
+
simulate_tree_construction( t )
|
48
48
|
return t
|
49
49
|
end
|
50
50
|
|
51
|
-
def simulate_tree_construction(tree)
|
52
|
-
@debug_listener.create_node(tree)
|
53
|
-
child_count(tree).times do |i|
|
54
|
-
child = self.child_of(tree, i)
|
55
|
-
simulate_tree_construction(child)
|
56
|
-
@debug_listener.add_child(tree, child)
|
51
|
+
def simulate_tree_construction( tree )
|
52
|
+
@debug_listener.create_node( tree )
|
53
|
+
child_count( tree ).times do |i|
|
54
|
+
child = self.child_of( tree, i )
|
55
|
+
simulate_tree_construction( child )
|
56
|
+
@debug_listener.add_child( tree, child )
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def copy_node(tree_node)
|
60
|
+
def copy_node( tree_node )
|
61
61
|
duplicate = super
|
62
62
|
@debug_listener.create_node duplicate
|
63
63
|
return duplicate
|
@@ -65,39 +65,39 @@ module TreeAdaptor
|
|
65
65
|
|
66
66
|
def create_flat_list
|
67
67
|
node = super
|
68
|
-
@debug_listener.flat_node(node)
|
68
|
+
@debug_listener.flat_node( node )
|
69
69
|
return node
|
70
70
|
end
|
71
71
|
|
72
|
-
def add_child(tree, child)
|
72
|
+
def add_child( tree, child )
|
73
73
|
case child
|
74
74
|
when Token
|
75
|
-
node = create_with_payload(child)
|
76
|
-
add_child(tree, node)
|
75
|
+
node = create_with_payload( child )
|
76
|
+
add_child( tree, node )
|
77
77
|
else
|
78
78
|
tree.nil? || child.nil? and return
|
79
|
-
super(tree, child)
|
80
|
-
@debug_listener.add_child(tree, child)
|
79
|
+
super( tree, child )
|
80
|
+
@debug_listener.add_child( tree, child )
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def become_root(new_root, old_root)
|
84
|
+
def become_root( new_root, old_root )
|
85
85
|
case new_root
|
86
86
|
when Token
|
87
|
-
n = create_with_payload(new_root)
|
88
|
-
super(n, old_root)
|
87
|
+
n = create_with_payload( new_root )
|
88
|
+
super( n, old_root )
|
89
89
|
else
|
90
|
-
n = super(new_root, old_root)
|
90
|
+
n = super( new_root, old_root )
|
91
91
|
end
|
92
|
-
@debug_listener.become_root(new_root, old_root)
|
92
|
+
@debug_listener.become_root( new_root, old_root )
|
93
93
|
return n
|
94
94
|
end
|
95
95
|
|
96
|
-
def set_token_boundaries(tree, start_token, stop_token)
|
97
|
-
super(tree, start_token, stop_token)
|
96
|
+
def set_token_boundaries( tree, start_token, stop_token )
|
97
|
+
super( tree, start_token, stop_token )
|
98
98
|
return unless tree && start_token && stop_token
|
99
|
-
@debug_listener.set_token_boundaries(tree,
|
100
|
-
start_token.token_index, stop_token.token_index)
|
99
|
+
@debug_listener.set_token_boundaries( tree,
|
100
|
+
start_token.token_index, stop_token.token_index )
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -110,8 +110,8 @@ not already a Debug::TreeNodeStream.
|
|
110
110
|
=end
|
111
111
|
class TreeNodeStream
|
112
112
|
|
113
|
-
def self.wrap(stream, debug_listener = nil)
|
114
|
-
stream.extend(self)
|
113
|
+
def self.wrap( stream, debug_listener = nil )
|
114
|
+
stream.extend( self )
|
115
115
|
stream.debug_listener ||= debug_listener
|
116
116
|
end
|
117
117
|
attr_accessor :debug_listener
|
@@ -119,36 +119,36 @@ class TreeNodeStream
|
|
119
119
|
def consume
|
120
120
|
node = @input >> 1
|
121
121
|
super
|
122
|
-
@debug_listener.consume_node(node)
|
122
|
+
@debug_listener.consume_node( node )
|
123
123
|
end
|
124
124
|
|
125
|
-
def look(i = 1)
|
125
|
+
def look( i = 1 )
|
126
126
|
node = super
|
127
|
-
id = @adaptor.unique_id(node)
|
128
|
-
text = @adaptor.text_of(node)
|
129
|
-
type = @adaptor.type_of(node)
|
130
|
-
@debug_listener.look(i, node)
|
131
|
-
return(node)
|
127
|
+
id = @adaptor.unique_id( node )
|
128
|
+
text = @adaptor.text_of( node )
|
129
|
+
type = @adaptor.type_of( node )
|
130
|
+
@debug_listener.look( i, node )
|
131
|
+
return( node )
|
132
132
|
end
|
133
133
|
|
134
|
-
def peek(i = 1)
|
134
|
+
def peek( i = 1 )
|
135
135
|
node = self >> 1
|
136
|
-
id = @adaptor.unique_id(node)
|
137
|
-
text = @adaptor.text_of(node)
|
138
|
-
type = @adaptor.type_of(node)
|
139
|
-
@debug_listener.look(i, node)
|
140
|
-
return(type)
|
136
|
+
id = @adaptor.unique_id( node )
|
137
|
+
text = @adaptor.text_of( node )
|
138
|
+
type = @adaptor.type_of( node )
|
139
|
+
@debug_listener.look( i, node )
|
140
|
+
return( type )
|
141
141
|
end
|
142
142
|
|
143
143
|
def mark
|
144
144
|
@last_marker = super
|
145
|
-
@debug_listener.mark(@last_marker)
|
146
|
-
return(@last_marker)
|
145
|
+
@debug_listener.mark( @last_marker )
|
146
|
+
return( @last_marker )
|
147
147
|
end
|
148
148
|
|
149
|
-
def rewind(marker = nil)
|
150
|
-
@debug_listener.rewind(marker)
|
151
|
-
super(marker || @last_marker)
|
149
|
+
def rewind( marker = nil )
|
150
|
+
@debug_listener.rewind( marker )
|
151
|
+
super( marker || @last_marker )
|
152
152
|
end
|
153
153
|
|
154
154
|
=begin This actually differs with reset in CommonTreeNodeStream -- why is this one blank?
|
data/lib/antlr3/tree/visitor.rb
CHANGED
@@ -48,34 +48,34 @@ children have been visited.
|
|
48
48
|
=end
|
49
49
|
|
50
50
|
class Visitor
|
51
|
-
def initialize(adaptor = nil)
|
51
|
+
def initialize( adaptor = nil )
|
52
52
|
@adaptor = adaptor || CommonTreeAdaptor.new()
|
53
53
|
@pre_action = nil
|
54
54
|
@post_action = nil
|
55
|
-
block_given? and yield(self)
|
55
|
+
block_given? and yield( self )
|
56
56
|
end
|
57
57
|
|
58
|
-
def pre_action(&block)
|
58
|
+
def pre_action( &block )
|
59
59
|
block_given? and @pre_action = block
|
60
60
|
return @pre_action
|
61
61
|
end
|
62
62
|
|
63
|
-
def post_action(&block)
|
63
|
+
def post_action( &block )
|
64
64
|
block_given? and @post_action = block
|
65
65
|
return @post_action
|
66
66
|
end
|
67
67
|
|
68
|
-
def visit(tree, pre_action = nil, post_action = nil)
|
69
|
-
flat = @adaptor.flat_list?(tree)
|
68
|
+
def visit( tree, pre_action = nil, post_action = nil )
|
69
|
+
flat = @adaptor.flat_list?( tree )
|
70
70
|
before = pre_action || @pre_action
|
71
71
|
after = post_action || @post_action
|
72
72
|
|
73
|
-
tree = before.call(tree) unless before.nil? or flat
|
74
|
-
@adaptor.child_count(tree).times do |index|
|
75
|
-
child = @adaptor.child_of(tree, index)
|
76
|
-
visit(child, pre_action, post_action)
|
73
|
+
tree = before.call( tree ) unless before.nil? or flat
|
74
|
+
@adaptor.child_count( tree ).times do |index|
|
75
|
+
child = @adaptor.child_of( tree, index )
|
76
|
+
visit( child, pre_action, post_action )
|
77
77
|
end
|
78
|
-
tree = after.call(tree) unless after.nil? or flat
|
78
|
+
tree = after.call( tree ) unless after.nil? or flat
|
79
79
|
|
80
80
|
return tree
|
81
81
|
end
|
data/lib/antlr3/tree/wizard.rb
CHANGED
@@ -130,15 +130,15 @@ A class that is used internally by AST::Wizard to tokenize tree patterns
|
|
130
130
|
|
131
131
|
autoload :StringScanner, 'strscan'
|
132
132
|
|
133
|
-
PATTERNS = [
|
134
|
-
[:space, /\s+/],
|
135
|
-
[:identifier, /[a-z_]\w*/i],
|
136
|
-
[:open, /\(/],
|
137
|
-
[:close, /\)/],
|
138
|
-
[:percent, /%/],
|
139
|
-
[:colon, /:/],
|
140
|
-
[:dot, /\./],
|
141
|
-
[:argument, /\[((?:[^\[\]\\]|\\\[|\\\]|\\.)*?)\]/]
|
133
|
+
PATTERNS = [
|
134
|
+
[ :space, /\s+/ ],
|
135
|
+
[ :identifier, /[a-z_]\w*/i ],
|
136
|
+
[ :open, /\(/ ],
|
137
|
+
[ :close, /\)/ ],
|
138
|
+
[ :percent, /%/ ],
|
139
|
+
[ :colon, /:/ ],
|
140
|
+
[ :dot, /\./ ],
|
141
|
+
[ :argument, /\[((?:[^\[\]\\]|\\\[|\\\]|\\.)*?)\]/ ]
|
142
142
|
]
|
143
143
|
|
144
144
|
attr_reader :text, :error, :pattern
|
@@ -154,7 +154,7 @@ A class that is used internally by AST::Wizard to tokenize tree patterns
|
|
154
154
|
@scanner.eos? and return EOF
|
155
155
|
|
156
156
|
type, = PATTERNS.find do |type, pattern|
|
157
|
-
@scanner.scan(pattern)
|
157
|
+
@scanner.scan( pattern )
|
158
158
|
end
|
159
159
|
|
160
160
|
case type
|
@@ -164,7 +164,7 @@ A class that is used internally by AST::Wizard to tokenize tree patterns
|
|
164
164
|
when :identifier then @text = @scanner.matched
|
165
165
|
when :argument
|
166
166
|
# remove escapes from \] sequences in the text argument
|
167
|
-
(@text = @scanner[1]).gsub!(/\\(?=[\[\]])/, '')
|
167
|
+
( @text = @scanner[ 1 ] ).gsub!( /\\(?=[\[\]])/, '' )
|
168
168
|
end
|
169
169
|
end while type == :space
|
170
170
|
|
@@ -208,7 +208,7 @@ from a tokenized tree pattern
|
|
208
208
|
return nil
|
209
209
|
end
|
210
210
|
|
211
|
-
CONTINUE_TYPES = [:open, :identifier, :percent, :dot]
|
211
|
+
CONTINUE_TYPES = [ :open, :identifier, :percent, :dot ]
|
212
212
|
|
213
213
|
def parse_tree
|
214
214
|
@token_type != :open and return nil
|
@@ -219,10 +219,10 @@ from a tokenized tree pattern
|
|
219
219
|
case @token_type
|
220
220
|
when :open
|
221
221
|
subtree = parse_tree
|
222
|
-
@adaptor.add_child(root, subtree)
|
222
|
+
@adaptor.add_child( root, subtree )
|
223
223
|
when :identifier, :percent, :dot
|
224
224
|
child = parse_node or return nil
|
225
|
-
@adaptor.add_child(root, child)
|
225
|
+
@adaptor.add_child( root, child )
|
226
226
|
else break
|
227
227
|
end
|
228
228
|
end
|
@@ -234,16 +234,16 @@ from a tokenized tree pattern
|
|
234
234
|
def parse_node
|
235
235
|
label = nil
|
236
236
|
if @token_type == :percent
|
237
|
-
(@token_type = @tokenizer.next_token) == :identifier or return nil
|
237
|
+
( @token_type = @tokenizer.next_token ) == :identifier or return nil
|
238
238
|
label = @tokenizer.text
|
239
|
-
(@token_type = @tokenizer.next_token) == :colon or return nil
|
239
|
+
( @token_type = @tokenizer.next_token ) == :colon or return nil
|
240
240
|
@token_type = @tokenizer.next_token
|
241
241
|
end
|
242
242
|
|
243
243
|
if @token_type == :dot
|
244
244
|
@token_type = @tokenizer.next_token
|
245
|
-
wildcard_payload = CommonToken.create(:type => 0, :text => '.')
|
246
|
-
node = WildcardPattern.new(wildcard_payload)
|
245
|
+
wildcard_payload = CommonToken.create( :type => 0, :text => '.' )
|
246
|
+
node = WildcardPattern.new( wildcard_payload )
|
247
247
|
label and node.label = label
|
248
248
|
return node
|
249
249
|
end
|
@@ -281,7 +281,7 @@ to validate tree structures as well as to extract nodes that match the pattern.
|
|
281
281
|
|
282
282
|
class Pattern < CommonTree
|
283
283
|
def self.parse( pattern_str, scheme )
|
284
|
-
PatternParser.parse(
|
284
|
+
PatternParser.parse(
|
285
285
|
pattern_str, scheme, PatternAdaptor.new( scheme.token_class )
|
286
286
|
)
|
287
287
|
end
|
@@ -349,20 +349,20 @@ A customized TreeAdaptor used by AST::Wizards to build tree patterns.
|
|
349
349
|
|
350
350
|
def find( tree, what )
|
351
351
|
case what
|
352
|
-
when Integer then find_token_type(tree, what)
|
353
|
-
when String then find_pattern(tree, what)
|
352
|
+
when Integer then find_token_type( tree, what )
|
353
|
+
when String then find_pattern( tree, what )
|
354
354
|
when Symbol then find_token_type( tree, @token_scheme[ what ] )
|
355
355
|
else raise ArgumentError, "search subject must be a token type (integer) or a string"
|
356
356
|
end
|
357
357
|
end
|
358
358
|
|
359
|
-
def find_token_type(tree, type)
|
359
|
+
def find_token_type( tree, type )
|
360
360
|
nodes = []
|
361
361
|
visit( tree, type ) { | t, | nodes << t }
|
362
362
|
return nodes
|
363
363
|
end
|
364
364
|
|
365
|
-
def find_pattern(tree, pattern)
|
365
|
+
def find_pattern( tree, pattern )
|
366
366
|
subtrees = []
|
367
367
|
visit_pattern( tree, pattern ) { | t, | subtrees << t }
|
368
368
|
return( subtrees )
|
@@ -392,7 +392,7 @@ A customized TreeAdaptor used by AST::Wizards to build tree patterns.
|
|
392
392
|
end
|
393
393
|
|
394
394
|
def visit_type( tree, parent, type, &block )
|
395
|
-
tree.nil? and return(nil)
|
395
|
+
tree.nil? and return( nil )
|
396
396
|
index = @adaptor.child_index( tree )
|
397
397
|
@adaptor.type_of( tree ) == type and yield( tree, parent, index, nil )
|
398
398
|
@adaptor.each_child( tree ) do | child |
|
@@ -422,20 +422,20 @@ A customized TreeAdaptor used by AST::Wizards to build tree patterns.
|
|
422
422
|
def match!( tree, pattern, labels = {} )
|
423
423
|
tree.nil? || pattern.nil? and return false
|
424
424
|
unless pattern.is_a? WildcardPattern
|
425
|
-
@adaptor.type_of(tree) == pattern.type or return false
|
426
|
-
pattern.has_text_arg && (@adaptor.text_of(tree) != pattern.text) and
|
425
|
+
@adaptor.type_of( tree ) == pattern.type or return false
|
426
|
+
pattern.has_text_arg && ( @adaptor.text_of( tree ) != pattern.text ) and
|
427
427
|
return false
|
428
428
|
end
|
429
429
|
labels[ pattern.label ] = tree if labels && pattern.label
|
430
430
|
|
431
|
-
number_of_children = @adaptor.child_count(tree)
|
431
|
+
number_of_children = @adaptor.child_count( tree )
|
432
432
|
return false unless number_of_children == pattern.child_count
|
433
433
|
|
434
434
|
number_of_children.times do |index|
|
435
|
-
actual_child = @adaptor.child_of(tree, index)
|
435
|
+
actual_child = @adaptor.child_of( tree, index )
|
436
436
|
pattern_child = pattern.child( index )
|
437
437
|
|
438
|
-
return(false) unless match!( actual_child, pattern_child, labels )
|
438
|
+
return( false ) unless match!( actual_child, pattern_child, labels )
|
439
439
|
end
|
440
440
|
|
441
441
|
return labels
|
@@ -444,11 +444,11 @@ A customized TreeAdaptor used by AST::Wizards to build tree patterns.
|
|
444
444
|
def equals( tree_a, tree_b, adaptor = @adaptor )
|
445
445
|
tree_a && tree_b or return( false )
|
446
446
|
|
447
|
-
adaptor.type_of(tree_a) == adaptor.type_of(tree_b) or return false
|
448
|
-
adaptor.text_of(tree_a) == adaptor.text_of(tree_b) or return false
|
447
|
+
adaptor.type_of( tree_a ) == adaptor.type_of( tree_b ) or return false
|
448
|
+
adaptor.text_of( tree_a ) == adaptor.text_of( tree_b ) or return false
|
449
449
|
|
450
|
-
child_count_a = adaptor.child_count(tree_a)
|
451
|
-
child_count_b = adaptor.child_count(tree_b)
|
450
|
+
child_count_a = adaptor.child_count( tree_a )
|
451
|
+
child_count_b = adaptor.child_count( tree_b )
|
452
452
|
child_count_a == child_count_b or return false
|
453
453
|
|
454
454
|
child_count_a.times do | i |
|
@@ -469,9 +469,9 @@ A customized TreeAdaptor used by AST::Wizards to build tree patterns.
|
|
469
469
|
when DOUBLE_ETC_PATTERN then raise ArgumentError, "invalid syntax: ... ..."
|
470
470
|
end
|
471
471
|
|
472
|
-
context = context.gsub(/([^\.\s])\.{3}([^\.])/, '\1 ... \2')
|
472
|
+
context = context.gsub( /([^\.\s])\.{3}([^\.])/, '\1 ... \2' )
|
473
473
|
context.strip!
|
474
|
-
nodes = context.split(/\s+/)
|
474
|
+
nodes = context.split( /\s+/ )
|
475
475
|
|
476
476
|
while tree = @adaptor.parent( tree ) and node = nodes.pop
|
477
477
|
if node == '...'
|
data/lib/antlr3/util.rb
CHANGED
@@ -73,6 +73,24 @@ private
|
|
73
73
|
END
|
74
74
|
end
|
75
75
|
|
76
|
+
def deprecate( name, extra_message = nil )
|
77
|
+
hidden_name = "deprecated_#{ name }"
|
78
|
+
method_defined?( hidden_name ) and return
|
79
|
+
|
80
|
+
alias_method( hidden_name, name )
|
81
|
+
private( hidden_name )
|
82
|
+
|
83
|
+
message = "warning: method #{ self }##{ name } is deprecated"
|
84
|
+
extra_message and message << '; ' << extra_message.to_s
|
85
|
+
|
86
|
+
class_eval( <<-END )
|
87
|
+
def #{ name }( *args, &block )
|
88
|
+
warn( #{ message.inspect } )
|
89
|
+
#{ hidden_name }( *args, &block )
|
90
|
+
end
|
91
|
+
END
|
92
|
+
end
|
93
|
+
|
76
94
|
def alias_accessor( alias_name, attr_name )
|
77
95
|
alias_method( alias_name, attr_name )
|
78
96
|
alias_method( :"#{ alias_name }=", :"#{ attr_name }=" )
|