synvert-core 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -4
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +0 -3
  5. data/Guardfile +0 -9
  6. data/README.md +30 -12
  7. data/Rakefile +1 -15
  8. data/lib/synvert/core/engine/erb.rb +1 -1
  9. data/lib/synvert/core/engine.rb +1 -1
  10. data/lib/synvert/core/node_ext.rb +0 -466
  11. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  12. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
  13. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
  14. data/lib/synvert/core/rewriter/instance.rb +83 -133
  15. data/lib/synvert/core/rewriter/scope/query_scope.rb +2 -2
  16. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -4
  17. data/lib/synvert/core/rewriter.rb +0 -10
  18. data/lib/synvert/core/version.rb +1 -1
  19. data/lib/synvert/core.rb +4 -6
  20. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  21. data/spec/synvert/core/node_ext_spec.rb +0 -795
  22. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  23. data/spec/synvert/core/rewriter/instance_spec.rb +47 -115
  24. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  25. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -4
  26. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +1 -4
  27. data/synvert-core-ruby.gemspec +4 -2
  28. metadata +44 -61
  29. data/lib/synvert/core/array_ext.rb +0 -48
  30. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  31. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  32. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  33. data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
  34. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  35. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  36. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  37. data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
  38. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  39. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  40. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  41. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  42. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  43. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  44. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  45. data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
  46. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  48. data/lib/synvert/core/node_query/compiler.rb +0 -25
  49. data/lib/synvert/core/node_query/lexer.rex +0 -99
  50. data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
  51. data/lib/synvert/core/node_query/parser.racc.rb +0 -306
  52. data/lib/synvert/core/node_query/parser.y +0 -60
  53. data/lib/synvert/core/node_query.rb +0 -36
  54. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  55. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
  56. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  57. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  58. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  59. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
  60. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  61. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  62. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  63. data/lib/synvert/core/rewriter/action.rb +0 -102
  64. data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
  65. data/spec/synvert/core/node_query/parser_spec.rb +0 -337
  66. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  67. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  68. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  69. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  70. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  71. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  73. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  74. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  75. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -1,299 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- #--
