synvert-core 1.1.1 → 1.3.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 +18 -0
- data/Gemfile +9 -0
- data/lib/synvert/core/array_ext.rb +9 -2
- data/lib/synvert/core/node_ext.rb +14 -2
- data/lib/synvert/core/node_query/compiler/array.rb +1 -1
- data/lib/synvert/core/node_query/compiler/attribute.rb +6 -18
- data/lib/synvert/core/node_query/compiler/comparable.rb +26 -19
- data/lib/synvert/core/node_query/compiler/expression.rb +22 -52
- 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 +116 -31
- data/lib/synvert/core/node_query/compiler/simple_selector.rb +29 -0
- 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 +27 -17
- data/lib/synvert/core/node_query/lexer.rex.rb +53 -29
- data/lib/synvert/core/node_query/parser.racc.rb +119 -315
- data/lib/synvert/core/node_query/parser.y +20 -42
- data/lib/synvert/core/node_query.rb +7 -7
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +7 -5
- data/spec/synvert/core/node_query/lexer_spec.rb +76 -50
- data/spec/synvert/core/node_query/parser_spec.rb +181 -114
- data/spec/synvert/core/rewriter/instance_spec.rb +3 -3
- data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +3 -3
- data/synvert-core-ruby.gemspec +0 -10
- metadata +3 -128
@@ -5,10 +5,10 @@
|
|
5
5
|
# It supports the following selectors:
|
6
6
|
#
|
7
7
|
# * AST node type: +.class+, +.send+
|
8
|
-
# * attribute value:
|
9
|
-
# * attribute regex: <code
|
10
|
-
# * attribute conditions:
|
11
|
-
# * nested attribute:
|
8
|
+
# * attribute value: +.send[receiver = nil]+, +.send[message = create]+
|
9
|
+
# * attribute regex: <code>.send[key=~/\A:([^'"]+)\z/]</code>, <code>.send[key!~/\A:([^'"]+)\z/]</code>
|
10
|
+
# * attribute conditions: +.send[message != nil]+, +.send[value > 1]+, +.send[value >= 1]+, +.send[value < 1]+, +.send[value <= 1]+
|
11
|
+
# * nested attribute: +.send[caller.message = map]+, +.send[arguments.size = 2]+
|
12
12
|
# * first or last child: +.def:first-child+, +.send:last-child+
|
13
13
|
# * nth-child or nth-last-child: +.def:nth-child(2)+, +.send:nth-last-child(2)+
|
14
14
|
# * descendant: +.class .send+
|
@@ -21,9 +21,9 @@
|
|
21
21
|
#
|
22
22
|
# * not_has: +.class:not_has(.def)+, it's same as +:not(:has())+ in css, just to make implementation easy.
|
23
23
|
# * nested selector: +.send[arguments = [size = 2][first = .sym][last = .hash]]+
|
24
|
-
# * array value: +.send[arguments = (a
|
25
|
-
# * IN operator: +.send[message IN (try
|
26
|
-
# * NOT IN operator: +.send[message NOT IN (create
|
24
|
+
# * array value: +.send[arguments = (a b)]+
|
25
|
+
# * IN operator: +.send[message IN (try try!)]+
|
26
|
+
# * NOT IN operator: +.send[message NOT IN (create build)]+
|
27
27
|
# * INCLUDES operator: +.send[arguments INCLUDES &block]+
|
28
28
|
# * dynamic attribute value: +.hash > .pair[key={{value}}]+
|
29
29
|
#
|
data/lib/synvert/core/version.rb
CHANGED
@@ -1033,7 +1033,7 @@ describe Parser::AST::Node do
|
|
1033
1033
|
node = parse(<<~EOS)
|
1034
1034
|
class Synvert
|
1035
1035
|
def foobar(foo, bar)
|
1036
|
-
foo
|
1036
|
+
{ foo => bar }
|
1037
1037
|
end
|
1038
1038
|
end
|
1039
1039
|
EOS
|
@@ -1056,10 +1056,12 @@ describe Parser::AST::Node do
|
|
1056
1056
|
],
|
1057
1057
|
body: [
|
1058
1058
|
{
|
1059
|
-
type: :
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1059
|
+
type: :hash,
|
1060
|
+
pairs: {
|
1061
|
+
type: :pair,
|
1062
|
+
key: { type: :lvar, name: :foo },
|
1063
|
+
value: { type: :lvar, name: :bar }
|
1064
|
+
}
|
1063
1065
|
}
|
1064
1066
|
]
|
1065
1067
|
}
|
@@ -29,7 +29,7 @@ module Synvert::Core::NodeQuery
|
|
29
29
|
[:tNODE_TYPE, "send"],
|
30
30
|
[:tOPEN_ATTRIBUTE, "["],
|
31
31
|
[:tKEY, "message"],
|
32
|
-
[:
|
32
|
+
[:tOPERATOR, "=="],
|
33
33
|
[:tIDENTIFIER_VALUE, "create"],
|
34
34
|
[:tCLOSE_ATTRIBUTE, "]"]
|
35
35
|
]
|
@@ -42,7 +42,7 @@ module Synvert::Core::NodeQuery
|
|
42
42
|
[:tNODE_TYPE, "send"],
|
43
43
|
[:tOPEN_ATTRIBUTE, "["],
|
44
44
|
[:tKEY, "receiver"],
|
45
|
-
[:
|
45
|
+
[:tOPERATOR, "=="],
|
46
46
|
[:tNIL, nil],
|
47
47
|
[:tCLOSE_ATTRIBUTE, "]"]
|
48
48
|
]
|
@@ -55,7 +55,7 @@ module Synvert::Core::NodeQuery
|
|
55
55
|
[:tNODE_TYPE, "send"],
|
56
56
|
[:tOPEN_ATTRIBUTE, "["],
|
57
57
|
[:tKEY, "message"],
|
58
|
-
[:
|
58
|
+
[:tOPERATOR, "=="],
|
59
59
|
[:tSTRING, "create"],
|
60
60
|
[:tCLOSE_ATTRIBUTE, "]"]
|
61
61
|
]
|
@@ -68,7 +68,7 @@ module Synvert::Core::NodeQuery
|
|
68
68
|
[:tNODE_TYPE, "send"],
|
69
69
|
[:tOPEN_ATTRIBUTE, "["],
|
70
70
|
[:tKEY, "message"],
|
71
|
-
[:
|
71
|
+
[:tOPERATOR, "=="],
|
72
72
|
[:tSTRING, "[]"],
|
73
73
|
[:tCLOSE_ATTRIBUTE, "]"]
|
74
74
|
]
|
@@ -81,7 +81,7 @@ module Synvert::Core::NodeQuery
|
|
81
81
|
[:tNODE_TYPE, "send"],
|
82
82
|
[:tOPEN_ATTRIBUTE, "["],
|
83
83
|
[:tKEY, "message"],
|
84
|
-
[:
|
84
|
+
[:tOPERATOR, "=="],
|
85
85
|
[:tSYMBOL, :create],
|
86
86
|
[:tCLOSE_ATTRIBUTE, "]"]
|
87
87
|
]
|
@@ -93,7 +93,7 @@ module Synvert::Core::NodeQuery
|
|
93
93
|
expected_tokens = [
|
94
94
|
[:tOPEN_ATTRIBUTE, "["],
|
95
95
|
[:tKEY, "value"],
|
96
|
-
[:
|
96
|
+
[:tOPERATOR, "=="],
|
97
97
|
[:tINTEGER, 1],
|
98
98
|
[:tCLOSE_ATTRIBUTE, "]"]
|
99
99
|
]
|
@@ -106,7 +106,7 @@ module Synvert::Core::NodeQuery
|
|
106
106
|
[:tNODE_TYPE, "send"],
|
107
107
|
[:tOPEN_ATTRIBUTE, "["],
|
108
108
|
[:tKEY, "value"],
|
109
|
-
[:
|
109
|
+
[:tOPERATOR, "=="],
|
110
110
|
[:tFLOAT, 1.1],
|
111
111
|
[:tCLOSE_ATTRIBUTE, "]"]
|
112
112
|
]
|
@@ -119,7 +119,7 @@ module Synvert::Core::NodeQuery
|
|
119
119
|
[:tNODE_TYPE, "send"],
|
120
120
|
[:tOPEN_ATTRIBUTE, "["],
|
121
121
|
[:tKEY, "value"],
|
122
|
-
[:
|
122
|
+
[:tOPERATOR, "=="],
|
123
123
|
[:tBOOLEAN, true],
|
124
124
|
[:tCLOSE_ATTRIBUTE, "]"]
|
125
125
|
]
|
@@ -132,7 +132,7 @@ module Synvert::Core::NodeQuery
|
|
132
132
|
[:tNODE_TYPE, "send"],
|
133
133
|
[:tOPEN_ATTRIBUTE, "["],
|
134
134
|
[:tKEY, "message"],
|
135
|
-
[:
|
135
|
+
[:tOPERATOR, "=="],
|
136
136
|
[:tIDENTIFIER_VALUE, "create!"],
|
137
137
|
[:tCLOSE_ATTRIBUTE, "]"]
|
138
138
|
]
|
@@ -145,7 +145,7 @@ module Synvert::Core::NodeQuery
|
|
145
145
|
[:tNODE_TYPE, "send"],
|
146
146
|
[:tOPEN_ATTRIBUTE, "["],
|
147
147
|
[:tKEY, "message"],
|
148
|
-
[:
|
148
|
+
[:tOPERATOR, "=="],
|
149
149
|
[:tIDENTIFIER_VALUE, "empty?"],
|
150
150
|
[:tCLOSE_ATTRIBUTE, "]"]
|
151
151
|
]
|
@@ -158,7 +158,7 @@ module Synvert::Core::NodeQuery
|
|
158
158
|
[:tNODE_TYPE, "send"],
|
159
159
|
[:tOPEN_ATTRIBUTE, "["],
|
160
160
|
[:tKEY, "message"],
|
161
|
-
[:
|
161
|
+
[:tOPERATOR, "=="],
|
162
162
|
[:tIDENTIFIER_VALUE, "<"],
|
163
163
|
[:tCLOSE_ATTRIBUTE, "]"]
|
164
164
|
]
|
@@ -169,7 +169,7 @@ module Synvert::Core::NodeQuery
|
|
169
169
|
[:tNODE_TYPE, "send"],
|
170
170
|
[:tOPEN_ATTRIBUTE, "["],
|
171
171
|
[:tKEY, "message"],
|
172
|
-
[:
|
172
|
+
[:tOPERATOR, "=="],
|
173
173
|
[:tIDENTIFIER_VALUE, "="],
|
174
174
|
[:tCLOSE_ATTRIBUTE, "]"]
|
175
175
|
]
|
@@ -180,7 +180,7 @@ module Synvert::Core::NodeQuery
|
|
180
180
|
[:tNODE_TYPE, "send"],
|
181
181
|
[:tOPEN_ATTRIBUTE, "["],
|
182
182
|
[:tKEY, "message"],
|
183
|
-
[:
|
183
|
+
[:tOPERATOR, "=="],
|
184
184
|
[:tIDENTIFIER_VALUE, ">"],
|
185
185
|
[:tCLOSE_ATTRIBUTE, "]"]
|
186
186
|
]
|
@@ -193,7 +193,7 @@ module Synvert::Core::NodeQuery
|
|
193
193
|
[:tNODE_TYPE, "send"],
|
194
194
|
[:tOPEN_ATTRIBUTE, "["],
|
195
195
|
[:tKEY, "arguments.first"],
|
196
|
-
[:
|
196
|
+
[:tOPERATOR, "=="],
|
197
197
|
[:tSTRING, ""],
|
198
198
|
[:tCLOSE_ATTRIBUTE, "]"]
|
199
199
|
]
|
@@ -206,7 +206,7 @@ module Synvert::Core::NodeQuery
|
|
206
206
|
[:tNODE_TYPE, "send"],
|
207
207
|
[:tOPEN_ATTRIBUTE, "["],
|
208
208
|
[:tKEY, "message"],
|
209
|
-
[:
|
209
|
+
[:tOPERATOR, "=="],
|
210
210
|
[:tIDENTIFIER_VALUE, "[]"],
|
211
211
|
[:tCLOSE_ATTRIBUTE, "]"]
|
212
212
|
]
|
@@ -219,20 +219,33 @@ module Synvert::Core::NodeQuery
|
|
219
219
|
[:tNODE_TYPE, "send"],
|
220
220
|
[:tOPEN_ATTRIBUTE, "["],
|
221
221
|
[:tKEY, "message"],
|
222
|
-
[:
|
222
|
+
[:tOPERATOR, "=="],
|
223
223
|
[:tSYMBOL, :[]=],
|
224
224
|
[:tCLOSE_ATTRIBUTE, "]"]
|
225
225
|
]
|
226
226
|
assert_tokens source, expected_tokens
|
227
227
|
end
|
228
228
|
|
229
|
+
it 'matches nil?' do
|
230
|
+
source = ".send[message=nil?]"
|
231
|
+
expected_tokens = [
|
232
|
+
[:tNODE_TYPE, "send"],
|
233
|
+
[:tOPEN_ATTRIBUTE, "["],
|
234
|
+
[:tKEY, "message"],
|
235
|
+
[:tOPERATOR, "=="],
|
236
|
+
[:tIDENTIFIER_VALUE, "nil?"],
|
237
|
+
[:tCLOSE_ATTRIBUTE, "]"]
|
238
|
+
]
|
239
|
+
assert_tokens source, expected_tokens
|
240
|
+
end
|
241
|
+
|
229
242
|
it 'matches attribute value' do
|
230
243
|
source = '.pair[key={{value}}]'
|
231
244
|
expected_tokens = [
|
232
245
|
[:tNODE_TYPE, "pair"],
|
233
246
|
[:tOPEN_ATTRIBUTE, "["],
|
234
247
|
[:tKEY, "key"],
|
235
|
-
[:
|
248
|
+
[:tOPERATOR, "=="],
|
236
249
|
[:tOPEN_DYNAMIC_ATTRIBUTE, "{{"],
|
237
250
|
[:tDYNAMIC_ATTRIBUTE, "value"],
|
238
251
|
[:tCLOSE_DYNAMIC_ATTRIBUTE, "}}"],
|
@@ -252,11 +265,11 @@ module Synvert::Core::NodeQuery
|
|
252
265
|
[:tNODE_TYPE, "send"],
|
253
266
|
[:tOPEN_ATTRIBUTE, "["],
|
254
267
|
[:tKEY, "receiver"],
|
255
|
-
[:
|
268
|
+
[:tOPERATOR, "=="],
|
256
269
|
[:tNODE_TYPE, "send"],
|
257
270
|
[:tOPEN_ATTRIBUTE, "["],
|
258
271
|
[:tKEY, "message"],
|
259
|
-
[:
|
272
|
+
[:tOPERATOR, "=="],
|
260
273
|
[:tSYMBOL, :create],
|
261
274
|
[:tCLOSE_ATTRIBUTE, "]"],
|
262
275
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -274,20 +287,20 @@ module Synvert::Core::NodeQuery
|
|
274
287
|
[:tNODE_TYPE, "send"],
|
275
288
|
[:tOPEN_ATTRIBUTE, "["],
|
276
289
|
[:tKEY, "arguments"],
|
277
|
-
[:
|
290
|
+
[:tOPERATOR, "=="],
|
278
291
|
[:tOPEN_ATTRIBUTE, "["],
|
279
292
|
[:tKEY, "size"],
|
280
|
-
[:
|
293
|
+
[:tOPERATOR, "=="],
|
281
294
|
[:tINTEGER, 2],
|
282
295
|
[:tCLOSE_ATTRIBUTE, "]"],
|
283
296
|
[:tOPEN_ATTRIBUTE, "["],
|
284
297
|
[:tKEY, "first"],
|
285
|
-
[:
|
298
|
+
[:tOPERATOR, "=="],
|
286
299
|
[:tNODE_TYPE, "str"],
|
287
300
|
[:tCLOSE_ATTRIBUTE, "]"],
|
288
301
|
[:tOPEN_ATTRIBUTE, "["],
|
289
302
|
[:tKEY, "last"],
|
290
|
-
[:
|
303
|
+
[:tOPERATOR, "=="],
|
291
304
|
[:tNODE_TYPE, "str"],
|
292
305
|
[:tCLOSE_ATTRIBUTE, "]"],
|
293
306
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -303,7 +316,7 @@ module Synvert::Core::NodeQuery
|
|
303
316
|
[:tNODE_TYPE, "send"],
|
304
317
|
[:tOPEN_ATTRIBUTE, "["],
|
305
318
|
[:tKEY, "message"],
|
306
|
-
[:
|
319
|
+
[:tOPERATOR, "!="],
|
307
320
|
[:tIDENTIFIER_VALUE, "create"],
|
308
321
|
[:tCLOSE_ATTRIBUTE, "]"]
|
309
322
|
]
|
@@ -315,7 +328,7 @@ module Synvert::Core::NodeQuery
|
|
315
328
|
expected_tokens = [
|
316
329
|
[:tOPEN_ATTRIBUTE, "["],
|
317
330
|
[:tKEY, "value"],
|
318
|
-
[:
|
331
|
+
[:tOPERATOR, ">"],
|
319
332
|
[:tINTEGER, 1],
|
320
333
|
[:tCLOSE_ATTRIBUTE, "]"]
|
321
334
|
]
|
@@ -327,7 +340,7 @@ module Synvert::Core::NodeQuery
|
|
327
340
|
expected_tokens = [
|
328
341
|
[:tOPEN_ATTRIBUTE, "["],
|
329
342
|
[:tKEY, "value"],
|
330
|
-
[:
|
343
|
+
[:tOPERATOR, "<"],
|
331
344
|
[:tINTEGER, 1],
|
332
345
|
[:tCLOSE_ATTRIBUTE, "]"]
|
333
346
|
]
|
@@ -339,7 +352,7 @@ module Synvert::Core::NodeQuery
|
|
339
352
|
expected_tokens = [
|
340
353
|
[:tOPEN_ATTRIBUTE, "["],
|
341
354
|
[:tKEY, "value"],
|
342
|
-
[:
|
355
|
+
[:tOPERATOR, ">="],
|
343
356
|
[:tINTEGER, 1],
|
344
357
|
[:tCLOSE_ATTRIBUTE, "]"]
|
345
358
|
]
|
@@ -351,7 +364,7 @@ module Synvert::Core::NodeQuery
|
|
351
364
|
expected_tokens = [
|
352
365
|
[:tOPEN_ATTRIBUTE, "["],
|
353
366
|
[:tKEY, "value"],
|
354
|
-
[:
|
367
|
+
[:tOPERATOR, "<="],
|
355
368
|
[:tINTEGER, 1],
|
356
369
|
[:tCLOSE_ATTRIBUTE, "]"]
|
357
370
|
]
|
@@ -364,7 +377,7 @@ module Synvert::Core::NodeQuery
|
|
364
377
|
[:tNODE_TYPE, "send"],
|
365
378
|
[:tOPEN_ATTRIBUTE, "["],
|
366
379
|
[:tKEY, "message"],
|
367
|
-
[:
|
380
|
+
[:tOPERATOR, "=~"],
|
368
381
|
[:tREGEXP, /create/i],
|
369
382
|
[:tCLOSE_ATTRIBUTE, "]"]
|
370
383
|
]
|
@@ -377,7 +390,7 @@ module Synvert::Core::NodeQuery
|
|
377
390
|
[:tNODE_TYPE, "send"],
|
378
391
|
[:tOPEN_ATTRIBUTE, "["],
|
379
392
|
[:tKEY, "message"],
|
380
|
-
[:
|
393
|
+
[:tOPERATOR, "!~"],
|
381
394
|
[:tREGEXP, /create/i],
|
382
395
|
[:tCLOSE_ATTRIBUTE, "]"]
|
383
396
|
]
|
@@ -390,7 +403,7 @@ module Synvert::Core::NodeQuery
|
|
390
403
|
[:tNODE_TYPE, "send"],
|
391
404
|
[:tOPEN_ATTRIBUTE, "["],
|
392
405
|
[:tKEY, "arguments"],
|
393
|
-
[:
|
406
|
+
[:tOPERATOR, "=="],
|
394
407
|
[:tOPEN_ARRAY, "("],
|
395
408
|
[:tCLOSE_ARRAY, ")"],
|
396
409
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -404,7 +417,7 @@ module Synvert::Core::NodeQuery
|
|
404
417
|
[:tNODE_TYPE, "send"],
|
405
418
|
[:tOPEN_ATTRIBUTE, "["],
|
406
419
|
[:tKEY, "arguments"],
|
407
|
-
[:
|
420
|
+
[:tOPERATOR, "=="],
|
408
421
|
[:tOPEN_ARRAY, "("],
|
409
422
|
[:tSYMBOL, :create],
|
410
423
|
[:tCLOSE_ARRAY, ")"],
|
@@ -419,7 +432,7 @@ module Synvert::Core::NodeQuery
|
|
419
432
|
[:tNODE_TYPE, "send"],
|
420
433
|
[:tOPEN_ATTRIBUTE, "["],
|
421
434
|
[:tKEY, "arguments"],
|
422
|
-
[:
|
435
|
+
[:tOPERATOR, "!="],
|
423
436
|
[:tOPEN_ARRAY, "("],
|
424
437
|
[:tSYMBOL, :create],
|
425
438
|
[:tCLOSE_ARRAY, ")"],
|
@@ -429,15 +442,14 @@ module Synvert::Core::NodeQuery
|
|
429
442
|
end
|
430
443
|
|
431
444
|
it 'matches IN' do
|
432
|
-
source = '.send[message IN (create
|
445
|
+
source = '.send[message IN (create build)]'
|
433
446
|
expected_tokens = [
|
434
447
|
[:tNODE_TYPE, "send"],
|
435
448
|
[:tOPEN_ATTRIBUTE, "["],
|
436
449
|
[:tKEY, "message"],
|
437
|
-
[:
|
450
|
+
[:tOPERATOR, "in"],
|
438
451
|
[:tOPEN_ARRAY, "("],
|
439
452
|
[:tIDENTIFIER_VALUE, "create"],
|
440
|
-
[:tCOMMA, ","],
|
441
453
|
[:tIDENTIFIER_VALUE, "build"],
|
442
454
|
[:tCLOSE_ARRAY, ")"],
|
443
455
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -446,15 +458,14 @@ module Synvert::Core::NodeQuery
|
|
446
458
|
end
|
447
459
|
|
448
460
|
it 'matches NOT IN' do
|
449
|
-
source = '.send[message NOT IN (create
|
461
|
+
source = '.send[message NOT IN (create build)]'
|
450
462
|
expected_tokens = [
|
451
463
|
[:tNODE_TYPE, "send"],
|
452
464
|
[:tOPEN_ATTRIBUTE, "["],
|
453
465
|
[:tKEY, "message"],
|
454
|
-
[:
|
466
|
+
[:tOPERATOR, "not_in"],
|
455
467
|
[:tOPEN_ARRAY, "("],
|
456
468
|
[:tIDENTIFIER_VALUE, "create"],
|
457
|
-
[:tCOMMA, ","],
|
458
469
|
[:tIDENTIFIER_VALUE, "build"],
|
459
470
|
[:tCLOSE_ARRAY, ")"],
|
460
471
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -468,7 +479,7 @@ module Synvert::Core::NodeQuery
|
|
468
479
|
[:tNODE_TYPE, "send"],
|
469
480
|
[:tOPEN_ATTRIBUTE, "["],
|
470
481
|
[:tKEY, "arguments"],
|
471
|
-
[:
|
482
|
+
[:tOPERATOR, "includes"],
|
472
483
|
[:tIDENTIFIER_VALUE, "&block"],
|
473
484
|
[:tCLOSE_ATTRIBUTE, "]"]
|
474
485
|
]
|
@@ -483,7 +494,7 @@ module Synvert::Core::NodeQuery
|
|
483
494
|
[:tNODE_TYPE, "send"],
|
484
495
|
[:tOPEN_ATTRIBUTE, "["],
|
485
496
|
[:tKEY, "receiver.message"],
|
486
|
-
[:
|
497
|
+
[:tOPERATOR, "=="],
|
487
498
|
[:tSYMBOL, :create],
|
488
499
|
[:tCLOSE_ATTRIBUTE, "]"]
|
489
500
|
]
|
@@ -498,7 +509,7 @@ module Synvert::Core::NodeQuery
|
|
498
509
|
[:tNODE_TYPE, "send"],
|
499
510
|
[:tOPEN_ATTRIBUTE, "["],
|
500
511
|
[:tKEY, "arguments"],
|
501
|
-
[:
|
512
|
+
[:tOPERATOR, "=="],
|
502
513
|
[:tSYMBOL, :create],
|
503
514
|
[:tCLOSE_ATTRIBUTE, "]"],
|
504
515
|
[:tINDEX, 0]
|
@@ -512,7 +523,7 @@ module Synvert::Core::NodeQuery
|
|
512
523
|
[:tNODE_TYPE, "send"],
|
513
524
|
[:tOPEN_ATTRIBUTE, "["],
|
514
525
|
[:tKEY, "arguments"],
|
515
|
-
[:
|
526
|
+
[:tOPERATOR, "=="],
|
516
527
|
[:tSYMBOL, :create],
|
517
528
|
[:tCLOSE_ATTRIBUTE, "]"],
|
518
529
|
[:tINDEX, -1]
|
@@ -526,7 +537,7 @@ module Synvert::Core::NodeQuery
|
|
526
537
|
[:tNODE_TYPE, "send"],
|
527
538
|
[:tOPEN_ATTRIBUTE, "["],
|
528
539
|
[:tKEY, "arguments"],
|
529
|
-
[:
|
540
|
+
[:tOPERATOR, "=="],
|
530
541
|
[:tSYMBOL, :create],
|
531
542
|
[:tCLOSE_ATTRIBUTE, "]"],
|
532
543
|
[:tINDEX, 0]
|
@@ -540,7 +551,7 @@ module Synvert::Core::NodeQuery
|
|
540
551
|
[:tNODE_TYPE, "send"],
|
541
552
|
[:tOPEN_ATTRIBUTE, "["],
|
542
553
|
[:tKEY, "arguments"],
|
543
|
-
[:
|
554
|
+
[:tOPERATOR, "=="],
|
544
555
|
[:tSYMBOL, :create],
|
545
556
|
[:tCLOSE_ATTRIBUTE, "]"],
|
546
557
|
[:tINDEX, -1]
|
@@ -560,7 +571,7 @@ module Synvert::Core::NodeQuery
|
|
560
571
|
context 'child' do
|
561
572
|
it 'matches' do
|
562
573
|
source = '.def > .send'
|
563
|
-
expected_tokens = [[:tNODE_TYPE, "def"], [:
|
574
|
+
expected_tokens = [[:tNODE_TYPE, "def"], [:tRELATIONSHIP, ">"], [:tNODE_TYPE, "send"]]
|
564
575
|
assert_tokens source, expected_tokens
|
565
576
|
end
|
566
577
|
end
|
@@ -568,7 +579,7 @@ module Synvert::Core::NodeQuery
|
|
568
579
|
context 'subsequent sibling' do
|
569
580
|
it 'matches' do
|
570
581
|
source = '.send ~ .send'
|
571
|
-
expected_tokens = [[:tNODE_TYPE, "send"], [:
|
582
|
+
expected_tokens = [[:tNODE_TYPE, "send"], [:tRELATIONSHIP, "~"], [:tNODE_TYPE, "send"]]
|
572
583
|
assert_tokens source, expected_tokens
|
573
584
|
end
|
574
585
|
end
|
@@ -576,7 +587,7 @@ module Synvert::Core::NodeQuery
|
|
576
587
|
context 'next sibling' do
|
577
588
|
it 'matches' do
|
578
589
|
source = '.send + .send'
|
579
|
-
expected_tokens = [[:tNODE_TYPE, "send"], [:
|
590
|
+
expected_tokens = [[:tNODE_TYPE, "send"], [:tRELATIONSHIP, "+"], [:tNODE_TYPE, "send"]]
|
580
591
|
assert_tokens source, expected_tokens
|
581
592
|
end
|
582
593
|
end
|
@@ -588,7 +599,7 @@ module Synvert::Core::NodeQuery
|
|
588
599
|
[:tNODE_TYPE, "class"],
|
589
600
|
[:tPSEUDO_CLASS, "has"],
|
590
601
|
[:tOPEN_SELECTOR, "("],
|
591
|
-
[:
|
602
|
+
[:tRELATIONSHIP, ">"],
|
592
603
|
[:tNODE_TYPE, "def"],
|
593
604
|
[:tCLOSE_SELECTOR, ")"]
|
594
605
|
]
|
@@ -603,12 +614,27 @@ module Synvert::Core::NodeQuery
|
|
603
614
|
[:tNODE_TYPE, "class"],
|
604
615
|
[:tPSEUDO_CLASS, "not_has"],
|
605
616
|
[:tOPEN_SELECTOR, "("],
|
606
|
-
[:
|
617
|
+
[:tRELATIONSHIP, ">"],
|
607
618
|
[:tNODE_TYPE, "def"],
|
608
619
|
[:tCLOSE_SELECTOR, ")"]
|
609
620
|
]
|
610
621
|
assert_tokens source, expected_tokens
|
611
622
|
end
|
612
623
|
end
|
624
|
+
|
625
|
+
context 'goto_scope' do
|
626
|
+
it 'matches' do
|
627
|
+
source = '.block <body> > .def'
|
628
|
+
expected_tokens = [
|
629
|
+
[:tNODE_TYPE, "block"],
|
630
|
+
[:tOPEN_GOTO_SCOPE, "<"],
|
631
|
+
[:tIDENTIFIER, "body"],
|
632
|
+
[:tCLOSE_GOTO_SCOPE, ">"],
|
633
|
+
[:tRELATIONSHIP, ">"],
|
634
|
+
[:tNODE_TYPE, "def"]
|
635
|
+
]
|
636
|
+
assert_tokens source, expected_tokens
|
637
|
+
end
|
638
|
+
end
|
613
639
|
end
|
614
640
|
end
|