oga 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,9 +84,7 @@ module Oga
84
84
  def parse(&block)
85
85
  @block = block
86
86
 
87
- yyparse(self, :yield_next_token)
88
-
89
- reset
87
+ super
90
88
 
91
89
  return
92
90
  end
@@ -35,7 +35,7 @@ module Oga
35
35
  # @see [Oga::XPath::Evaluator#initialize]
36
36
  #
37
37
  def css(expression)
38
- ast = CSS::Parser.new(expression).parse
38
+ ast = CSS::Parser.parse_with_cache(expression)
39
39
 
40
40
  return XPath::Evaluator.new(self).evaluate_ast(ast)
41
41
  end
@@ -17,6 +17,8 @@ module Oga
17
17
  # * `on_text`
18
18
  # * `on_element`
19
19
  # * `on_element_children`
20
+ # * `on_attribute`
21
+ # * `on_attributes`
20
22
  # * `after_element`
21
23
  #
22
24
  # For example:
@@ -57,6 +59,14 @@ module Oga
57
59
  # end
58
60
  # end
59
61
  #
62
+ # ## Attributes
63
+ #
64
+ # Attributes returned by `on_attribute` are passed as an Hash as the 3rd
65
+ # argument of the `on_element` callback. The keys of this Hash are the
66
+ # attribute names (optionally prefixed by their namespace) and their values.
67
+ # You can overwrite `on_attribute` to control individual attributes and
68
+ # `on_attributes` to control the final set.
69
+ #
60
70
  class SaxParser < Parser
61
71
  ##
62
72
  # @param [Object] handler The SAX handler to delegate callbacks to.
@@ -86,7 +96,7 @@ module Oga
86
96
  # @see [Oga::XML::Parser#on_element]
87
97
  # @return [Array]
88
98
  #
89
- def on_element(namespace, name, attrs = {})
99
+ def on_element(namespace, name, attrs = [])
90
100
  run_callback(:on_element, namespace, name, attrs)
91
101
 
92
102
  return namespace, name
@@ -101,6 +111,45 @@ module Oga
101
111
  #
102
112
  def after_element(namespace_with_name)
103
113
  run_callback(:after_element, *namespace_with_name)
114
+
115
+ return
116
+ end
117
+
118
+ ##
119
+ # Manually overwrite this method since for this one we _do_ want the
120
+ # return value so it can be passed to `on_element`.
121
+ #
122
+ # @see [Oga::XML::Parser#on_attribute]
123
+ #
124
+ def on_attribute(name, ns = nil, value = nil)
125
+ if @handler.respond_to?(:on_attribute)
126
+ return run_callback(:on_attribute, name, ns, value)
127
+ end
128
+
129
+ key = ns ? "#{ns}:#{name}" : name
130
+
131
+ return {key => value}
132
+ end
133
+
134
+ ##
135
+ # Merges the attributes together into a Hash.
136
+ #
137
+ # @param [Array] attrs
138
+ # @return [Hash]
139
+ #
140
+ def on_attributes(attrs)
141
+ if @handler.respond_to?(:on_attributes)
142
+ return run_callback(:on_attributes, attrs)
143
+ end
144
+
145
+ merged = {}
146
+
147
+ attrs.each do |pair|
148
+ # Hash#merge requires an extra allocation, this doesn't.
149
+ pair.each { |key, value| merged[key] = value }
150
+ end
151
+
152
+ return merged
104
153
  end
105
154
 
106
155
  private
@@ -5,19 +5,48 @@ module Oga
5
5
  # have any children, attributes and the likes; just text.
6
6
  #
7
7
  class Text < CharacterNode
8
+ def initialize(*args)
9
+ super
10
+
11
+ @decoded = false
12
+ end
13
+
14
+ ##
15
+ # @param [String] value
16
+ #
17
+ def text=(value)
18
+ @decoded = false
19
+ @text = value
20
+ end
21
+
22
+ ##
23
+ # Returns the text as a String. Upon the first call any XML/HTML entities
24
+ # are decoded.
25
+ #
26
+ # @return [String]
27
+ #
28
+ def text
29
+ unless @decoded
30
+ decoder = html? ? HTML::Entities : Entities
31
+ @text = decoder.decode(@text)
32
+ @decoded = true
33
+ end
34
+
35
+ return @text
36
+ end
37
+
8
38
  ##
9
39
  # @see [Oga::XML::CharacterNode#to_xml]
10
40
  #
11
41
  def to_xml
12
42
  node = parent
13
- root = root_node
14
43
 
15
- if root.is_a?(Document) and node.is_a?(Element) and root.html? \
44
+ if node.is_a?(Element) and html? \
16
45
  and Lexer::LITERAL_HTML_ELEMENTS.include?(node.name)
17
46
  return super
18
- else
19
- return Entities.encode(super)
20
47
  end
48
+
49
+ return Entities.encode(super)
21
50
  end
22
51
  end # Text
23
52
  end # XML
@@ -82,7 +82,7 @@ module Oga
82
82
  # @return [Mixed]
83
83
  #
84
84
  def evaluate(string)
85
- ast = Parser.new(string).parse
85
+ ast = Parser.parse_with_cache(string)
86
86
 
87
87
  return evaluate_ast(ast)
88
88
  end
@@ -1657,6 +1657,11 @@ module Oga
1657
1657
  ns_matches = true
1658
1658
  end
1659
1659
 
1660
+ if !ns and !ns_matches
1661
+ ns_matches = xml_node.respond_to?(:default_namespace?) &&
1662
+ xml_node.default_namespace?
1663
+ end
1664
+
1660
1665
  return name_matches && ns_matches
1661
1666
  end
1662
1667
 
@@ -1463,9 +1463,8 @@ ts = p
1463
1463
  _keys = cs << 1
1464
1464
  _inds = _xpath_lexer_index_offsets[cs]
1465
1465
  _slen = _xpath_lexer_key_spans[cs]