4
- # This file is automatically generated. Do not modify it.
5
- # Generated by: oedipus_lex version 2.6.0.
6
- # Source: lib/synvert/core/node_query/lexer.rex
7
- #++
8
-
9
-
10
- ##
11
- # The generated lexer Synvert::Core::NodeQuery::Lexer
12
-
13
- class Synvert::Core::NodeQuery::Lexer
14
- require 'strscan'
15
-
16
- # :stopdoc:
17
- OPEN_ATTRIBUTE = /\[/
18
- CLOSE_ATTRIBUTE = /\]/
19
- OPEN_ARRAY = /\(/
20
- CLOSE_ARRAY = /\)/
21
- OPEN_SELECTOR = /\(/
22
- CLOSE_SELECTOR = /\)/
23
- OPEN_DYNAMIC_ATTRIBUTE = /{{/
24
- CLOSE_DYNAMIC_ATTRIBUTE = /}}/
25
- NODE_TYPE = /\.[a-z]+/
26
- IDENTIFIER = /[\.\w]+/
27
- IDENTIFIER_VALUE = /[\.\w!&:\?<>=]+/
28
- FALSE = /false/
29
- FLOAT = /\d+\.\d+/
30
- INTEGER = /\d+/
31
- NIL = /nil/
32
- REGEXP_BODY = /(?:[^\/]|\\\/)*/
33
- REGEXP = /\/(#{REGEXP_BODY})(?<!\\)\/([imxo]*)/
34
- SYMBOL = /:[\w!\?<>=]+/
35
- TRUE = /true/
36
- SINGLE_QUOTE_STRING = /'.*?'/
37
- DOUBLE_QUOTE_STRING = /".*?"/
38
- # :startdoc:
39
- # :stopdoc:
40
- class LexerError < StandardError ; end
41
- class ScanError < LexerError ; end
42
- # :startdoc:
43
-
44
- ##
45
- # The file name / path
46
-
47
- attr_accessor :filename
48
-
49
- ##
50
- # The StringScanner for this lexer.
51
-
52
- attr_accessor :ss
53
-
54
- ##
55
- # The current lexical state.
56
-
57
- attr_accessor :state
58
-
59
- alias :match :ss
60
-
61
- ##
62
- # The match groups for the current scan.
63
-
64
- def matches
65
- m = (1..9).map { |i| ss[i] }
66
- m.pop until m[-1] or m.empty?
67
- m
68
- end
69
-
70
- ##
71
- # Yields on the current action.
72
-
73
- def action
74
- yield
75
- end
76
-
77
-
78
- ##
79
- # The current scanner class. Must be overridden in subclasses.
80
-
81
- def scanner_class
82
- StringScanner
83
- end unless instance_methods(false).map(&:to_s).include?("scanner_class")
84
-
85
- ##
86
- # Parse the given string.
87
-
88
- def parse str
89
- self.ss = scanner_class.new str
90
- self.state ||= nil
91
-
92
- do_parse
93
- end
94
-
95
- ##
96
- # Read in and parse the file at +path+.
97
-
98
- def parse_file path
99
- self.filename = path
100
- open path do |f|
101
- parse f.read
102
- end
103
- end
104
-
105
- ##
106
- # The current location in the parse.
107
-
108
- def location
109
- [
110
- (filename || "<input>"),
111
- ].compact.join(":")
112
- end
113
-
114
- ##
115
- # Lex the next token.
116
-
117
- def next_token
118
-
119
- token = nil
120
-
121
- until ss.eos? or token do
122
- token =
123
- case state
124
- when nil then
125
- case
126
- when ss.skip(/\s+/) then
127
- # do nothing
128
- when text = ss.scan(/:has/) then
129
- action { [:tPSEUDO_CLASS, text[1..-1]] }
130
- when text = ss.scan(/:not_has/) then
131
- action { [:tPSEUDO_CLASS, text[1..-1]] }
132
- when text = ss.scan(/#{NODE_TYPE}/) then
133
- action { [:tNODE_TYPE, text[1..]] }
134
- when text = ss.scan(/#{IDENTIFIER}/) then
135
- action { [:tGOTO_SCOPE, text] }
136
- when text = ss.scan(/>/) then
137
- action { [:tRELATIONSHIP, text] }
138
- when text = ss.scan(/~/) then
139
- action { [:tRELATIONSHIP, text] }
140
- when text = ss.scan(/\+/) then
141
- action { [:tRELATIONSHIP, text] }
142
- when text = ss.scan(/#{OPEN_SELECTOR}/) then
143
- action { [:tOPEN_SELECTOR, text] }
144
- when text = ss.scan(/#{CLOSE_SELECTOR}/) then
145
- action { [:tCLOSE_SELECTOR, text] }
146
- when text = ss.scan(/#{OPEN_ATTRIBUTE}/) then
147
- action { @nested_count += 1; @state = :KEY; [:tOPEN_ATTRIBUTE, text] }
148
- else
149
- text = ss.string[ss.pos .. -1]
150
- raise ScanError, "can not match (#{state.inspect}) at #{location}: '#{text}'"
151
- end
152
- when :KEY then
153
- case
154
- when ss.skip(/\s+/) then
155
- # do nothing
156
- when ss.skip(/\^=/) then
157
- action { @state = :VALUE; [:tOPERATOR, '^='] }
158
- when ss.skip(/\$=/) then
159
- action { @state = :VALUE; [:tOPERATOR, '$='] }
160
- when ss.skip(/\*=/) then
161
- action { @state = :VALUE; [:tOPERATOR, '*='] }
162
- when ss.skip(/!=/) then
163
- action { @state = :VALUE; [:tOPERATOR, '!='] }
164
- when ss.skip(/=~/) then
165
- action { @state = :VALUE; [:tOPERATOR, '=~'] }
166
- when ss.skip(/!~/) then
167
- action { @state = :VALUE; [:tOPERATOR, '!~'] }
168
- when ss.skip(/>=/) then
169
- action { @state = :VALUE; [:tOPERATOR, '>='] }
170
- when ss.skip(/<=/) then
171
- action { @state = :VALUE; [:tOPERATOR, '<='] }
172
- when ss.skip(/>/) then
173
- action { @state = :VALUE; [:tOPERATOR, '>'] }
174
- when ss.skip(/</) then
175
- action { @state = :VALUE; [:tOPERATOR, '<'] }
176
- when ss.skip(/=/) then
177
- action { @state = :VALUE; [:tOPERATOR, '=='] }
178
- when ss.skip(/includes/i) then
179
- action { @state = :VALUE; [:tOPERATOR, 'includes'] }
180
- when ss.skip(/not in/i) then
181
- action { @state = :VALUE; [:tOPERATOR, 'not_in'] }
182
- when ss.skip(/in/i) then
183
- action { @state = :VALUE; [:tOPERATOR, 'in'] }
184
- when text = ss.scan(/#{IDENTIFIER}/) then
185
- action { [:tKEY, text] }
186
- else
187
- text = ss.string[ss.pos .. -1]
188
- raise ScanError, "can not match (#{state.inspect}) at #{location}: '#{text}'"
189
- end
190
- when :VALUE then
191
- case
192
- when ss.skip(/\s+/) then
193
- # do nothing
194
- when text = ss.scan(/\[\]=/) then
195
- action { [:tIDENTIFIER_VALUE, text] }
196
- when text = ss.scan(/\[\]/) then
197
- action { [:tIDENTIFIER_VALUE, text] }
198
- when text = ss.scan(/:\[\]=/) then
199
- action { [:tSYMBOL, text[1..-1].to_sym] }
200
- when text = ss.scan(/:\[\]/) then
201
- action { [:tSYMBOL, text[1..-1].to_sym] }
202
- when text = ss.scan(/#{OPEN_DYNAMIC_ATTRIBUTE}/) then
203
- action { @state = :DYNAMIC_ATTRIBUTE; [:tOPEN_DYNAMIC_ATTRIBUTE, text] }
204
- when text = ss.scan(/#{OPEN_ARRAY}/) then
205
- action { @state = :ARRAY_VALUE; [:tOPEN_ARRAY, text] }
206
- when text = ss.scan(/#{CLOSE_ATTRIBUTE}/) then
207
- action { @nested_count -= 1; @state = @nested_count == 0 ? nil : :VALUE; [:tCLOSE_ATTRIBUTE, text] }
208
- when text = ss.scan(/#{NIL}\?/) then
209
- action { [:tIDENTIFIER_VALUE, text] }
210
- when ss.skip(/#{NIL}/) then
211
- action { [:tNIL, nil] }
212
- when ss.skip(/#{TRUE}/) then
213
- action { [:tBOOLEAN, true] }
214
- when ss.skip(/#{FALSE}/) then
215
- action { [:tBOOLEAN, false] }
216
- when text = ss.scan(/#{SYMBOL}/) then
217
- action { [:tSYMBOL, text[1..-1].to_sym] }
218
- when text = ss.scan(/#{FLOAT}/) then
219
- action { [:tFLOAT, text.to_f] }
220
- when text = ss.scan(/#{INTEGER}/) then
221
- action { [:tINTEGER, text.to_i] }
222
- when text = ss.scan(/#{REGEXP}/) then
223
- action { [:tREGEXP, eval(text)] }
224
- when text = ss.scan(/#{DOUBLE_QUOTE_STRING}/) then
225
- action { [:tSTRING, text[1...-1]] }
226
- when text = ss.scan(/#{SINGLE_QUOTE_STRING}/) then
227
- action { [:tSTRING, text[1...-1]] }
228
- when text = ss.scan(/#{NODE_TYPE}/) then
229
- action { [:tNODE_TYPE, text[1..]] }
230
- when text = ss.scan(/#{OPEN_ATTRIBUTE}/) then
231
- action { @nested_count += 1; @state = :KEY; [:tOPEN_ATTRIBUTE, text] }
232
- when text = ss.scan(/#{IDENTIFIER_VALUE}/) then
233
- action { [:tIDENTIFIER_VALUE, text] }
234
- else
235
- text = ss.string[ss.pos .. -1]
236
- raise ScanError, "can not match (#{state.inspect}) at #{location}: '#{text}'"
237
- end
238
- when :DYNAMIC_ATTRIBUTE then
239
- case
240
- when text = ss.scan(/#{CLOSE_DYNAMIC_ATTRIBUTE}/) then
241
- action { @state = :VALUE; [:tCLOSE_DYNAMIC_ATTRIBUTE, text] }
242
- when text = ss.scan(/#{IDENTIFIER}/) then
243
- action { [:tDYNAMIC_ATTRIBUTE, text] }
244
- else
245
- text = ss.string[ss.pos .. -1]
246
- raise ScanError, "can not match (#{state.inspect}) at #{location}: '#{text}'"
247
- end
248
- when :ARRAY_VALUE then
249
- case
250
- when ss.skip(/\s+/) then
251
- # do nothing
252
- when text = ss.scan(/#{CLOSE_ARRAY}/) then
253
- action { @state = :VALUE; [:tCLOSE_ARRAY, text] }
254
- when text = ss.scan(/#{NIL}\?/) then
255
- action { [:tIDENTIFIER_VALUE, text] }
256
- when ss.skip(/#{NIL}/) then
257
- action { [:tNIL, nil] }
258
- when ss.skip(/#{TRUE}/) then
259
- action { [:tBOOLEAN, true] }
260
- when ss.skip(/#{FALSE}/) then
261
- action { [:tBOOLEAN, false] }
262
- when text = ss.scan(/#{SYMBOL}/) then
263
- action { [:tSYMBOL, text[1..-1].to_sym] }
264
- when text = ss.scan(/#{FLOAT}/) then
265
- action { [:tFLOAT, text.to_f] }
266
- when text = ss.scan(/#{INTEGER}/) then
267
- action { [:tINTEGER, text.to_i] }
268
- when text = ss.scan(/#{REGEXP}/) then
269
- action { [:tREGEXP, eval(text)] }
270
- when text = ss.scan(/#{DOUBLE_QUOTE_STRING}/) then
271
- action { [:tSTRING, text[1...-1]] }
272
- when text = ss.scan(/#{SINGLE_QUOTE_STRING}/) then
273
- action { [:tSTRING, text[1...-1]] }
274
- when text = ss.scan(/#{IDENTIFIER_VALUE}/) then
275
- action { [:tIDENTIFIER_VALUE, text] }
276
- else
277
- text = ss.string[ss.pos .. -1]
278
- raise ScanError, "can not match (#{state.inspect}) at #{location}: '#{text}'"
279
- end
280
- else
281
- raise ScanError, "undefined state at #{location}: '#{state}'"
282
- end # token = case state
283
-
284
- next unless token # allow functions to trigger redo w/ nil
285
- end # while
286
-
287
- raise LexerError, "bad lexical result at #{location}: #{token.inspect}" unless
288
- token.nil? || (Array === token && token.size >= 2)
289
-
290
- # auto-switch state
291
- self.state = token.last if token && token.first == :state
292
-
293
- token
294
- end # def next_token
295
- def initialize
296
- @nested_count = 0
297
- end
298
- def do_parse; end
299
- end # class
@@ -1,306 +0,0 @@
1
- #
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.6.0
4
- # from Racc grammar file "".
5
- #
6
-
7
- require 'racc/parser.rb'
8
- module Synvert
9
- module Core
10
- module NodeQuery
11
- class Parser < Racc::Parser
12
-
13
- def initialize
14
- @lexer = Lexer.new
15
- end
16
-
17
- def parse string
18
- @lexer.parse string
19
- do_parse
20
- end
21
-
22
- def next_token
23
- @lexer.next_token
24
- end
25
- ##### State transition tables begin ###
26
-
27
- racc_action_table = [
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 ]
36
-
37
- racc_action_check = [
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 ]
46
-
47
- racc_action_pointer = [
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 ]
53
-
54
- racc_action_default = [
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 ]
60
-
61
- racc_goto_table = [
62
- 25, 13, 36, 25, 11, 12, 1, 17, 9, 16,
63
- 23, nil, nil, nil, 22, 40, 25 ]
64
-
65
- racc_goto_check = [
66
- 3, 4, 7, 3, 2, 2, 1, 5, 1, 2,
67
- 6, nil, nil, nil, 4, 7, 3 ]
68
-
69
- racc_goto_pointer = [
70
- nil, 6, -1, -21, -6, -7, -11, -22 ]
71
-
72
- racc_goto_default = [
73
- nil, nil, 2, 3, nil, nil, 37, nil ]
74
-
75
- racc_reduce_table = [
76
- 0, 0, :racc_error,
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
106
-
107
- racc_token_table = {
108
- false => 0,
109
- :error => 1,
110
- :tNODE_TYPE => 2,
111
- :tGOTO_SCOPE => 3,
112
- :tATTRIBUTE => 4,
113
- :tKEY => 5,
114
- :tIDENTIFIER => 6,
115
- :tIDENTIFIER_VALUE => 7,
116
- :tPSEUDO_CLASS => 8,
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
138
-
139
- racc_use_result_var = false
140
-
141
- Racc_arg = [
142
- racc_action_table,
143
- racc_action_check,
144
- racc_action_default,
145
- racc_action_pointer,
146
- racc_goto_table,
147
- racc_goto_check,
148
- racc_goto_default,
149
- racc_goto_pointer,
150
- racc_nt_base,
151
- racc_reduce_table,
152
- racc_token_table,
153
- racc_shift_n,
154
- racc_reduce_n,
155
- racc_use_result_var ]
156
-
157
- Racc_token_to_s_table = [
158
- "$end",
159
- "error",
160
- "tNODE_TYPE",
161
- "tGOTO_SCOPE",
162
- "tATTRIBUTE",
163
- "tKEY",
164
- "tIDENTIFIER",
165
- "tIDENTIFIER_VALUE",
166
- "tPSEUDO_CLASS",
167
- "tRELATIONSHIP",
168
- "tOPEN_ATTRIBUTE",
169
- "tCLOSE_ATTRIBUTE",
170
- "tOPEN_DYNAMIC_ATTRIBUTE",
171
- "tCLOSE_DYNAMIC_ATTRIBUTE",
172
- "tOPEN_ARRAY",
173
- "tCLOSE_ARRAY",
174
- "tOPEN_SELECTOR",
175
- "tCLOSE_SELECTOR",
176
- "tOPERATOR",
177
- "tARRAY_VALUE",
178
- "tDYNAMIC_ATTRIBUTE",
179
- "tBOOLEAN",
180
- "tFLOAT",
181
- "tINTEGER",
182
- "tNIL",
183
- "tREGEXP",
184
- "tSTRING",
185
- "tSYMBOL",
186
- "$start",
187
- "expression",
188
- "selector",
189
- "basic_selector",
190
- "attribute_list",
191
- "attribute",
192
- "value",
193
- "array_value" ]
194
-
195
- Racc_debug_parser = false
196
-
197
- ##### State transition tables end #####
198
-
199
- # reduce 0 omitted
200
-
201
- def _reduce_1(val, _values)
202
- Compiler::Expression.new(selector: val[0], rest: val[1])
203
- end
204
-
205
- def _reduce_2(val, _values)
206
- Compiler::Expression.new(selector: val[0])
207
- end
208
-
209
- def _reduce_3(val, _values)
210
- Compiler::Selector.new(basic_selector: val[0])
211
- end
212
-
213
- def _reduce_4(val, _values)
214
- Compiler::Selector.new(pseudo_class: val[0], pseudo_selector: val[2])
215
- end
216
-
217
- def _reduce_5(val, _values)
218
- Compiler::Selector.new(relationship: val[0], rest: val[1])
219
- end
220
-
221
- def _reduce_6(val, _values)
222
- Compiler::Selector.new(goto_scope: val[0], rest: val[1])
223
- end
224
-
225
- def _reduce_7(val, _values)
226
- Compiler::BasicSelector.new(node_type: val[0])
227
- end
228
-
229
- def _reduce_8(val, _values)
230
- Compiler::BasicSelector.new(node_type: val[0], attribute_list: val[1])
231
- end
232
-
233
- def _reduce_9(val, _values)
234
- Compiler::AttributeList.new(attribute: val[1], rest: val[3])
235
- end
236
-
237
- def _reduce_10(val, _values)
238
- Compiler::AttributeList.new(attribute: val[1])
239
- end
240
-
241
- def _reduce_11(val, _values)
242
- Compiler::Attribute.new(key: val[0], value: val[2], operator: val[1])
243
- end
244
-
245
- def _reduce_12(val, _values)
246
- Compiler::Attribute.new(key: val[0], value: Compiler::Array.new, operator: val[1])
247
- end
248
-
249
- def _reduce_13(val, _values)
250
- Compiler::Attribute.new(key: val[0], value: val[3], operator: val[1])
251
- end
252
-
253
- def _reduce_14(val, _values)
254
- Compiler::Array.new(value: val[0], rest: val[1])
255
- end
256
-
257
- def _reduce_15(val, _values)
258
- Compiler::Array.new(value: val[0])
259
- end
260
-
261
- # reduce 16 omitted
262
-
263
- def _reduce_17(val, _values)
264
- Compiler::DynamicAttribute.new(value: val[1])
265
- end
266
-
267
- def _reduce_18(val, _values)
268
- Compiler::Boolean.new(value: val[0])
269
- end
270
-
271
- def _reduce_19(val, _values)
272
- Compiler::Float.new(value: val[0])
273
- end
274
-
275
- def _reduce_20(val, _values)
276
- Compiler::Integer.new(value: val[0])
277
- end
278
-
279
- def _reduce_21(val, _values)
280
- Compiler::Nil.new(value: val[0])
281
- end
282
-
283
- def _reduce_22(val, _values)
284
- Compiler::Regexp.new(value: val[0])
285
- end
286
-
287
- def _reduce_23(val, _values)
288
- Compiler::String.new(value: val[0])
289
- end
290
-
291
- def _reduce_24(val, _values)
292
- Compiler::Symbol.new(value: val[0])
293
- end
294
-
295
- def _reduce_25(val, _values)
296
- Compiler::Identifier.new(value: val[0])
297
- end
298
-
299
- def _reduce_none(val, _values)
300
- val[0]
301
- end
302
-
303
- end # class Parser
304
- end # module NodeQuery
305
- end # module Core
306
- end # module Synvert
@@ -1,60 +0,0 @@
1
- class Synvert::Core::NodeQuery::Parser
2
- options no_result_var
3
- token tNODE_TYPE tGOTO_SCOPE tATTRIBUTE tKEY tIDENTIFIER tIDENTIFIER_VALUE tPSEUDO_CLASS tRELATIONSHIP
4
- tOPEN_ATTRIBUTE tCLOSE_ATTRIBUTE tOPEN_DYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE
5
- tOPEN_ARRAY tCLOSE_ARRAY tOPEN_SELECTOR tCLOSE_SELECTOR
6
- tOPERATOR tARRAY_VALUE tDYNAMIC_ATTRIBUTE tBOOLEAN tFLOAT tINTEGER tNIL tREGEXP tSTRING tSYMBOL
7
- rule
8
- expression
9
- : selector expression { Compiler::Expression.new(selector: val[0], rest: val[1]) }
10
- | selector { Compiler::Expression.new(selector: val[0]) }
11
-
12
- selector
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]) }
21
-
22
- attribute_list
23
- : tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE attribute_list { Compiler::AttributeList.new(attribute: val[1], rest: val[3]) }
24
- | tOPEN_ATTRIBUTE attribute tCLOSE_ATTRIBUTE { Compiler::AttributeList.new(attribute: val[1]) }
25
-
26
- attribute
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]) }
30
-
31
- array_value
32
- : value array_value { Compiler::Array.new(value: val[0], rest: val[1]) }
33
- | value { Compiler::Array.new(value: val[0]) }
34
-
35
- value
36
- : basic_selector
37
- | tOPEN_DYNAMIC_ATTRIBUTE tDYNAMIC_ATTRIBUTE tCLOSE_DYNAMIC_ATTRIBUTE { Compiler::DynamicAttribute.new(value: val[1]) }
38
- | tBOOLEAN { Compiler::Boolean.new(value: val[0]) }
39
- | tFLOAT { Compiler::Float.new(value: val[0]) }
40
- | tINTEGER { Compiler::Integer.new(value: val[0])}
41
- | tNIL { Compiler::Nil.new(value: val[0]) }
42
- | tREGEXP { Compiler::Regexp.new(value: val[0]) }
43
- | tSTRING { Compiler::String.new(value: val[0]) }
44
- | tSYMBOL { Compiler::Symbol.new(value: val[0]) }
45
- | tIDENTIFIER_VALUE { Compiler::Identifier.new(value: val[0]) }
46
- end
47
-
48
- ---- inner
49
- def initialize
50
- @lexer = Lexer.new
51
- end
52
-
53
- def parse string
54
- @lexer.parse string
55
- do_parse
56
- end
57
-
58
- def next_token
59
- @lexer.next_token
60
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # NodeQuery defines a node query language, which is a css like syntax for matching nodes.
4
- #
5
- # It supports the following selectors:
6
- #
7
- # * AST node type: +.class+, +.send+
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
- # * descendant: +.class .send+
13
- # * child: +.class > .def+
14
- # * following sibling: <code>.def + .def</code>
15
- # * subsequnt sibling: +.def ~ .def+
16
- # * has: +.class:has(.def)+
17
- #
18
- # It also supports some custom selectors:
19
- #
20
- # * not_has: +.class:not_has(.def)+, it's same as +:not(:has())+ in css, just to make implementation easy.
21
- # * nested selector: +.send[arguments = [size = 2][first = .sym][last = .hash]]+
22
- # * array value: +.send[arguments = (a b)]+
23
- # * IN operator: +.send[message IN (try try!)]+
24
- # * NOT IN operator: +.send[message NOT IN (create build)]+
25
- # * INCLUDES operator: +.send[arguments INCLUDES &block]+
26
- # * dynamic attribute value: +.hash > .pair[key={{value}}]+
27
- # * goto scope: +.class body > .def+
28
- #
29
- # @example
30
- # # it matches methods call nodes, like `puts message` or `p message`
31
- # Synvert::Core::NodeQuery::Parser.parse('.send[receiver = nil][message IN (puts, p)]').query_nodes(node)
32
- module Synvert::Core::NodeQuery
33
- autoload :Compiler, 'synvert/core/node_query/compiler'
34
- autoload :Lexer, 'synvert/core/node_query/lexer.rex'
35
- autoload :Parser, 'synvert/core/node_query/parser.racc'
36
- end