oga 0.2.3-java → 0.3.0-java

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
data/lib/oga/xml/text.rb CHANGED
@@ -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,543 +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, 22, 21, 26, 25, 22, 21, 53, 48, 4,
62
- 79, 17, 24, 23, 77, 54, 26, 25, 22, 21,
63
- 73, 58, 4, 48, 17, 24, 23, 27, 23, 26,
64
- 25, 22, 21, 22, 21, 4, 46, 17, 24, 23,
65
- 27, 23, 26, 25, 22, 21, 22, 21, 4, 46,
66
- 17, 24, 23, 27, -18, 26, 25, 22, 21, 48,
67
- -17, 4, 83, 17, 24, 23, 27, 28, 26, 25,
68
- 22, 21, nil, nil, 4, nil, 17, 24, 23, 27,
69
- nil, 26, 25, 22, 21, nil, nil, 4, nil, 17,
70
- 24, 23, 27, nil, 26, 25, 22, 21, nil, nil,
71
- 4, nil, 17, 24, 23, 27, nil, 26, 25, 22,
72
- 21, nil, nil, 4, nil, 17, 24, 23, 27, nil,
73
- 26, 25, 22, 21, nil, nil, 4, nil, 17, 24,
74
- 23, 27, nil, 26, 25, 22, 21, nil, nil, 4,
75
- nil, 17, 24, 23, 27, nil, 26, 25, 22, 21,
76
- nil, nil, 4, nil, 17, 24, 23, 27, nil, 26,
77
- 25, 22, 21, nil, nil, 4, nil, 17, 24, 23,
78
- 27, nil, 26, 25, 22, 21, nil, nil, 4, nil,
79
- 17, 24, 23, 27, nil, 26, 25, 22, 21, nil,
80
- nil, 4, nil, 17, 24, 23, 27, nil, 26, 25,
81
- 22, 21, nil, nil, 4, nil, 17, 24, 23, 27,
82
- nil, 26, 25, 22, 21, nil, nil, 4, nil, 17,
83
- 24, 23, 27, nil, 26, 25, 22, 21, nil, nil,
84
- 4, nil, 17, 24, 23, 27, nil, 26, 25, 22,
85
- 21, nil, nil, 4, nil, 17, 24, nil, 27, nil,
86
- nil, 82, nil, nil, nil, nil, nil, nil, nil, nil,
87
- nil, 27, 29, 30, 31, 32, 33, 34, 35, 36,
88
- 37, 38, 39, 40, 42, 41, 81, nil, nil, nil,
89
- nil, 29, 30, 31, 32, 33, 34, 35, 36, 37,
90
- 38, 39, 40, 42, 41, 29, 30, 31, 32, 33,
91
- 34, 35, 36, 37, 38, 39, 40, 42, 41, 29,
92
- nil, nil, 32, 33, 34, 35, 36, 37, 38, 39,
93
- 40, 42, 41, 29, 30, nil, 32, 33, 34, 35,
94
- 36, 37, 38, 39, 40, 42, 41, 29, nil, nil,
95
- 32, 33, 34, nil, nil, 37, 38, 39, 40, 42,
96
- 41, 29, nil, nil, 32, 33, 34, nil, nil, 37,
97
- 38, 39, 40, 42, 41, 29, nil, nil, 32, 33,
98
- 34, 29, nil, nil, 32, 33, 34, 42, 41, nil,
99
- nil, nil, 29, 42, 41, 32, 33, 34, 29, nil,
100
- nil, 32, 33, 34, 42, 41, nil, nil, nil, nil,
101
- 42, 41, 29, 30, 31, 32, 33, 34, 35, 36,
102
- 37, 38, 39, 40, 42, 41 ]
103
-
104
- racc_action_check = [
105
- 54, 23, 23, 54, 54, 54, 54, 22, 51, 54,
106
- 54, 54, 54, 46, 53, 22, 46, 46, 46, 46,
107
- 43, 28, 46, 15, 46, 46, 36, 54, 48, 36,
108
- 36, 36, 36, 48, 48, 36, 14, 36, 36, 4,
109
- 46, 17, 4, 4, 4, 4, 17, 17, 4, 13,
110
- 4, 4, 42, 36, 9, 42, 42, 42, 42, 75,
111
- 5, 42, 80, 42, 42, 41, 4, 1, 41, 41,
112
- 41, 41, nil, nil, 41, nil, 41, 41, 40, 42,
113
- nil, 40, 40, 40, 40, nil, nil, 40, nil, 40,
114
- 40, 39, 41, nil, 39, 39, 39, 39, nil, nil,
115
- 39, nil, 39, 39, 38, 40, nil, 38, 38, 38,
116
- 38, nil, nil, 38, nil, 38, 38, 37, 39, nil,
117
- 37, 37, 37, 37, nil, nil, 37, nil, 37, 37,
118
- 35, 38, nil, 35, 35, 35, 35, nil, nil, 35,
119
- nil, 35, 35, 82, 37, nil, 82, 82, 82, 82,
120
- nil, nil, 82, nil, 82, 82, 0, 35, nil, 0,
121
- 0, 0, 0, nil, nil, 0, nil, 0, 0, 29,
122
- 82, nil, 29, 29, 29, 29, nil, nil, 29, nil,
123
- 29, 29, 30, 0, nil, 30, 30, 30, 30, nil,
124
- nil, 30, nil, 30, 30, 31, 29, nil, 31, 31,
125
- 31, 31, nil, nil, 31, nil, 31, 31, 32, 30,
126
- nil, 32, 32, 32, 32, nil, nil, 32, nil, 32,
127
- 32, 33, 31, nil, 33, 33, 33, 33, nil, nil,
128
- 33, nil, 33, 33, 34, 32, nil, 34, 34, 34,
129
- 34, nil, nil, 34, nil, 34, 34, nil, 33, nil,
130
- nil, 78, nil, nil, nil, nil, nil, nil, nil, nil,
131
- nil, 34, 78, 78, 78, 78, 78, 78, 78, 78,
132
- 78, 78, 78, 78, 78, 78, 74, nil, nil, nil,
133
- nil, 74, 74, 74, 74, 74, 74, 74, 74, 74,
134
- 74, 74, 74, 74, 74, 44, 44, 44, 44, 44,
135
- 44, 44, 44, 44, 44, 44, 44, 44, 44, 60,
136
- nil, nil, 60, 60, 60, 60, 60, 60, 60, 60,
137
- 60, 60, 60, 61, 61, nil, 61, 61, 61, 61,
138
- 61, 61, 61, 61, 61, 61, 61, 65, nil, nil,
139
- 65, 65, 65, nil, nil, 65, 65, 65, 65, 65,
140
- 65, 66, nil, nil, 66, 66, 66, nil, nil, 66,
141
- 66, 66, 66, 66, 66, 67, nil, nil, 67, 67,
142
- 67, 68, nil, nil, 68, 68, 68, 67, 67, nil,
143
- nil, nil, 69, 68, 68, 69, 69, 69, 70, nil,
144
- nil, 70, 70, 70, 69, 69, nil, nil, nil, nil,
145
- 70, 70, 2, 2, 2, 2, 2, 2, 2, 2,
146
- 2, 2, 2, 2, 2, 2 ]
147
-
148
- racc_action_pointer = [
149
- 154, 67, 387, nil, 37, 47, nil, nil, nil, 41,
150
- nil, nil, nil, 40, 27, 10, nil, 39, nil, nil,
151
- nil, nil, 4, -6, nil, nil, nil, nil, 21, 167,
152
- 180, 193, 206, 219, 232, 128, 24, 115, 102, 89,
153
- 76, 63, 50, 8, 280, nil, 11, nil, 26, nil,
154
- nil, -5, nil, 7, -2, nil, nil, nil, nil, nil,
155
- 294, 308, nil, nil, nil, 322, 336, 350, 356, 367,
156
- 373, nil, nil, nil, 266, 46, nil, nil, 247, nil,
157
- 50, nil, 141, nil, nil ]
158
-
159
- racc_action_default = [
160
- -2, -58, -1, -3, -58, -5, -6, -7, -8, -9,
161
- -10, -11, -12, -13, -15, -58, -21, -24, -25, -26,
162
- -27, -28, -29, -47, -54, -55, -56, -57, -58, -58,
163
- -58, -58, -58, -58, -58, -58, -58, -58, -58, -58,
164
- -58, -58, -58, -3, -58, -14, -58, -16, -58, -17,
165
- -18, -23, -22, -58, -58, -46, -48, -49, 85, -32,
166
- -33, -34, -35, -36, -37, -38, -39, -40, -41, -42,
167
- -43, -44, -45, -4, -58, -19, -20, -30, -52, -50,
168
- -58, -31, -58, -51, -53 ]
169
-
170
- racc_goto_table = [
171
- 2, 45, 47, 1, 44, 43, 56, 55, nil, nil,
172
- nil, nil, 49, 50, 51, nil, 52, nil, nil, 57,
173
- 80, nil, nil, nil, nil, nil, nil, nil, nil, 59,
174
- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
175
- 70, 71, 72, 49, 50, 75, 74, 76, 84 ]
176
-
177
- racc_goto_check = [
178
- 2, 13, 13, 1, 2, 3, 17, 20, nil, nil,
179
- nil, nil, 4, 8, 15, nil, 16, nil, nil, 8,
180
- 21, nil, nil, nil, nil, nil, nil, nil, nil, 2,
181
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
182
- 2, 2, 2, 4, 8, 15, 2, 16, 21 ]
183
-
184
- racc_goto_pointer = [
185
- nil, 3, 0, 1, -5, nil, nil, nil, -4, nil,
186
- nil, nil, nil, -12, nil, -3, -1, -17, nil, nil,
187
- -16, -34 ]
188
-
189
- racc_goto_default = [
190
- nil, nil, 78, 3, 5, 6, 7, 8, 9, 10,
191
- 11, 12, 13, nil, 14, 15, 16, 18, 19, 20,
192
- nil, nil ]
193
-
194
- racc_reduce_table = [
195
- 0, 0, :racc_error,
196
- 1, 31, :_reduce_1,
197
- 0, 31, :_reduce_2,
198
- 1, 32, :_reduce_none,
199
- 3, 32, :_reduce_4,
200
- 1, 33, :_reduce_none,
201
- 1, 33, :_reduce_none,
202
- 1, 33, :_reduce_none,
203
- 1, 33, :_reduce_none,
204
- 1, 33, :_reduce_none,
205
- 1, 33, :_reduce_none,
206
- 1, 33, :_reduce_none,
207
- 1, 33, :_reduce_none,
208
- 1, 34, :_reduce_none,
209
- 2, 34, :_reduce_14,
210
- 1, 34, :_reduce_none,
211
- 2, 34, :_reduce_16,
212
- 1, 45, :_reduce_none,
213
- 1, 45, :_reduce_none,
214
- 3, 46, :_reduce_19,
215
- 3, 46, :_reduce_20,
216
- 1, 39, :_reduce_21,
217
- 2, 40, :_reduce_22,
218
- 2, 40, :_reduce_23,
219
- 1, 40, :_reduce_24,
220
- 1, 42, :_reduce_25,
221
- 1, 47, :_reduce_26,
222
- 1, 47, :_reduce_27,
223
- 1, 49, :_reduce_28,
224
- 1, 48, :_reduce_29,
225
- 3, 48, :_reduce_30,
226
- 3, 43, :_reduce_31,
227
- 3, 35, :_reduce_32,
228
- 3, 35, :_reduce_33,
229
- 3, 35, :_reduce_34,
230
- 3, 35, :_reduce_35,
231
- 3, 35, :_reduce_36,
232
- 3, 35, :_reduce_37,
233
- 3, 35, :_reduce_38,
234
- 3, 35, :_reduce_39,
235
- 3, 35, :_reduce_40,
236
- 3, 35, :_reduce_41,
237
- 3, 35, :_reduce_42,
238
- 3, 35, :_reduce_43,
239
- 3, 35, :_reduce_44,
240
- 3, 35, :_reduce_45,
241
- 2, 44, :_reduce_46,
242
- 1, 44, :_reduce_47,
243
- 1, 50, :_reduce_none,
244
- 1, 50, :_reduce_none,
245
- 3, 38, :_reduce_50,
246
- 4, 38, :_reduce_51,
247
- 1, 51, :_reduce_52,
248
- 3, 51, :_reduce_53,
249
- 1, 36, :_reduce_54,
250
- 1, 37, :_reduce_55,
251
- 1, 37, :_reduce_56,
252
- 1, 41, :_reduce_57 ]
253
-
254
- racc_reduce_n = 58
255
-
256
- racc_shift_n = 85
257
-
258
- racc_token_table = {
259
- false => 0,
260
- :error => 1,
261
- :T_AXIS => 2,
262
- :T_COLON => 3,
263
- :T_COMMA => 4,
264
- :T_FLOAT => 5,
265
- :T_INT => 6,
266
- :T_IDENT => 7,
267
- :T_TYPE_TEST => 8,
268
- :T_LBRACK => 9,
269
- :T_RBRACK => 10,
270
- :T_LPAREN => 11,
271
- :T_RPAREN => 12,
272
- :T_SLASH => 13,
273
- :T_STRING => 14,
274
- :T_PIPE => 15,
275
- :T_AND => 16,
276
- :T_OR => 17,
277
- :T_ADD => 18,
278
- :T_DIV => 19,
279
- :T_MOD => 20,
280
- :T_EQ => 21,
281
- :T_NEQ => 22,
282
- :T_LT => 23,
283
- :T_GT => 24,
284
- :T_LTE => 25,
285
- :T_GTE => 26,
286
- :T_SUB => 27,
287
- :T_MUL => 28,
288
- :T_VAR => 29 }
289
-
290
- racc_nt_base = 30
291
-
292
- racc_use_result_var = false
293
-
294
- Racc_arg = [
295
- racc_action_table,
296
- racc_action_check,
297
- racc_action_default,
298
- racc_action_pointer,
299
- racc_goto_table,
300
- racc_goto_check,
301
- racc_goto_default,
302
- racc_goto_pointer,
303
- racc_nt_base,
304
- racc_reduce_table,
305
- racc_token_table,
306
- racc_shift_n,
307
- racc_reduce_n,
308
- racc_use_result_var ]
309
-
310
- Racc_token_to_s_table = [
311
- "$end",
312
- "error",
313
- "T_AXIS",
314
- "T_COLON",
315
- "T_COMMA",
316
- "T_FLOAT",
317
- "T_INT",
318
- "T_IDENT",
319
- "T_TYPE_TEST",
320
- "T_LBRACK",
321
- "T_RBRACK",
322
- "T_LPAREN",
323
- "T_RPAREN",
324
- "T_SLASH",
325
- "T_STRING",
326
- "T_PIPE",
327
- "T_AND",
328
- "T_OR",
329
- "T_ADD",
330
- "T_DIV",
331
- "T_MOD",
332
- "T_EQ",
333
- "T_NEQ",
334
- "T_LT",
335
- "T_GT",
336
- "T_LTE",
337
- "T_GTE",
338
- "T_SUB",
339
- "T_MUL",
340
- "T_VAR",
341
- "$start",
342
- "xpath",
343
- "expression",
344
- "expression_members",
345
- "expression_with_predicate",
346
- "operator",
347
- "string",
348
- "number",
349
- "call",
350
- "path",
351
- "absolute_path",
352
- "variable",
353
- "node_test_as_axis",
354
- "predicate",
355
- "axis",
356
- "path_member",
357
- "path_members",
358
- "node_test",
359
- "node_name",
360
- "type_test",
361
- "axis_value",
362
- "call_args" ]
363
-
364
- Racc_debug_parser = false
365
-
366
- ##### State transition tables end #####
367
-
368
- # reduce 0 omitted
369
-
370
- def _reduce_1(val, _values)
371
- val[0]
372
- end
305
+ def combine_optional_operator(val)
306
+ ret = val[0]
373
307
 