1466
- _wide = ( _wide)
1467
- _wide = (data.getbyte(p) || 0)
1468
- _trans = if ( _slen > 0 &&
1466
+ _wide = ( (data.getbyte(p) || 0))
1467
+ _trans = if ( _slen > 0 &&
1469
1468
  _xpath_lexer_trans_keys[_keys] <= _wide &&
1470
1469
  _wide <= _xpath_lexer_trans_keys[_keys + 1]
1471
1470
  ) then
@@ -1,13 +1,257 @@
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 XPath
8
+ ##
9
+ # AST parser for XPath expressions. The AST is built using `AST::Node`
10
+ # instances.
1
11
  #
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.12
4
- # from Racc grammer file "".
12
+ # Unlike {Oga::XML::Parser} this parser only takes String instances as input.
5
13
  #
14
+ class Parser < LL::Driver
15
+ CONFIG = LL::DriverConfig.new
16
+
17
+ CONFIG.terminals = [
18
+ :$EOF, # 0
19
+ :T_AXIS, # 1
20
+ :T_COLON, # 2
21
+ :T_COMMA, # 3
22
+ :T_FLOAT, # 4
23
+ :T_INT, # 5
24
+ :T_IDENT, # 6
25
+ :T_TYPE_TEST, # 7
26
+ :T_LBRACK, # 8
27
+ :T_RBRACK, # 9
28
+ :T_LPAREN, # 10
29
+ :T_RPAREN, # 11
30
+ :T_SLASH, # 12
31
+ :T_STRING, # 13
32
+ :T_PIPE, # 14
33
+ :T_AND, # 15
34
+ :T_OR, # 16
35
+ :T_ADD, # 17
36
+ :T_DIV, # 18
37
+ :T_MOD, # 19
38
+ :T_EQ, # 20
39
+ :T_NEQ, # 21
40
+ :T_LT, # 22
41
+ :T_GT, # 23
42
+ :T_LTE, # 24
43
+ :T_GTE, # 25
44
+ :T_SUB, # 26
45
+ :T_MUL, # 27
46
+ :T_VAR, # 28
47
+ ].freeze
48
+
49
+ CONFIG.rules = [
50
+ [3, 0, 8, 34], # 0
51
+ [3, 1, 4, 35, 6, 0, 0, 3], # 1
52
+ [3, 2, 0, 3, 1, 16], # 2
53
+ [3, 3, 4, 36, 6, 0, 0, 5], # 3
54
+ [3, 4, 0, 5, 1, 15], # 4
55
+ [3, 5, 4, 37, 6, 0, 0, 7], # 5
56
+ [3, 6, 0, 7, 1, 20], # 6
57
+ [3, 7, 0, 7, 1, 21], # 7
58
+ [3, 8, 4, 38, 6, 0, 0, 9], # 8
59
+ [3, 9, 0, 9, 1, 22], # 9
60
+ [3, 10, 0, 9, 1, 23], # 10
61
+ [3, 11, 0, 9, 1, 24], # 11
62
+ [3, 12, 0, 9, 1, 25], # 12
63
+ [3, 13, 4, 39, 6, 0, 0, 11], # 13
64
+ [3, 14, 0, 11, 1, 17], # 14
65
+ [3, 15, 0, 11, 1, 26], # 15
66
+ [3, 16, 8, 40, 0, 13], # 16
67
+ [3, 17, 0, 11, 1, 18], # 17
68
+ [3, 18, 0, 11, 1, 19], # 18
69
+ [3, 19, 0, 11, 1, 27], # 19
70
+ [3, 20, 4, 41, 6, 0, 0, 15], # 20
71
+ [3, 21, 0, 15, 1, 14], # 21
72
+ [3, 22, 0, 16], # 22
73
+ [3, 23, 0, 19], # 23
74
+ [3, 24, 0, 31], # 24
75
+ [3, 25, 0, 32], # 25
76
+ [3, 26, 0, 33], # 26
77
+ [3, 27, 1, 11, 0, 1, 1, 10], # 27
78
+ [3, 28, 0, 17], # 28
79
+ [3, 29, 4, 42, 6, 0, 0, 20], # 29
80
+ [3, 30, 0, 20, 1, 12], # 30
81
+ [3, 31, 8, 43, 1, 12], # 31
82
+ [3, 32, 0, 21], # 32
83
+ [3, 33, 0, 29], # 33
84
+ [3, 34, 0, 22, 1, 6], # 34
85
+ [3, 35, 0, 24], # 35
86
+ [3, 36, 1, 11, 0, 27, 1, 10], # 36
87
+ [3, 37, 8, 44, 1, 6, 1, 2], # 37
88
+ [3, 38, 8, 45], # 38
89
+ [3, 39, 1, 9, 0, 1, 1, 8], # 39
90
+ [3, 40, 1, 7], # 40
91
+ [3, 41, 8, 46, 1, 6], # 41
92
+ [3, 42, 1, 6, 1, 2], # 42
93
+ [3, 43, 4, 47, 6, 0, 0, 1], # 43
94
+ [3, 44, 2, 0], # 44
95
+ [3, 45, 0, 1, 1, 3], # 45
96
+ [3, 46, 8, 48, 0, 30, 1, 1], # 46
97
+ [3, 47, 0, 25], # 47
98
+ [3, 48, 0, 24], # 48
99
+ [3, 49, 1, 13], # 49
100
+ [3, 50, 1, 5], # 50
101
+ [3, 51, 1, 4], # 51
102
+ [3, 52, 1, 28], # 52
103
+ [3, 53, 0, 1], # 53
104
+ [3, 54, 0, 2], # 54
105
+ [3, 55, 0, 4], # 55
106
+ [3, 56, 0, 6], # 56
107
+ [3, 57, 0, 8], # 57
108
+ [3, 58, 0, 10], # 58
109
+ [3, 59, 0, 12], # 59
110
+ [3, 60, 0, 14], # 60
111
+ [3, 61, 0, 18], # 61
112
+ [3, 62, 0, 17], # 62
113
+ [3, 63, 0, 23], # 63
114
+ [3, 64, 0, 23], # 64
115
+ [3, 65, 0, 26], # 65
116
+ [3, 66, 0, 28], # 66
117
+ [3, 67, 0, 23], # 67
118
+ ].freeze
119
+
120
+ CONFIG.table = [
121
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 0
122
+ [-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, -1, -1, -1, 1], # 1
123
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 2
124
+ [-1, 3, -1, -1, 3, 3, 3, 3, -1, -1, 3, -1, 3, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3], # 3
125
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 4
126
+ [-1, 5, -1, -1, 5, 5, 5, 5, -1, -1, 5, -1, 5, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5], # 5
127
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, -1], # 6
128
+ [-1, 8, -1, -1, 8, 8, 8, 8, -1, -1, 8, -1, 8, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8], # 7
129
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 10, 11, 12, -1, -1, -1], # 8
130
+ [-1, 13, -1, -1, 13, 13, 13, 13, -1, -1, 13, -1, 13, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13], # 9
131
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1], # 10
132
+ [-1, 16, -1, -1, 16, 16, 16, 16, -1, -1, 16, -1, 16, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16], # 11
133
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 18, -1, -1, -1, -1, -1, -1, -1, 19, -1], # 12
134
+ [-1, 20, -1, -1, 20, 20, 20, 20, -1, -1, 20, -1, 20, 20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 20], # 13
135
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 14
136
+ [-1, 22, -1, -1, 25, 25, 22, 22, -1, -1, 27, -1, 23, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26], # 15
137
+ [-1, 28, -1, -1, -1, -1, 28, 28, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 16
138
+ [-1, 29, -1, -1, -1, -1, 29, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 17
139
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 30, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 18
140
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 19
141
+ [-1, 33, -1, -1, -1, -1, 32, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 20
142
+ [-1, -1, -1, -1, -1, -1, 34, 35, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 21
143
+ [38, 38, 37, 38, 38, 38, 38, 38, 38, 38, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38], # 22
144
+ [-1, -1, -1, -1, -1, -1, -1, -1, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 23
145
+ [-1, -1, -1, -1, -1, -1, -1, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 24
146
+ [-1, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 25
147
+ [-1, -1, 42, -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, -1], # 26
148
+ [44, 43, 44, 44, 43, 43, 43, 43, 44, 44, 43, 44, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 43], # 27
149
+ [-1, -1, -1, 45, -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], # 28
150
+ [-1, 46, -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, -1, -1], # 29
151
+ [-1, -1, -1, -1, -1, -1, 47, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 30
152
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 49, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 31
153
+ [-1, -1, -1, -1, 51, 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 32
154
+ [-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, -1, -1, -1, 52], # 33
155
+ [-1, 53, -1, -1, 53, 53, 53, 53, -1, -1, 53, -1, 53, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 53], # 34
156
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 35
157
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 36
158
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56, 56, -1, -1, -1, -1, -1, -1, -1], # 37
159
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57, 57, 57, 57, -1, -1, -1], # 38
160
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, 58, -1, -1], # 39
161
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59, 59, -1, -1, -1, -1, -1, -1, -1, 59, -1], # 40
162
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 41
163
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 61, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 42
164
+ [-1, 62, -1, -1, -1, -1, 62, 62, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 43
165
+ [-1, -1, -1, -1, -1, -1, -1, -1, 63, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 44
166
+ [-1, -1, -1, -1, -1, -1, -1, -1, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 45
167
+ [-1, -1, 65, -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, -1], # 46
168
+ [-1, -1, -1, 66, -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], # 47
169
+ [-1, -1, -1, -1, -1, -1, -1, -1, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 48
170
+ ].freeze
171
+
172
+ CONFIG.actions = [
173
+ [:_rule_0, 1], # 0
174
+ [:_rule_1, 2], # 1
175
+ [:_rule_2, 2], # 2
176
+ [:_rule_3, 2], # 3
177
+ [:_rule_4, 2], # 4
178
+ [:_rule_5, 2], # 5
179
+ [:_rule_6, 2], # 6
180
+ [:_rule_7, 2], # 7
181
+ [:_rule_8, 2], # 8
182
+ [:_rule_9, 2], # 9
183
+ [:_rule_10, 2], # 10
184
+ [:_rule_11, 2], # 11
185
+ [:_rule_12, 2], # 12
186
+ [:_rule_13, 2], # 13
187
+ [:_rule_14, 2], # 14
188
+ [:_rule_15, 2], # 15
189
+ [:_rule_16, 2], # 16
190
+ [:_rule_17, 2], # 17
191
+ [:_rule_18, 2], # 18
192
+ [:_rule_19, 2], # 19
193
+ [:_rule_20, 2], # 20
194
+ [:_rule_21, 2], # 21
195
+ [:_rule_22, 1], # 22
196
+ [:_rule_23, 1], # 23
197
+ [:_rule_24, 1], # 24
198
+ [:_rule_25, 1], # 25
199
+ [:_rule_26, 1], # 26
200
+ [:_rule_27, 3], # 27
201
+ [:_rule_28, 1], # 28
202
+ [:_rule_29, 2], # 29
203
+ [:_rule_30, 2], # 30
204
+ [:_rule_31, 2], # 31
205
+ [:_rule_32, 1], # 32
206
+ [:_rule_33, 1], # 33
207
+ [:_rule_34, 2], # 34
208
+ [:_rule_35, 1], # 35
209
+ [:_rule_36, 3], # 36
210
+ [:_rule_37, 3], # 37
211
+ [:_rule_38, 1], # 38
212
+ [:_rule_39, 3], # 39
213
+ [:_rule_40, 1], # 40
214
+ [:_rule_41, 2], # 41
215
+ [:_rule_42, 2], # 42
216
+ [:_rule_43, 2], # 43
217
+ [:_rule_44, 0], # 44
218
+ [:_rule_45, 2], # 45
219
+ [:_rule_46, 3], # 46
220
+ [:_rule_47, 1], # 47
221
+ [:_rule_48, 1], # 48
222
+ [:_rule_49, 1], # 49
223
+ [:_rule_50, 1], # 50
224
+ [:_rule_51, 1], # 51
225
+ [:_rule_52, 1], # 52
226
+ [:_rule_53, 1], # 53
227
+ [:_rule_54, 1], # 54
228
+ [:_rule_55, 1], # 55
229
+ [:_rule_56, 1], # 56
230
+ [:_rule_57, 1], # 57
231
+ [:_rule_58, 1], # 58
232
+ [:_rule_59, 1], # 59
233
+ [:_rule_60, 1], # 60
234
+ [:_rule_61, 1], # 61
235
+ [:_rule_62, 1], # 62
236
+ [:_rule_63, 1], # 63
237
+ [:_rule_64, 1], # 64
238
+ [:_rule_65, 1], # 65
239
+ [:_rule_66, 1], # 66
240
+ [:_rule_67, 1], # 67
241
+ ].freeze
6
242
 
7
- require 'racc/parser.rb'
8
- module Oga
9
- module XPath
10
- class Parser < Racc::Parser
243
+ ##
244
+ # @return [Oga::LRU]
245
+ #
246
+ CACHE = LRU.new
247
+
248
+ ##
249
+ # @param [String] data
250
+ # @return [AST::Node]
251
+ #
252
+ def self.parse_with_cache(data)
253
+ return CACHE.get_or_set(data) { new(data).parse }
254
+ end
11
255
 
12
256
  ##
13
257
  # @param [String] data The input to parse.
@@ -32,531 +276,345 @@ module Oga
32
276
  #
33
277
  # @yieldparam [Array]
34
278
  #
35
- def yield_next_token
36
- @lexer.advance do |*args|
37
- yield args
279
+ def each_token
280
+ @lexer.advance do |type, value, line|
281
+ @line = line if line
282
+
283
+ yield [type, value]
38
284
  end
39
285
 
40
- yield [false, false]
286
+ yield [-1, -1]
41
287
  end
42
288
 
43
289
  ##
44
- # Parses the input and returns the corresponding AST.
45
- #
46
- # @example
47
- # parser = Oga::XPath::Parser.new('//foo')
48
- # ast = parser.parse
290
+ # @param [Array] val
49
291
  #
50
- # @return [AST::Node]
292
+ def combine_operators(val)
293
+ ret = val[0]
294
+
295
+ val[1].each do |expr|
296
+ ret = s(expr[0], ret, expr[1])
297
+ end
298
+
299
+ return ret
300
+ end
301
+
302
+ ##
303
+ # @param [Array] val
51
304
  #
52
- def parse
53
- ast = yyparse(self, :yield_next_token)
54
-
55
- return ast
56
- end
57
- # vim: set ft=racc:
58
- ##### State transition tables begin ###
59
-
60
- racc_action_table = [
61
- 23, 28, 23, 26, 25, 22, 21, 22, 21, 4,
62
- 23, 17, 24, 26, 25, 22, 21, 22, 21, 4,
63
- 23, 17, 24, 26, 25, 22, 21, 27, -17, 4,
64
- 23, 17, 24, 26, 25, 22, 21, 27, -18, 4,
65
- 23, 17, 24, 26, 25, 22, 21, 27, 46, 4,
66
- 23, 17, 24, 26, 25, 22, 21, 27, 46, 4,
67
- 23, 17, 24, 26, 25, 22, 21, 27, 48, 4,
68
- 23, 17, 24, 26, 25, 22, 21, 27, 58, 4,
69
- 23, 17, 24, 26, 25, 22, 21, 27, 73, 4,
70
- 23, 17, 24, 26, 25, 22, 21, 27, 48, 4,
71
- 23, 17, 24, 26, 25, 22, 21, 27, 77, 4,
72
- 23, 17, 24, 26, 25, 22, 21, 27, 48, 4,
73
- 23, 17, 24, 26, 25, 22, 21, 27, 83, 4,
74
- 23, 17, 24, 26, 25, 22, 21, 27, nil, 4,
75
- 23, 17, 24, 26, 25, 22, 21, 27, nil, 4,
76
- 23, 17, 24, 26, 25, 22, 21, 27, nil, 4,
77
- 23, 17, 24, 26, 25, 22, 21, 27, nil, 4,
78
- 23, 17, 24, 26, 25, 22, 21, 27, 53, 4,
79
- 79, 17, 24, nil, nil, nil, 54, 27, nil, 23,
80
- nil, 82, 26, 25, 22, 21, nil, 27, 4, nil,
81
- 17, 24, 29, 30, 31, 32, 33, 34, 35, 36,
82
- 37, 38, 39, 40, 42, 41, 27, 81, nil, nil,
83
- nil, nil, 29, 30, 31, 32, 33, 34, 35, 36,
84
- 37, 38, 39, 40, 42, 41, 29, 30, 31, 32,
85
- 33, 34, 35, 36, 37, 38, 39, 40, 42, 41,
86
- 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
87
- 39, 40, 42, 41, 29, nil, nil, 32, 33, 34,
88
- 35, 36, 37, 38, 39, 40, 42, 41, 29, 30,
89
- nil, 32, 33, 34, 35, 36, 37, 38, 39, 40,
90
- 42, 41, 29, 23, nil, 32, 33, 34, 22, 21,
91
- 37, 38, 39, 40, 42, 41, 29, nil, nil, 32,
92
- 33, 34, nil, nil, 37, 38, 39, 40, 42, 41,
93
- 29, nil, nil, 32, 33, 34, 29, nil, nil, 32,
94
- 33, 34, 42, 41, nil, nil, nil, 29, 42, 41,
95
- 32, 33, 34, 29, nil, nil, 32, 33, 34, 42,
96
- 41, nil, nil, nil, nil, 42, 41 ]
97
-
98
- racc_action_check = [
99
- 0, 1, 17, 0, 0, 0, 0, 17, 17, 0,
100
- 4, 0, 0, 4, 4, 4, 4, 23, 23, 4,
101
- 29, 4, 4, 29, 29, 29, 29, 0, 5, 29,
102
- 30, 29, 29, 30, 30, 30, 30, 4, 9, 30,
103
- 31, 30, 30, 31, 31, 31, 31, 29, 13, 31,
104
- 32, 31, 31, 32, 32, 32, 32, 30, 14, 32,
105
- 33, 32, 32, 33, 33, 33, 33, 31, 15, 33,
106
- 34, 33, 33, 34, 34, 34, 34, 32, 28, 34,
107
- 35, 34, 34, 35, 35, 35, 35, 33, 43, 35,
108
- 36, 35, 35, 36, 36, 36, 36, 34, 51, 36,
109
- 37, 36, 36, 37, 37, 37, 37, 35, 53, 37,
110
- 38, 37, 37, 38, 38, 38, 38, 36, 75, 38,
111
- 39, 38, 38, 39, 39, 39, 39, 37, 80, 39,
112
- 40, 39, 39, 40, 40, 40, 40, 38, nil, 40,
113
- 41, 40, 40, 41, 41, 41, 41, 39, nil, 41,
114
- 42, 41, 41, 42, 42, 42, 42, 40, nil, 42,
115
- 46, 42, 42, 46, 46, 46, 46, 41, nil, 46,
116
- 54, 46, 46, 54, 54, 54, 54, 42, 22, 54,
117
- 54, 54, 54, nil, nil, nil, 22, 46, nil, 82,
118
- nil, 78, 82, 82, 82, 82, nil, 54, 82, nil,
119
- 82, 82, 78, 78, 78, 78, 78, 78, 78, 78,
120
- 78, 78, 78, 78, 78, 78, 82, 74, nil, nil,
121
- nil, nil, 74, 74, 74, 74, 74, 74, 74, 74,
122
- 74, 74, 74, 74, 74, 74, 2, 2, 2, 2,
123
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
124
- 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
125
- 44, 44, 44, 44, 60, nil, nil, 60, 60, 60,
126
- 60, 60, 60, 60, 60, 60, 60, 60, 61, 61,
127
- nil, 61, 61, 61, 61, 61, 61, 61, 61, 61,
128
- 61, 61, 65, 48, nil, 65, 65, 65, 48, 48,
129
- 65, 65, 65, 65, 65, 65, 66, nil, nil, 66,
130
- 66, 66, nil, nil, 66, 66, 66, 66, 66, 66,
131
- 67, nil, nil, 67, 67, 67, 68, nil, nil, 68,
132
- 68, 68, 67, 67, nil, nil, nil, 69, 68, 68,
133
- 69, 69, 69, 70, nil, nil, 70, 70, 70, 69,
134
- 69, nil, nil, nil, nil, 70, 70 ]
135
-
136
- racc_action_pointer = [
137
- -2, 1, 221, nil, 8, 15, nil, nil, nil, 25,
138
- nil, nil, nil, 39, 49, 55, nil, 0, nil, nil,
139
- nil, nil, 175, 10, nil, nil, nil, nil, 78, 18,
140
- 28, 38, 48, 58, 68, 78, 88, 98, 108, 118,
141
- 128, 138, 148, 76, 235, nil, 158, nil, 291, nil,
142
- nil, 85, nil, 101, 168, nil, nil, nil, nil, nil,
143
- 249, 263, nil, nil, nil, 277, 291, 305, 311, 322,
144
- 328, nil, nil, nil, 207, 105, nil, nil, 187, nil,
145
- 116, nil, 187, nil, nil ]
146
-
147
- racc_action_default = [
148
- -2, -58, -1, -3, -58, -5, -6, -7, -8, -9,
149
- -10, -11, -12, -13, -15, -58, -21, -24, -25, -26,
150
- -27, -28, -29, -47, -54, -55, -56, -57, -58, -58,
151
- -58, -58, -58, -58, -58, -58, -58, -58, -58, -58,
152
- -58, -58, -58, -3, -58, -14, -58, -16, -58, -17,
153
- -18, -23, -22, -58, -58, -46, -48, -49, 85, -32,
154
- -33, -34, -35, -36, -37, -38, -39, -40, -41, -42,
155
- -43, -44, -45, -4, -58, -19, -20, -30, -52, -50,
156
- -58, -31, -58, -51, -53 ]
157
-
158
- racc_goto_table = [
159
- 2, 45, 47, 1, 44, 43, 56, 55, nil, nil,
160
- nil, nil, 49, 50, 51, nil, 52, nil, nil, 57,
161
- 80, nil, nil, nil, nil, nil, nil, nil, nil, 59,
162
- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
163
- 70, 71, 72, 49, 50, 75, 74, 76, 84 ]
164
-
165
- racc_goto_check = [
166
- 2, 13, 13, 1, 2, 3, 17, 20, nil, nil,
167
- nil, nil, 4, 8, 15, nil, 16, nil, nil, 8,
168
- 21, nil, nil, nil, nil, nil, nil, nil, nil, 2,
169
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
170
- 2, 2, 2, 4, 8, 15, 2, 16, 21 ]
171
-
172
- racc_goto_pointer = [
173
- nil, 3, 0, 1, -5, nil, nil, nil, -4, nil,
174
- nil, nil, nil, -12, nil, -3, -1, -17, nil, nil,
175
- -16, -34 ]
176
-
177
- racc_goto_default = [
178
- nil, nil, 78, 3, 5, 6, 7, 8, 9, 10,
179
- 11, 12, 13, nil, 14, 15, 16, 18, 19, 20,
180
- nil, nil ]
181
-
182
- racc_reduce_table = [
183
- 0, 0, :racc_error,
184
- 1, 31, :_reduce_1,
185
- 0, 31, :_reduce_2,
186
- 1, 32, :_reduce_none,
187
- 3, 32, :_reduce_4,
188
- 1, 33, :_reduce_none,
189
- 1, 33, :_reduce_none,
190
- 1, 33, :_reduce_none,
191
- 1, 33, :_reduce_none,
192
- 1, 33, :_reduce_none,
193
- 1, 33, :_reduce_none,
194
- 1, 33, :_reduce_none,
195
- 1, 33, :_reduce_none,
196
- 1, 34, :_reduce_none,
197
- 2, 34, :_reduce_14,
198
- 1, 34, :_reduce_none,
199
- 2, 34, :_reduce_16,
200
- 1, 45, :_reduce_none,
201
- 1, 45, :_reduce_none,
202
- 3, 46, :_reduce_19,
203
- 3, 46, :_reduce_20,
204
- 1, 39, :_reduce_21,
205
- 2, 40, :_reduce_22,
206
- 2, 40, :_reduce_23,
207
- 1, 40, :_reduce_24,
208
- 1, 42, :_reduce_25,
209
- 1, 47, :_reduce_26,
210
- 1, 47, :_reduce_27,
211
- 1, 49, :_reduce_28,
212
- 1, 48, :_reduce_29,
213
- 3, 48, :_reduce_30,
214
- 3, 43, :_reduce_31,
215
- 3, 35, :_reduce_32,
216
- 3, 35, :_reduce_33,
217
- 3, 35, :_reduce_34,
218
- 3, 35, :_reduce_35,
219
- 3, 35, :_reduce_36,
220
- 3, 35, :_reduce_37,
221
- 3, 35, :_reduce_38,
222
- 3, 35, :_reduce_39,
223
- 3, 35, :_reduce_40,
224
- 3, 35, :_reduce_41,
225
- 3, 35, :_reduce_42,
226
- 3, 35, :_reduce_43,
227
- 3, 35, :_reduce_44,
228
- 3, 35, :_reduce_45,
229
- 2, 44, :_reduce_46,
230
- 1, 44, :_reduce_47,
231
- 1, 50, :_reduce_none,
232
- 1, 50, :_reduce_none,
233
- 3, 38, :_reduce_50,
234
- 4, 38, :_reduce_51,
235
- 1, 51, :_reduce_52,
236
- 3, 51, :_reduce_53,
237
- 1, 36, :_reduce_54,
238
- 1, 37, :_reduce_55,
239
- 1, 37, :_reduce_56,
240
- 1, 41, :_reduce_57 ]
241
-
242
- racc_reduce_n = 58
243
-
244
- racc_shift_n = 85
245
-
246
- racc_token_table = {
247
- false => 0,
248
- :error => 1,
249
- :T_AXIS => 2,
250
- :T_COLON => 3,
251
- :T_COMMA => 4,
252
- :T_FLOAT => 5,
253
- :T_INT => 6,
254
- :T_IDENT => 7,
255
- :T_TYPE_TEST => 8,
256
- :T_LBRACK => 9,
257
- :T_RBRACK => 10,
258
- :T_LPAREN => 11,
259
- :T_RPAREN => 12,
260
- :T_SLASH => 13,
261
- :T_STRING => 14,
262
- :T_PIPE => 15,
263
- :T_AND => 16,
264
- :T_OR => 17,
265
- :T_ADD => 18,
266
- :T_DIV => 19,
267
- :T_MOD => 20,
268
- :T_EQ => 21,
269
- :T_NEQ => 22,
270
- :T_LT => 23,
271
- :T_GT => 24,
272
- :T_LTE => 25,
273
- :T_GTE => 26,
274
- :T_SUB => 27,
275
- :T_MUL => 28,
276
- :T_VAR => 29 }
277
-
278
- racc_nt_base = 30
279
-
280
- racc_use_result_var = false
281
-
282
- Racc_arg = [
283
- racc_action_table,
284
- racc_action_check,
285
- racc_action_default,
286
- racc_action_pointer,
287
- racc_goto_table,
288
- racc_goto_check,
289
- racc_goto_default,
290
- racc_goto_pointer,
291
- racc_nt_base,
292
- racc_reduce_table,
293
- racc_token_table,
294
- racc_shift_n,
295
- racc_reduce_n,
296
- racc_use_result_var ]
297
-
298
- Racc_token_to_s_table = [
299
- "$end",
300
- "error",
301
- "T_AXIS",
302
- "T_COLON",
303
- "T_COMMA",
304
- "T_FLOAT",
305
- "T_INT",
306
- "T_IDENT",
307
- "T_TYPE_TEST",
308
- "T_LBRACK",
309
- "T_RBRACK",
310
- "T_LPAREN",
311
- "T_RPAREN",
312
- "T_SLASH",
313
- "T_STRING",
314
- "T_PIPE",
315
- "T_AND",
316
- "T_OR",
317
- "T_ADD",
318
- "T_DIV",
319
- "T_MOD",
320
- "T_EQ",
321
- "T_NEQ",
322
- "T_LT",
323
- "T_GT",
324
- "T_LTE",
325
- "T_GTE",
326
- "T_SUB",
327
- "T_MUL",
328
- "T_VAR",
329
- "$start",
330
- "xpath",
331
- "expression",
332
- "expression_members",
333
- "expression_with_predicate",
334
- "operator",
335
- "string",
336
- "number",
337
- "call",
338
- "path",
339
- "absolute_path",
340
- "variable",
341
- "node_test_as_axis",
342
- "predicate",
343
- "axis",
344
- "path_member",
345
- "path_members",
346
- "node_test",
347
- "node_name",
348
- "type_test",
349
- "axis_value",
350
- "call_args" ]
351
-
352
- Racc_debug_parser = false
353
-
354
- ##### State transition tables end #####
355
-
356
- # reduce 0 omitted
357
-
358
- def _reduce_1(val, _values)
359
- val[0]
360
- end
305
+ def combine_optional_operator(val)
306
+ ret = val[0]
361
307
 
362
- def _reduce_2(val, _values)
363
- nil
364
- end
308
+ if val[1]
309
+ ret = s(val[1][0], ret, val[1][1])
310
+ end
365
311
 
366
- # reduce 3 omitted
312
+ ret
313
+ end
367
314
 
368
- def _reduce_4(val, _values)
369
- val[1]
370
- end
315
+ def _rule_0(val)
316
+ val[0]
317
+ end
371
318
 
372
- # reduce 5 omitted
319
+ def _rule_1(val)
320
+ combine_operators(val)
321
+ end
373
322
 
374
- # reduce 6 omitted
323
+ def _rule_2(val)
324
+ [:or, val[1]]
325
+ end
375
326
 
376
- # reduce 7 omitted
327
+ def _rule_3(val)
328
+ combine_operators(val)
329
+ end
377
330
 
378
- # reduce 8 omitted
331
+ def _rule_4(val)
332
+ [:and, val[1]]
333
+ end
379
334
 
380
- # reduce 9 omitted
335
+ def _rule_5(val)
336
+ combine_operators(val)
337
+ end
381
338
 
382
- # reduce 10 omitted
339
+ def _rule_6(val)
340
+ [:eq, val[1]]
341
+ end
383
342
 
384
- # reduce 11 omitted
343
+ def _rule_7(val)
344
+ [:neq, val[1]]
345
+ end
385
346
 
386
- # reduce 12 omitted
347
+ def _rule_8(val)
348
+ combine_operators(val)
349
+ end
387
350
 
388
- # reduce 13 omitted
351
+ def _rule_9(val)
352
+ [:lt, val[1]]
353
+ end
389
354
 
390
- def _reduce_14(val, _values)
391
- s(:predicate, val[0], val[1])
392
- end
355
+ def _rule_10(val)
356
+ [:gt, val[1]]
357
+ end
393
358
 
394
- # reduce 15 omitted
359
+ def _rule_11(val)
360
+ [:lte, val[1]]
361
+ end
395
362
 
396
- def _reduce_16(val, _values)
397
- s(:predicate, val[0], val[1])
398
- end
363
+ def _rule_12(val)
364
+ [:gte, val[1]]
365
+ end
399
366
 
400
- # reduce 17 omitted
367
+ def _rule_13(val)
368
+ combine_operators(val)
369
+ end
401
370
 
402
- # reduce 18 omitted
371
+ def _rule_14(val)
372
+ [:add, val[1]]
373
+ end
403
374
 
404
- def _reduce_19(val, _values)
405
- [val[0], val[2]]
406
- end
375
+ def _rule_15(val)
376
+ [:sub, val[1]]
377
+ end
407
378
 
408
- def _reduce_20(val, _values)
409
- [val[0], *val[2]]
410
- end
379
+ def _rule_16(val)
380
+ combine_optional_operator(val)
381
+ end
411
382
 
412
- def _reduce_21(val, _values)
413
- s(:path, *val[0])
414
- end
383
+ def _rule_17(val)
384
+ [:div, val[1]]
385
+ end
415
386
 
416
- def _reduce_22(val, _values)
417
- s(:absolute_path, *val[1])
418
- end
387
+ def _rule_18(val)
388
+ [:mod, val[1]]
389
+ end
419
390
 
420
- def _reduce_23(val, _values)
421
- s(:absolute_path, val[1])
422
- end
391
+ def _rule_19(val)
392
+ [:mul, val[1]]
393
+ end
423
394
 
424
- def _reduce_24(val, _values)
425
- s(:absolute_path)
426
- end
395
+ def _rule_20(val)
396
+ combine_operators(val)
397
+ end
427
398
 
428
- def _reduce_25(val, _values)
429
- s(:axis, 'child', val[0])
430
- end
399
+ def _rule_21(val)
400
+ [:pipe, val[1]]
401
+ end
431
402
 
432
- def _reduce_26(val, _values)
433
- s(:test, *val[0])
434
- end
403
+ def _rule_22(val)
404
+ val[0]
405
+ end
435
406
 
436
- def _reduce_27(val, _values)
437
- val[0]
438
- end
407
+ def _rule_23(val)
408
+ val[0]
409
+ end
439
410
 
440
- def _reduce_28(val, _values)
441
- s(:type_test, val[0])
442
- end
411
+ def _rule_24(val)
412
+ val[0]
413
+ end
443
414
 
444
- def _reduce_29(val, _values)
445
- [nil, val[0]]
446
- end
415
+ def _rule_25(val)
416
+ val[0]
417
+ end
447
418
 
448
- def _reduce_30(val, _values)
449
- [val[0], val[2]]
450
- end
419
+ def _rule_26(val)
420
+ val[0]
421
+ end
451
422
 
452
- def _reduce_31(val, _values)
453
- val[1]
454
- end
423
+ def _rule_27(val)
424
+ val[1]
425
+ end
455
426
 
456
- def _reduce_32(val, _values)
457
- s(:pipe, val[0], val[2])
458
- end
427
+ def _rule_28(val)
428
+ val[0].length > 1 ? s(:path, *val[0]) : val[0][0]
429
+ end
459
430
 
460
- def _reduce_33(val, _values)
461
- s(:and, val[0], val[2])
462
- end
431
+ def _rule_29(val)
432
+ [val[0], *val[1]]
433
+ end
463
434
 
464
- def _reduce_34(val, _values)
465
- s(:or, val[0], val[2])
466
- end
435
+ def _rule_30(val)
436
+ val[1]
437
+ end
467
438
 
468
- def _reduce_35(val, _values)
469
- s(:add, val[0], val[2])
470
- end
439
+ def _rule_31(val)
440
+ s(:absolute_path, *val[1])
441
+ end
471
442
 
472
- def _reduce_36(val, _values)
473
- s(:div, val[0], val[2])
474
- end
443
+ def _rule_32(val)
444
+ val[0]
445
+ end
475
446
 
476
- def _reduce_37(val, _values)
477
- s(:mod, val[0], val[2])
478
- end
447
+ def _rule_33(val)
448
+ val[0]
449
+ end
479
450
 
480
- def _reduce_38(val, _values)
481
- s(:eq, val[0], val[2])
482
- end
451
+ def _rule_34(val)
452
+
453
+ type = val[1][0]
454
+ args = val[1][1]
455
+ pred = val[1][2]
456
+
457
+ if type == :test
458
+ # Whenever a bare test is used (e.g. just "A") this actually means
459
+ # "child::A". Handling this on parser level is the easiest.
460
+ if args
461
+ node = s(:axis, 'child', s(:test, val[0], args))
462
+ else
463
+ node = s(:axis, 'child', s(:test, nil, val[0]))
464
+ end
465
+ else
466
+ node = s(type, val[0], *args)
467
+ end
468
+
469
+ if pred
470
+ node = s(:predicate, node, pred)
471
+ end
472
+
473
+ node
474
+
475
+ end
483
476
 
484
- def _reduce_39(val, _values)
485
- s(:neq, val[0], val[2])
486
- end
477
+ def _rule_35(val)
478
+ s(:axis, 'child', val[0])
479
+ end
487
480
 
488
- def _reduce_40(val, _values)
489
- s(:lt, val[0], val[2])
490
- end
481
+ def _rule_36(val)
482
+ [:call, val[1]]
483
+ end
491
484
 
492
- def _reduce_41(val, _values)
493
- s(:gt, val[0], val[2])
494
- end
485
+ def _rule_37(val)
486
+ [:test, val[1], val[2]]
487
+ end
495
488
 
496
- def _reduce_42(val, _values)
497
- s(:lte, val[0], val[2])
498
- end
489
+ def _rule_38(val)
490
+ [:test, nil, val[0]]
491
+ end
499
492
 
500
- def _reduce_43(val, _values)
501
- s(:gte, val[0], val[2])
502
- end
493
+ def _rule_39(val)
494
+ val[1]
495
+ end
503
496
 
504
- def _reduce_44(val, _values)
505
- s(:mul, val[0], val[2])
506
- end
497
+ def _rule_40(val)
498
+ s(:type_test, val[0])
499
+ end
507
500
 
508
- def _reduce_45(val, _values)
509
- s(:sub, val[0], val[2])
510
- end
501
+ def _rule_41(val)
502
+
503
+ val[1] ? s(:test, val[0], val[1]) : s(:test, nil, val[0])
504
+
505
+ end
511
506
 
512
- def _reduce_46(val, _values)
513
- s(:axis, val[0], val[1])
514
- end
507
+ def _rule_42(val)
508
+ val[1]
509
+ end
515
510
 
516
- def _reduce_47(val, _values)
517
- s(:axis, val[0])
518
- end
511
+ def _rule_43(val)
512
+ [val[0], *val[1]]
513
+ end
519
514
 
520
- # reduce 48 omitted
515
+ def _rule_44(val)
516
+ val
517
+ end
521
518
 
522
- # reduce 49 omitted
519
+ def _rule_45(val)
520
+ val[1]
521
+ end
523
522
 
524
- def _reduce_50(val, _values)
525
- s(:call, val[0])
526
- end
523
+ def _rule_46(val)
524
+
525
+ ret = s(:axis, val[0], val[1])
527
526
 
528
- def _reduce_51(val, _values)
529
- s(:call, val[0], *val[2])
530
- end
527
+ if val[2]
528
+ ret = s(:predicate, ret, val[2])
529
+ end
531
530
 
532
- def _reduce_52(val, _values)
533
- val
534
- end
531
+ ret
532
+
533
+ end
535
534
 
536
- def _reduce_53(val, _values)
537
- val[2].unshift(val[0])
538
- end
535
+ def _rule_47(val)
536
+ val[0]
537
+ end
539
538
 
540
- def _reduce_54(val, _values)
541
- s(:string, val[0])
542
- end
539
+ def _rule_48(val)
540
+ val[0]
541
+ end
543
542
 
544
- def _reduce_55(val, _values)
545
- s(:int, val[0])
546
- end
543
+ def _rule_49(val)
544
+ s(:string, val[0])
545
+ end
547
546
 
548
- def _reduce_56(val, _values)
549
- s(:float, val[0])
550
- end
547
+ def _rule_50(val)
548
+ s(:int, val[0])
549
+ end
551
550
 
552
- def _reduce_57(val, _values)
553
- s(:var, val[0])
554
- end
551
+ def _rule_51(val)
552
+ s(:float, val[0])
553
+ end
555
554
 
556
- def _reduce_none(val, _values)
557
- val[0]
558
- end
555
+ def _rule_52(val)
556
+ s(:var, val[0])
557
+ end
558
+
559
+ def _rule_53(val)
560
+ val[0]
561
+ end
562
+
563
+ def _rule_54(val)
564
+ val[0]
565
+ end
566
+
567
+ def _rule_55(val)
568
+ val[0]
569
+ end
570
+
571
+ def _rule_56(val)
572
+ val[0]
573
+ end
574
+
575
+ def _rule_57(val)
576
+ val[0]
577
+ end
578
+
579
+ def _rule_58(val)
580
+ val[0]
581
+ end
582
+
583
+ def _rule_59(val)
584
+ val[0]
585
+ end
559
586
 
560
- end # class Parser
561
- end # module XPath
562
- end # module Oga
587
+ def _rule_60(val)
588
+ val[0]
589
+ end
590
+
591
+ def _rule_61(val)
592
+ val[0]
593
+ end
594
+
595
+ def _rule_62(val)
596
+ val[0]
597
+ end
598
+
599
+ def _rule_63(val)
600
+ val[0]
601
+ end
602
+
603
+ def _rule_64(val)
604
+ val[0]
605
+ end
606
+
607
+ def _rule_65(val)
608
+ val[0]
609
+ end
610
+
611
+ def _rule_66(val)
612
+ val[0]
613
+ end
614
+
615
+ def _rule_67(val)
616
+ val[0]
617
+ end
618
+ end
619
+ end
620
+ end