oga 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,7 @@
46
46
  # stack.
47
47
  #
48
48
 
49
- newline = '\n' | '\r\n';
49
+ newline = '\r\n' | '\n' | '\r';
50
50
 
51
51
  action count_newlines {
52
52
  if ( fc == '\n' ) lines++;
data/lib/oga.rb CHANGED
@@ -1,11 +1,11 @@
1
- gem 'racc'
2
-
3
1
  require 'ast'
4
2
  require 'set'
5
3
  require 'stringio'
4
+ require 'thread'
6
5
 
7
6
  require_relative 'oga/version'
8
7
  require_relative 'oga/oga'
8
+ require_relative 'oga/lru'
9
9
 
10
10
  # Load these first so that the native extensions don't have to define the
11
11
  # Oga::XML namespace.
@@ -34,6 +34,7 @@ require_relative 'oga/xml/xml_declaration'
34
34
  require_relative 'oga/xml/processing_instruction'
35
35
  require_relative 'oga/xml/doctype'
36
36
  require_relative 'oga/xml/namespace'
37
+ require_relative 'oga/xml/default_namespace'
37
38
  require_relative 'oga/xml/attribute'
38
39
  require_relative 'oga/xml/element'
39
40
  require_relative 'oga/xml/node_set'
@@ -43,6 +44,7 @@ require_relative 'oga/xml/pull_parser'
43
44
 
44
45
  require_relative 'oga/html/parser'
45
46
  require_relative 'oga/html/sax_parser'
47
+ require_relative 'oga/html/entities'
46
48
 
47
49
  require_relative 'oga/xpath/lexer'
48
50
  require_relative 'oga/xpath/parser'
@@ -360,9 +360,8 @@ ts = p
360
360
  _keys = cs << 1
361
361
  _inds = _css_lexer_index_offsets[cs]
362
362
  _slen = _css_lexer_key_spans[cs]
363
- _wide = ( _wide)
364
- _wide = (data.getbyte(p) || 0)
365
- _trans = if ( _slen > 0 &&
363
+ _wide = ( (data.getbyte(p) || 0))
364
+ _trans = if ( _slen > 0 &&
366
365
  _css_lexer_trans_keys[_keys] <= _wide &&
367
366
  _wide <= _css_lexer_trans_keys[_keys + 1]
368
367
  ) then
@@ -1,13 +1,231 @@
1
+ # This file is automatically generated by ruby-ll. Manually changing this file
2
+ # is not recommended as any changes will be lost the next time this parser is
3
+ # re-generated.
4
+ require 'll/setup'
5
+
6
+ module Oga
7
+ module CSS
8
+ ##
9
+ # AST parser for CSS expressions.
10
+ #
11
+ # This parser does _not_ build a CSS specific AST, instead it directly produces
12
+ # an XPath AST. This removes the need to transform the AST or generate
13
+ # corresponding XPath expressions as a String.
1
14
  #
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.12
4
- # from Racc grammer file "".
15
+ # Similar to {Oga::XPath::Parser} this parser only takes String instances as
16
+ # input.
5
17
  #
18
+ class Parser < LL::Driver
19
+ CONFIG = LL::DriverConfig.new
20
+
21
+ CONFIG.terminals = [
22
+ :$EOF, # 0
23
+ :T_IDENT, # 1
24
+ :T_PIPE, # 2
25
+ :T_LBRACK, # 3
26
+ :T_RBRACK, # 4
27
+ :T_COLON, # 5
28
+ :T_SPACE, # 6
29
+ :T_LPAREN, # 7
30
+ :T_RPAREN, # 8
31
+ :T_MINUS, # 9
32
+ :T_EQ, # 10
33
+ :T_SPACE_IN, # 11
34
+ :T_STARTS_WITH, # 12
35
+ :T_ENDS_WITH, # 13
36
+ :T_IN, # 14
37
+ :T_HYPHEN_IN, # 15
38
+ :T_GREATER, # 16
39
+ :T_TILDE, # 17
40
+ :T_PLUS, # 18
41
+ :T_NTH, # 19
42
+ :T_INT, # 20
43
+ :T_STRING, # 21
44
+ :T_ODD, # 22
45
+ :T_EVEN, # 23
46
+ :T_DOT, # 24
47
+ :T_HASH, # 25
48
+ ].freeze
49
+
50
+ CONFIG.rules = [
51
+ [3, 0, 0, 1], # 0
52
+ [3, 1, 2, 0], # 1
53
+ [3, 2, 4, 29, 6, 0, 0, 3], # 2
54
+ [3, 3, 0, 3, 1, 6], # 3
55
+ [3, 4, 8, 30, 0, 4], # 4
56
+ [3, 5, 8, 31, 0, 5], # 5
57
+ [3, 6, 0, 10], # 6
58
+ [3, 7, 0, 7], # 7
59
+ [3, 8, 0, 6, 1, 16], # 8
60
+ [3, 9, 0, 6, 1, 17], # 9
61
+ [3, 10, 0, 6, 1, 18], # 10
62
+ [3, 11, 0, 7], # 11
63
+ [3, 12, 0, 5], # 12
64
+ [3, 13, 0, 8], # 13
65
+ [3, 14, 8, 32, 1, 1], # 14
66
+ [3, 15, 1, 1, 1, 2], # 15
67
+ [3, 16, 4, 33, 6, 0, 0, 11], # 16
68
+ [3, 17, 0, 17], # 17
69
+ [3, 18, 0, 18], # 18
70
+ [3, 19, 0, 19], # 19
71
+ [3, 20, 0, 12], # 20
72
+ [3, 21, 1, 4, 0, 13, 1, 3], # 21
73
+ [3, 22, 0, 15], # 22
74
+ [3, 23, 0, 8], # 23
75
+ [3, 24, 8, 34, 0, 14], # 24
76
+ [3, 25, 1, 10], # 25
77
+ [3, 26, 1, 11], # 26
78
+ [3, 27, 1, 12], # 27
79
+ [3, 28, 1, 13], # 28
80
+ [3, 29, 1, 14], # 29
81
+ [3, 30, 1, 15], # 30
82
+ [3, 31, 1, 1, 1, 24], # 31
83
+ [3, 32, 1, 1, 1, 25], # 32
84
+ [3, 33, 8, 35, 0, 20], # 33
85
+ [3, 34, 1, 1, 1, 5], # 34
86
+ [3, 35, 1, 8, 0, 22, 1, 7], # 35
87
+ [3, 36, 0, 27], # 36
88
+ [3, 37, 0, 28], # 37
89
+ [3, 38, 0, 25], # 38
90
+ [3, 39, 0, 3], # 39
91
+ [3, 40, 1, 21], # 40
92
+ [3, 41, 1, 20], # 41
93
+ [3, 42, 8, 36, 0, 26], # 42
94
+ [3, 43, 8, 37, 0, 26, 1, 9], # 43
95
+ [3, 44, 8, 39, 8, 38, 0, 24], # 44
96
+ [3, 45, 1, 19], # 45
97
+ [3, 46, 1, 22], # 46
98
+ [3, 47, 1, 23], # 47
99
+ [3, 48, 0, 2], # 48
100
+ [3, 49, 0, 10], # 49
101
+ [3, 50, 0, 10], # 50
102
+ [3, 51, 0, 9], # 51
103
+ [3, 52, 0, 11], # 52
104
+ [3, 53, 0, 23, 0, 16], # 53
105
+ [3, 54, 0, 21], # 54
106
+ [3, 55, 0, 24], # 55
107
+ [3, 56, 0, 24], # 56
108
+ [3, 57, 0, 26], # 57
109
+ [3, 58, 0, 24], # 58
110
+ ].freeze
111
+
112
+ CONFIG.table = [
113
+ [1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0], # 0
114
+ [-1, 2, -1, 2, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, -1, -1, -1, -1, -1, 2, 2], # 1
115
+ [-1, -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 2
116
+ [-1, 4, -1, 6, -1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, -1, -1, -1, -1, -1, 6, 6], # 3
117
+ [-1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 4
118
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1], # 5
119
+ [-1, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 12, 12, -1, -1, -1, -1, -1, -1, -1], # 6
120
+ [-1, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 7
121
+ [-1, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 8
122
+ [-1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 9
123
+ [-1, -1, -1, 16, -1, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 16], # 10
124
+ [-1, -1, -1, 20, -1, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 18], # 11
125
+ [-1, -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 12
126
+ [-1, 22, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 13
127
+ [-1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 14
128
+ [-1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 15
129
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 25, 26, 27, 28, 29, 30, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 16
130
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 31, -1], # 17
131
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 32], # 18
132
+ [-1, -1, -1, -1, -1, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 19
133
+ [-1, -1, -1, -1, -1, 34, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 20
134
+ [-1, -1, -1, -1, -1, -1, -1, 35, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 21
135
+ [-1, 39, -1, 39, -1, 39, -1, -1, -1, 38, -1, -1, -1, -1, -1, -1, 39, 39, 39, 38, 38, -1, 36, 37, 39, 39], # 22
136
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 40, -1, -1, -1, -1], # 23
137
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1], # 24
138
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, 44, -1, -1, -1, -1, -1], # 25
139
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1], # 26
140
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, -1, -1, -1], # 27
141
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 47, -1, -1], # 28
142
+ [-1, -1, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 29
143
+ [-1, -1, -1, 49, -1, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 49, 49], # 30
144
+ [-1, -1, -1, 50, -1, 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 50, 50], # 31
145
+ [-1, -1, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 32
146
+ [-1, -1, -1, 52, -1, 52, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52, 52], # 33
147
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 53, 53, 53, 53, 53, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 34
148
+ [-1, -1, -1, -1, -1, -1, -1, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 35
149
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, -1], # 36
150
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56, -1, -1, -1, -1, -1], # 37
151
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1], # 38
152
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58, -1, -1, -1, -1, -1], # 39
153
+ ].freeze
154
+
155
+ CONFIG.actions = [
156
+ [:_rule_0, 1], # 0
157
+ [:_rule_1, 0], # 1
158
+ [:_rule_2, 2], # 2
159
+ [:_rule_3, 2], # 3
160
+ [:_rule_4, 2], # 4
161
+ [:_rule_5, 2], # 5
162
+ [:_rule_6, 1], # 6
163
+ [:_rule_7, 1], # 7
164
+ [:_rule_8, 2], # 8
165
+ [:_rule_9, 2], # 9
166
+ [:_rule_10, 2], # 10
167
+ [:_rule_11, 1], # 11
168
+ [:_rule_12, 1], # 12
169
+ [:_rule_13, 1], # 13
170
+ [:_rule_14, 2], # 14
171
+ [:_rule_15, 2], # 15
172
+ [:_rule_16, 2], # 16
173
+ [:_rule_17, 1], # 17
174
+ [:_rule_18, 1], # 18
175
+ [:_rule_19, 1], # 19
176
+ [:_rule_20, 1], # 20
177
+ [:_rule_21, 3], # 21
178
+ [:_rule_22, 1], # 22
179
+ [:_rule_23, 1], # 23
180
+ [:_rule_24, 2], # 24
181
+ [:_rule_25, 1], # 25
182
+ [:_rule_26, 1], # 26
183
+ [:_rule_27, 1], # 27
184
+ [:_rule_28, 1], # 28
185
+ [:_rule_29, 1], # 29
186
+ [:_rule_30, 1], # 30
187
+ [:_rule_31, 2], # 31
188
+ [:_rule_32, 2], # 32
189
+ [:_rule_33, 2], # 33
190
+ [:_rule_34, 2], # 34
191
+ [:_rule_35, 3], # 35
192
+ [:_rule_36, 1], # 36
193
+ [:_rule_37, 1], # 37
194
+ [:_rule_38, 1], # 38
195
+ [:_rule_39, 1], # 39
196
+ [:_rule_40, 1], # 40
197
+ [:_rule_41, 1], # 41
198
+ [:_rule_42, 2], # 42
199
+ [:_rule_43, 3], # 43
200
+ [:_rule_44, 3], # 44
201
+ [:_rule_45, 1], # 45
202
+ [:_rule_46, 1], # 46
203
+ [:_rule_47, 1], # 47
204
+ [:_rule_48, 1], # 48
205
+ [:_rule_49, 1], # 49
206
+ [:_rule_50, 1], # 50
207
+ [:_rule_51, 1], # 51
208
+ [:_rule_52, 1], # 52
209
+ [:_rule_53, 2], # 53
210
+ [:_rule_54, 1], # 54
211
+ [:_rule_55, 1], # 55
212
+ [:_rule_56, 1], # 56
213
+ [:_rule_57, 1], # 57
214
+ [:_rule_58, 1], # 58
215
+ ].freeze
6
216
 
7
- require 'racc/parser.rb'
8
- module Oga
9
- module CSS
10
- class Parser < Racc::Parser
217
+ ##
218
+ # @return [Oga::LRU]
219
+ #
220
+ CACHE = LRU.new
221
+
222
+ ##
223
+ # @param [String] data
224
+ # @return [AST::Node]
225
+ #
226
+ def self.parse_with_cache(data)
227
+ return CACHE.get_or_set(data) { new(data).parse }
228
+ end
11
229
 
12
230
  ##
13
231
  # @param [String] data The input to parse.
@@ -37,12 +255,12 @@ module Oga
37
255
  #
38
256
  # @yieldparam [Array]
39
257
  #
40
- def yield_next_token
258
+ def each_token
41
259
  @lexer.advance do |*args|
42
260
  yield args
43
261
  end
44
262
 
45
- yield [false, false]
263
+ yield [-1, -1]
46
264
  end
47
265
 
48
266
  ##
@@ -66,9 +284,7 @@ module Oga
66
284
  def parse
67
285
  reset
68
286
 
69
- ast = yyparse(self, :yield_next_token)
70
-
71
- return ast
287
+ return super
72
288
  end
73
289
 
74
290
  ##
@@ -207,6 +423,104 @@ module Oga
207
423
  return s(:call, 'not', s(:axis, 'child', s(:type_test, 'node')))
208
424
  end
209
425
 
426
+ ##
427
+ # Generates the AST for the `=` operator.
428
+ #
429
+ # @param [AST::Node] attr
430
+ # @param [AST::Node] value
431
+ # @return [AST::Node]
432
+ #
433
+ def on_op_eq(attr, value)
434
+ return s(:eq, attr, value)
435
+ end
436
+
437
+ ##
438
+ # Generates the AST for the `~=` operator.
439
+ #
440
+ # @param [AST::Node] attr
441
+ # @param [AST::Node] value
442
+ # @return [AST::Node]
443
+ #
444
+ def on_op_space_in(attr, value)
445
+ return s(
446
+ :call,
447
+ 'contains',
448
+ s(:call, 'concat', s(:string, ' '), attr, s(:string, ' ')),
449
+ s(:call, 'concat', s(:string, ' '), value, s(:string, ' '))
450
+ )
451
+ end
452
+
453
+ ##
454
+ # Generates the AST for the `^=` operator.
455
+ #
456
+ # @param [AST::Node] attr
457
+ # @param [AST::Node] value
458
+ # @return [AST::Node]
459
+ #
460
+ def on_op_starts_with(attr, value)
461
+ return s(:call, 'starts-with', attr, value)
462
+ end
463
+
464
+ ##
465
+ # Generates the AST for the `$=` operator.
466
+ #
467
+ # @param [AST::Node] attr
468
+ # @param [AST::Node] value
469
+ # @return [AST::Node]
470
+ #
471
+ def on_op_ends_with(attr, value)
472
+ return s(
473
+ :eq,
474
+ s(
475
+ :call,
476
+ 'substring',
477
+ attr,
478
+ s(
479
+ :add,
480
+ s(
481
+ :sub,
482
+ s(:call, 'string-length', attr),
483
+ s(:call, 'string-length', value)
484
+ ),
485
+ s(:int, 1)
486
+ ),
487
+ s(:call, 'string-length', value)
488
+ ),
489
+ value
490
+ )
491
+ end
492
+
493
+ ##
494
+ # Generates the AST for the `*=` operator.
495
+ #
496
+ # @param [AST::Node] attr
497
+ # @param [AST::Node] value
498
+ # @return [AST::Node]
499
+ #
500
+ def on_op_in(attr, value)
501
+ return s(:call, 'contains', attr, value)
502
+ end
503
+
504
+ ##
505
+ # Generates the AST for the `|=` operator.
506
+ #
507
+ # @param [AST::Node] attr
508
+ # @param [AST::Node] value
509
+ # @return [AST::Node]
510
+ #
511
+ def on_op_hyphen_in(attr, value)
512
+ return s(
513
+ :or,
514
+ s(:eq, attr, value),
515
+ s(
516
+ :call,
517
+ 'starts-with',
518
+ attr,
519
+ s(:call, 'concat', value, s(:string, '-'))
520
+ )
521
+ )
522
+ end
523
+
210
524
  private
211
525
 
212
526
  ##
@@ -297,510 +611,290 @@ module Oga
297
611
  return mod_val
298
612
  end
299
613
 
300
- # vim: set ft=racc:
301
- ##### State transition tables begin ###
302
-
303
- racc_action_table = [
304
- 13, 24, 19, 13, 23, 19, 25, 23, 26, 35,
305
- 13, 40, 19, 41, 23, 9, 10, 11, 9, 10,
306
- 11, 43, 44, 20, 21, 45, 20, 21, 13, 48,
307
- 19, 49, 23, 20, 21, 68, 68, 68, 13, 68,
308
- 19, 68, 23, 9, 10, 11, 64, 19, 68, 23,
309
- 74, 20, 21, 9, 10, 11, 63, 62, 75, 65,
310
- 66, 20, 21, 19, 13, 23, 62, 77, 20, 21,
311
- 19, 13, 23, 19, 62, 23, 62, nil, nil, 9,
312
- 10, 11, 13, nil, 20, 21, 9, 10, 11, nil,
313
- nil, 20, 21, nil, 20, 21, nil, 9, 10, 11,
314
- 50, 51, 52, 53, 54, 55 ]
315
-
316
- racc_action_check = [
317
- 0, 1, 0, 25, 0, 25, 3, 25, 4, 13,
318
- 19, 20, 5, 21, 5, 0, 0, 0, 25, 25,
319
- 25, 22, 23, 0, 0, 24, 25, 25, 26, 35,
320
- 26, 36, 26, 5, 5, 50, 51, 52, 43, 53,
321
- 43, 54, 43, 26, 26, 26, 43, 6, 55, 6,
322
- 56, 26, 26, 43, 43, 43, 43, 43, 57, 43,
323
- 43, 43, 43, 7, 9, 7, 63, 64, 6, 6,
324
- 28, 10, 28, 29, 75, 29, 77, nil, nil, 9,
325
- 9, 9, 11, nil, 7, 7, 10, 10, 10, nil,
326
- nil, 28, 28, nil, 29, 29, nil, 11, 11, 11,
327
- 37, 37, 37, 37, 37, 37 ]
328
-
329
- racc_action_pointer = [
330
- -2, 1, nil, -1, 1, 8, 43, 59, nil, 62,
331
- 69, 80, nil, 6, nil, nil, nil, nil, nil, 8,
332
- 9, 11, 13, 20, 25, 1, 26, nil, 66, 69,
333
- nil, nil, nil, nil, nil, 27, 26, 89, nil, nil,
334
- nil, nil, nil, 36, nil, nil, nil, nil, nil, nil,
335
- 13, 14, 15, 17, 19, 26, 41, 38, nil, nil,
336
- nil, nil, nil, 45, 47, nil, nil, nil, nil, nil,
337
- nil, nil, nil, nil, nil, 53, nil, 55, nil, nil ]
338
-
339
- racc_action_default = [
340
- -2, -59, -1, -3, -4, -7, -8, -10, -12, -16,
341
- -16, -16, -19, -20, -23, -24, -25, -26, -27, -59,
342
- -59, -59, -40, -59, -59, -59, -59, -22, -9, -11,
343
- -13, -17, -18, -14, -15, -59, -59, -29, -30, -31,
344
- -38, -39, -41, -59, -42, 80, -6, -5, -21, -28,
345
- -59, -59, -59, -59, -59, -59, -59, -44, -45, -46,
346
- -47, -48, -50, -51, -59, -57, -58, -32, -49, -33,
347
- -34, -35, -36, -37, -43, -55, -52, -53, -56, -54 ]
348
-
349
- racc_goto_table = [
350
- 3, 57, 28, 29, 27, 67, 69, 70, 71, 72,
351
- 73, 32, 32, 32, 31, 31, 31, 30, 33, 34,
352
- 1, 76, 2, 4, 39, 46, 47, 27, 27, 36,
353
- 37, 38, 42, 78, 56, 79, 58, 59, 60, nil,
354
- nil, nil, nil, 61 ]
355
-
356
- racc_goto_check = [
357
- 3, 23, 5, 5, 11, 19, 19, 19, 19, 19,
358
- 19, 7, 7, 7, 8, 8, 8, 9, 9, 9,
359
- 1, 23, 2, 4, 10, 3, 3, 11, 11, 16,
360
- 17, 18, 21, 23, 22, 23, 24, 25, 26, nil,
361
- nil, nil, nil, 3 ]
362
-
363
- racc_goto_pointer = [
364
- nil, 20, 22, 0, 23, -4, nil, 2, 5, 8,
365
- 5, -1, nil, nil, nil, nil, 10, 11, 12, -45,
366
- nil, 10, -9, -42, -7, -6, -5 ]
367
-
368
- racc_goto_default = [
369
- nil, nil, nil, nil, nil, 5, 6, 7, 8, nil,
370
- 12, 14, 15, 16, 17, 18, nil, nil, nil, nil,
371
- 22, nil, nil, nil, nil, nil, nil ]
372
-
373
- racc_reduce_table = [
374
- 0, 0, :racc_error,
375
- 1, 28, :_reduce_1,
376
- 0, 28, :_reduce_2,
377
- 1, 29, :_reduce_3,
378
- 1, 29, :_reduce_4,
379
- 3, 31, :_reduce_5,
380
- 3, 31, :_reduce_6,
381
- 1, 30, :_reduce_7,
382
- 1, 30, :_reduce_none,
383
- 2, 30, :_reduce_9,
384
- 1, 30, :_reduce_none,
385
- 2, 30, :_reduce_11,
386
- 1, 33, :_reduce_12,
387
- 2, 34, :_reduce_13,
388
- 2, 34, :_reduce_14,
389
- 2, 34, :_reduce_15,
390
- 0, 36, :_reduce_none,
391
- 1, 36, :_reduce_none,
392
- 1, 36, :_reduce_none,
393
- 1, 35, :_reduce_19,
394
- 1, 37, :_reduce_20,
395
- 3, 37, :_reduce_21,
396
- 2, 32, :_reduce_22,
397
- 1, 32, :_reduce_none,
398
- 1, 38, :_reduce_none,
399
- 1, 38, :_reduce_none,
400
- 1, 38, :_reduce_none,
401
- 1, 38, :_reduce_none,
402
- 3, 42, :_reduce_28,
403
- 1, 43, :_reduce_none,
404
- 1, 43, :_reduce_none,
405
- 1, 44, :_reduce_31,
406
- 3, 45, :_reduce_32,
407
- 3, 45, :_reduce_33,
408
- 3, 45, :_reduce_34,
409
- 3, 45, :_reduce_35,
410
- 3, 45, :_reduce_36,
411
- 3, 45, :_reduce_37,
412
- 2, 39, :_reduce_38,
413
- 2, 40, :_reduce_39,
414
- 1, 41, :_reduce_40,
415
- 2, 41, :_reduce_41,
416
- 2, 47, :_reduce_42,
417
- 3, 48, :_reduce_43,
418
- 1, 49, :_reduce_none,
419
- 1, 49, :_reduce_none,
420
- 1, 49, :_reduce_none,
421
- 1, 49, :_reduce_none,
422
- 1, 49, :_reduce_none,
423
- 1, 46, :_reduce_49,
424
- 1, 50, :_reduce_50,
425
- 1, 53, :_reduce_51,
426
- 2, 53, :_reduce_52,
427
- 2, 53, :_reduce_53,
428
- 3, 53, :_reduce_54,
429
- 2, 53, :_reduce_55,
430
- 3, 53, :_reduce_56,
431
- 1, 51, :_reduce_57,
432
- 1, 52, :_reduce_58 ]
433
-
434
- racc_reduce_n = 59
435
-
436
- racc_shift_n = 80
437
-
438
- racc_token_table = {
439
- false => 0,
440
- :error => 1,
441
- :T_IDENT => 2,
442
- :T_PIPE => 3,
443
- :T_LBRACK => 4,
444
- :T_RBRACK => 5,
445
- :T_COLON => 6,
446
- :T_SPACE => 7,
447
- :T_LPAREN => 8,
448
- :T_RPAREN => 9,
449
- :T_MINUS => 10,
450
- :T_EQ => 11,
451
- :T_SPACE_IN => 12,
452
- :T_STARTS_WITH => 13,
453
- :T_ENDS_WITH => 14,
454
- :T_IN => 15,
455
- :T_HYPHEN_IN => 16,
456
- :T_GREATER => 17,
457
- :T_TILDE => 18,
458
- :T_PLUS => 19,
459
- :T_NTH => 20,
460
- :T_INT => 21,
461
- :T_STRING => 22,
462
- :T_ODD => 23,
463
- :T_EVEN => 24,
464
- :T_DOT => 25,
465
- :T_HASH => 26 }
466
-
467
- racc_nt_base = 27
468
-
469
- racc_use_result_var = false
470
-
471
- Racc_arg = [
472
- racc_action_table,
473
- racc_action_check,
474
- racc_action_default,
475
- racc_action_pointer,
476
- racc_goto_table,
477
- racc_goto_check,
478
- racc_goto_default,
479
- racc_goto_pointer,
480
- racc_nt_base,
481
- racc_reduce_table,
482
- racc_token_table,
483
- racc_shift_n,
484
- racc_reduce_n,
485
- racc_use_result_var ]
486
-
487
- Racc_token_to_s_table = [
488
- "$end",
489
- "error",
490
- "T_IDENT",
491
- "T_PIPE",
492
- "T_LBRACK",
493
- "T_RBRACK",
494
- "T_COLON",
495
- "T_SPACE",
496
- "T_LPAREN",
497
- "T_RPAREN",
498
- "T_MINUS",
499
- "T_EQ",
500
- "T_SPACE_IN",
501
- "T_STARTS_WITH",
502
- "T_ENDS_WITH",
503
- "T_IN",
504
- "T_HYPHEN_IN",
505
- "T_GREATER",
506
- "T_TILDE",
507
- "T_PLUS",
508
- "T_NTH",
509
- "T_INT",
510
- "T_STRING",
511
- "T_ODD",
512
- "T_EVEN",
513
- "T_DOT",
514
- "T_HASH",
515
- "$start",
516
- "css",
517
- "selectors",
518
- "selector",
519
- "selectors_",
520
- "predicates",
521
- "descendant_or_self",
522
- "axis",
523
- "node_test",
524
- "axis_selector",
525
- "node_name",
526
- "predicate",
527
- "class",
528
- "id",
529
- "pseudo_class",
530
- "attribute_predicate",
531
- "attribute_predicate_members",
532
- "attribute",
533
- "operator",
534
- "string",
535
- "pseudo_name",
536
- "pseudo_args",
537
- "pseudo_arg",
538
- "integer",
539
- "odd",
540
- "even",
541
- "nth" ]
542
-
543
- Racc_debug_parser = false
544
-
545
- ##### State transition tables end #####
546
-
547
- # reduce 0 omitted
548
-
549
- def _reduce_1(val, _values)
550
- val[0]
551
- end
614
+ def _rule_0(val)
615
+ val[0]
616
+ end
552
617
 
553
- def _reduce_2(val, _values)
554
- nil
555
- end
618
+ def _rule_1(val)
619
+ nil
620
+ end
621
+
622
+ def _rule_2(val)
623
+
624
+ # Single selector
625
+ if val[1].empty?
626
+ ret = val[0]
556
627
 
557
- def _reduce_3(val, _values)
558
- # a single "+ y" selector
559
- if val[0].is_a?(Array)
560
- return s(:path, *val[0])
561
- else
562
- return val[0]
628
+ if ret.is_a?(Array)
629
+ ret = s(:path, *ret)
563
630
  end
564
-
565
- end
566
631
 
567
- def _reduce_4(val, _values)
568
- s(:path, *val[0].flatten)
569
- end
632
+ # Multiple selectors
633
+ else
634
+ steps = [val[0]]
635
+
636
+ val[1].each do |step|
637
+ # "+ foo" is broken up into two steps.
638
+ if step.is_a?(Array)
639
+ # Using Array#+ or Array#| would require allocating an extra Array
640
+ step.each { |sub| steps << sub }
641
+ else
642
+ steps << step
643
+ end
644
+ end
570
645
 
571
- def _reduce_5(val, _values)
572
- val[0] << val[2]
573
- end
646
+ ret = s(:path, *steps)
647
+ end
574
648
 
575
- def _reduce_6(val, _values)
576
- [val[0], val[2]]
577
- end
649
+ ret
650
+
651
+ end
578
652
 
579
- def _reduce_7(val, _values)
580
- s(:predicate, s(:axis, 'descendant', on_test(nil, '*')), val[0])
581
-
582
- end
653
+ def _rule_3(val)
654
+ val[1]
655
+ end
583
656
 
584
- # reduce 8 omitted
657
+ def _rule_4(val)
658
+
659
+ val[1] ? s(:predicate, val[0], val[1]) : val[0]
660
+
661
+ end
585
662
 
586
- def _reduce_9(val, _values)
587
- s(:predicate, val[0], val[1])
588
- end
663
+ def _rule_5(val)
664
+
665
+ val[1] ? s(:predicate, val[0], val[1]) : val[0]
666
+
667
+ end
589
668
 
590
- # reduce 10 omitted
669
+ def _rule_6(val)
670
+
671
+ s(:predicate, s(:axis, 'descendant', on_test(nil, '*')), val[0])
672
+
673
+ end
591
674
 
592
- def _reduce_11(val, _values)
593
- s(:predicate, val[0], val[1])
594
- end
675
+ def _rule_7(val)
676
+ s(:axis, 'descendant', val[0])
677
+ end
595
678
 
596
- def _reduce_12(val, _values)
597
- s(:axis, 'descendant', val[0])
598
- end
679
+ def _rule_8(val)
680
+
681
+ s(:axis, 'child', val[1])
682
+
683
+ end
599
684
 
600
- def _reduce_13(val, _values)
601
- s(:axis, 'child', val[1])
602
-
603
- end
685
+ def _rule_9(val)
686
+
687
+ s(:axis, 'following-sibling', val[1])
688
+
689
+ end
604
690
 
605
- def _reduce_14(val, _values)
606
- s(:axis, 'following-sibling', val[1])
607
-
608
- end
691
+ def _rule_10(val)
692
+
693
+ [
694
+ s(
695
+ :predicate,
696
+ s(:axis, 'following-sibling', on_test(nil, '*')),
697
+ s(:int, 1)
698
+ ),
699
+ s(:axis, 'self', val[1])
700
+ ]
701
+
702
+ end
609
703
 
610
- def _reduce_15(val, _values)
611
- [
612
- s(
613
- :predicate,
614
- s(:axis, 'following-sibling', on_test(nil, '*')),
615
- s(:int, 1)
616
- ),
617
- s(:axis, 'self', val[1])
618
- ]
619
-
620
- end
704
+ def _rule_11(val)
705
+ val[0]
706
+ end
621
707
 
622
- # reduce 16 omitted
708
+ def _rule_12(val)
709
+ val[0]
710
+ end
623
711
 
624
- # reduce 17 omitted
712
+ def _rule_13(val)
713
+ on_test(*val[0])
714
+ end
625
715
 
626
- # reduce 18 omitted
716
+ def _rule_14(val)
717
+ val[1] ? [val[0], val[1]] : [nil, val[0]]
718
+ end
627
719
 
628
- def _reduce_19(val, _values)
629
- on_test(*val[0])
630
- end
720
+ def _rule_15(val)
721
+ val[1]
722
+ end
631
723
 
632
- def _reduce_20(val, _values)
633
- [nil, val[0]]
634
- end
724
+ def _rule_16(val)
725
+
726
+ ret = val[0]
635
727
 
636
- def _reduce_21(val, _values)
637
- [val[0], val[2]]
638
- end
728
+ val[1].each do |pred|
729
+ ret = s(:and, ret, pred)
730
+ end
639
731
 
640
- def _reduce_22(val, _values)
641
- s(:and, val[0], val[1])
642
- end
732
+ ret
733
+
734
+ end
643
735
 
644
- # reduce 23 omitted
736
+ def _rule_17(val)
737
+ val[0]
738
+ end
645
739
 
646
- # reduce 24 omitted
740
+ def _rule_18(val)
741
+ val[0]
742
+ end
647
743
 
648
- # reduce 25 omitted
744
+ def _rule_19(val)
745
+ val[0]
746
+ end
649
747
 
650
- # reduce 26 omitted
748
+ def _rule_20(val)
749
+ val[0]
750
+ end
651
751
 
652
- # reduce 27 omitted
752
+ def _rule_21(val)
753
+ val[1]
754
+ end
653
755
 
654
- def _reduce_28(val, _values)
655
- val[1]
656
- end
756
+ def _rule_22(val)
757
+ val[0]
758
+ end
657
759
 
658
- # reduce 29 omitted
760
+ def _rule_23(val)
761
+ s(:axis, 'attribute', on_test(*val[0]))
762
+ end
659
763
 
660
- # reduce 30 omitted
764
+ def _rule_24(val)
765
+
766
+ op_type = val[1] ? val[1][0] : nil
661
767
 
662
- def _reduce_31(val, _values)
663
- s(:axis, 'attribute', on_test(*val[0]))
664
- end
768
+ case op_type
769
+ # a="b"
770
+ when :eq
771
+ on_op_eq(val[0], val[1][1])
665
772
 
666
- def _reduce_32(val, _values)
667
- s(:eq, val[0], val[2])
668
-
669
- end
773
+ # a~="b"
774
+ when :space_in
775
+ on_op_space_in(val[0], val[1][1])
670
776
 
671
- def _reduce_33(val, _values)
672
- s(
673
- :call,
674
- 'contains',
675
- s(:call, 'concat', s(:string, ' '), val[0], s(:string, ' ')),
676
- s(:call, 'concat', s(:string, ' '), val[2], s(:string, ' '))
677
- )
678
-
679
- end
777
+ # a^="b"
778
+ when :starts_with
779
+ on_op_starts_with(val[0], val[1][1])
680
780
 
681
- def _reduce_34(val, _values)
682
- s(:call, 'starts-with', val[0], val[2])
683
-
684
- end
781
+ # a$="b"
782
+ when :ends_with
783
+ on_op_ends_with(val[0], val[1][1])
685
784
 
686
- def _reduce_35(val, _values)
687
- s(
688
- :eq,
689
- s(
690
- :call,
691
- 'substring',
692
- val[0],
693
- s(
694
- :add,
695
- s(
696
- :sub,
697
- s(:call, 'string-length', val[0]),
698
- s(:call, 'string-length', val[2])
699
- ),
700
- s(:int, 1)
701
- ),
702
- s(:call, 'string-length', val[2])
703
- ),
704
- val[2]
705
- )
706
-
707
- end
785
+ # a*="b"
786
+ when :in
787
+ on_op_in(val[0], val[1][1])
708
788
 
709
- def _reduce_36(val, _values)
710
- s(:call, 'contains', val[0], val[2])
711
-
712
- end
789
+ # a|="b"
790
+ when :hyphen_in
791
+ on_op_hyphen_in(val[0], val[1][1])
713
792
 
714
- def _reduce_37(val, _values)
715
- s(
716
- :or,
717
- s(:eq, val[0], val[2]),
718
- s(
719
- :call,
720
- 'starts-with',
721
- val[0],
722
- s(:call, 'concat', val[2], s(:string, '-'))
723
- )
724
- )
725
-
726
- end
793
+ else
794
+ val[0]
795
+ end
796
+
797
+ end
727
798
 
728
- def _reduce_38(val, _values)
729
- axis = s(:axis, 'attribute', s(:test, nil, 'class'))
799
+ def _rule_25(val)
800
+ :eq
801
+ end
730
802
 
731
- s(
732
- :call,
733
- 'contains',
734
- s(:call, 'concat', s(:string, ' '), axis, s(:string, ' ')),
735
- s(:string, " #{val[1]} ")
736
- )
737
-
738
- end
803
+ def _rule_26(val)
804
+ :space_in
805
+ end
739
806
 
740
- def _reduce_39(val, _values)
741
- s(
742
- :eq,
743
- s(:axis, 'attribute', s(:test, nil, 'id')),
744
- s(:string, val[1])
745
- )
746
-
747
- end
807
+ def _rule_27(val)
808
+ :starts_with
809
+ end
748
810
 
749
- def _reduce_40(val, _values)
750
- on_pseudo_class(val[0])
751
- end
811
+ def _rule_28(val)
812
+ :ends_with
813
+ end
752
814
 
753
- def _reduce_41(val, _values)
754
- on_pseudo_class(val[0], val[1])
755
- end
815
+ def _rule_29(val)
816
+ :in
817
+ end
756
818
 
757
- def _reduce_42(val, _values)
758
- val[1]
759
- end
819
+ def _rule_30(val)
820
+ :hyphen_in
821
+ end
760
822
 
761
- def _reduce_43(val, _values)
762
- val[1]
763
- end
823
+ def _rule_31(val)
824
+
825
+ axis = s(:axis, 'attribute', s(:test, nil, 'class'))
826
+
827
+ s(
828
+ :call,
829
+ 'contains',
830
+ s(:call, 'concat', s(:string, ' '), axis, s(:string, ' ')),
831
+ s(:string, " #{val[1]} ")
832
+ )
833
+
834
+ end
764
835
 
765
- # reduce 44 omitted
836
+ def _rule_32(val)
837
+
838
+ s(
839
+ :eq,
840
+ s(:axis, 'attribute', s(:test, nil, 'id')),
841
+ s(:string, val[1])
842
+ )
843
+
844
+ end
766
845
 
767
- # reduce 45 omitted
846
+ def _rule_33(val)
847
+ on_pseudo_class(val[0], val[1])
848
+ end
768
849
 
769
- # reduce 46 omitted
850
+ def _rule_34(val)
851
+ val[1]
852
+ end
770
853
 
771
- # reduce 47 omitted
854
+ def _rule_35(val)
855
+ val[1]
856
+ end
772
857
 
773
- # reduce 48 omitted
858
+ def _rule_36(val)
859
+ val[0]
860
+ end
774
861
 
775
- def _reduce_49(val, _values)
776
- s(:string, val[0])
777
- end
862
+ def _rule_37(val)
863
+ val[0]
864
+ end
778
865
 
779
- def _reduce_50(val, _values)
780
- s(:int, val[0].to_i)
781
- end
866
+ def _rule_38(val)
867
+ val[0]
868
+ end
782
869
 
783
- def _reduce_51(val, _values)
784
- s(:nth, s(:int, 1))
785
- end
870
+ def _rule_39(val)
871
+ val[0]
872
+ end
786
873
 
787
- def _reduce_52(val, _values)
788
- s(:nth, s(:int, 1), val[1])
789
- end
874
+ def _rule_40(val)
875
+ s(:string, val[0])
876
+ end
790
877
 
791
- def _reduce_53(val, _values)
792
- s(:nth, s(:int, 1))
793
- end
878
+ def _rule_41(val)
879
+ s(:int, val[0].to_i)
880
+ end
794
881
 
795
- def _reduce_54(val, _values)
796
- s(:nth, s(:int, -1), val[2])
797
- end
882
+ def _rule_42(val)
883
+
884
+ val[1] ? s(:nth, s(:int, 1), val[1]) : s(:nth, s(:int, 1))
885
+
886
+ end
798
887
 
799
- def _reduce_55(val, _values)
800
- s(:nth, val[0])
801
- end
888
+ def _rule_43(val)
889
+
890
+ val[2] ? s(:nth, s(:int, -1), val[2]) : s(:nth, s(:int, 1))
891
+
892
+ end
802
893
 
803
- def _reduce_56(val, _values)
894
+ def _rule_44(val)
895
+
896
+ # 2n+1
897
+ if val[1] and val[2]
804
898
  a = val[0]
805
899
  b = val[2]
806
900
 
@@ -810,21 +904,73 @@ def _reduce_56(val, _values)
810
904
  end
811
905
 
812
906
  s(:nth, a, b)
813
-
814
- end
815
907
 
816
- def _reduce_57(val, _values)
817
- s(:nth, s(:int, 2), s(:int, 1))
818
- end
908
+ # 2n
909
+ elsif val[1]
910
+ s(:nth, val[0])
819
911
 
820
- def _reduce_58(val, _values)
821
- s(:nth, s(:int, 2))
822
- end
912
+ # 2
913
+ else
914
+ val[0]
915
+ end
916
+
917
+ end
823
918
 
824
- def _reduce_none(val, _values)
825
- val[0]
826
- end
919
+ def _rule_45(val)
920
+ :nth
921
+ end
922
+
923
+ def _rule_46(val)
924
+ s(:nth, s(:int, 2), s(:int, 1))
925
+ end
926
+
927
+ def _rule_47(val)
928
+ s(:nth, s(:int, 2))
929
+ end
827
930
 
828
- end # class Parser
829
- end # module CSS
830
- end # module Oga
931
+ def _rule_48(val)
932
+ val[0]
933
+ end
934
+
935
+ def _rule_49(val)
936
+ val[0]
937
+ end
938
+
939
+ def _rule_50(val)
940
+ val[0]
941
+ end
942
+
943
+ def _rule_51(val)
944
+ val[0]
945
+ end
946
+
947
+ def _rule_52(val)
948
+ val[0]
949
+ end
950
+
951
+ def _rule_53(val)
952
+ val
953
+ end
954
+
955
+ def _rule_54(val)
956
+ val[0]
957
+ end
958
+
959
+ def _rule_55(val)
960
+ val[0]
961
+ end
962
+
963
+ def _rule_56(val)
964
+ val[0]
965
+ end
966
+
967
+ def _rule_57(val)
968
+ val[0]
969
+ end
970
+
971
+ def _rule_58(val)
972
+ val[0]
973
+ end
974
+ end
975
+ end
976
+ end