374
- def _reduce_2(val, _values)
375
- nil
376
- end
308
+ if val[1]
309
+ ret = s(val[1][0], ret, val[1][1])
310
+ end
377
311
 
378
- # reduce 3 omitted
312
+ ret
313
+ end
379
314
 
380
- def _reduce_4(val, _values)
381
- val[1]
382
- end
315
+ def _rule_0(val)
316
+ val[0]
317
+ end
383
318
 
384
- # reduce 5 omitted
319
+ def _rule_1(val)
320
+ combine_operators(val)
321
+ end
385
322
 
386
- # reduce 6 omitted
323
+ def _rule_2(val)
324
+ [:or, val[1]]
325
+ end
387
326
 
388
- # reduce 7 omitted
327
+ def _rule_3(val)
328
+ combine_operators(val)
329
+ end
389
330
 
390
- # reduce 8 omitted
331
+ def _rule_4(val)
332
+ [:and, val[1]]
333
+ end
391
334
 
392
- # reduce 9 omitted
335
+ def _rule_5(val)
336
+ combine_operators(val)
337
+ end
393
338
 
394
- # reduce 10 omitted
339
+ def _rule_6(val)
340
+ [:eq, val[1]]
341
+ end
395
342
 
396
- # reduce 11 omitted
343
+ def _rule_7(val)
344
+ [:neq, val[1]]
345
+ end
397
346
 
