synvert-core 1.2.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +9 -0
- data/lib/synvert/core/node_query/compiler/attribute.rb +6 -18
- data/lib/synvert/core/node_query/compiler/basic_selector.rb +28 -0
- data/lib/synvert/core/node_query/compiler/comparable.rb +26 -19
- data/lib/synvert/core/node_query/compiler/expression.rb +8 -93
- data/lib/synvert/core/node_query/compiler/identifier.rb +1 -1
- data/lib/synvert/core/node_query/compiler/regexp.rb +2 -2
- data/lib/synvert/core/node_query/compiler/selector.rb +91 -34
- data/lib/synvert/core/node_query/compiler/string.rb +1 -1
- data/lib/synvert/core/node_query/compiler.rb +1 -0
- data/lib/synvert/core/node_query/lexer.rex +20 -26
- data/lib/synvert/core/node_query/lexer.rex.rb +35 -51
- data/lib/synvert/core/node_query/parser.racc.rb +115 -293
- data/lib/synvert/core/node_query/parser.y +16 -35
- data/lib/synvert/core/node_query.rb +3 -4
- data/lib/synvert/core/rewriter/action/delete_action.rb +4 -2
- data/lib/synvert/core/rewriter/action/remove_action.rb +5 -2
- data/lib/synvert/core/rewriter/instance.rb +8 -4
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_query/lexer_spec.rb +46 -106
- data/spec/synvert/core/node_query/parser_spec.rb +116 -129
- data/spec/synvert/core/rewriter/instance_spec.rb +12 -7
- data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +9 -2
- data/synvert-core-ruby.gemspec +0 -10
- metadata +3 -128
@@ -25,213 +25,116 @@ module Synvert
|
|
25
25
|
##### State transition tables begin ###
|
26
26
|
|
27
27
|
racc_action_table = [
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
nil,
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
nil, nil, 43, nil, nil, nil, nil, nil, nil, 44,
|
37
|
-
45, 46, 47, 48, 49, 50, 44, 45, 46, 47,
|
38
|
-
48, 49, 50, 44, 45, 46, 47, 48, 49, 50,
|
39
|
-
8, nil, nil, nil, 51, nil, nil, 8, nil, nil,
|
40
|
-
nil, 51, 43, nil, 8, nil, nil, nil, 51, 43,
|
41
|
-
nil, 59, nil, nil, nil, nil, 43, nil, nil, nil,
|
42
|
-
nil, nil, nil, 44, 45, 46, 47, 48, 49, 50,
|
43
|
-
44, 45, 46, 47, 48, 49, 50, 44, 45, 46,
|
44
|
-
47, 48, 49, 50, 8, nil, nil, nil, 51, nil,
|
45
|
-
nil, 8, nil, nil, nil, 51, 43, nil, 8, 63,
|
46
|
-
nil, nil, 51, 43, nil, nil, 67, nil, nil, nil,
|
47
|
-
43, nil, nil, 69, nil, nil, nil, 44, 45, 46,
|
48
|
-
47, 48, 49, 50, 44, 45, 46, 47, 48, 49,
|
49
|
-
50, 44, 45, 46, 47, 48, 49, 50, 8, nil,
|
50
|
-
nil, nil, 51, nil, nil, 8, nil, nil, nil, 51,
|
51
|
-
43, nil, 8, 71, nil, nil, nil, 43, 6, 2,
|
52
|
-
3, 4, nil, nil, nil, nil, nil, nil, nil, nil,
|
53
|
-
5, 44, 45, 46, 47, 48, 49, 50, 44, 45,
|
54
|
-
46, 47, 48, 49, 50, 8, nil, nil, nil, 8,
|
55
|
-
nil, 6, 2, 3, 4, 6, 2, 3, 4, nil,
|
56
|
-
nil, nil, 8, 5, nil, nil, 8, 5, 6, 2,
|
57
|
-
3, 4, 6, 2, 3, 4, nil, nil, nil, 8,
|
58
|
-
5, nil, nil, 8, 5, 6, 2, 3, 4, 6,
|
59
|
-
2, 3, 4, nil, nil, nil, nil, 5, nil, nil,
|
60
|
-
nil, 5, 35, 28, 30, 29, 32, 31, 34, 33,
|
61
|
-
38, 37, 36 ]
|
28
|
+
7, 7, 6, 8, 10, 34, 14, 4, 5, 15,
|
29
|
+
26, 18, 24, 19, 20, 21, 14, 38, 39, 27,
|
30
|
+
28, 29, 30, 31, 32, 33, 7, 41, 7, 6,
|
31
|
+
nil, 34, nil, 7, 4, 5, 26, nil, 34, 35,
|
32
|
+
nil, nil, nil, 26, nil, 27, 28, 29, 30, 31,
|
33
|
+
32, 33, 27, 28, 29, 30, 31, 32, 33, 7,
|
34
|
+
6, 7, 6, 7, 6, 4, 5, 4, 5, 4,
|
35
|
+
5 ]
|
62
36
|
|
63
37
|
racc_action_check = [
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
nil,
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
nil, nil, 33, nil, nil, nil, nil, nil, nil, 31,
|
73
|
-
31, 31, 31, 31, 31, 31, 32, 32, 32, 32,
|
74
|
-
32, 32, 32, 33, 33, 33, 33, 33, 33, 33,
|
75
|
-
34, nil, nil, nil, 34, nil, nil, 35, nil, nil,
|
76
|
-
nil, 35, 34, nil, 36, nil, nil, nil, 36, 35,
|
77
|
-
nil, 35, nil, nil, nil, nil, 36, nil, nil, nil,
|
78
|
-
nil, nil, nil, 34, 34, 34, 34, 34, 34, 34,
|
79
|
-
35, 35, 35, 35, 35, 35, 35, 36, 36, 36,
|
80
|
-
36, 36, 36, 36, 41, nil, nil, nil, 41, nil,
|
81
|
-
nil, 59, nil, nil, nil, 59, 41, nil, 61, 41,
|
82
|
-
nil, nil, 61, 59, nil, nil, 59, nil, nil, nil,
|
83
|
-
61, nil, nil, 61, nil, nil, nil, 41, 41, 41,
|
84
|
-
41, 41, 41, 41, 59, 59, 59, 59, 59, 59,
|
85
|
-
59, 61, 61, 61, 61, 61, 61, 61, 62, nil,
|
86
|
-
nil, nil, 62, nil, nil, 65, nil, nil, nil, 65,
|
87
|
-
62, nil, 0, 62, nil, nil, nil, 65, 0, 0,
|
88
|
-
0, 0, nil, nil, nil, nil, nil, nil, nil, nil,
|
89
|
-
0, 62, 62, 62, 62, 62, 62, 62, 65, 65,
|
90
|
-
65, 65, 65, 65, 65, 2, nil, nil, nil, 3,
|
91
|
-
nil, 2, 2, 2, 2, 3, 3, 3, 3, nil,
|
92
|
-
nil, nil, 4, 2, nil, nil, 7, 3, 4, 4,
|
93
|
-
4, 4, 7, 7, 7, 7, nil, nil, nil, 14,
|
94
|
-
4, nil, nil, 20, 7, 14, 14, 14, 14, 20,
|
95
|
-
20, 20, 20, nil, nil, nil, nil, 14, nil, nil,
|
96
|
-
nil, 20, 24, 24, 24, 24, 24, 24, 24, 24,
|
97
|
-
24, 24, 24 ]
|
38
|
+
21, 0, 0, 1, 4, 21, 7, 0, 0, 8,
|
39
|
+
21, 14, 21, 16, 17, 18, 20, 26, 36, 21,
|
40
|
+
21, 21, 21, 21, 21, 21, 24, 38, 2, 2,
|
41
|
+
nil, 24, nil, 37, 2, 2, 24, nil, 37, 24,
|
42
|
+
nil, nil, nil, 37, nil, 24, 24, 24, 24, 24,
|
43
|
+
24, 24, 37, 37, 37, 37, 37, 37, 37, 5,
|
44
|
+
5, 6, 6, 10, 10, 5, 5, 6, 6, 10,
|
45
|
+
10 ]
|
98
46
|
|
99
47
|
racc_action_pointer = [
|
100
|
-
|
101
|
-
nil, nil, nil,
|
102
|
-
|
103
|
-
|
104
|
-
nil,
|
105
|
-
nil, nil, nil, nil, nil, nil, nil, nil, nil, 169,
|
106
|
-
nil, 176, 216, nil, 7, 223, 10, nil, 9, nil,
|
107
|
-
10, nil, 12, nil, nil, nil, nil, nil, nil ]
|
48
|
+
-1, 3, 26, nil, -12, 57, 59, -4, 9, nil,
|
49
|
+
61, nil, nil, nil, 6, nil, -4, 3, -3, nil,
|
50
|
+
6, -2, nil, nil, 24, nil, -3, nil, nil, nil,
|
51
|
+
nil, nil, nil, nil, nil, nil, 3, 31, 14, nil,
|
52
|
+
nil, nil ]
|
108
53
|
|
109
54
|
racc_action_default = [
|
110
|
-
-
|
111
|
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
-14, -
|
115
|
-
-41, -42, -15, -16, -17, -18, -19, -20, -21, -43,
|
116
|
-
-22, -43, -43, -23, -43, -32, -43, -24, -43, -25,
|
117
|
-
-43, -26, -43, -27, -31, -34, -28, -29, -30 ]
|
55
|
+
-26, -26, -2, -3, -26, -26, -26, -7, -26, -1,
|
56
|
+
-26, -5, -6, -8, -26, 42, -26, -26, -26, -4,
|
57
|
+
-10, -26, -9, -11, -26, -16, -26, -18, -19, -20,
|
58
|
+
-21, -22, -23, -24, -25, -12, -26, -15, -26, -13,
|
59
|
+
-14, -17 ]
|
118
60
|
|
119
61
|
racc_goto_table = [
|
120
|
-
|
121
|
-
|
122
|
-
70, 72, 25, 7, 74, 7, 7, 7, nil, 39,
|
123
|
-
7, nil, nil, nil, nil, nil, nil, 7, nil, nil,
|
124
|
-
nil, nil, nil, 7, 40, 52, 53, 54, 55, 56,
|
125
|
-
57, 58, 60 ]
|
62
|
+
25, 13, 36, 25, 11, 12, 1, 17, 9, 16,
|
63
|
+
23, nil, nil, nil, 22, 40, 25 ]
|
126
64
|
|
127
65
|
racc_goto_check = [
|
128
|
-
|
129
|
-
|
130
|
-
6, 6, 1, 2, 6, 2, 2, 2, nil, 3,
|
131
|
-
2, nil, nil, nil, nil, nil, nil, 2, nil, nil,
|
132
|
-
nil, nil, nil, 2, 5, 5, 5, 5, 5, 5,
|
133
|
-
5, 5, 5 ]
|
66
|
+
3, 4, 7, 3, 2, 2, 1, 5, 1, 2,
|
67
|
+
6, nil, nil, nil, 4, 7, 3 ]
|
134
68
|
|
135
69
|
racc_goto_pointer = [
|
136
|
-
nil,
|
70
|
+
nil, 6, -1, -21, -6, -7, -11, -22 ]
|
137
71
|
|
138
72
|
racc_goto_default = [
|
139
|
-
nil, nil,
|
73
|
+
nil, nil, 2, 3, nil, nil, 37, nil ]
|
140
74
|
|
141
75
|
racc_reduce_table = [
|
142
76
|
0, 0, :racc_error,
|
143
|
-
2,
|
144
|
-
|
145
|
-
|
146
|
-
4,
|
147
|
-
|
148
|
-
2,
|
149
|
-
1,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
4,
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
3,
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
5, 46, :_reduce_30,
|
173
|
-
2, 48, :_reduce_31,
|
174
|
-
1, 48, :_reduce_32,
|
175
|
-
1, 47, :_reduce_none,
|
176
|
-
3, 47, :_reduce_34,
|
177
|
-
1, 47, :_reduce_35,
|
178
|
-
1, 47, :_reduce_36,
|
179
|
-
1, 47, :_reduce_37,
|
180
|
-
1, 47, :_reduce_38,
|
181
|
-
1, 47, :_reduce_39,
|
182
|
-
1, 47, :_reduce_40,
|
183
|
-
1, 47, :_reduce_41,
|
184
|
-
1, 47, :_reduce_42 ]
|
185
|
-
|
186
|
-
racc_reduce_n = 43
|
187
|
-
|
188
|
-
racc_shift_n = 79
|
77
|
+
2, 29, :_reduce_1,
|
78
|
+
1, 29, :_reduce_2,
|
79
|
+
1, 30, :_reduce_3,
|
80
|
+
4, 30, :_reduce_4,
|
81
|
+
2, 30, :_reduce_5,
|
82
|
+
2, 30, :_reduce_6,
|
83
|
+
1, 31, :_reduce_7,
|
84
|
+
2, 31, :_reduce_8,
|
85
|
+
4, 32, :_reduce_9,
|
86
|
+
3, 32, :_reduce_10,
|
87
|
+
3, 33, :_reduce_11,
|
88
|
+
4, 33, :_reduce_12,
|
89
|
+
5, 33, :_reduce_13,
|
90
|
+
2, 35, :_reduce_14,
|
91
|
+
1, 35, :_reduce_15,
|
92
|
+
1, 34, :_reduce_none,
|
93
|
+
3, 34, :_reduce_17,
|
94
|
+
1, 34, :_reduce_18,
|
95
|
+
1, 34, :_reduce_19,
|
96
|
+
1, 34, :_reduce_20,
|
97
|
+
1, 34, :_reduce_21,
|
98
|
+
1, 34, :_reduce_22,
|
99
|
+
1, 34, :_reduce_23,
|
100
|
+
1, 34, :_reduce_24,
|
101
|
+
1, 34, :_reduce_25 ]
|
102
|
+
|
103
|
+
racc_reduce_n = 26
|
104
|
+
|
105
|
+
racc_shift_n = 42
|
189
106
|
|
190
107
|
racc_token_table = {
|
191
108
|
false => 0,
|
192
109
|
:error => 1,
|
193
110
|
:tNODE_TYPE => 2,
|
194
|
-
:
|
195
|
-
:
|
196
|
-
:
|
197
|
-
:
|
198
|
-
:
|
111
|
+
:tGOTO_SCOPE => 3,
|
112
|
+
:tATTRIBUTE => 4,
|
113
|
+
:tKEY => 5,
|
114
|
+
:tIDENTIFIER => 6,
|
115
|
+
:tIDENTIFIER_VALUE => 7,
|
199
116
|
:tPSEUDO_CLASS => 8,
|
200
|
-
:
|
201
|
-
:
|
202
|
-
:
|
203
|
-
:
|
204
|
-
:
|
205
|
-
:
|
206
|
-
:
|
207
|
-
:
|
208
|
-
:
|
209
|
-
:
|
210
|
-
:
|
211
|
-
:
|
212
|
-
:
|
213
|
-
:
|
214
|
-
:
|
215
|
-
:
|
216
|
-
:
|
217
|
-
:
|
218
|
-
:
|
219
|
-
|
220
|
-
|
221
|
-
:tIN => 30,
|
222
|
-
:tNOT_IN => 31,
|
223
|
-
:tINCLUDES => 32,
|
224
|
-
:tARRAY_VALUE => 33,
|
225
|
-
:tDYNAMIC_ATTRIBUTE => 34,
|
226
|
-
:tBOOLEAN => 35,
|
227
|
-
:tFLOAT => 36,
|
228
|
-
:tINTEGER => 37,
|
229
|
-
:tNIL => 38,
|
230
|
-
:tREGEXP => 39,
|
231
|
-
:tSTRING => 40,
|
232
|
-
:tSYMBOL => 41 }
|
233
|
-
|
234
|
-
racc_nt_base = 42
|
117
|
+
:tRELATIONSHIP => 9,
|
118
|
+
:tOPEN_ATTRIBUTE => 10,
|
119
|
+
:tCLOSE_ATTRIBUTE => 11,
|
120
|
+
:tOPEN_DYNAMIC_ATTRIBUTE => 12,
|
121
|
+
:tCLOSE_DYNAMIC_ATTRIBUTE => 13,
|
122
|
+
:tOPEN_ARRAY => 14,
|
123
|
+
:tCLOSE_ARRAY => 15,
|
124
|
+
:tOPEN_SELECTOR => 16,
|
125
|
+
:tCLOSE_SELECTOR => 17,
|
126
|
+
:tOPERATOR => 18,
|
127
|
+
:tARRAY_VALUE => 19,
|
128
|
+
:tDYNAMIC_ATTRIBUTE => 20,
|
129
|
+
:tBOOLEAN => 21,
|
130
|
+
:tFLOAT => 22,
|
131
|
+
:tINTEGER => 23,
|
132
|
+
:tNIL => 24,
|
133
|
+
:tREGEXP => 25,
|
134
|
+
:tSTRING => 26,
|
135
|
+
:tSYMBOL => 27 }
|
136
|
+
|
137
|
+
racc_nt_base = 28
|
235
138
|
|
236
139
|
racc_use_result_var = false
|
237
140
|
|
@@ -255,15 +158,13 @@ Racc_token_to_s_table = [
|
|
255
158
|
"$end",
|
256
159
|
"error",
|
257
160
|
"tNODE_TYPE",
|
161
|
+
"tGOTO_SCOPE",
|
258
162
|
"tATTRIBUTE",
|
259
163
|
"tKEY",
|
260
164
|
"tIDENTIFIER",
|
261
165
|
"tIDENTIFIER_VALUE",
|
262
|
-
"tINDEX",
|
263
166
|
"tPSEUDO_CLASS",
|
264
|
-
"
|
265
|
-
"tSUBSEQUENT_SIBLING",
|
266
|
-
"tNEXT_SIBLING",
|
167
|
+
"tRELATIONSHIP",
|
267
168
|
"tOPEN_ATTRIBUTE",
|
268
169
|
"tCLOSE_ATTRIBUTE",
|
269
170
|
"tOPEN_DYNAMIC_ATTRIBUTE",
|
@@ -272,19 +173,7 @@ Racc_token_to_s_table = [
|
|
272
173
|
"tCLOSE_ARRAY",
|
273
174
|
"tOPEN_SELECTOR",
|
274
175
|
"tCLOSE_SELECTOR",
|
275
|
-
"
|
276
|
-
"tCLOSE_GOTO_SCOPE",
|
277
|
-
"tEQUAL",
|
278
|
-
"tNOT_EQUAL",
|
279
|
-
"tMATCH",
|
280
|
-
"tNOT_MATCH",
|
281
|
-
"tGREATER_THAN",
|
282
|
-
"tGREATER_THAN_OR_EQUAL",
|
283
|
-
"tLESS_THAN",
|
284
|
-
"tLESS_THAN_OR_EQUAL",
|
285
|
-
"tIN",
|
286
|
-
"tNOT_IN",
|
287
|
-
"tINCLUDES",
|
176
|
+
"tOPERATOR",
|
288
177
|
"tARRAY_VALUE",
|
289
178
|
"tDYNAMIC_ATTRIBUTE",
|
290
179
|
"tBOOLEAN",
|
@@ -297,6 +186,7 @@ Racc_token_to_s_table = [
|
|
297
186
|
"$start",
|
298
187
|
"expression",
|
299
188
|
"selector",
|
189
|
+
"basic_selector",
|
300
190
|
"attribute_list",
|
301
191
|
"attribute",
|
302
192
|
"value",
|
@@ -309,168 +199,100 @@ Racc_debug_parser = false
|
|
309
199
|
# reduce 0 omitted
|
310
200
|
|
311
201
|
def _reduce_1(val, _values)
|
312
|
-
Compiler::Expression.new(
|
202
|
+
Compiler::Expression.new(selector: val[0], rest: val[1])
|
313
203
|
end
|
314
204
|
|
315
205
|
def _reduce_2(val, _values)
|
316
|
-
Compiler::Expression.new(
|
206
|
+
Compiler::Expression.new(selector: val[0])
|
317
207
|
end
|
318
208
|
|
319
209
|
def _reduce_3(val, _values)
|
320
|
-
Compiler::
|
210
|
+
Compiler::Selector.new(basic_selector: val[0])
|
321
211
|
end
|
322
212
|
|
323
213
|
def _reduce_4(val, _values)
|
324
|
-
Compiler::
|
214
|
+
Compiler::Selector.new(pseudo_class: val[0], pseudo_selector: val[2])
|
325
215
|
end
|
326
216
|
|
327
217
|
def _reduce_5(val, _values)
|
328
|
-
Compiler::
|
218
|
+
Compiler::Selector.new(relationship: val[0], rest: val[1])
|
329
219
|
end
|
330
220
|
|
331
221
|
def _reduce_6(val, _values)
|
332
|
-
Compiler::
|
222
|
+
Compiler::Selector.new(goto_scope: val[0], rest: val[1])
|
333
223
|
end
|
334
224
|
|
335
225
|
def _reduce_7(val, _values)
|
336
|
-
Compiler::
|
226
|
+
Compiler::BasicSelector.new(node_type: val[0])
|
337
227
|
end
|
338
228
|
|
339
229
|
def _reduce_8(val, _values)
|
340
|
-
Compiler::
|
230
|
+
Compiler::BasicSelector.new(node_type: val[0], attribute_list: val[1])
|
341
231
|
end
|
342
232
|
|
343
233
|
def _reduce_9(val, _values)
|
344
|
-
Compiler::
|
234
|
+
Compiler::AttributeList.new(attribute: val[1], rest: val[3])
|
345
235
|
end
|
346
236
|
|
347
237
|
def _reduce_10(val, _values)
|
348
|
-
Compiler::
|
238
|
+
Compiler::AttributeList.new(attribute: val[1])
|
349
239
|
end
|
350
240
|
|
351
241
|
def _reduce_11(val, _values)
|
352
|
-
Compiler::
|
242
|
+
Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1])
|
353
243
|
end
|
354
244
|
|
355
245
|
def _reduce_12(val, _values)
|
356
|
-
Compiler::
|
246
|
+
Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: val[1])
|
357
247
|
end
|
358
248
|
|
359
249
|
def _reduce_13(val, _values)
|
360
|
-
Compiler::
|
250
|
+
Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1])
|
361
251
|
end
|
362
252
|
|
363
253
|
def _reduce_14(val, _values)
|
364
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :!=)
|
365
|
-
end
|
366
|
-
|
367
|
-
def _reduce_15(val, _values)
|
368
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :!~)
|
369
|
-
end
|
370
|
-
|
371
|
-
def _reduce_16(val, _values)
|
372
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :=~)
|
373
|
-
end
|
374
|
-
|
375
|
-
def _reduce_17(val, _values)
|
376
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :>=)
|
377
|
-
end
|
378
|
-
|
379
|
-
def _reduce_18(val, _values)
|
380
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :>)
|
381
|
-
end
|
382
|
-
|
383
|
-
def _reduce_19(val, _values)
|
384
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :<=)
|
385
|
-
end
|
386
|
-
|
387
|
-
def _reduce_20(val, _values)
|
388
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :<)
|
389
|
-
end
|
390
|
-
|
391
|
-
def _reduce_21(val, _values)
|
392
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :==)
|
393
|
-
end
|
394
|
-
|
395
|
-
def _reduce_22(val, _values)
|
396
|
-
Compiler::Attribute.new(key: val[0], value: val[2], operator: :includes)
|
397
|
-
end
|
398
|
-
|
399
|
-
def _reduce_23(val, _values)
|
400
|
-
Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :!=)
|
401
|
-
end
|
402
|
-
|
403
|
-
def _reduce_24(val, _values)
|
404
|
-
Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :==)
|
405
|
-
end
|
406
|
-
|
407
|
-
def _reduce_25(val, _values)
|
408
|
-
Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :not_in)
|
409
|
-
end
|
410
|
-
|
411
|
-
def _reduce_26(val, _values)
|
412
|
-
Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :in)
|
413
|
-
end
|
414
|
-
|
415
|
-
def _reduce_27(val, _values)
|
416
|
-
Compiler::Attribute.new(key: val[0], value: val[3], operator: :!=)
|
417
|
-
end
|
418
|
-
|
419
|
-
def _reduce_28(val, _values)
|
420
|
-
Compiler::Attribute.new(key: val[0], value: val[3], operator: :==)
|
421
|
-
end
|
422
|
-
|
423
|
-
def _reduce_29(val, _values)
|
424
|
-
Compiler::Attribute.new(key: val[0], value: val[3], operator: :not_in)
|
425
|
-
end
|
426
|
-
|
427
|
-
def _reduce_30(val, _values)
|
428
|
-
Compiler::Attribute.new(key: val[0], value: val[3], operator: :in)
|
429
|
-
end
|
430
|
-
|
431
|
-
def _reduce_31(val, _values)
|
432
254
|
Compiler::Array.new(value: val[0], rest: val[1])
|
433
255
|
end
|
434
256
|
|
435
|
-
def
|
257
|
+
def _reduce_15(val, _values)
|
436
258
|
Compiler::Array.new(value: val[0])
|
437
259
|
end
|
438
260
|
|
439
|
-
# reduce
|
261
|
+
# reduce 16 omitted
|
440
262
|
|
441
|
-
def
|
263
|
+
def _reduce_17(val, _values)
|
442
264
|
Compiler::DynamicAttribute.new(value: val[1])
|
443
265
|
end
|
444
266
|
|
445
|
-
def
|
267
|
+
def _reduce_18(val, _values)
|
446
268
|
Compiler::Boolean.new(value: val[0])
|
447
269
|
end
|
448
270
|
|
449
|
-
def
|
271
|
+
def _reduce_19(val, _values)
|
450
272
|
Compiler::Float.new(value: val[0])
|
451
273
|
end
|
452
274
|
|
453
|
-
def
|
275
|
+
def _reduce_20(val, _values)
|
454
276
|
Compiler::Integer.new(value: val[0])
|
455
277
|
end
|
456
278
|
|
457
|
-
def
|
279
|
+
def _reduce_21(val, _values)
|
458
280
|
Compiler::Nil.new(value: val[0])
|
459
281
|
end
|
460
282
|
|
461
|
-
def
|
283
|
+
def _reduce_22(val, _values)
|
462
284
|
Compiler::Regexp.new(value: val[0])
|
463
285
|
end
|
464
286
|
|
465
|
-
def
|
287
|
+
def _reduce_23(val, _values)
|
466
288
|
Compiler::String.new(value: val[0])
|
467
289
|
end
|
468
290
|
|
469
|
-
def
|
291
|
+
def _reduce_24(val, _values)
|
470
292
|
Compiler::Symbol.new(value: val[0])
|
471
293
|
end
|
472
294
|
|
473
|
-
def
|
295
|
+
def _reduce_25(val, _values)
|
474
296
|
Compiler::Identifier.new(value: val[0])
|
475
297
|
end
|
476
298
|
|
@@ -1,58 +1,39 @@
|
|
1
1
|
class Synvert::Core::NodeQuery::Parser
|
2
2
|
options no_result_var
|
3
|
-
token tNODE_TYPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE
|
4
|
-
tCHILD tSUBSEQUENT_SIBLING tNEXT_SIBLING
|
3
|
+
token tNODE_TYPE tGOTO_SCOPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE tPSEUDO_CLASS tRELATIONSHIP
|
5
4
|
tOPEN_ATTRIBUTE tCLOSE_ATTRIBUTE tOPEN_DYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE
|
6
|
-
tOPEN_ARRAY tCLOSE_ARRAY tOPEN_SELECTOR tCLOSE_SELECTOR
|
7
|
-
|
8
|
-
tARRAY_VALUE tDYNAMIC_ATTRIBUTE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
|
5
|
+
tOPEN_ARRAY tCLOSE_ARRAY tOPEN_SELECTOR tCLOSE_SELECTOR
|
6
|
+
tOPERATOR tARRAY_VALUE tDYNAMIC_ATTRIBUTE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
|
9
7
|
rule
|
10
8
|
expression
|
11
|
-
:
|
12
|
-
| tSUBSEQUENT_SIBLING expression { Compiler::Expression.new(rest: val[1], relationship: :subsequent_sibling) }
|
13
|
-
| tNEXT_SIBLING expression { Compiler::Expression.new(rest: val[1], relationship: :next_sibling) }
|
14
|
-
| tOPEN_GOTO_SCOPE tIDENTIFIER tCLOSE_GOTO_SCOPE expression { Compiler::Expression.new(goto_scope: val[1], rest: val[3]) }
|
15
|
-
| tPSEUDO_CLASS tOPEN_SELECTOR expression tCLOSE_SELECTOR { Compiler::Expression.new(relationship: val[0].to_sym, rest: val[2]) }
|
16
|
-
| selector expression { Compiler::Expression.new(selector: val[0], rest: val[1]) }
|
9
|
+
: selector expression { Compiler::Expression.new(selector: val[0], rest: val[1]) }
|
17
10
|
| selector { Compiler::Expression.new(selector: val[0]) }
|
18
11
|
|
19
12
|
selector
|
20
|
-
:
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
13
|
+
: basic_selector { Compiler::Selector.new(basic_selector: val[0]) }
|
14
|
+
| tPSEUDO_CLASS tOPEN_SELECTOR selector tCLOSE_SELECTOR { Compiler::Selector.new(pseudo_class: val[0], pseudo_selector: val[2]) }
|
15
|
+
| tRELATIONSHIP selector { Compiler::Selector.new(relationship: val[0], rest: val[1]) }
|
16
|
+
| tGOTO_SCOPE selector { Compiler::Selector.new(goto_scope: val[0], rest: val[1]) }
|
17
|
+
|
18
|
+
basic_selector
|
19
|
+
: tNODE_TYPE { Compiler::BasicSelector.new(node_type: val[0]) }
|
20
|
+
| tNODE_TYPE attribute_list { Compiler::BasicSelector.new(node_type: val[0], attribute_list: val[1]) }
|
25
21
|
|
26
22
|
attribute_list
|
27
23
|
: tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE attribute_list { Compiler::AttributeList.new(attribute: val[1], rest: val[3]) }
|
28
24
|
| tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE { Compiler::AttributeList.new(attribute: val[1]) }
|
29
|
-
;
|
30
25
|
|
31
26
|
attribute
|
32
|
-
: tKEY
|
33
|
-
| tKEY
|
34
|
-
| tKEY
|
35
|
-
| tKEY tGREATER_THAN_OR_EQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :>=) }
|
36
|
-
| tKEY tGREATER_THAN value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :>) }
|
37
|
-
| tKEY tLESS_THAN_OR_EQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :<=) }
|
38
|
-
| tKEY tLESS_THAN value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :<) }
|
39
|
-
| tKEY tEQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :==) }
|
40
|
-
| tKEY tINCLUDES value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :includes) }
|
41
|
-
| tKEY tNOT_EQUAL tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :!=) }
|
42
|
-
| tKEY tEQUAL tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :==) }
|
43
|
-
| tKEY tNOT_IN tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :not_in) }
|
44
|
-
| tKEY tIN tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :in) }
|
45
|
-
| tKEY tNOT_EQUAL tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :!=) }
|
46
|
-
| tKEY tEQUAL tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :==) }
|
47
|
-
| tKEY tNOT_IN tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :not_in) }
|
48
|
-
| tKEY tIN tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :in) }
|
27
|
+
: tKEY tOPERATOR value { Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1]) }
|
28
|
+
| tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: val[1]) }
|
29
|
+
| tKEY tOPERATOR tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1]) }
|
49
30
|
|
50
31
|
array_value
|
51
32
|
: value array_value { Compiler::Array.new(value: val[0], rest: val[1]) }
|
52
33
|
| value { Compiler::Array.new(value: val[0]) }
|
53
34
|
|
54
35
|
value
|
55
|
-
:
|
36
|
+
: basic_selector
|
56
37
|
| tOPEN_DYNAMIC_ATTRIBUTE tDYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE { Compiler::DynamicAttribute.new(value: val[1]) }
|
57
38
|
| tBOOLEAN { Compiler::Boolean.new(value: val[0]) }
|
58
39
|
| tFLOAT { Compiler::Float.new(value: val[0]) }
|
@@ -9,12 +9,10 @@
|
|
9
9
|
# * attribute regex: <code>.send[key=~/\A:([^'"]+)\z/]</code>, <code>.send[key!~/\A:([^'"]+)\z/]</code>
|
10
10
|
# * attribute conditions: +.send[message != nil]+, +.send[value > 1]+, +.send[value >= 1]+, +.send[value < 1]+, +.send[value <= 1]+
|
11
11
|
# * nested attribute: +.send[caller.message = map]+, +.send[arguments.size = 2]+
|
12
|
-
# * first or last child: +.def:first-child+, +.send:last-child+
|
13
|
-
# * nth-child or nth-last-child: +.def:nth-child(2)+, +.send:nth-last-child(2)+
|
14
12
|
# * descendant: +.class .send+
|
15
13
|
# * child: +.class > .def+
|
16
|
-
# * following sibling: <code>.def
|
17
|
-
# * subsequnt sibling: +.def
|
14
|
+
# * following sibling: <code>.def + .def</code>
|
15
|
+
# * subsequnt sibling: +.def ~ .def+
|
18
16
|
# * has: +.class:has(.def)+
|
19
17
|
#
|
20
18
|
# It also supports some custom selectors:
|
@@ -26,6 +24,7 @@
|
|
26
24
|
# * NOT IN operator: +.send[message NOT IN (create build)]+
|
27
25
|
# * INCLUDES operator: +.send[arguments INCLUDES &block]+
|
28
26
|
# * dynamic attribute value: +.hash > .pair[key={{value}}]+
|
27
|
+
# * goto scope: +.class body > .def+
|
29
28
|
#
|
30
29
|
# @example
|
31
30
|
# # it matches methods call nodes, like `puts message` or `p message`
|
@@ -7,9 +7,11 @@ module Synvert::Core
|
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::Instance]
|
9
9
|
# @param selectors [Array<Symbol, String>] used to select child nodes
|
10
|
-
|
10
|
+
# @option and_comma [Boolean] delete extra comma.
|
11
|
+
def initialize(instance, *selectors, and_comma: false)
|
11
12
|
super(instance, nil)
|
12
13
|
@selectors = selectors
|
14
|
+
@and_comma = and_comma
|
13
15
|
end
|
14
16
|
|
15
17
|
# The rewritten code, always empty string.
|
@@ -26,7 +28,7 @@ module Synvert::Core
|
|
26
28
|
@end_pos = @selectors.map { |selector| @node.child_node_range(selector) }
|
27
29
|
.compact.map(&:end_pos).max
|
28
30
|
squeeze_spaces
|
29
|
-
remove_comma
|
31
|
+
remove_comma if @and_comma
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|