synvert-core 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +9 -0
- data/lib/synvert/core/node_ext.rb +14 -2
- 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 +8 -76
- 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 +102 -20
- 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 +19 -16
- data/lib/synvert/core/node_query/lexer.rex.rb +34 -27
- data/lib/synvert/core/node_query/parser.racc.rb +118 -287
- data/lib/synvert/core/node_query/parser.y +17 -36
- data/lib/synvert/core/node_query.rb +7 -7
- 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_ext_spec.rb +7 -5
- data/spec/synvert/core/node_query/lexer_spec.rb +48 -48
- data/spec/synvert/core/node_query/parser_spec.rb +139 -107
- data/spec/synvert/core/rewriter/instance_spec.rb +12 -7
- data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +3 -3
- data/synvert-core-ruby.gemspec +0 -10
- metadata +3 -128
@@ -1,60 +1,41 @@
|
|
1
1
|
class Synvert::Core::NodeQuery::Parser
|
2
2
|
options no_result_var
|
3
|
-
token tNODE_TYPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE tINDEX tPSEUDO_CLASS
|
4
|
-
tCHILD tSUBSEQUENT_SIBLING tNEXT_SIBLING
|
3
|
+
token tNODE_TYPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE tINDEX tPSEUDO_CLASS tRELATIONSHIP
|
5
4
|
tOPEN_ATTRIBUTE tCLOSE_ATTRIBUTE tOPEN_DYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE
|
6
5
|
tOPEN_ARRAY tCLOSE_ARRAY tOPEN_SELECTOR tCLOSE_SELECTOR tOPEN_GOTO_SCOPE tCLOSE_GOTO_SCOPE
|
7
|
-
|
8
|
-
tARRAY_VALUE tDYNAMIC_ATTRIBUTE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
13
|
+
: simple_selector { Compiler::Selector.new(simple_selector: val[0]) }
|
14
|
+
| simple_selector tINDEX { Compiler::Selector.new(simple_selector: val[0], index: val[1]) }
|
15
|
+
| simple_selector tPSEUDO_CLASS tOPEN_SELECTOR selector tCLOSE_SELECTOR { Compiler::Selector.new(simple_selector: val[0], pseudo_class: val[1], pseudo_selector: val[3]) }
|
16
|
+
| tPSEUDO_CLASS tOPEN_SELECTOR selector tCLOSE_SELECTOR { Compiler::Selector.new(pseudo_class: val[0], pseudo_selector: val[2]) }
|
17
|
+
| tRELATIONSHIP selector { Compiler::Selector.new(relationship: val[0], rest: val[1]) }
|
18
|
+
| tOPEN_GOTO_SCOPE tIDENTIFIER tCLOSE_GOTO_SCOPE selector { Compiler::Selector.new(goto_scope: val[1], rest: val[3]) }
|
19
|
+
|
20
|
+
simple_selector
|
21
|
+
: tNODE_TYPE { Compiler::SimpleSelector.new(node_type: val[0]) }
|
22
|
+
| tNODE_TYPE attribute_list { Compiler::SimpleSelector.new(node_type: val[0], attribute_list: val[1]) }
|
27
23
|
|
28
24
|
attribute_list
|
29
25
|
: tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE attribute_list { Compiler::AttributeList.new(attribute: val[1], rest: val[3]) }
|
30
26
|
| tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE { Compiler::AttributeList.new(attribute: val[1]) }
|
31
|
-
;
|
32
27
|
|
33
28
|
attribute
|
34
|
-
: tKEY
|
35
|
-
| tKEY
|
36
|
-
| tKEY
|
37
|
-
| tKEY tGREATER_THAN_OR_EQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :>=) }
|
38
|
-
| tKEY tGREATER_THAN value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :>) }
|
39
|
-
| tKEY tLESS_THAN_OR_EQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :<=) }
|
40
|
-
| tKEY tLESS_THAN value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :<) }
|
41
|
-
| tKEY tEQUAL value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :==) }
|
42
|
-
| tKEY tINCLUDES value { Compiler::Attribute.new(key: val[0], value: val[2], operator: :includes) }
|
43
|
-
| tKEY tNOT_EQUAL tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :!=) }
|
44
|
-
| tKEY tEQUAL tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :==) }
|
45
|
-
| tKEY tNOT_IN tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :not_in) }
|
46
|
-
| tKEY tIN tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: :in) }
|
47
|
-
| tKEY tNOT_EQUAL tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :!=) }
|
48
|
-
| tKEY tEQUAL tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :==) }
|
49
|
-
| tKEY tNOT_IN tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :not_in) }
|
50
|
-
| tKEY tIN tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: :in) }
|
29
|
+
: tKEY tOPERATOR value { Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1]) }
|
30
|
+
| tKEY tOPERATOR tOPEN_ARRAY tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: val[1]) }
|
31
|
+
| tKEY tOPERATOR tOPEN_ARRAY array_value tCLOSE_ARRAY { Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1]) }
|
51
32
|
|
52
33
|
array_value
|
53
34
|
: value array_value { Compiler::Array.new(value: val[0], rest: val[1]) }
|
54
35
|
| value { Compiler::Array.new(value: val[0]) }
|
55
36
|
|
56
37
|
value
|
57
|
-
:
|
38
|
+
: simple_selector
|
58
39
|
| tOPEN_DYNAMIC_ATTRIBUTE tDYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE { Compiler::DynamicAttribute.new(value: val[1]) }
|
59
40
|
| tBOOLEAN { Compiler::Boolean.new(value: val[0]) }
|
60
41
|
| tFLOAT { Compiler::Float.new(value: val[0]) }
|
@@ -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
|
#
|
@@ -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
|
@@ -6,8 +6,11 @@ module Synvert::Core
|
|
6
6
|
# Initialize a RemoveAction.
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::RemoveAction]
|
9
|
-
|
9
|
+
# @param options [Hash] options.
|
10
|
+
# @option and_comma [Boolean] delete extra comma.
|
11
|
+
def initialize(instance, and_comma: false)
|
10
12
|
super(instance, nil)
|
13
|
+
@and_comma = and_comma
|
11
14
|
end
|
12
15
|
|
13
16
|
# The rewritten code, always empty string.
|
@@ -27,7 +30,7 @@ module Synvert::Core
|
|
27
30
|
@begin_pos = @node.loc.expression.begin_pos
|
28
31
|
@end_pos = @node.loc.expression.end_pos
|
29
32
|
squeeze_spaces
|
30
|
-
remove_comma
|
33
|
+
remove_comma if @and_command
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -333,8 +333,10 @@ module Synvert::Core
|
|
333
333
|
# with_node type: 'send', message: { in: %w[puts p] } do
|
334
334
|
# remove
|
335
335
|
# end
|
336
|
-
|
337
|
-
|
336
|
+
# @param options [Hash] options.
|
337
|
+
# @option and_comma [Boolean] delete extra comma.
|
338
|
+
def remove(**options)
|
339
|
+
@actions << Rewriter::RemoveAction.new(self, **options).process
|
338
340
|
end
|
339
341
|
|
340
342
|
# Parse +delete+ dsl, it creates a {Synvert::Core::Rewriter::DeleteAction} to delete child nodes.
|
@@ -346,8 +348,10 @@ module Synvert::Core
|
|
346
348
|
# delete :receiver, :dot
|
347
349
|
# end
|
348
350
|
# @param selectors [Array<Symbol>] selector names of child node.
|
349
|
-
|
350
|
-
|
351
|
+
# @param options [Hash]
|
352
|
+
# @option and_comma [Boolean] delete extra comma.
|
353
|
+
def delete(*selectors, **options)
|
354
|
+
@actions << Rewriter::DeleteAction.new(self, *selectors, **options).process
|
351
355
|
end
|
352
356
|
|
353
357
|
# Parse +wrap+ dsl, it creates a {Synvert::Core::Rewriter::WrapAction} to
|
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,7 +219,7 @@ 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
|
]
|
@@ -232,7 +232,7 @@ module Synvert::Core::NodeQuery
|
|
232
232
|
[:tNODE_TYPE, "send"],
|
233
233
|
[:tOPEN_ATTRIBUTE, "["],
|
234
234
|
[:tKEY, "message"],
|
235
|
-
[:
|
235
|
+
[:tOPERATOR, "=="],
|
236
236
|
[:tIDENTIFIER_VALUE, "nil?"],
|
237
237
|
[:tCLOSE_ATTRIBUTE, "]"]
|
238
238
|
]
|
@@ -245,7 +245,7 @@ module Synvert::Core::NodeQuery
|
|
245
245
|
[:tNODE_TYPE, "pair"],
|
246
246
|
[:tOPEN_ATTRIBUTE, "["],
|
247
247
|
[:tKEY, "key"],
|
248
|
-
[:
|
248
|
+
[:tOPERATOR, "=="],
|
249
249
|
[:tOPEN_DYNAMIC_ATTRIBUTE, "{{"],
|
250
250
|
[:tDYNAMIC_ATTRIBUTE, "value"],
|
251
251
|
[:tCLOSE_DYNAMIC_ATTRIBUTE, "}}"],
|
@@ -265,11 +265,11 @@ module Synvert::Core::NodeQuery
|
|
265
265
|
[:tNODE_TYPE, "send"],
|
266
266
|
[:tOPEN_ATTRIBUTE, "["],
|
267
267
|
[:tKEY, "receiver"],
|
268
|
-
[:
|
268
|
+
[:tOPERATOR, "=="],
|
269
269
|
[:tNODE_TYPE, "send"],
|
270
270
|
[:tOPEN_ATTRIBUTE, "["],
|
271
271
|
[:tKEY, "message"],
|
272
|
-
[:
|
272
|
+
[:tOPERATOR, "=="],
|
273
273
|
[:tSYMBOL, :create],
|
274
274
|
[:tCLOSE_ATTRIBUTE, "]"],
|
275
275
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -287,20 +287,20 @@ module Synvert::Core::NodeQuery
|
|
287
287
|
[:tNODE_TYPE, "send"],
|
288
288
|
[:tOPEN_ATTRIBUTE, "["],
|
289
289
|
[:tKEY, "arguments"],
|
290
|
-
[:
|
290
|
+
[:tOPERATOR, "=="],
|
291
291
|
[:tOPEN_ATTRIBUTE, "["],
|
292
292
|
[:tKEY, "size"],
|
293
|
-
[:
|
293
|
+
[:tOPERATOR, "=="],
|
294
294
|
[:tINTEGER, 2],
|
295
295
|
[:tCLOSE_ATTRIBUTE, "]"],
|
296
296
|
[:tOPEN_ATTRIBUTE, "["],
|
297
297
|
[:tKEY, "first"],
|
298
|
-
[:
|
298
|
+
[:tOPERATOR, "=="],
|
299
299
|
[:tNODE_TYPE, "str"],
|
300
300
|
[:tCLOSE_ATTRIBUTE, "]"],
|
301
301
|
[:tOPEN_ATTRIBUTE, "["],
|
302
302
|
[:tKEY, "last"],
|
303
|
-
[:
|
303
|
+
[:tOPERATOR, "=="],
|
304
304
|
[:tNODE_TYPE, "str"],
|
305
305
|
[:tCLOSE_ATTRIBUTE, "]"],
|
306
306
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -316,7 +316,7 @@ module Synvert::Core::NodeQuery
|
|
316
316
|
[:tNODE_TYPE, "send"],
|
317
317
|
[:tOPEN_ATTRIBUTE, "["],
|
318
318
|
[:tKEY, "message"],
|
319
|
-
[:
|
319
|
+
[:tOPERATOR, "!="],
|
320
320
|
[:tIDENTIFIER_VALUE, "create"],
|
321
321
|
[:tCLOSE_ATTRIBUTE, "]"]
|
322
322
|
]
|
@@ -328,7 +328,7 @@ module Synvert::Core::NodeQuery
|
|
328
328
|
expected_tokens = [
|
329
329
|
[:tOPEN_ATTRIBUTE, "["],
|
330
330
|
[:tKEY, "value"],
|
331
|
-
[:
|
331
|
+
[:tOPERATOR, ">"],
|
332
332
|
[:tINTEGER, 1],
|
333
333
|
[:tCLOSE_ATTRIBUTE, "]"]
|
334
334
|
]
|
@@ -340,7 +340,7 @@ module Synvert::Core::NodeQuery
|
|
340
340
|
expected_tokens = [
|
341
341
|
[:tOPEN_ATTRIBUTE, "["],
|
342
342
|
[:tKEY, "value"],
|
343
|
-
[:
|
343
|
+
[:tOPERATOR, "<"],
|
344
344
|
[:tINTEGER, 1],
|
345
345
|
[:tCLOSE_ATTRIBUTE, "]"]
|
346
346
|
]
|
@@ -352,7 +352,7 @@ module Synvert::Core::NodeQuery
|
|
352
352
|
expected_tokens = [
|
353
353
|
[:tOPEN_ATTRIBUTE, "["],
|
354
354
|
[:tKEY, "value"],
|
355
|
-
[:
|
355
|
+
[:tOPERATOR, ">="],
|
356
356
|
[:tINTEGER, 1],
|
357
357
|
[:tCLOSE_ATTRIBUTE, "]"]
|
358
358
|
]
|
@@ -364,7 +364,7 @@ module Synvert::Core::NodeQuery
|
|
364
364
|
expected_tokens = [
|
365
365
|
[:tOPEN_ATTRIBUTE, "["],
|
366
366
|
[:tKEY, "value"],
|
367
|
-
[:
|
367
|
+
[:tOPERATOR, "<="],
|
368
368
|
[:tINTEGER, 1],
|
369
369
|
[:tCLOSE_ATTRIBUTE, "]"]
|
370
370
|
]
|
@@ -377,7 +377,7 @@ module Synvert::Core::NodeQuery
|
|
377
377
|
[:tNODE_TYPE, "send"],
|
378
378
|
[:tOPEN_ATTRIBUTE, "["],
|
379
379
|
[:tKEY, "message"],
|
380
|
-
[:
|
380
|
+
[:tOPERATOR, "=~"],
|
381
381
|
[:tREGEXP, /create/i],
|
382
382
|
[:tCLOSE_ATTRIBUTE, "]"]
|
383
383
|
]
|
@@ -390,7 +390,7 @@ module Synvert::Core::NodeQuery
|
|
390
390
|
[:tNODE_TYPE, "send"],
|
391
391
|
[:tOPEN_ATTRIBUTE, "["],
|
392
392
|
[:tKEY, "message"],
|
393
|
-
[:
|
393
|
+
[:tOPERATOR, "!~"],
|
394
394
|
[:tREGEXP, /create/i],
|
395
395
|
[:tCLOSE_ATTRIBUTE, "]"]
|
396
396
|
]
|
@@ -403,7 +403,7 @@ module Synvert::Core::NodeQuery
|
|
403
403
|
[:tNODE_TYPE, "send"],
|
404
404
|
[:tOPEN_ATTRIBUTE, "["],
|
405
405
|
[:tKEY, "arguments"],
|
406
|
-
[:
|
406
|
+
[:tOPERATOR, "=="],
|
407
407
|
[:tOPEN_ARRAY, "("],
|
408
408
|
[:tCLOSE_ARRAY, ")"],
|
409
409
|
[:tCLOSE_ATTRIBUTE, "]"]
|
@@ -417,7 +417,7 @@ module Synvert::Core::NodeQuery
|
|
417
417
|
[:tNODE_TYPE, "send"],
|
418
418
|
[:tOPEN_ATTRIBUTE, "["],
|
419
419
|
[:tKEY, "arguments"],
|
420
|
-
[:
|
420
|
+
[:tOPERATOR, "=="],
|
421
421
|
[:tOPEN_ARRAY, "("],
|
422
422
|
[:tSYMBOL, :create],
|
423
423
|
[:tCLOSE_ARRAY, ")"],
|
@@ -432,7 +432,7 @@ module Synvert::Core::NodeQuery
|
|
432
432
|
[:tNODE_TYPE, "send"],
|
433
433
|
[:tOPEN_ATTRIBUTE, "["],
|
434
434
|
[:tKEY, "arguments"],
|
435
|
-
[:
|
435
|
+
[:tOPERATOR, "!="],
|
436
436
|
[:tOPEN_ARRAY, "("],
|
437
437
|
[:tSYMBOL, :create],
|
438
438
|
[:tCLOSE_ARRAY, ")"],
|
@@ -447,7 +447,7 @@ module Synvert::Core::NodeQuery
|
|
447
447
|
[:tNODE_TYPE, "send"],
|
448
448
|
[:tOPEN_ATTRIBUTE, "["],
|
449
449
|
[:tKEY, "message"],
|
450
|
-
[:
|
450
|
+
[:tOPERATOR, "in"],
|
451
451
|
[:tOPEN_ARRAY, "("],
|
452
452
|
[:tIDENTIFIER_VALUE, "create"],
|
453
453
|
[:tIDENTIFIER_VALUE, "build"],
|
@@ -463,7 +463,7 @@ module Synvert::Core::NodeQuery
|
|
463
463
|
[:tNODE_TYPE, "send"],
|
464
464
|
[:tOPEN_ATTRIBUTE, "["],
|
465
465
|
[:tKEY, "message"],
|
466
|
-
[:
|
466
|
+
[:tOPERATOR, "not_in"],
|
467
467
|
[:tOPEN_ARRAY, "("],
|
468
468
|
[:tIDENTIFIER_VALUE, "create"],
|
469
469
|
[:tIDENTIFIER_VALUE, "build"],
|
@@ -479,7 +479,7 @@ module Synvert::Core::NodeQuery
|
|
479
479
|
[:tNODE_TYPE, "send"],
|
480
480
|
[:tOPEN_ATTRIBUTE, "["],
|
481
481
|
[:tKEY, "arguments"],
|
482
|
-
[:
|
482
|
+
[:tOPERATOR, "includes"],
|
483
483
|
[:tIDENTIFIER_VALUE, "&block"],
|
484
484
|
[:tCLOSE_ATTRIBUTE, "]"]
|
485
485
|
]
|
@@ -494,7 +494,7 @@ module Synvert::Core::NodeQuery
|
|
494
494
|
[:tNODE_TYPE, "send"],
|
495
495
|
[:tOPEN_ATTRIBUTE, "["],
|
496
496
|
[:tKEY, "receiver.message"],
|
497
|
-
[:
|
497
|
+
[:tOPERATOR, "=="],
|
498
498
|
[:tSYMBOL, :create],
|
499
499
|
[:tCLOSE_ATTRIBUTE, "]"]
|
500
500
|
]
|
@@ -509,7 +509,7 @@ module Synvert::Core::NodeQuery
|
|
509
509
|
[:tNODE_TYPE, "send"],
|
510
510
|
[:tOPEN_ATTRIBUTE, "["],
|
511
511
|
[:tKEY, "arguments"],
|
512
|
-
[:
|
512
|
+
[:tOPERATOR, "=="],
|
513
513
|
[:tSYMBOL, :create],
|
514
514
|
[:tCLOSE_ATTRIBUTE, "]"],
|
515
515
|
[:tINDEX, 0]
|
@@ -523,7 +523,7 @@ module Synvert::Core::NodeQuery
|
|
523
523
|
[:tNODE_TYPE, "send"],
|
524
524
|
[:tOPEN_ATTRIBUTE, "["],
|
525
525
|
[:tKEY, "arguments"],
|
526
|
-
[:
|
526
|
+
[:tOPERATOR, "=="],
|
527
527
|
[:tSYMBOL, :create],
|
528
528
|
[:tCLOSE_ATTRIBUTE, "]"],
|
529
529
|
[:tINDEX, -1]
|
@@ -537,7 +537,7 @@ module Synvert::Core::NodeQuery
|
|
537
537
|
[:tNODE_TYPE, "send"],
|
538
538
|
[:tOPEN_ATTRIBUTE, "["],
|
539
539
|
[:tKEY, "arguments"],
|
540
|
-
[:
|
540
|
+
[:tOPERATOR, "=="],
|
541
541
|
[:tSYMBOL, :create],
|
542
542
|
[:tCLOSE_ATTRIBUTE, "]"],
|
543
543
|
[:tINDEX, 0]
|
@@ -551,7 +551,7 @@ module Synvert::Core::NodeQuery
|
|
551
551
|
[:tNODE_TYPE, "send"],
|
552
552
|
[:tOPEN_ATTRIBUTE, "["],
|
553
553
|
[:tKEY, "arguments"],
|
554
|
-
[:
|
554
|
+
[:tOPERATOR, "=="],
|
555
555
|
[:tSYMBOL, :create],
|
556
556
|
[:tCLOSE_ATTRIBUTE, "]"],
|
557
557
|
[:tINDEX, -1]
|
@@ -571,7 +571,7 @@ module Synvert::Core::NodeQuery
|
|
571
571
|
context 'child' do
|
572
572
|
it 'matches' do
|
573
573
|
source = '.def > .send'
|
574
|
-
expected_tokens = [[:tNODE_TYPE, "def"], [:
|
574
|
+
expected_tokens = [[:tNODE_TYPE, "def"], [:tRELATIONSHIP, ">"], [:tNODE_TYPE, "send"]]
|
575
575
|
assert_tokens source, expected_tokens
|
576
576
|
end
|
577
577
|
end
|
@@ -579,7 +579,7 @@ module Synvert::Core::NodeQuery
|
|
579
579
|
context 'subsequent sibling' do
|
580
580
|
it 'matches' do
|
581
581
|
source = '.send ~ .send'
|
582
|
-
expected_tokens = [[:tNODE_TYPE, "send"], [:
|
582
|
+
expected_tokens = [[:tNODE_TYPE, "send"], [:tRELATIONSHIP, "~"], [:tNODE_TYPE, "send"]]
|
583
583
|
assert_tokens source, expected_tokens
|
584
584
|
end
|
585
585
|
end
|
@@ -587,7 +587,7 @@ module Synvert::Core::NodeQuery
|
|
587
587
|
context 'next sibling' do
|
588
588
|
it 'matches' do
|
589
589
|
source = '.send + .send'
|
590
|
-
expected_tokens = [[:tNODE_TYPE, "send"], [:
|
590
|
+
expected_tokens = [[:tNODE_TYPE, "send"], [:tRELATIONSHIP, "+"], [:tNODE_TYPE, "send"]]
|
591
591
|
assert_tokens source, expected_tokens
|
592
592
|
end
|
593
593
|
end
|
@@ -599,7 +599,7 @@ module Synvert::Core::NodeQuery
|
|
599
599
|
[:tNODE_TYPE, "class"],
|
600
600
|
[:tPSEUDO_CLASS, "has"],
|
601
601
|
[:tOPEN_SELECTOR, "("],
|
602
|
-
[:
|
602
|
+
[:tRELATIONSHIP, ">"],
|
603
603
|
[:tNODE_TYPE, "def"],
|
604
604
|
[:tCLOSE_SELECTOR, ")"]
|
605
605
|
]
|
@@ -614,7 +614,7 @@ module Synvert::Core::NodeQuery
|
|
614
614
|
[:tNODE_TYPE, "class"],
|
615
615
|
[:tPSEUDO_CLASS, "not_has"],
|
616
616
|
[:tOPEN_SELECTOR, "("],
|
617
|
-
[:
|
617
|
+
[:tRELATIONSHIP, ">"],
|
618
618
|
[:tNODE_TYPE, "def"],
|
619
619
|
[:tCLOSE_SELECTOR, ")"]
|
620
620
|
]
|
@@ -630,7 +630,7 @@ module Synvert::Core::NodeQuery
|
|
630
630
|
[:tOPEN_GOTO_SCOPE, "<"],
|
631
631
|
[:tIDENTIFIER, "body"],
|
632
632
|
[:tCLOSE_GOTO_SCOPE, ">"],
|
633
|
-
[:
|
633
|
+
[:tRELATIONSHIP, ">"],
|
634
634
|
[:tNODE_TYPE, "def"]
|
635
635
|
]
|
636
636
|
assert_tokens source, expected_tokens
|