398
- # reduce 12 omitted
347
+ def _rule_8(val)
348
+ combine_operators(val)
349
+ end
399
350
 
400
- # reduce 13 omitted
351
+ def _rule_9(val)
352
+ [:lt, val[1]]
353
+ end
401
354
 
402
- def _reduce_14(val, _values)
403
- s(:predicate, val[0], val[1])
404
- end
355
+ def _rule_10(val)
356
+ [:gt, val[1]]
357
+ end
405
358
 
406
- # reduce 15 omitted
359
+ def _rule_11(val)
360
+ [:lte, val[1]]
361
+ end
407
362
 
408
- def _reduce_16(val, _values)
409
- s(:predicate, val[0], val[1])
410
- end
363
+ def _rule_12(val)
364
+ [:gte, val[1]]
365
+ end
411
366
 
412
- # reduce 17 omitted
367
+ def _rule_13(val)
368
+ combine_operators(val)
369
+ end
413
370
 
414
- # reduce 18 omitted
371
+ def _rule_14(val)
372
+ [:add, val[1]]
373
+ end
415
374
 
416
- def _reduce_19(val, _values)
417
- [val[0], val[2]]
418
- end
375
+ def _rule_15(val)
376
+ [:sub, val[1]]
377
+ end
419
378
 
420
- def _reduce_20(val, _values)
421
- [val[0], *val[2]]
422
- end
379
+ def _rule_16(val)
380
+ combine_optional_operator(val)
381
+ end
423
382
 
