rubocop-ast 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/ast.rb +17 -0
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +44 -125
- data/lib/rubocop/ast/node/array_node.rb +1 -0
- data/lib/rubocop/ast/node/block_node.rb +1 -0
- data/lib/rubocop/ast/node/def_node.rb +5 -0
- data/lib/rubocop/ast/node/keyword_splat_node.rb +1 -0
- data/lib/rubocop/ast/node/mixin/collection_node.rb +1 -0
- data/lib/rubocop/ast/node/mixin/descendence.rb +116 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +2 -0
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +9 -0
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +1 -0
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +7 -3
- data/lib/rubocop/ast/node/pair_node.rb +4 -0
- data/lib/rubocop/ast/node/regexp_node.rb +9 -4
- data/lib/rubocop/ast/node_pattern.rb +44 -870
- data/lib/rubocop/ast/node_pattern/builder.rb +72 -0
- data/lib/rubocop/ast/node_pattern/comment.rb +45 -0
- data/lib/rubocop/ast/node_pattern/compiler.rb +104 -0
- data/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb +56 -0
- data/lib/rubocop/ast/node_pattern/compiler/binding.rb +78 -0
- data/lib/rubocop/ast/node_pattern/compiler/debug.rb +168 -0
- data/lib/rubocop/ast/node_pattern/compiler/node_pattern_subcompiler.rb +146 -0
- data/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb +420 -0
- data/lib/rubocop/ast/node_pattern/compiler/subcompiler.rb +57 -0
- data/lib/rubocop/ast/node_pattern/lexer.rb +70 -0
- data/lib/rubocop/ast/node_pattern/lexer.rex +39 -0
- data/lib/rubocop/ast/node_pattern/lexer.rex.rb +182 -0
- data/lib/rubocop/ast/node_pattern/method_definer.rb +143 -0
- data/lib/rubocop/ast/node_pattern/node.rb +275 -0
- data/lib/rubocop/ast/node_pattern/parser.racc.rb +470 -0
- data/lib/rubocop/ast/node_pattern/parser.rb +66 -0
- data/lib/rubocop/ast/node_pattern/parser.y +103 -0
- data/lib/rubocop/ast/node_pattern/sets.rb +37 -0
- data/lib/rubocop/ast/node_pattern/with_meta.rb +111 -0
- data/lib/rubocop/ast/processed_source.rb +5 -1
- data/lib/rubocop/ast/traversal.rb +149 -172
- data/lib/rubocop/ast/version.rb +1 -1
- metadata +37 -3
@@ -0,0 +1,275 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
class NodePattern
|
6
|
+
# Base class for AST Nodes of a `NodePattern`
|
7
|
+
class Node < ::Parser::AST::Node
|
8
|
+
extend Forwardable
|
9
|
+
include ::RuboCop::AST::Descendence
|
10
|
+
|
11
|
+
MATCHES_WITHIN_SET = %i[symbol number string].to_set.freeze
|
12
|
+
private_constant :MATCHES_WITHIN_SET
|
13
|
+
|
14
|
+
###
|
15
|
+
# To be overriden by subclasses
|
16
|
+
###
|
17
|
+
|
18
|
+
def rest?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def capture?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Integer, Range] An Integer for fixed length terms, otherwise a Range.
|
27
|
+
# Note: `arity.end` may be `Float::INFINITY`
|
28
|
+
def arity
|
29
|
+
1
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Array<Node>, nil] replace node with result, or `nil` if no change requested.
|
33
|
+
def in_sequence_head
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
###
|
38
|
+
# Utilities
|
39
|
+
###
|
40
|
+
|
41
|
+
# @return [Array<Node>]
|
42
|
+
def children_nodes
|
43
|
+
children.grep(Node)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Node] most nodes have only one child
|
47
|
+
def child
|
48
|
+
children[0]
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Integer] nb of captures of that node and its descendants
|
52
|
+
def nb_captures
|
53
|
+
children_nodes.sum(&:nb_captures)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Boolean] returns true iff matches variable number of elements
|
57
|
+
def variadic?
|
58
|
+
arity.is_a?(Range)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Boolean] returns true for nodes having a Ruby literal equivalent
|
62
|
+
# that matches withing a Set (e.g. `42`, `:sym` but not `/regexp/`)
|
63
|
+
def matches_within_set?
|
64
|
+
MATCHES_WITHIN_SET.include?(type)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Range] arity as a Range
|
68
|
+
def arity_range
|
69
|
+
a = arity
|
70
|
+
a.is_a?(Range) ? a : INT_TO_RANGE[a]
|
71
|
+
end
|
72
|
+
|
73
|
+
def with(type: @type, children: @children, location: @location)
|
74
|
+
self.class.new(type, children, { location: location })
|
75
|
+
end
|
76
|
+
|
77
|
+
INT_TO_RANGE = Hash.new { |h, k| h[k] = k..k }
|
78
|
+
private_constant :INT_TO_RANGE
|
79
|
+
|
80
|
+
# :nodoc:
|
81
|
+
module ForbidInSeqHead
|
82
|
+
def in_sequence_head
|
83
|
+
raise NodePattern::Invalid, "A sequence can not start with a #{type}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
###
|
88
|
+
# Subclasses for specific node types
|
89
|
+
###
|
90
|
+
|
91
|
+
# Node class for `$something`
|
92
|
+
class Capture < Node
|
93
|
+
# Delegate most introspection methods to it's only child
|
94
|
+
def_delegators :child, :arity, :rest?
|
95
|
+
|
96
|
+
def capture?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
def nb_captures
|
101
|
+
1 + super
|
102
|
+
end
|
103
|
+
|
104
|
+
def in_sequence_head
|
105
|
+
wildcard, original_child = child.in_sequence_head
|
106
|
+
return unless original_child
|
107
|
+
|
108
|
+
[wildcard, self] # ($...) => (_ $...)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Node class for `(type first second ...)`
|
113
|
+
class Sequence < Node
|
114
|
+
include ForbidInSeqHead
|
115
|
+
|
116
|
+
def initialize(type, children = [], properties = {})
|
117
|
+
if (replace = children.first.in_sequence_head)
|
118
|
+
children = [*replace, *children[1..-1]]
|
119
|
+
end
|
120
|
+
|
121
|
+
super
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Node class for `predicate?(:arg, :list)`
|
126
|
+
class Predicate < Node
|
127
|
+
def method_name
|
128
|
+
children.first
|
129
|
+
end
|
130
|
+
|
131
|
+
def arg_list
|
132
|
+
children[1..-1]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
FunctionCall = Predicate
|
136
|
+
|
137
|
+
# Node class for `int+`
|
138
|
+
class Repetition < Node
|
139
|
+
include ForbidInSeqHead
|
140
|
+
|
141
|
+
def operator
|
142
|
+
children[1]
|
143
|
+
end
|
144
|
+
|
145
|
+
ARITIES = {
|
146
|
+
'*': 0..Float::INFINITY,
|
147
|
+
'+': 1..Float::INFINITY,
|
148
|
+
'?': 0..1
|
149
|
+
}.freeze
|
150
|
+
|
151
|
+
def arity
|
152
|
+
ARITIES[operator]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Node class for `...`
|
157
|
+
class Rest < Node
|
158
|
+
ARITY = (0..Float::INFINITY).freeze
|
159
|
+
private_constant :ARITY
|
160
|
+
|
161
|
+
def rest?
|
162
|
+
true
|
163
|
+
end
|
164
|
+
|
165
|
+
def arity
|
166
|
+
ARITY
|
167
|
+
end
|
168
|
+
|
169
|
+
def in_sequence_head
|
170
|
+
[Node.new(:wildcard), self]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Node class for `<int str ...>`
|
175
|
+
class AnyOrder < Node
|
176
|
+
include ForbidInSeqHead
|
177
|
+
|
178
|
+
ARITIES = Hash.new { |h, k| h[k] = k - 1..Float::INFINITY }
|
179
|
+
private_constant :ARITIES
|
180
|
+
|
181
|
+
def term_nodes
|
182
|
+
ends_with_rest? ? children[0...-1] : children
|
183
|
+
end
|
184
|
+
|
185
|
+
def ends_with_rest?
|
186
|
+
children.last.rest?
|
187
|
+
end
|
188
|
+
|
189
|
+
def rest_node
|
190
|
+
children.last if ends_with_rest?
|
191
|
+
end
|
192
|
+
|
193
|
+
def arity
|
194
|
+
return children.size unless ends_with_rest?
|
195
|
+
|
196
|
+
ARITIES[children.size]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Circumvent broken `Range#minmax` for infinity ranges in 2.6-
|
201
|
+
module MapMinMax
|
202
|
+
if RUBY_VERSION >= '2.7'
|
203
|
+
def map_min_max(enum)
|
204
|
+
enum.map(&:minmax)
|
205
|
+
end
|
206
|
+
else
|
207
|
+
def map_min_max(enum)
|
208
|
+
enum.map { |r| [r.min, r.max] } # rubocop:disable Style/MinMax
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# A list (potentially empty) of nodes; part of a Union
|
214
|
+
class Subsequence < Node
|
215
|
+
include ForbidInSeqHead
|
216
|
+
include MapMinMax
|
217
|
+
|
218
|
+
def arity
|
219
|
+
min, max = map_min_max(children.map(&:arity_range)).transpose.map(&:sum)
|
220
|
+
min == max ? min || 0 : min..max # Note: || 0 for empty case, where min == max == nil.
|
221
|
+
end
|
222
|
+
|
223
|
+
def in_sequence_head
|
224
|
+
super if children.empty?
|
225
|
+
|
226
|
+
return unless (replace = children.first.in_sequence_head)
|
227
|
+
|
228
|
+
[with(children: [*replace, *children[1..-1]])]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Node class for `{ ... }`
|
233
|
+
class Union < Node
|
234
|
+
include MapMinMax
|
235
|
+
|
236
|
+
def arity
|
237
|
+
minima, maxima = map_min_max(children.map(&:arity_range)).transpose
|
238
|
+
min = minima.min
|
239
|
+
max = maxima.max
|
240
|
+
min == max ? min : min..max
|
241
|
+
end
|
242
|
+
|
243
|
+
def in_sequence_head
|
244
|
+
return unless children.any?(&:in_sequence_head)
|
245
|
+
|
246
|
+
new_children = children.map do |child|
|
247
|
+
next child unless (replace = child.in_sequence_head)
|
248
|
+
|
249
|
+
if replace.size > 1
|
250
|
+
Subsequence.new(:subsequence, replace, loc: child.loc)
|
251
|
+
else
|
252
|
+
replace.first
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
[with(children: new_children)]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
# Registry
|
261
|
+
MAP = Hash.new(Node).merge!(
|
262
|
+
sequence: Sequence,
|
263
|
+
repetition: Repetition,
|
264
|
+
rest: Rest,
|
265
|
+
capture: Capture,
|
266
|
+
predicate: Predicate,
|
267
|
+
any_order: AnyOrder,
|
268
|
+
function_call: FunctionCall,
|
269
|
+
subsequence: Subsequence,
|
270
|
+
union: Union
|
271
|
+
).freeze
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,470 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# DO NOT MODIFY!!!!
|
4
|
+
# This file is automatically generated by Racc 1.4.16
|
5
|
+
# from Racc grammar file "".
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'racc/parser.rb'
|
9
|
+
module RuboCop
|
10
|
+
module AST
|
11
|
+
class NodePattern
|
12
|
+
class Parser < Racc::Parser
|
13
|
+
##### State transition tables begin ###
|
14
|
+
|
15
|
+
racc_action_table = [
|
16
|
+
14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
|
17
|
+
60, 22, 20, 4, 40, 5, 43, 6, 7, 8,
|
18
|
+
28, 23, 56, 50, 66, 61, 24, 51, 51, 40,
|
19
|
+
58, 14, 15, 16, 21, 18, 17, 19, 10, 11,
|
20
|
+
12, nil, 22, 20, 4, nil, 5, nil, 6, 7,
|
21
|
+
8, 28, 23, nil, nil, -34, 14, 15, 16, 21,
|
22
|
+
18, 17, 19, 10, 11, 12, nil, 22, 20, 4,
|
23
|
+
nil, 5, nil, 6, 7, 8, 9, 23, 14, 15,
|
24
|
+
16, 21, 18, 17, 19, 10, 11, 12, nil, 22,
|
25
|
+
20, 4, nil, 5, nil, 6, 7, 8, 9, 23,
|
26
|
+
14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
|
27
|
+
nil, 22, 20, 4, nil, 5, nil, 6, 7, 8,
|
28
|
+
9, 23, 14, 15, 16, 21, 18, 17, 19, 10,
|
29
|
+
11, 12, nil, 22, 20, 4, nil, 5, nil, 6,
|
30
|
+
7, 8, 9, 23, 14, 15, 16, 21, 18, 17,
|
31
|
+
19, 10, 11, 12, nil, 22, 20, 4, nil, 5,
|
32
|
+
nil, 6, 7, 8, 9, 23, 14, 15, 16, 21,
|
33
|
+
18, 17, 19, 10, 11, 12, nil, 22, 20, 4,
|
34
|
+
nil, 5, nil, 6, 7, 8, 9, 23, 14, 15,
|
35
|
+
16, 21, 18, 17, 19, 10, 11, 12, nil, 22,
|
36
|
+
20, 4, nil, 5, nil, 6, 7, 8, 28, 23,
|
37
|
+
14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
|
38
|
+
nil, 22, 20, 4, 44, 5, nil, 6, 7, 8,
|
39
|
+
28, 23, 14, 15, 16, 21, 18, 17, 19, 10,
|
40
|
+
11, 12, nil, 22, 20, 4, nil, 5, nil, 6,
|
41
|
+
7, 8, 9, 23, 14, 15, 16, 21, 18, 17,
|
42
|
+
19, 10, 11, 12, nil, 22, 20, 4, nil, 5,
|
43
|
+
52, 6, 7, 8, 9, 23, 14, 15, 16, 21,
|
44
|
+
18, 17, 19, 10, 11, 12, nil, 22, 20, 4,
|
45
|
+
nil, 5, nil, 6, 7, 8, 9, 23, 14, 15,
|
46
|
+
16, 21, 18, 17, 19, 10, 11, 12, nil, 22,
|
47
|
+
20, 4, nil, 5, nil, 6, 7, 8, 9, 23,
|
48
|
+
14, 15, 16, 21, 18, 17, 19, 10, 11, 12,
|
49
|
+
nil, 22, 20, 4, nil, 5, nil, 6, 7, 8,
|
50
|
+
9, 23, 47, 48, 49, -1, -1, -1, -2, -2,
|
51
|
+
-2 ]
|
52
|
+
|
53
|
+
racc_action_check = [
|
54
|
+
42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
|
55
|
+
54, 42, 42, 42, 11, 42, 24, 42, 42, 42,
|
56
|
+
42, 42, 42, 30, 62, 54, 1, 63, 30, 10,
|
57
|
+
42, 59, 59, 59, 59, 59, 59, 59, 59, 59,
|
58
|
+
59, nil, 59, 59, 59, nil, 59, nil, 59, 59,
|
59
|
+
59, 59, 59, nil, nil, 59, 5, 5, 5, 5,
|
60
|
+
5, 5, 5, 5, 5, 5, nil, 5, 5, 5,
|
61
|
+
nil, 5, nil, 5, 5, 5, 5, 5, 6, 6,
|
62
|
+
6, 6, 6, 6, 6, 6, 6, 6, nil, 6,
|
63
|
+
6, 6, nil, 6, nil, 6, 6, 6, 6, 6,
|
64
|
+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
65
|
+
nil, 7, 7, 7, nil, 7, nil, 7, 7, 7,
|
66
|
+
7, 7, 8, 8, 8, 8, 8, 8, 8, 8,
|
67
|
+
8, 8, nil, 8, 8, 8, nil, 8, nil, 8,
|
68
|
+
8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
|
69
|
+
9, 9, 9, 9, nil, 9, 9, 9, nil, 9,
|
70
|
+
nil, 9, 9, 9, 9, 9, 0, 0, 0, 0,
|
71
|
+
0, 0, 0, 0, 0, 0, nil, 0, 0, 0,
|
72
|
+
nil, 0, nil, 0, 0, 0, 0, 0, 4, 4,
|
73
|
+
4, 4, 4, 4, 4, 4, 4, 4, nil, 4,
|
74
|
+
4, 4, nil, 4, nil, 4, 4, 4, 4, 4,
|
75
|
+
27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
76
|
+
nil, 27, 27, 27, 27, 27, nil, 27, 27, 27,
|
77
|
+
27, 27, 28, 28, 28, 28, 28, 28, 28, 28,
|
78
|
+
28, 28, nil, 28, 28, 28, nil, 28, nil, 28,
|
79
|
+
28, 28, 28, 28, 33, 33, 33, 33, 33, 33,
|
80
|
+
33, 33, 33, 33, nil, 33, 33, 33, nil, 33,
|
81
|
+
33, 33, 33, 33, 33, 33, 40, 40, 40, 40,
|
82
|
+
40, 40, 40, 40, 40, 40, nil, 40, 40, 40,
|
83
|
+
nil, 40, nil, 40, 40, 40, 40, 40, 50, 50,
|
84
|
+
50, 50, 50, 50, 50, 50, 50, 50, nil, 50,
|
85
|
+
50, 50, nil, 50, nil, 50, 50, 50, 50, 50,
|
86
|
+
61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
|
87
|
+
nil, 61, 61, 61, nil, 61, nil, 61, 61, 61,
|
88
|
+
61, 61, 29, 29, 29, 25, 25, 25, 26, 26,
|
89
|
+
26 ]
|
90
|
+
|
91
|
+
racc_action_pointer = [
|
92
|
+
164, 26, nil, nil, 186, 54, 76, 98, 120, 142,
|
93
|
+
17, 2, nil, nil, nil, nil, nil, nil, nil, nil,
|
94
|
+
nil, nil, nil, nil, 16, 318, 321, 208, 230, 315,
|
95
|
+
-2, nil, nil, 252, nil, nil, nil, nil, nil, nil,
|
96
|
+
274, nil, -2, nil, nil, nil, nil, nil, nil, nil,
|
97
|
+
296, nil, nil, nil, -6, nil, nil, nil, nil, 29,
|
98
|
+
nil, 318, -2, -3, nil, nil, nil ]
|
99
|
+
|
100
|
+
racc_action_default = [
|
101
|
+
-47, -47, -1, -2, -31, -47, -47, -47, -47, -47,
|
102
|
+
-36, -36, -11, -12, -13, -14, -15, -16, -17, -18,
|
103
|
+
-19, -20, -21, -44, -47, -23, -24, -31, -32, -47,
|
104
|
+
-47, -27, -42, -47, -40, -5, -6, -7, -8, -9,
|
105
|
+
-47, -10, -31, 67, -3, -43, -25, -28, -29, -30,
|
106
|
+
-47, -33, -4, -41, -47, -38, -22, -45, -46, -31,
|
107
|
+
-37, -47, -47, -47, -35, -39, -26 ]
|
108
|
+
|
109
|
+
racc_goto_table = [
|
110
|
+
1, 33, 64, 32, 25, 34, 35, 36, 37, 38,
|
111
|
+
54, 26, 39, 41, 27, 42, 46, 63, 62, nil,
|
112
|
+
nil, nil, nil, nil, nil, nil, 45, 25, 38, nil,
|
113
|
+
nil, nil, nil, 53, 26, nil, nil, nil, nil, nil,
|
114
|
+
55, 57, 25, nil, nil, nil, 59, nil, nil, 26,
|
115
|
+
34, nil, nil, nil, nil, nil, nil, nil, nil, 53,
|
116
|
+
nil, 65 ]
|
117
|
+
|
118
|
+
racc_goto_check = [
|
119
|
+
1, 5, 13, 9, 2, 1, 1, 1, 1, 1,
|
120
|
+
14, 3, 6, 6, 4, 8, 10, 11, 12, nil,
|
121
|
+
nil, nil, nil, nil, nil, nil, 9, 2, 1, nil,
|
122
|
+
nil, nil, nil, 1, 3, nil, nil, nil, nil, nil,
|
123
|
+
1, 9, 2, nil, nil, nil, 5, nil, nil, 3,
|
124
|
+
1, nil, nil, nil, nil, nil, nil, nil, nil, 1,
|
125
|
+
nil, 1 ]
|
126
|
+
|
127
|
+
racc_goto_pointer = [
|
128
|
+
nil, 0, 0, 7, 10, -4, 2, nil, -8, -1,
|
129
|
+
-13, -42, -41, -57, -30 ]
|
130
|
+
|
131
|
+
racc_goto_default = [
|
132
|
+
nil, 29, 2, 3, nil, nil, nil, 13, nil, nil,
|
133
|
+
nil, 30, nil, 31, nil ]
|
134
|
+
|
135
|
+
racc_reduce_table = [
|
136
|
+
0, 0, :racc_error,
|
137
|
+
1, 34, :_reduce_none,
|
138
|
+
1, 34, :_reduce_2,
|
139
|
+
3, 35, :_reduce_3,
|
140
|
+
3, 35, :_reduce_4,
|
141
|
+
2, 35, :_reduce_5,
|
142
|
+
2, 35, :_reduce_6,
|
143
|
+
2, 35, :_reduce_7,
|
144
|
+
2, 35, :_reduce_8,
|
145
|
+
2, 35, :_reduce_9,
|
146
|
+
2, 35, :_reduce_10,
|
147
|
+
1, 35, :_reduce_11,
|
148
|
+
1, 35, :_reduce_none,
|
149
|
+
1, 40, :_reduce_13,
|
150
|
+
1, 40, :_reduce_14,
|
151
|
+
1, 40, :_reduce_15,
|
152
|
+
1, 40, :_reduce_16,
|
153
|
+
1, 40, :_reduce_17,
|
154
|
+
1, 40, :_reduce_18,
|
155
|
+
1, 40, :_reduce_19,
|
156
|
+
1, 40, :_reduce_20,
|
157
|
+
1, 40, :_reduce_21,
|
158
|
+
3, 36, :_reduce_22,
|
159
|
+
1, 42, :_reduce_none,
|
160
|
+
1, 42, :_reduce_none,
|
161
|
+
2, 42, :_reduce_25,
|
162
|
+
5, 42, :_reduce_26,
|
163
|
+
1, 42, :_reduce_none,
|
164
|
+
1, 43, :_reduce_none,
|
165
|
+
1, 43, :_reduce_none,
|
166
|
+
1, 43, :_reduce_none,
|
167
|
+
0, 44, :_reduce_none,
|
168
|
+
1, 44, :_reduce_none,
|
169
|
+
2, 46, :_reduce_33,
|
170
|
+
0, 45, :_reduce_none,
|
171
|
+
1, 45, :_reduce_none,
|
172
|
+
0, 39, :_reduce_none,
|
173
|
+
3, 39, :_reduce_37,
|
174
|
+
1, 47, :_reduce_38,
|
175
|
+
3, 47, :_reduce_39,
|
176
|
+
1, 38, :_reduce_40,
|
177
|
+
2, 38, :_reduce_41,
|
178
|
+
1, 37, :_reduce_42,
|
179
|
+
2, 37, :_reduce_43,
|
180
|
+
0, 41, :_reduce_44,
|
181
|
+
2, 41, :_reduce_45,
|
182
|
+
2, 41, :_reduce_46 ]
|
183
|
+
|
184
|
+
racc_reduce_n = 47
|
185
|
+
|
186
|
+
racc_shift_n = 67
|
187
|
+
|
188
|
+
racc_token_table = {
|
189
|
+
false => 0,
|
190
|
+
:error => 1,
|
191
|
+
:tSYMBOL => 2,
|
192
|
+
:tNUMBER => 3,
|
193
|
+
:tSTRING => 4,
|
194
|
+
:tWILDCARD => 5,
|
195
|
+
:tPARAM_NAMED => 6,
|
196
|
+
:tPARAM_CONST => 7,
|
197
|
+
:tPARAM_NUMBER => 8,
|
198
|
+
:tFUNCTION_CALL => 9,
|
199
|
+
:tPREDICATE => 10,
|
200
|
+
:tNODE_TYPE => 11,
|
201
|
+
:tARG_LIST => 12,
|
202
|
+
:tUNIFY => 13,
|
203
|
+
:tREGEXP => 14,
|
204
|
+
"(" => 15,
|
205
|
+
")" => 16,
|
206
|
+
"[" => 17,
|
207
|
+
"]" => 18,
|
208
|
+
"!" => 19,
|
209
|
+
"^" => 20,
|
210
|
+
"`" => 21,
|
211
|
+
"$" => 22,
|
212
|
+
"{" => 23,
|
213
|
+
"}" => 24,
|
214
|
+
"<" => 25,
|
215
|
+
">" => 26,
|
216
|
+
"?" => 27,
|
217
|
+
"*" => 28,
|
218
|
+
"+" => 29,
|
219
|
+
"..." => 30,
|
220
|
+
"," => 31,
|
221
|
+
"|" => 32 }
|
222
|
+
|
223
|
+
racc_nt_base = 33
|
224
|
+
|
225
|
+
racc_use_result_var = false
|
226
|
+
|
227
|
+
Racc_arg = [
|
228
|
+
racc_action_table,
|
229
|
+
racc_action_check,
|
230
|
+
racc_action_default,
|
231
|
+
racc_action_pointer,
|
232
|
+
racc_goto_table,
|
233
|
+
racc_goto_check,
|
234
|
+
racc_goto_default,
|
235
|
+
racc_goto_pointer,
|
236
|
+
racc_nt_base,
|
237
|
+
racc_reduce_table,
|
238
|
+
racc_token_table,
|
239
|
+
racc_shift_n,
|
240
|
+
racc_reduce_n,
|
241
|
+
racc_use_result_var ]
|
242
|
+
|
243
|
+
Racc_token_to_s_table = [
|
244
|
+
"$end",
|
245
|
+
"error",
|
246
|
+
"tSYMBOL",
|
247
|
+
"tNUMBER",
|
248
|
+
"tSTRING",
|
249
|
+
"tWILDCARD",
|
250
|
+
"tPARAM_NAMED",
|
251
|
+
"tPARAM_CONST",
|
252
|
+
"tPARAM_NUMBER",
|
253
|
+
"tFUNCTION_CALL",
|
254
|
+
"tPREDICATE",
|
255
|
+
"tNODE_TYPE",
|
256
|
+
"tARG_LIST",
|
257
|
+
"tUNIFY",
|
258
|
+
"tREGEXP",
|
259
|
+
"\"(\"",
|
260
|
+
"\")\"",
|
261
|
+
"\"[\"",
|
262
|
+
"\"]\"",
|
263
|
+
"\"!\"",
|
264
|
+
"\"^\"",
|
265
|
+
"\"`\"",
|
266
|
+
"\"$\"",
|
267
|
+
"\"{\"",
|
268
|
+
"\"}\"",
|
269
|
+
"\"<\"",
|
270
|
+
"\">\"",
|
271
|
+
"\"?\"",
|
272
|
+
"\"*\"",
|
273
|
+
"\"+\"",
|
274
|
+
"\"...\"",
|
275
|
+
"\",\"",
|
276
|
+
"\"|\"",
|
277
|
+
"$start",
|
278
|
+
"node_pattern",
|
279
|
+
"node_pattern_no_union",
|
280
|
+
"union",
|
281
|
+
"variadic_pattern_list",
|
282
|
+
"node_pattern_list",
|
283
|
+
"args",
|
284
|
+
"atom",
|
285
|
+
"separated_variadic_patterns",
|
286
|
+
"variadic_pattern",
|
287
|
+
"repetition",
|
288
|
+
"opt_capture",
|
289
|
+
"opt_rest",
|
290
|
+
"rest",
|
291
|
+
"arg_list" ]
|
292
|
+
|
293
|
+
Racc_debug_parser = false
|
294
|
+
|
295
|
+
##### State transition tables end #####
|
296
|
+
|
297
|
+
# reduce 0 omitted
|
298
|
+
|
299
|
+
# reduce 1 omitted
|
300
|
+
|
301
|
+
def _reduce_2(val, _values)
|
302
|
+
enforce_unary(val[0])
|
303
|
+
end
|
304
|
+
|
305
|
+
def _reduce_3(val, _values)
|
306
|
+
emit_list :sequence, *val
|
307
|
+
end
|
308
|
+
|
309
|
+
def _reduce_4(val, _values)
|
310
|
+
emit_list :intersection, *val
|
311
|
+
end
|
312
|
+
|
313
|
+
def _reduce_5(val, _values)
|
314
|
+
emit_unary_op :negation, *val
|
315
|
+
end
|
316
|
+
|
317
|
+
def _reduce_6(val, _values)
|
318
|
+
emit_unary_op :ascend, *val
|
319
|
+
end
|
320
|
+
|
321
|
+
def _reduce_7(val, _values)
|
322
|
+
emit_unary_op :descend, *val
|
323
|
+
end
|
324
|
+
|
325
|
+
def _reduce_8(val, _values)
|
326
|
+
emit_capture(*val)
|
327
|
+
end
|
328
|
+
|
329
|
+
def _reduce_9(val, _values)
|
330
|
+
emit_call :function_call, *val
|
331
|
+
end
|
332
|
+
|
333
|
+
def _reduce_10(val, _values)
|
334
|
+
emit_call :predicate, *val
|
335
|
+
end
|
336
|
+
|
337
|
+
def _reduce_11(val, _values)
|
338
|
+
emit_call :node_type, *val
|
339
|
+
end
|
340
|
+
|
341
|
+
# reduce 12 omitted
|
342
|
+
|
343
|
+
def _reduce_13(val, _values)
|
344
|
+
emit_atom :symbol, *val
|
345
|
+
end
|
346
|
+
|
347
|
+
def _reduce_14(val, _values)
|
348
|
+
emit_atom :number, *val
|
349
|
+
end
|
350
|
+
|
351
|
+
def _reduce_15(val, _values)
|
352
|
+
emit_atom :string, *val
|
353
|
+
end
|
354
|
+
|
355
|
+
def _reduce_16(val, _values)
|
356
|
+
emit_atom :const, *val
|
357
|
+
end
|
358
|
+
|
359
|
+
def _reduce_17(val, _values)
|
360
|
+
emit_atom :named_parameter, *val
|
361
|
+
end
|
362
|
+
|
363
|
+
def _reduce_18(val, _values)
|
364
|
+
emit_atom :positional_parameter, *val
|
365
|
+
end
|
366
|
+
|
367
|
+
def _reduce_19(val, _values)
|
368
|
+
emit_atom :regexp, *val
|
369
|
+
end
|
370
|
+
|
371
|
+
def _reduce_20(val, _values)
|
372
|
+
emit_atom :wildcard, *val
|
373
|
+
end
|
374
|
+
|
375
|
+
def _reduce_21(val, _values)
|
376
|
+
emit_atom :unify, *val
|
377
|
+
end
|
378
|
+
|
379
|
+
def _reduce_22(val, _values)
|
380
|
+
emit_union(*val)
|
381
|
+
end
|
382
|
+
|
383
|
+
# reduce 23 omitted
|
384
|
+
|
385
|
+
# reduce 24 omitted
|
386
|
+
|
387
|
+
def _reduce_25(val, _values)
|
388
|
+
main, repeat_t = val
|
389
|
+
emit_unary_op(:repetition, repeat_t, main, repeat_t)
|
390
|
+
|
391
|
+
end
|
392
|
+
|
393
|
+
def _reduce_26(val, _values)
|
394
|
+
opt_capture, bracket, node_pattern_list, opt_rest, close_bracket = val
|
395
|
+
node_pattern_list << opt_rest if opt_rest
|
396
|
+
main = emit_list :any_order, bracket, node_pattern_list, close_bracket
|
397
|
+
emit_capture(opt_capture, main)
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
# reduce 27 omitted
|
402
|
+
|
403
|
+
# reduce 28 omitted
|
404
|
+
|
405
|
+
# reduce 29 omitted
|
406
|
+
|
407
|
+
# reduce 30 omitted
|
408
|
+
|
409
|
+
# reduce 31 omitted
|
410
|
+
|
411
|
+
# reduce 32 omitted
|
412
|
+
|
413
|
+
def _reduce_33(val, _values)
|
414
|
+
emit_capture(val[0], emit_atom(:rest, val[1]))
|
415
|
+
end
|
416
|
+
|
417
|
+
# reduce 34 omitted
|
418
|
+
|
419
|
+
# reduce 35 omitted
|
420
|
+
|
421
|
+
# reduce 36 omitted
|
422
|
+
|
423
|
+
def _reduce_37(val, _values)
|
424
|
+
val
|
425
|
+
end
|
426
|
+
|
427
|
+
def _reduce_38(val, _values)
|
428
|
+
val
|
429
|
+
end
|
430
|
+
|
431
|
+
def _reduce_39(val, _values)
|
432
|
+
val[0] << val[2]
|
433
|
+
end
|
434
|
+
|
435
|
+
def _reduce_40(val, _values)
|
436
|
+
val
|
437
|
+
end
|
438
|
+
|
439
|
+
def _reduce_41(val, _values)
|
440
|
+
val[0] << val[1]
|
441
|
+
end
|
442
|
+
|
443
|
+
def _reduce_42(val, _values)
|
444
|
+
val
|
445
|
+
end
|
446
|
+
|
447
|
+
def _reduce_43(val, _values)
|
448
|
+
val[0] << val[1]
|
449
|
+
end
|
450
|
+
|
451
|
+
def _reduce_44(val, _values)
|
452
|
+
[[]]
|
453
|
+
end
|
454
|
+
|
455
|
+
def _reduce_45(val, _values)
|
456
|
+
val[0].last << val[1]; val[0]
|
457
|
+
end
|
458
|
+
|
459
|
+
def _reduce_46(val, _values)
|
460
|
+
val[0] << []
|
461
|
+
end
|
462
|
+
|
463
|
+
def _reduce_none(val, _values)
|
464
|
+
val[0]
|
465
|
+
end
|
466
|
+
|
467
|
+
end # class Parser
|
468
|
+
end # class NodePattern
|
469
|
+
end # module AST
|
470
|
+
end # module RuboCop
|