synvert-core 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +0 -1
  3. data/.gitignore +0 -5
  4. data/CHANGELOG.md +12 -0
  5. data/Gemfile +0 -3
  6. data/Gemfile.lock +101 -0
  7. data/Guardfile +0 -9
  8. data/README.md +31 -13
  9. data/Rakefile +1 -15
  10. data/lib/synvert/core/engine/erb.rb +1 -1
  11. data/lib/synvert/core/engine.rb +1 -1
  12. data/lib/synvert/core/node_ext.rb +0 -639
  13. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  14. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -5
  15. data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +1 -1
  16. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -5
  17. data/lib/synvert/core/rewriter/condition.rb +5 -1
  18. data/lib/synvert/core/rewriter/instance.rb +91 -140
  19. data/lib/synvert/core/rewriter/scope/query_scope.rb +8 -6
  20. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -87
  21. data/lib/synvert/core/rewriter.rb +0 -10
  22. data/lib/synvert/core/version.rb +1 -1
  23. data/lib/synvert/core.rb +4 -6
  24. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  25. data/spec/synvert/core/node_ext_spec.rb +0 -965
  26. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  27. data/spec/synvert/core/rewriter/instance_spec.rb +64 -131
  28. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  29. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -16
  30. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +22 -13
  31. data/synvert-core-ruby.gemspec +5 -3
  32. metadata +46 -62
  33. data/lib/synvert/core/array_ext.rb +0 -48
  34. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  35. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  36. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  37. data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
  38. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  39. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  40. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  41. data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
  42. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  43. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  44. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  45. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  46. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  48. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  49. data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
  50. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  51. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  52. data/lib/synvert/core/node_query/compiler.rb +0 -25
  53. data/lib/synvert/core/node_query/lexer.rex +0 -99
  54. data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
  55. data/lib/synvert/core/node_query/parser.racc.rb +0 -306
  56. data/lib/synvert/core/node_query/parser.y +0 -60
  57. data/lib/synvert/core/node_query.rb +0 -36
  58. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  59. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
  60. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  61. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  62. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  63. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
  64. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  65. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  66. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  67. data/lib/synvert/core/rewriter/action.rb +0 -102
  68. data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
  69. data/spec/synvert/core/node_query/parser_spec.rb +0 -337
  70. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  71. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  73. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  74. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  75. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  76. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  77. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  78. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  79. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Synvert::Core::NodeQuery::Compiler