424
- def _reduce_21(val, _values)
425
- s(:path, *val[0])
426
- end
383
+ def _rule_17(val)
384
+ [:div, val[1]]
385
+ end
427
386
 
428
- def _reduce_22(val, _values)
429
- s(:absolute_path, *val[1])
430
- end
387
+ def _rule_18(val)
388
+ [:mod, val[1]]
389
+ end
431
390
 
432
- def _reduce_23(val, _values)
433
- s(:absolute_path, val[1])
434
- end
391
+ def _rule_19(val)
392
+ [:mul, val[1]]
393
+ end
435
394
 
436
- def _reduce_24(val, _values)
437
- s(:absolute_path)
438
- end
395
+ def _rule_20(val)
396
+ combine_operators(val)
397
+ end
439
398
 
440
- def _reduce_25(val, _values)
441
- s(:axis, 'child', val[0])
442
- end
399
+ def _rule_21(val)
400
+ [:pipe, val[1]]
401
+ end
443
402
 
444
- def _reduce_26(val, _values)
445
- s(:test, *val[0])
446
- end
403
+ def _rule_22(val)
404
+ val[0]
405
+ end
447
406
 
448
- def _reduce_27(val, _values)
449
- val[0]
450
- end
407
+ def _rule_23(val)
408
+ val[0]
409
+ end
451
410
 