4
- autoload :InvalidOperatorError, 'synvert/core/node_query/compiler/invalid_operator_error'
5
- autoload :ParseError, 'synvert/core/node_query/compiler/parse_error'
6
-
7
- autoload :Comparable, 'synvert/core/node_query/compiler/comparable'
8
-
9
- autoload :Expression, 'synvert/core/node_query/compiler/expression'
10
- autoload :Selector, 'synvert/core/node_query/compiler/selector'
11
- autoload :BasicSelector, 'synvert/core/node_query/compiler/basic_selector'
12
- autoload :AttributeList, 'synvert/core/node_query/compiler/attribute_list'
13
- autoload :Attribute, 'synvert/core/node_query/compiler/attribute'
14
-
15
- autoload :Array, 'synvert/core/node_query/compiler/array'
16
- autoload :Boolean, 'synvert/core/node_query/compiler/boolean'
17
- autoload :DynamicAttribute, 'synvert/core/node_query/compiler/dynamic_attribute'
18
- autoload :Float, 'synvert/core/node_query/compiler/float'
19
- autoload :Identifier, 'synvert/core/node_query/compiler/identifier'
20
- autoload :Integer, 'synvert/core/node_query/compiler/integer'
21
- autoload :Nil, 'synvert/core/node_query/compiler/nil'
22
- autoload :Regexp, 'synvert/core/node_query/compiler/regexp'
23
- autoload :String, 'synvert/core/node_query/compiler/string'
24
- autoload :Symbol, 'synvert/core/node_query/compiler/symbol'
25
- end
@@ -1,99 +0,0 @@
1
- class Synvert::Core::NodeQuery::Lexer
2
-
3
- macros
4
- OPEN_ATTRIBUTE /\[/
5
- CLOSE_ATTRIBUTE /\]/
6
- OPEN_ARRAY /\(/
7
- CLOSE_ARRAY /\)/
8
- OPEN_SELECTOR /\(/
9
- CLOSE_SELECTOR /\)/
10
- OPEN_DYNAMIC_ATTRIBUTE /{{/
11
- CLOSE_DYNAMIC_ATTRIBUTE /}}/
12
- NODE_TYPE /\.[a-z]+/
13
- IDENTIFIER /[\.\w]+/
14
- IDENTIFIER_VALUE /[\.\w!&:\?<>=]+/
15
- FALSE /false/
16
- FLOAT /\d+\.\d+/
17
- INTEGER /\d+/
18
- NIL /nil/
19
- REGEXP_BODY /(?:[^\/]|\\\/)*/
20
- REGEXP /\/(#{REGEXP_BODY})(?<!\\)\/([imxo]*)/
21
- SYMBOL /:[\w!\?<>=]+/
22
- TRUE /true/
23
- SINGLE_QUOTE_STRING /'.*?'/
24
- DOUBLE_QUOTE_STRING /".*?"/
25
-
26
- rules
27
-
28
- # [:state] pattern [actions]
29
- /\s+/
30
- /:has/ { [:tPSEUDO_CLASS, text[1..-1]] }
31
- /:not_has/ { [:tPSEUDO_CLASS, text[1..-1]] }
32
- /#{NODE_TYPE}/ { [:tNODE_TYPE, text[1..]] }
33
- /#{IDENTIFIER}/ { [:tGOTO_SCOPE, text] }
34
- />/ { [:tRELATIONSHIP, text] }
35
- /~/ { [:tRELATIONSHIP, text] }
36
- /\+/ { [:tRELATIONSHIP, text] }
37
- /#{OPEN_SELECTOR}/ { [:tOPEN_SELECTOR, text] }
38
- /#{CLOSE_SELECTOR}/ { [:tCLOSE_SELECTOR, text] }
39
- /#{OPEN_ATTRIBUTE}/ { @nested_count += 1; @state = :KEY; [:tOPEN_ATTRIBUTE, text] }
40
- :KEY /\s+/
41
- :KEY /\^=/ { @state = :VALUE; [:tOPERATOR, '^='] }
42
- :KEY /\$=/ { @state = :VALUE; [:tOPERATOR, '$='] }
43
- :KEY /\*=/ { @state = :VALUE; [:tOPERATOR, '*='] }
44
- :KEY /!=/ { @state = :VALUE; [:tOPERATOR, '!='] }
45
- :KEY /=~/ { @state = :VALUE; [:tOPERATOR, '=~'] }
46
- :KEY /!~/ { @state = :VALUE; [:tOPERATOR, '!~'] }
47
- :KEY />=/ { @state = :VALUE; [:tOPERATOR, '>='] }
48
- :KEY /<=/ { @state = :VALUE; [:tOPERATOR, '<='] }
49
- :KEY />/ { @state = :VALUE; [:tOPERATOR, '>'] }
50
- :KEY /</ { @state = :VALUE; [:tOPERATOR, '<'] }
51
- :KEY /=/ { @state = :VALUE; [:tOPERATOR, '=='] }
52
- :KEY /includes/i { @state = :VALUE; [:tOPERATOR, 'includes'] }
53
- :KEY /not in/i { @state = :VALUE; [:tOPERATOR, 'not_in'] }
54
- :KEY /in/i { @state = :VALUE; [:tOPERATOR, 'in'] }
55
- :KEY /#{IDENTIFIER}/ { [:tKEY, text] }
56
- :VALUE /\s+/
57
- :VALUE /\[\]=/ { [:tIDENTIFIER_VALUE, text] }
58
- :VALUE /\[\]/ { [:tIDENTIFIER_VALUE, text] }
59
- :VALUE /:\[\]=/ { [:tSYMBOL, text[1..-1].to_sym] }
60
- :VALUE /:\[\]/ { [:tSYMBOL, text[1..-1].to_sym] }
61
- :VALUE /#{OPEN_DYNAMIC_ATTRIBUTE}/ { @state = :DYNAMIC_ATTRIBUTE; [:tOPEN_DYNAMIC_ATTRIBUTE, text] }
62
- :VALUE /#{OPEN_ARRAY}/ { @state = :ARRAY_VALUE; [:tOPEN_ARRAY, text] }
63
- :VALUE /#{CLOSE_ATTRIBUTE}/ { @nested_count -= 1; @state = @nested_count == 0 ? nil : :VALUE; [:tCLOSE_ATTRIBUTE, text] }
64
- :VALUE /#{NIL}\?/ { [:tIDENTIFIER_VALUE, text] }
65
- :VALUE /#{NIL}/ { [:tNIL, nil] }
66
- :VALUE /#{TRUE}/ { [:tBOOLEAN, true] }
67
- :VALUE /#{FALSE}/ { [:tBOOLEAN, false] }
68
- :VALUE /#{SYMBOL}/ { [:tSYMBOL, text[1..-1].to_sym] }
69
- :VALUE /#{FLOAT}/ { [:tFLOAT, text.to_f] }
70
- :VALUE /#{INTEGER}/ { [:tINTEGER, text.to_i] }
71
- :VALUE /#{REGEXP}/ { [:tREGEXP, eval(text)] }
72
- :VALUE /#{DOUBLE_QUOTE_STRING}/ { [:tSTRING, text[1...-1]] }
73
- :VALUE /#{SINGLE_QUOTE_STRING}/ { [:tSTRING, text[1...-1]] }
74
- :VALUE /#{NODE_TYPE}/ { [:tNODE_TYPE, text[1..]] }
75
- :VALUE /#{OPEN_ATTRIBUTE}/ { @nested_count += 1; @state = :KEY; [:tOPEN_ATTRIBUTE, text] }
76
- :VALUE /#{IDENTIFIER_VALUE}/ { [:tIDENTIFIER_VALUE, text] }
77
- :DYNAMIC_ATTRIBUTE /#{CLOSE_DYNAMIC_ATTRIBUTE}/ { @state = :VALUE; [:tCLOSE_DYNAMIC_ATTRIBUTE, text] }
78
- :DYNAMIC_ATTRIBUTE /#{IDENTIFIER}/ { [:tDYNAMIC_ATTRIBUTE, text] }
79
- :ARRAY_VALUE /\s+/
80
- :ARRAY_VALUE /#{CLOSE_ARRAY}/ { @state = :VALUE; [:tCLOSE_ARRAY, text] }
81
- :ARRAY_VALUE /#{NIL}\?/ { [:tIDENTIFIER_VALUE, text] }
82
- :ARRAY_VALUE /#{NIL}/ { [:tNIL, nil] }
83
- :ARRAY_VALUE /#{TRUE}/ { [:tBOOLEAN, true] }
84
- :ARRAY_VALUE /#{FALSE}/ { [:tBOOLEAN, false] }
85
- :ARRAY_VALUE /#{SYMBOL}/ { [:tSYMBOL, text[1..-1].to_sym] }
86
- :ARRAY_VALUE /#{FLOAT}/ { [:tFLOAT, text.to_f] }
87
- :ARRAY_VALUE /#{INTEGER}/ { [:tINTEGER, text.to_i] }
88
- :ARRAY_VALUE /#{REGEXP}/ { [:tREGEXP, eval(text)] }
89
- :ARRAY_VALUE /#{DOUBLE_QUOTE_STRING}/ { [:tSTRING, text[1...-1]] }
90
- :ARRAY_VALUE /#{SINGLE_QUOTE_STRING}/ { [:tSTRING, text[1...-1]] }
91
- :ARRAY_VALUE /#{IDENTIFIER_VALUE}/ { [:tIDENTIFIER_VALUE, text] }
92
-
93
- inner
94
- def initialize
95
- @nested_count = 0
96
- end
97
-
98
- def do_parse; end
99
- end
@@ -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