452
- def _reduce_28(val, _values)
453
- s(:type_test, val[0])
454
- end
411
+ def _rule_24(val)
412
+ val[0]
413
+ end
455
414
 
456
- def _reduce_29(val, _values)
457
- [nil, val[0]]
458
- end
415
+ def _rule_25(val)
416
+ val[0]
417
+ end
459
418
 
460
- def _reduce_30(val, _values)
461
- [val[0], val[2]]
462
- end
419
+ def _rule_26(val)
420
+ val[0]
421
+ end
463
422
 
464
- def _reduce_31(val, _values)
465
- val[1]
466
- end
423
+ def _rule_27(val)
424
+ val[1]
425
+ end
467
426
 
468
- def _reduce_32(val, _values)
469
- s(:pipe, val[0], val[2])
470
- end
427
+ def _rule_28(val)
428
+ val[0].length > 1 ? s(:path, *val[0]) : val[0][0]
429
+ end
471
430
 
472
- def _reduce_33(val, _values)
473
- s(:and, val[0], val[2])
474
- end
431
+ def _rule_29(val)
432
+ [val[0], *val[1]]
433
+ end
475
434
 
476
- def _reduce_34(val, _values)
477
- s(:or, val[0], val[2])
478
- end
435
+ def _rule_30(val)
436
+ val[1]
437
+ end
479
438
 
480
- def _reduce_35(val, _values)
481
- s(:add, val[0], val[2])
482
- end
439
+ def _rule_31(val)
440
+ s(:absolute_path, *val[1])
441
+ end
483
442
 
484
- def _reduce_36(val, _values)
485
- s(:div, val[0], val[2])
486
- end
443
+ def _rule_32(val)
444
+ val[0]
445
+ end
487
446
 
488
- def _reduce_37(val, _values)
489
- s(:mod, val[0], val[2])
490
- end
447
+ def _rule_33(val)
448
+ val[0]
449
+ end
491
450
 
492
- def _reduce_38(val, _values)
493
- s(:eq, val[0], val[2])
494
- 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
495
476
 
496
- def _reduce_39(val, _values)
497
- s(:neq, val[0], val[2])
498
- end
477
+ def _rule_35(val)
478
+ s(:axis, 'child', val[0])
479
+ end
499
480
 
500
- def _reduce_40(val, _values)
501
- s(:lt, val[0], val[2])
502
- end
481
+ def _rule_36(val)
482
+ [:call, val[1]]
483
+ end
503
484
 
504
- def _reduce_41(val, _values)
505
- s(:gt, val[0], val[2])
506
- end
485
+ def _rule_37(val)
486
+ [:test, val[1], val[2]]
487
+ end
507
488
 
508
- def _reduce_42(val, _values)
509
- s(:lte, val[0], val[2])
510
- end
489
+ def _rule_38(val)
490
+ [:test, nil, val[0]]
491
+ end
511
492
 
512
- def _reduce_43(val, _values)
513
- s(:gte, val[0], val[2])
514
- end
493
+ def _rule_39(val)
494
+ val[1]
495
+ end
515
496
 
516
- def _reduce_44(val, _values)
517
- s(:mul, val[0], val[2])
518
- end
497
+ def _rule_40(val)
498
+ s(:type_test, val[0])
499
+ end
519
500
 
520
- def _reduce_45(val, _values)
521
- s(:sub, val[0], val[2])
522
- end
501
+ def _rule_41(val)
502
+
503
+ val[1] ? s(:test, val[0], val[1]) : s(:test, nil, val[0])
504
+
505
+ end
523
506
 
524
- def _reduce_46(val, _values)
525
- s(:axis, val[0], val[1])
526
- end
507
+ def _rule_42(val)
508
+ val[1]
509
+ end
527
510
 
528
- def _reduce_47(val, _values)
529
- s(:axis, val[0])
530
- end
511
+ def _rule_43(val)
512
+ [val[0], *val[1]]
513
+ end
531
514
 
532
- # reduce 48 omitted
515
+ def _rule_44(val)
516
+ val
517
+ end
533
518
 
534
- # reduce 49 omitted
519
+ def _rule_45(val)
520
+ val[1]
521
+ end
535
522
 
536
- def _reduce_50(val, _values)
537
- s(:call, val[0])
538
- end
523
+ def _rule_46(val)
524
+
525
+ ret = s(:axis, val[0], val[1])
539
526
 
540
- def _reduce_51(val, _values)
541
- s(:call, val[0], *val[2])
542
- end
527
+ if val[2]
528
+ ret = s(:predicate, ret, val[2])
529
+ end
543
530
 
544
- def _reduce_52(val, _values)
545
- val
546
- end
531
+ ret
532
+
533
+ end
547
534
 
548
- def _reduce_53(val, _values)
549
- val[2].unshift(val[0])
550
- end
535
+ def _rule_47(val)
536
+ val[0]
537
+ end
551
538
 
552
- def _reduce_54(val, _values)
553
- s(:string, val[0])
554
- end
539
+ def _rule_48(val)
540
+ val[0]
541
+ end
555
542
 
556
- def _reduce_55(val, _values)
557
- s(:int, val[0])
558
- end
543
+ def _rule_49(val)
544
+ s(:string, val[0])
545
+ end
559
546
 
560
- def _reduce_56(val, _values)
561
- s(:float, val[0])
562
- end
547
+ def _rule_50(val)
548
+ s(:int, val[0])
549
+ end
563
550
 
564
- def _reduce_57(val, _values)
565
- s(:var, val[0])
566
- end
551
+ def _rule_51(val)
552
+ s(:float, val[0])
553
+ end
567
554
 
568
- def _reduce_none(val, _values)
569
- val[0]
570
- 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
571
586
 
572
- end # class Parser
573
- end # module XPath
574
- 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