gammo 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +9 -1
- data/README.md +402 -2
- data/Rakefile +6 -0
- data/lib/gammo/attribute.rb +13 -4
- data/lib/gammo/attributes.rb +95 -0
- data/lib/gammo/node.rb +120 -26
- data/lib/gammo/parser.rb +3 -1
- data/lib/gammo/version.rb +1 -1
- data/lib/gammo/xpath.rb +74 -0
- data/lib/gammo/xpath/ast/axis.rb +231 -0
- data/lib/gammo/xpath/ast/expression.rb +250 -0
- data/lib/gammo/xpath/ast/function.rb +179 -0
- data/lib/gammo/xpath/ast/node_test.rb +86 -0
- data/lib/gammo/xpath/ast/path.rb +100 -0
- data/lib/gammo/xpath/ast/subclassify.rb +35 -0
- data/lib/gammo/xpath/ast/value.rb +150 -0
- data/lib/gammo/xpath/context.rb +23 -0
- data/lib/gammo/xpath/errors.rb +9 -0
- data/lib/gammo/xpath/node_set.rb +43 -0
- data/lib/gammo/xpath/parser.rb +1099 -0
- data/lib/gammo/xpath/parser.y +513 -0
- data/misc/table.erubi +1 -1
- metadata +16 -2
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'gammo/xpath/node_set'
|
2
|
+
|
3
|
+
module Gammo
|
4
|
+
module XPath
|
5
|
+
module AST
|
6
|
+
# @!visibility private
|
7
|
+
class Filter
|
8
|
+
attr_reader :expr, :predicates
|
9
|
+
|
10
|
+
def initialize(expr, predicates: [])
|
11
|
+
@expr = expr
|
12
|
+
@predicates = predicates
|
13
|
+
end
|
14
|
+
|
15
|
+
def evaluate(context)
|
16
|
+
value = expr.evaluate(context).to_node_set_value(context)
|
17
|
+
node_set = value.to_node_set(context)
|
18
|
+
predicates.each do |predicate|
|
19
|
+
new_node_set = NodeSet.new
|
20
|
+
node_set.each do |node|
|
21
|
+
context.node = node
|
22
|
+
context.position += 1
|
23
|
+
new_node_set << node if predicate.evaluate(context)
|
24
|
+
end
|
25
|
+
node_set.replace(new_node_set)
|
26
|
+
end
|
27
|
+
value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @!visibility private
|
32
|
+
class LocationPath
|
33
|
+
attr_accessor :absolute, :steps
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@absolute = false
|
37
|
+
@steps = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def evaluate(context)
|
41
|
+
# If this location path needs to be absolute and given context
|
42
|
+
# is not document, this gets owner document node at first.
|
43
|
+
cloned = context.dup
|
44
|
+
context_node = context.node
|
45
|
+
context_node = context_node.owner_document if absolute && !context_node.document?
|
46
|
+
|
47
|
+
node_set = NodeSet.new
|
48
|
+
node_set << context_node
|
49
|
+
evaluate_with_node_set(cloned, node_set)
|
50
|
+
Value::NodeSet.new(node_set)
|
51
|
+
end
|
52
|
+
|
53
|
+
def insert_first_step(step)
|
54
|
+
steps.unshift(step)
|
55
|
+
end
|
56
|
+
|
57
|
+
def append_step(step)
|
58
|
+
steps << step
|
59
|
+
end
|
60
|
+
|
61
|
+
def evaluate_with_node_set(context, node_set)
|
62
|
+
steps.each do |step|
|
63
|
+
duplicates = Set.new([])
|
64
|
+
new_nodes = NodeSet.new
|
65
|
+
includes_duplicate_nodes = (!node_set.subtrees_are_disjoint? || (!step.instance_of?(Axis::Child) && !step.instance_of?(Axis::Self) && !step.instance_of?(Axis::Descendant) && !step.instance_of?(Axis::DescendantOrSelf) && !step.instance_of?(Axis::Attribute)))
|
66
|
+
|
67
|
+
if node_set.subtrees_are_disjoint? && (step.instance_of?(Axis::Child) || step.instance_of?(Axis::Self))
|
68
|
+
new_nodes.disjoint = true
|
69
|
+
end
|
70
|
+
|
71
|
+
node_set.dup.each_with_index do |node, i|
|
72
|
+
matches = NodeSet.new
|
73
|
+
step.evaluate_context_node_with_node_set(context, node, matches)
|
74
|
+
matches.each do |node|
|
75
|
+
new_nodes << node if !includes_duplicate_nodes || duplicates.add?(node)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
node_set.replace(new_nodes)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# @!visibility private
|
84
|
+
class Path
|
85
|
+
attr_reader :filter, :location_path
|
86
|
+
|
87
|
+
def initialize(filter, location_path)
|
88
|
+
@filter = filter
|
89
|
+
@location_path = location_path
|
90
|
+
end
|
91
|
+
|
92
|
+
def evaluate(context)
|
93
|
+
node_set = filter.evaluate(context).to_node_set(context)
|
94
|
+
location_path.evaluate_with_node_set(context, node_set)
|
95
|
+
Value::NodeSet.new(node_set)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'gammo/xpath/errors'
|
2
|
+
|
3
|
+
module Gammo
|
4
|
+
module XPath
|
5
|
+
module AST
|
6
|
+
# Class for making subclass declarable/fetchable
|
7
|
+
# @!visibility private
|
8
|
+
module Subclassify
|
9
|
+
# @!visibility private
|
10
|
+
def map
|
11
|
+
@map ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# @!visibility private
|
15
|
+
def declare(key)
|
16
|
+
look_for_superclass.map[key] = self
|
17
|
+
end
|
18
|
+
|
19
|
+
# @!visibility private
|
20
|
+
def fetch(key)
|
21
|
+
fail NotFoundError, "%s not found" % key unless klass = map[key.to_sym]
|
22
|
+
klass
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# @!visibility private
|
28
|
+
def look_for_superclass
|
29
|
+
klass = superclass
|
30
|
+
ancestors.find { |ancestor| ancestor == klass }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module Gammo
|
2
|
+
module XPath
|
3
|
+
module AST
|
4
|
+
# Class for representing any value in Gammo::XPath internally.
|
5
|
+
# This should not referred from end users, should be converted to
|
6
|
+
# primitive classes or Gammo::XPath::NodeSet.
|
7
|
+
# @!visibility private
|
8
|
+
class Value
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def evaluate(context)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def node_set?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def number?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def string?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def bool?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_node_set_value(context)
|
36
|
+
Value::NodeSet.new(to_node_set(context))
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_node_set(context)
|
40
|
+
XPath::NodeSet.new
|
41
|
+
end
|
42
|
+
|
43
|
+
# @!visibility private
|
44
|
+
class VariableReference < Value
|
45
|
+
def evaluate(context)
|
46
|
+
variables = context.variables
|
47
|
+
# TODO: Is this correct?
|
48
|
+
return String.new('') unless variables.key?(value.to_sym)
|
49
|
+
ret = variables[value.to_sym]
|
50
|
+
ret = ret.call if ret.respond_to?(:call)
|
51
|
+
case ret
|
52
|
+
when Integer, Float then Number.new(ret)
|
53
|
+
else String.new(ret)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @!visibility private
|
59
|
+
class NodeSet < Value
|
60
|
+
def to_node_set(context)
|
61
|
+
value
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_bool
|
65
|
+
!value.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_number
|
69
|
+
to_s.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s
|
73
|
+
return '' if value.empty?
|
74
|
+
value.first.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def node_set?
|
78
|
+
true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @!visibility private
|
83
|
+
class Boolean < Value
|
84
|
+
def to_bool
|
85
|
+
value
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_number
|
89
|
+
value ? 1 : 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
value.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def bool?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# @!visibility private
|
102
|
+
class Number < Value
|
103
|
+
def to_bool
|
104
|
+
!value.zero?
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_number
|
108
|
+
value
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_s
|
112
|
+
value.to_s
|
113
|
+
end
|
114
|
+
|
115
|
+
def number?
|
116
|
+
true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# @!visibility private
|
121
|
+
class String < Value
|
122
|
+
def initialize(value)
|
123
|
+
super
|
124
|
+
# TODO: Get rid of these slices. These should be taken care by
|
125
|
+
# the parsing layer.
|
126
|
+
@value = @value.slice(1..-1) if value.start_with?(?")
|
127
|
+
@value = @value.slice(0..-2) if value.end_with?(?")
|
128
|
+
end
|
129
|
+
|
130
|
+
def to_bool
|
131
|
+
!value.empty?
|
132
|
+
end
|
133
|
+
|
134
|
+
def to_number
|
135
|
+
# TODO
|
136
|
+
value.to_i
|
137
|
+
end
|
138
|
+
|
139
|
+
def to_s
|
140
|
+
value
|
141
|
+
end
|
142
|
+
|
143
|
+
def string?
|
144
|
+
true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Gammo
|
2
|
+
module XPath
|
3
|
+
# Class for representing a context
|
4
|
+
# https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Introduction
|
5
|
+
# @!visibility private
|
6
|
+
class Context
|
7
|
+
# Defines context node, context position and context size.
|
8
|
+
attr_accessor :node, :position, :size
|
9
|
+
|
10
|
+
# Variables to be expanded in placeholders.
|
11
|
+
attr_reader :variables
|
12
|
+
|
13
|
+
# @param [Gammo::Node] node
|
14
|
+
# @param [Hash{Symbol => String, Symbol, Integer, TrueClass, FalseClass, #call}] variables
|
15
|
+
def initialize(node:, variables: {})
|
16
|
+
@node = node
|
17
|
+
@position = 1
|
18
|
+
@size = 1
|
19
|
+
@variables = variables
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Gammo
|
4
|
+
module XPath
|
5
|
+
# Class for representing node set
|
6
|
+
# Especially this class will be used for expressing the result of evaluation
|
7
|
+
# of a given XPath expressions.
|
8
|
+
class NodeSet
|
9
|
+
extend Forwardable
|
10
|
+
def_delegators :@nodes, :<<, :each, :each_with_index, :length, :size,
|
11
|
+
:map, :[], :first, :last, :concat, :all?, :any?, :empty?
|
12
|
+
|
13
|
+
attr_reader :nodes
|
14
|
+
|
15
|
+
attr_accessor :disjoint
|
16
|
+
|
17
|
+
# Constructs a new instance of Gammo::XPath::NodeSet.
|
18
|
+
# @return [Gammo::XPath::NodeSet]
|
19
|
+
def initialize
|
20
|
+
@nodes = []
|
21
|
+
@disjoint = false
|
22
|
+
end
|
23
|
+
|
24
|
+
# Replaces self nodes with an other node set destructively.
|
25
|
+
# @param [Gammo::XPath::NodeSet] other
|
26
|
+
# @return [Gammo::XPath::NodeSet]
|
27
|
+
# @!visibility private
|
28
|
+
def replace(other)
|
29
|
+
@nodes.replace(other.nodes)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @!visibility private
|
33
|
+
def subtrees_are_disjoint?
|
34
|
+
!!@disjoint
|
35
|
+
end
|
36
|
+
|
37
|
+
# @!visibility private
|
38
|
+
def to_s
|
39
|
+
first.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,1099 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.5.0
|
4
|
+
# from Racc grammar file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
module Gammo
|
9
|
+
module XPath
|
10
|
+
class Parser < Racc::Parser
|
11
|
+
|
12
|
+
module_eval(<<'...end parser.y/module_eval...', 'parser.y', 228)
|
13
|
+
|
14
|
+
# 2.2 Characters (Extensible Markup Language (XML) 1.0 (Fifth Edition))
|
15
|
+
#
|
16
|
+
# This represents "Char" range defined in 2.2 Characters.
|
17
|
+
# [2] Char ::=
|
18
|
+
# [#x1-#xD7FF] |
|
19
|
+
# [#xE000-#xFFFD] |
|
20
|
+
# [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
|
21
|
+
#
|
22
|
+
# @see https://www.w3.org/TR/xml11/#charsets
|
23
|
+
CHAR = /[\x9\xA\xD\u{20}-\u{d7ff}\u{e000}-\u{fffd}\u{10000}-\u{10ffff}]/
|
24
|
+
|
25
|
+
# 2.3 Common Syntactic Constructs (Extensible Markup Language (XML) 1.0 (Fifth Edition))
|
26
|
+
#
|
27
|
+
# [3] S ::= (#x20 | #x9 | #xD | #A)+
|
28
|
+
#
|
29
|
+
# @see https://www.w3.org/TR/xml11/#NT-S
|
30
|
+
S = /[\x20\x9\xD\xA]/
|
31
|
+
|
32
|
+
# [4] NameStartChar ::=
|
33
|
+
# ":" |
|
34
|
+
# [A-Z] |
|
35
|
+
# "_" |
|
36
|
+
# [a-z] |
|
37
|
+
# [#xC0-#xD6] |
|
38
|
+
# [#xD8-#xF6] |
|
39
|
+
# [#xF8-#x2FF] |
|
40
|
+
# [#x370-#x37D] |
|
41
|
+
# [#x37F-#x1FFF] |
|
42
|
+
# [#x200C-#x200D] |
|
43
|
+
# [#x2070-#x218F] |
|
44
|
+
# [#x2C00-#x2FEF] |
|
45
|
+
# [#x3001-#xD7FF] |
|
46
|
+
# [#xF900-#xFDCF] |
|
47
|
+
# [#xFDF0-#xFFFD] |
|
48
|
+
# [#x10000-#xEFFFF]
|
49
|
+
#
|
50
|
+
# @see https://www.w3.org/TR/xml11/#NT-NameStartChar
|
51
|
+
name_start_chars = %w[
|
52
|
+
:
|
53
|
+
a-zA-Z_
|
54
|
+
\\u00c0-\\u00d6
|
55
|
+
\\u00d8-\\u00f6
|
56
|
+
\\u00f8-\\u02ff
|
57
|
+
\\u0370-\\u037d
|
58
|
+
\\u037f-\\u1fff
|
59
|
+
\\u200c-\\u200d
|
60
|
+
\\u2070-\\u218f
|
61
|
+
\\u2c00-\\u2fef
|
62
|
+
\\u3001-\\ud7ff
|
63
|
+
\\uf900-\\ufdcf
|
64
|
+
\\ufdf0-\\ufffd
|
65
|
+
\\u{10000}-\\u{effff}
|
66
|
+
]
|
67
|
+
NAME_START_CHARS = /[#{name_start_chars.join}]/
|
68
|
+
|
69
|
+
# [4a] NameChar ::=
|
70
|
+
# NameStartChar |
|
71
|
+
# "-" |
|
72
|
+
# "." |
|
73
|
+
# [0-9] |
|
74
|
+
# #xB7 |
|
75
|
+
# [#x0300-#x036F] |
|
76
|
+
# [#x203F-#x2040]
|
77
|
+
#
|
78
|
+
# @see https://www.w3.org/TR/xml11/#NT-NameChar
|
79
|
+
name_chars = name_start_chars + %w[
|
80
|
+
\\-
|
81
|
+
\\.
|
82
|
+
0-9
|
83
|
+
\\u00b7
|
84
|
+
\\u0300-\\u036f
|
85
|
+
\\u203f-\\u2040
|
86
|
+
]
|
87
|
+
NAME_CHARS = /[#{name_chars.join}]/
|
88
|
+
|
89
|
+
# [5] Name ::= NameStartChar (NameChar)*
|
90
|
+
#
|
91
|
+
# @see https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Name
|
92
|
+
NAME = /#{NAME_START_CHARS}#{NAME_CHARS}*/
|
93
|
+
|
94
|
+
# 2.3. Axes
|
95
|
+
#
|
96
|
+
# [6] AxisName ::=
|
97
|
+
# 'ancestor'
|
98
|
+
# | 'ancestor-or-self'
|
99
|
+
# | 'attribute'
|
100
|
+
# | 'child'
|
101
|
+
# | 'descendant'
|
102
|
+
# | 'descendant-or-self'
|
103
|
+
# | 'following'
|
104
|
+
# | 'following-sibling'
|
105
|
+
# | 'namespace'
|
106
|
+
# | 'parent'
|
107
|
+
# | 'preceding'
|
108
|
+
# | 'preceding-sibling'
|
109
|
+
# | 'self'
|
110
|
+
#
|
111
|
+
# @see https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AxisName
|
112
|
+
AXES = /
|
113
|
+
ancestor-or-self|
|
114
|
+
ancestor|
|
115
|
+
attribute|
|
116
|
+
child|
|
117
|
+
descendant-or-self|
|
118
|
+
descendant|
|
119
|
+
following-sibling|
|
120
|
+
following|
|
121
|
+
namespace|
|
122
|
+
parent|
|
123
|
+
preceding-sibling|
|
124
|
+
preceding|
|
125
|
+
self
|
126
|
+
/x
|
127
|
+
|
128
|
+
# 3 Declaring Namespaces
|
129
|
+
#
|
130
|
+
# The "NCName" is picked from the section.
|
131
|
+
#
|
132
|
+
# Note that we need to take care of exceptional handling.
|
133
|
+
#
|
134
|
+
# [4] NCName ::= NCNameStartChar NCNameChar* /* An XML Name, minus the ":" */
|
135
|
+
# [5] NCNamrChar ::= NameChar - ':'
|
136
|
+
# [6] NCNameStartChar ::= NameStartChar - ':'
|
137
|
+
#
|
138
|
+
# @see https://www.w3.org/TR/xml-names11/#ns-decl
|
139
|
+
NC_NAME_CHARS = /[#{(name_chars - [':']).join}]/
|
140
|
+
NC_NAME_START_CHARS = /[#{(name_start_chars - [':']).join}]/
|
141
|
+
NC_NAME = /#{NC_NAME_START_CHARS}#{NC_NAME_CHARS}*/
|
142
|
+
|
143
|
+
# 4. Qualified Names
|
144
|
+
#
|
145
|
+
# The rules for "QName", "PrefixedName", "UnprefixedName", "Prefix" and
|
146
|
+
# "LocalPart" are picked from the section.
|
147
|
+
#
|
148
|
+
# [7] QName ::= PrefixedName | UnprefixedName
|
149
|
+
# [8] PrefixedName ::= Prefix ':' LocalPart
|
150
|
+
# [9] UnprefixedName ::= LocalPart
|
151
|
+
# [10] Prefix ::= NCName
|
152
|
+
# [11] LocalPart ::= NCName
|
153
|
+
#
|
154
|
+
# @see https://www.w3.org/TR/xml-names11/#ns-qualnames
|
155
|
+
PREFIX = NC_NAME
|
156
|
+
LOCAL_PART = NC_NAME
|
157
|
+
PREFIXED_NAME = /#{PREFIX}:#{LOCAL_PART}/
|
158
|
+
UNPREFIXED_NAME = LOCAL_PART
|
159
|
+
Q_NAME = /#{PREFIXED_NAME}|#{UNPREFIXED_NAME}/
|
160
|
+
|
161
|
+
# 3.7 Lexical Structure
|
162
|
+
#
|
163
|
+
# The rules for "NodeType" and "Digits" are picked from the section.
|
164
|
+
# @see https://www.w3.org/TR/1999/REC-xpath-19991116/#exprlex
|
165
|
+
DIGITS = /[0-9]+/
|
166
|
+
NODE_TYPE = /comment|text|processing-instruction|node/
|
167
|
+
|
168
|
+
# EXPR_TOKENS is defined for tokenizing primitive tokens for "ExprToken",
|
169
|
+
# except other rules.
|
170
|
+
# @see https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-ExprToken
|
171
|
+
EXPR_TOKENS = {
|
172
|
+
'(' => :T_LPAREN,
|
173
|
+
')' => :T_RPAREN,
|
174
|
+
'[' => :T_LBRACK,
|
175
|
+
']' => :T_RBRACK,
|
176
|
+
'.' => :T_DOT,
|
177
|
+
'..' => :T_DOTDOT,
|
178
|
+
'@' => :T_AT,
|
179
|
+
',' => :T_COMMA,
|
180
|
+
'::' => :T_COLONCOLON
|
181
|
+
}.freeze
|
182
|
+
# Declaring the regexp consisting of EXPR_TOKENS keys to keep the token order.
|
183
|
+
EXPRS = /\(|\)|\[|\]|@|,|::|\.\.|\./
|
184
|
+
|
185
|
+
# OPERATOR_TOKENS is defined for tokenizing primitive tokens for "Operator"
|
186
|
+
# and "OperatorName" except other rules.
|
187
|
+
# @see https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-Operator
|
188
|
+
OPERATOR_TOKENS = {
|
189
|
+
'and' => :T_AND,
|
190
|
+
'or' => :T_OR,
|
191
|
+
'mod' => :T_MOD,
|
192
|
+
'div' => :T_DIV,
|
193
|
+
'/' => :T_SLASH,
|
194
|
+
'//' => :T_SLASHSLASH,
|
195
|
+
"|" => :T_PIPE,
|
196
|
+
'+' => :T_PLUS,
|
197
|
+
'-' => :T_MINUS,
|
198
|
+
'=' => :T_EQ,
|
199
|
+
'!=' => :T_NEQ,
|
200
|
+
'<' => :T_LT,
|
201
|
+
'>' => :T_GT,
|
202
|
+
'<=' => :T_LTE,
|
203
|
+
'>=' => :T_GTE
|
204
|
+
}.freeze
|
205
|
+
# Declaring the regexp consisting of OPERATOR_TOKENS keys to keep the token order.
|
206
|
+
OPERATORS = /and|or|mod|div|\/\/|\/|\||\+|-|\=|!=|<=|>=|<|>/
|
207
|
+
|
208
|
+
require 'strscan'
|
209
|
+
require 'forwardable'
|
210
|
+
require 'gammo/xpath/errors'
|
211
|
+
require 'gammo/xpath/ast/axis'
|
212
|
+
require 'gammo/xpath/ast/expression'
|
213
|
+
require 'gammo/xpath/ast/function'
|
214
|
+
require 'gammo/xpath/ast/node_test'
|
215
|
+
require 'gammo/xpath/ast/path'
|
216
|
+
require 'gammo/xpath/ast/value'
|
217
|
+
|
218
|
+
extend Forwardable
|
219
|
+
def_delegators :@scanner, :scan, :eos?
|
220
|
+
|
221
|
+
def initialize(input)
|
222
|
+
super()
|
223
|
+
@yydebug = true
|
224
|
+
@input = input
|
225
|
+
@scanner = StringScanner.new(input)
|
226
|
+
end
|
227
|
+
|
228
|
+
def parse
|
229
|
+
@query = []
|
230
|
+
advance { |symbol, val| @query << [symbol, val] }
|
231
|
+
do_parse
|
232
|
+
end
|
233
|
+
|
234
|
+
def next_token
|
235
|
+
@query.shift
|
236
|
+
end
|
237
|
+
|
238
|
+
def lookup_namespace_uri(prefix)
|
239
|
+
prefix == 'xml' ? 'http://www.w3.org/XML/1998/namespace' : nil
|
240
|
+
end
|
241
|
+
|
242
|
+
def expand_qname(qname)
|
243
|
+
return [qname, nil] unless colon = qname.index(':')
|
244
|
+
namespace_uri = lookup_namespace_uri(qname.slice(0..colon))
|
245
|
+
fail ParseError, 'invalid qname: %s' % qname unless namespace_uri
|
246
|
+
[qname.slice(colon..-1), namespace_uri]
|
247
|
+
end
|
248
|
+
|
249
|
+
def token(symbol, val, &block)
|
250
|
+
@prev_token = symbol
|
251
|
+
block.call(symbol, val)
|
252
|
+
end
|
253
|
+
|
254
|
+
def fetch(key, constraints)
|
255
|
+
unless symbol = constraints[key]
|
256
|
+
fail ParseError, "unexpected token: #{symbol}, want = #{constraints.keys}"
|
257
|
+
end
|
258
|
+
yield symbol
|
259
|
+
end
|
260
|
+
|
261
|
+
def advance(&block)
|
262
|
+
@prev_token = nil
|
263
|
+
until eos?
|
264
|
+
case
|
265
|
+
# Skip whitespace everywhere.
|
266
|
+
when scan(/#{S}+/) then next
|
267
|
+
when expr = scan(EXPRS)
|
268
|
+
fetch(expr, EXPR_TOKENS) do |symbol|
|
269
|
+
token(symbol, expr, &block)
|
270
|
+
end
|
271
|
+
when operator = scan(OPERATORS)
|
272
|
+
fetch operator, OPERATOR_TOKENS do |symbol|
|
273
|
+
# "div" is available in both operator and name_test tokens.
|
274
|
+
if symbol == :T_DIV && @prev_token != :T_NUMBER
|
275
|
+
token(:T_NAME_TEST, operator, &block)
|
276
|
+
next
|
277
|
+
end
|
278
|
+
token(symbol, operator, &block)
|
279
|
+
end
|
280
|
+
when axis = scan(AXES) then token(:T_AXIS_NAME, axis, &block)
|
281
|
+
when node_type = scan(NODE_TYPE)
|
282
|
+
# NOTE: processing-instruction is not supported by Gammo.
|
283
|
+
token(:T_NODE_TYPE, node_type, &block)
|
284
|
+
when name = scan(/\*|#{NC_NAME}|#{Q_NAME}/)
|
285
|
+
if name == ?* && @prev_token == :T_NUMBER
|
286
|
+
token(:T_MUL, name, &block)
|
287
|
+
next
|
288
|
+
end
|
289
|
+
# TODO: Stripping should be taken care by regexp.
|
290
|
+
token @scanner.peek(1) == ?( ? :T_FUNCTION_NAME : :T_NAME_TEST, name.strip, &block
|
291
|
+
when literal = scan(/"[^"]*"|'[^']*'/) then token(:T_LITERAL, literal, &block)
|
292
|
+
when number = scan(/#{DIGITS}(\.(#{DIGITS})?)?/) then token(:T_NUMBER, number, &block)
|
293
|
+
when ref = scan(/\$#{Q_NAME}/) then token(:T_VARIABLE_REFERENCE, ref, &block)
|
294
|
+
else
|
295
|
+
fail ParseError, "unexpected token: #{@scanner.string[@scanner.pos..-1]}"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
...end parser.y/module_eval...
|
300
|
+
##### State transition tables begin ###
|
301
|
+
|
302
|
+
racc_action_table = [
|
303
|
+
4, 14, 98, 44, 35, 15, 16, 11, 99, 15,
|
304
|
+
16, 11, 44, 12, 13, 10, 19, 12, 13, 10,
|
305
|
+
15, 16, 11, 58, 59, 60, 61, 23, 12, 13,
|
306
|
+
10, 18, 20, 21, 4, 14, 37, 38, 35, 15,
|
307
|
+
16, 11, 44, 15, 16, 11, 55, 12, 13, 10,
|
308
|
+
19, 12, 13, 10, 15, 16, 11, 58, 59, 60,
|
309
|
+
61, 23, 12, 13, 10, 18, 20, 21, 4, 14,
|
310
|
+
37, 38, 35, 15, 16, 11, 46, 15, 16, 11,
|
311
|
+
47, 12, 13, 10, 19, 12, 13, 10, 15, 16,
|
312
|
+
11, 58, 59, 60, 61, 23, 12, 13, 10, 18,
|
313
|
+
20, 21, 4, 14, 62, 63, 35, 65, 66, 64,
|
314
|
+
65, 66, 64, 65, 66, 64, 37, 38, 19, 37,
|
315
|
+
38, 44, 15, 16, 11, 56, 57, 62, 63, 23,
|
316
|
+
12, 13, 10, 18, 20, 21, 4, 14, 62, 63,
|
317
|
+
35, 37, 38, 12, 13, 62, 63, 52, 14, 56,
|
318
|
+
57, 55, 19, 62, 63, 48, 15, 16, 11, 68,
|
319
|
+
50, 97, 77, 23, 12, 13, 10, 18, 20, 21,
|
320
|
+
4, 14, 51, 44, 35, 36, 75, nil, nil, nil,
|
321
|
+
nil, nil, nil, nil, nil, nil, 19, 79, 4, 14,
|
322
|
+
15, 16, 11, nil, nil, nil, nil, 23, 12, 13,
|
323
|
+
10, 18, 20, 21, 19, nil, nil, nil, 15, 16,
|
324
|
+
11, nil, nil, nil, nil, 23, 12, 13, 10, 18,
|
325
|
+
20, 21, 4, 14, nil, nil, 35, nil, nil, nil,
|
326
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 19, nil,
|
327
|
+
nil, nil, 15, 16, 11, nil, nil, nil, nil, 23,
|
328
|
+
12, 13, 10, 18, 20, 21, 4, 14, nil, nil,
|
329
|
+
35, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
330
|
+
nil, nil, 19, nil, nil, nil, 15, 16, 11, nil,
|
331
|
+
nil, nil, nil, 23, 12, 13, 10, 18, 20, 21,
|
332
|
+
4, 14, nil, nil, 35, nil, nil, nil, nil, nil,
|
333
|
+
nil, nil, nil, nil, nil, nil, 19, nil, nil, nil,
|
334
|
+
15, 16, 11, nil, nil, nil, nil, 23, 12, 13,
|
335
|
+
10, 18, 20, 21, 4, 14, nil, nil, 35, nil,
|
336
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
337
|
+
19, nil, nil, nil, 15, 16, 11, nil, nil, nil,
|
338
|
+
nil, 23, 12, 13, 10, 18, 20, 21, 4, 14,
|
339
|
+
nil, nil, 35, nil, nil, nil, nil, nil, nil, nil,
|
340
|
+
nil, nil, nil, nil, 19, nil, nil, nil, 15, 16,
|
341
|
+
11, nil, nil, nil, nil, 23, 12, 13, 10, 18,
|
342
|
+
20, 21, 4, 14, nil, nil, 35, nil, nil, nil,
|
343
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 19, nil,
|
344
|
+
nil, nil, 15, 16, 11, nil, nil, nil, nil, 23,
|
345
|
+
12, 13, 10, 18, 20, 21, 4, 14, nil, nil,
|
346
|
+
35, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
347
|
+
nil, nil, 19, nil, nil, nil, 15, 16, 11, nil,
|
348
|
+
nil, nil, nil, 23, 12, 13, 10, 18, 20, 21,
|
349
|
+
4, 14, nil, nil, 35, nil, nil, nil, nil, nil,
|
350
|
+
nil, nil, nil, nil, nil, nil, 19, nil, nil, nil,
|
351
|
+
15, 16, 11, nil, nil, nil, nil, 23, 12, 13,
|
352
|
+
10, 18, 20, 21, 4, 14, nil, nil, 35, nil,
|
353
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
354
|
+
19, nil, nil, nil, 15, 16, 11, nil, nil, nil,
|
355
|
+
nil, 23, 12, 13, 10, 18, 20, 21, 4, 14,
|
356
|
+
nil, nil, 35, nil, nil, nil, nil, nil, nil, nil,
|
357
|
+
nil, nil, nil, nil, 19, nil, nil, nil, 15, 16,
|
358
|
+
11, nil, nil, nil, nil, 23, 12, 13, 10, 18,
|
359
|
+
20, 21, 4, 14, nil, nil, 35, nil, nil, nil,
|
360
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 19, nil,
|
361
|
+
nil, nil, 15, 16, 11, nil, nil, nil, nil, 23,
|
362
|
+
12, 13, 10, 18, 20, 21, 4, 14, nil, nil,
|
363
|
+
35, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
364
|
+
nil, nil, 19, nil, nil, nil, 15, 16, 11, nil,
|
365
|
+
nil, nil, nil, 23, 12, 13, 10, 18, 20, 21,
|
366
|
+
4, 14, nil, nil, 35, nil, nil, nil, nil, nil,
|
367
|
+
nil, nil, nil, nil, nil, nil, 19, nil, nil, nil,
|
368
|
+
15, 16, 11, nil, nil, nil, nil, 23, 12, 13,
|
369
|
+
10, 18, 20, 21 ]
|
370
|
+
|
371
|
+
racc_action_check = [
|
372
|
+
65, 65, 78, 28, 65, 4, 4, 4, 78, 5,
|
373
|
+
5, 5, 45, 4, 4, 4, 65, 5, 5, 5,
|
374
|
+
65, 65, 65, 86, 86, 86, 86, 65, 65, 65,
|
375
|
+
65, 65, 65, 65, 19, 19, 40, 40, 19, 53,
|
376
|
+
53, 53, 7, 38, 38, 38, 29, 53, 53, 53,
|
377
|
+
19, 38, 38, 38, 19, 19, 19, 31, 31, 31,
|
378
|
+
31, 19, 19, 19, 19, 19, 19, 19, 35, 35,
|
379
|
+
39, 39, 35, 37, 37, 37, 10, 52, 52, 52,
|
380
|
+
13, 37, 37, 37, 35, 52, 52, 52, 35, 35,
|
381
|
+
35, 87, 87, 87, 87, 35, 35, 35, 35, 35,
|
382
|
+
35, 35, 44, 44, 91, 91, 44, 93, 93, 93,
|
383
|
+
33, 33, 33, 92, 92, 92, 83, 83, 44, 84,
|
384
|
+
84, 54, 44, 44, 44, 85, 85, 88, 88, 44,
|
385
|
+
44, 44, 44, 44, 44, 44, 48, 48, 89, 89,
|
386
|
+
48, 2, 2, 8, 8, 90, 90, 27, 27, 30,
|
387
|
+
30, 76, 48, 32, 32, 17, 48, 48, 48, 36,
|
388
|
+
23, 72, 49, 48, 48, 48, 48, 48, 48, 48,
|
389
|
+
50, 50, 25, 43, 50, 1, 47, nil, nil, nil,
|
390
|
+
nil, nil, nil, nil, nil, nil, 50, 50, 51, 51,
|
391
|
+
50, 50, 50, nil, nil, nil, nil, 50, 50, 50,
|
392
|
+
50, 50, 50, 50, 51, nil, nil, nil, 51, 51,
|
393
|
+
51, nil, nil, nil, nil, 51, 51, 51, 51, 51,
|
394
|
+
51, 51, 55, 55, nil, nil, 55, nil, nil, nil,
|
395
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 55, nil,
|
396
|
+
nil, nil, 55, 55, 55, nil, nil, nil, nil, 55,
|
397
|
+
55, 55, 55, 55, 55, 55, 56, 56, nil, nil,
|
398
|
+
56, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
399
|
+
nil, nil, 56, nil, nil, nil, 56, 56, 56, nil,
|
400
|
+
nil, nil, nil, 56, 56, 56, 56, 56, 56, 56,
|
401
|
+
57, 57, nil, nil, 57, nil, nil, nil, nil, nil,
|
402
|
+
nil, nil, nil, nil, nil, nil, 57, nil, nil, nil,
|
403
|
+
57, 57, 57, nil, nil, nil, nil, 57, 57, 57,
|
404
|
+
57, 57, 57, 57, 58, 58, nil, nil, 58, nil,
|
405
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
406
|
+
58, nil, nil, nil, 58, 58, 58, nil, nil, nil,
|
407
|
+
nil, 58, 58, 58, 58, 58, 58, 58, 59, 59,
|
408
|
+
nil, nil, 59, nil, nil, nil, nil, nil, nil, nil,
|
409
|
+
nil, nil, nil, nil, 59, nil, nil, nil, 59, 59,
|
410
|
+
59, nil, nil, nil, nil, 59, 59, 59, 59, 59,
|
411
|
+
59, 59, 60, 60, nil, nil, 60, nil, nil, nil,
|
412
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 60, nil,
|
413
|
+
nil, nil, 60, 60, 60, nil, nil, nil, nil, 60,
|
414
|
+
60, 60, 60, 60, 60, 60, 61, 61, nil, nil,
|
415
|
+
61, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
416
|
+
nil, nil, 61, nil, nil, nil, 61, 61, 61, nil,
|
417
|
+
nil, nil, nil, 61, 61, 61, 61, 61, 61, 61,
|
418
|
+
62, 62, nil, nil, 62, nil, nil, nil, nil, nil,
|
419
|
+
nil, nil, nil, nil, nil, nil, 62, nil, nil, nil,
|
420
|
+
62, 62, 62, nil, nil, nil, nil, 62, 62, 62,
|
421
|
+
62, 62, 62, 62, 63, 63, nil, nil, 63, nil,
|
422
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
423
|
+
63, nil, nil, nil, 63, 63, 63, nil, nil, nil,
|
424
|
+
nil, 63, 63, 63, 63, 63, 63, 63, 64, 64,
|
425
|
+
nil, nil, 64, nil, nil, nil, nil, nil, nil, nil,
|
426
|
+
nil, nil, nil, nil, 64, nil, nil, nil, 64, 64,
|
427
|
+
64, nil, nil, nil, nil, 64, 64, 64, 64, 64,
|
428
|
+
64, 64, 0, 0, nil, nil, 0, nil, nil, nil,
|
429
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 0, nil,
|
430
|
+
nil, nil, 0, 0, 0, nil, nil, nil, nil, 0,
|
431
|
+
0, 0, 0, 0, 0, 0, 66, 66, nil, nil,
|
432
|
+
66, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
433
|
+
nil, nil, 66, nil, nil, nil, 66, 66, 66, nil,
|
434
|
+
nil, nil, nil, 66, 66, 66, 66, 66, 66, 66,
|
435
|
+
99, 99, nil, nil, 99, nil, nil, nil, nil, nil,
|
436
|
+
nil, nil, nil, nil, nil, nil, 99, nil, nil, nil,
|
437
|
+
99, 99, 99, nil, nil, nil, nil, 99, 99, 99,
|
438
|
+
99, 99, 99, 99 ]
|
439
|
+
|
440
|
+
racc_action_pointer = [
|
441
|
+
560, 175, 139, nil, -17, -13, nil, 22, 113, nil,
|
442
|
+
50, nil, nil, 62, nil, nil, nil, 141, nil, 32,
|
443
|
+
nil, nil, nil, 142, nil, 168, nil, 145, -17, 33,
|
444
|
+
142, 48, 148, 95, nil, 66, 159, 51, 21, 68,
|
445
|
+
34, nil, nil, 153, 100, -8, nil, 157, 134, 143,
|
446
|
+
168, 186, 55, 17, 101, 220, 254, 288, 322, 356,
|
447
|
+
390, 424, 458, 492, 526, -2, 594, nil, nil, nil,
|
448
|
+
nil, nil, 140, nil, nil, nil, 138, nil, -17, nil,
|
449
|
+
nil, nil, nil, 114, 117, 118, 14, 82, 122, 133,
|
450
|
+
140, 99, 98, 92, nil, nil, nil, nil, nil, 628,
|
451
|
+
nil ]
|
452
|
+
|
453
|
+
racc_action_default = [
|
454
|
+
-65, -65, -1, -2, -3, -65, -6, -19, -65, -11,
|
455
|
+
-65, -13, -14, -65, -16, -23, -24, -25, -26, -65,
|
456
|
+
-28, -29, -30, -65, -36, -63, -38, -39, -42, -44,
|
457
|
+
-46, -48, -51, -56, -59, -65, -65, -65, -65, -4,
|
458
|
+
-5, -9, -17, -20, -65, -19, -12, -65, -65, -65,
|
459
|
+
-65, -65, -65, -65, -43, -65, -65, -65, -65, -65,
|
460
|
+
-65, -65, -65, -65, -65, -65, -65, -64, 101, -7,
|
461
|
+
-8, -18, -65, -22, -10, -15, -45, -27, -65, -32,
|
462
|
+
-33, -34, -37, -40, -41, -47, -49, -50, -52, -53,
|
463
|
+
-54, -55, -57, -58, -60, -61, -62, -21, -31, -65,
|
464
|
+
-35 ]
|
465
|
+
|
466
|
+
racc_goto_table = [
|
467
|
+
39, 40, 81, 1, 41, 67, 71, 88, 89, 90,
|
468
|
+
91, 86, 87, 92, 93, 69, 70, 71, 76, 85,
|
469
|
+
45, 53, 49, 54, 72, 78, 82, nil, nil, nil,
|
470
|
+
nil, nil, nil, nil, 94, 95, 96, nil, nil, nil,
|
471
|
+
nil, nil, 74, nil, nil, nil, nil, 73, 83, 84,
|
472
|
+
nil, 100 ]
|
473
|
+
|
474
|
+
racc_goto_check = [
|
475
|
+
3, 3, 18, 1, 8, 27, 12, 25, 25, 25,
|
476
|
+
25, 24, 24, 26, 26, 6, 6, 12, 22, 23,
|
477
|
+
7, 5, 1, 11, 13, 17, 20, nil, nil, nil,
|
478
|
+
nil, nil, nil, nil, 27, 27, 27, nil, nil, nil,
|
479
|
+
nil, nil, 8, nil, nil, nil, nil, 1, 3, 3,
|
480
|
+
nil, 18 ]
|
481
|
+
|
482
|
+
racc_goto_pointer = [
|
483
|
+
nil, 3, nil, -4, nil, -6, -22, 12, -3, nil,
|
484
|
+
nil, -5, -37, -20, nil, nil, nil, -25, -48, nil,
|
485
|
+
-25, nil, -30, -36, -45, -51, -49, -30 ]
|
486
|
+
|
487
|
+
racc_goto_default = [
|
488
|
+
nil, 80, 26, 2, 3, 5, 6, 7, nil, 8,
|
489
|
+
9, 43, 42, nil, 17, 28, 22, nil, nil, 25,
|
490
|
+
24, 27, 29, 30, 31, 32, 33, 34 ]
|
491
|
+
|
492
|
+
racc_reduce_table = [
|
493
|
+
0, 0, :racc_error,
|
494
|
+
1, 38, :_reduce_1,
|
495
|
+
1, 38, :_reduce_2,
|
496
|
+
1, 40, :_reduce_3,
|
497
|
+
2, 40, :_reduce_4,
|
498
|
+
2, 40, :_reduce_5,
|
499
|
+
1, 39, :_reduce_6,
|
500
|
+
3, 39, :_reduce_7,
|
501
|
+
3, 39, :_reduce_8,
|
502
|
+
2, 42, :_reduce_9,
|
503
|
+
3, 42, :_reduce_10,
|
504
|
+
1, 42, :_reduce_none,
|
505
|
+
2, 45, :_reduce_none,
|
506
|
+
1, 45, :_reduce_13,
|
507
|
+
1, 43, :_reduce_14,
|
508
|
+
3, 43, :_reduce_15,
|
509
|
+
1, 41, :_reduce_16,
|
510
|
+
1, 47, :_reduce_17,
|
511
|
+
2, 47, :_reduce_18,
|
512
|
+
0, 44, :_reduce_none,
|
513
|
+
1, 44, :_reduce_20,
|
514
|
+
3, 48, :_reduce_21,
|
515
|
+
1, 49, :_reduce_none,
|
516
|
+
1, 46, :_reduce_23,
|
517
|
+
1, 46, :_reduce_24,
|
518
|
+
1, 37, :_reduce_none,
|
519
|
+
1, 51, :_reduce_26,
|
520
|
+
3, 51, :_reduce_27,
|
521
|
+
1, 51, :_reduce_28,
|
522
|
+
1, 51, :_reduce_29,
|
523
|
+
1, 51, :_reduce_none,
|
524
|
+
4, 52, :_reduce_31,
|
525
|
+
3, 52, :_reduce_32,
|
526
|
+
1, 54, :_reduce_none,
|
527
|
+
1, 53, :_reduce_34,
|
528
|
+
3, 53, :_reduce_35,
|
529
|
+
1, 55, :_reduce_none,
|
530
|
+
3, 55, :_reduce_37,
|
531
|
+
1, 56, :_reduce_none,
|
532
|
+
1, 56, :_reduce_none,
|
533
|
+
3, 56, :_reduce_40,
|
534
|
+
3, 56, :_reduce_41,
|
535
|
+
1, 57, :_reduce_none,
|
536
|
+
2, 57, :_reduce_43,
|
537
|
+
1, 50, :_reduce_none,
|
538
|
+
3, 50, :_reduce_45,
|
539
|
+
1, 58, :_reduce_none,
|
540
|
+
3, 58, :_reduce_47,
|
541
|
+
1, 59, :_reduce_none,
|
542
|
+
3, 59, :_reduce_49,
|
543
|
+
3, 59, :_reduce_50,
|
544
|
+
1, 60, :_reduce_none,
|
545
|
+
3, 60, :_reduce_52,
|
546
|
+
3, 60, :_reduce_53,
|
547
|
+
3, 60, :_reduce_54,
|
548
|
+
3, 60, :_reduce_55,
|
549
|
+
1, 61, :_reduce_none,
|
550
|
+
3, 61, :_reduce_57,
|
551
|
+
3, 61, :_reduce_58,
|
552
|
+
1, 62, :_reduce_none,
|
553
|
+
3, 62, :_reduce_60,
|
554
|
+
3, 62, :_reduce_61,
|
555
|
+
3, 62, :_reduce_62,
|
556
|
+
1, 63, :_reduce_none,
|
557
|
+
2, 63, :_reduce_64 ]
|
558
|
+
|
559
|
+
racc_reduce_n = 65
|
560
|
+
|
561
|
+
racc_shift_n = 101
|
562
|
+
|
563
|
+
racc_token_table = {
|
564
|
+
false => 0,
|
565
|
+
:error => 1,
|
566
|
+
:T_SLASH => 2,
|
567
|
+
:T_SLASHSLASH => 3,
|
568
|
+
:T_PIPE => 4,
|
569
|
+
:T_PLUS => 5,
|
570
|
+
:T_MINUS => 6,
|
571
|
+
:T_EQ => 7,
|
572
|
+
:T_NEQ => 8,
|
573
|
+
:T_LT => 9,
|
574
|
+
:T_GT => 10,
|
575
|
+
:T_LTE => 11,
|
576
|
+
:T_GTE => 12,
|
577
|
+
:T_AND => 13,
|
578
|
+
:T_OR => 14,
|
579
|
+
:T_DIV => 15,
|
580
|
+
:T_MOD => 16,
|
581
|
+
:T_MUL => 17,
|
582
|
+
:T_LPAREN => 18,
|
583
|
+
:T_RPAREN => 19,
|
584
|
+
:T_LBRACK => 20,
|
585
|
+
:T_RBRACK => 21,
|
586
|
+
:T_DOT => 22,
|
587
|
+
:T_DOTDOT => 23,
|
588
|
+
:T_AT => 24,
|
589
|
+
:T_COMMA => 25,
|
590
|
+
:T_COLONCOLON => 26,
|
591
|
+
:T_NC_NAME => 27,
|
592
|
+
:T_Q_NAME => 28,
|
593
|
+
:T_FUNCTION_NAME => 29,
|
594
|
+
:T_NAME_TEST => 30,
|
595
|
+
:T_NODE_TYPE => 31,
|
596
|
+
:T_AXIS_NAME => 32,
|
597
|
+
:T_VARIABLE_REFERENCE => 33,
|
598
|
+
:T_LITERAL => 34,
|
599
|
+
:T_NUMBER => 35 }
|
600
|
+
|
601
|
+
racc_nt_base = 36
|
602
|
+
|
603
|
+
racc_use_result_var = true
|
604
|
+
|
605
|
+
Racc_arg = [
|
606
|
+
racc_action_table,
|
607
|
+
racc_action_check,
|
608
|
+
racc_action_default,
|
609
|
+
racc_action_pointer,
|
610
|
+
racc_goto_table,
|
611
|
+
racc_goto_check,
|
612
|
+
racc_goto_default,
|
613
|
+
racc_goto_pointer,
|
614
|
+
racc_nt_base,
|
615
|
+
racc_reduce_table,
|
616
|
+
racc_token_table,
|
617
|
+
racc_shift_n,
|
618
|
+
racc_reduce_n,
|
619
|
+
racc_use_result_var ]
|
620
|
+
|
621
|
+
Racc_token_to_s_table = [
|
622
|
+
"$end",
|
623
|
+
"error",
|
624
|
+
"T_SLASH",
|
625
|
+
"T_SLASHSLASH",
|
626
|
+
"T_PIPE",
|
627
|
+
"T_PLUS",
|
628
|
+
"T_MINUS",
|
629
|
+
"T_EQ",
|
630
|
+
"T_NEQ",
|
631
|
+
"T_LT",
|
632
|
+
"T_GT",
|
633
|
+
"T_LTE",
|
634
|
+
"T_GTE",
|
635
|
+
"T_AND",
|
636
|
+
"T_OR",
|
637
|
+
"T_DIV",
|
638
|
+
"T_MOD",
|
639
|
+
"T_MUL",
|
640
|
+
"T_LPAREN",
|
641
|
+
"T_RPAREN",
|
642
|
+
"T_LBRACK",
|
643
|
+
"T_RBRACK",
|
644
|
+
"T_DOT",
|
645
|
+
"T_DOTDOT",
|
646
|
+
"T_AT",
|
647
|
+
"T_COMMA",
|
648
|
+
"T_COLONCOLON",
|
649
|
+
"T_NC_NAME",
|
650
|
+
"T_Q_NAME",
|
651
|
+
"T_FUNCTION_NAME",
|
652
|
+
"T_NAME_TEST",
|
653
|
+
"T_NODE_TYPE",
|
654
|
+
"T_AXIS_NAME",
|
655
|
+
"T_VARIABLE_REFERENCE",
|
656
|
+
"T_LITERAL",
|
657
|
+
"T_NUMBER",
|
658
|
+
"$start",
|
659
|
+
"expr",
|
660
|
+
"location_path",
|
661
|
+
"relative_location_path",
|
662
|
+
"absolute_location_path",
|
663
|
+
"descendant_or_self",
|
664
|
+
"step",
|
665
|
+
"node_test",
|
666
|
+
"optional_predicates",
|
667
|
+
"axis_specifier",
|
668
|
+
"abbreviated_step",
|
669
|
+
"repeatable_predicates",
|
670
|
+
"predicate",
|
671
|
+
"predicate_expr",
|
672
|
+
"or_expr",
|
673
|
+
"primary_expr",
|
674
|
+
"function_call",
|
675
|
+
"arguments",
|
676
|
+
"argument",
|
677
|
+
"union_expr",
|
678
|
+
"path_expr",
|
679
|
+
"filter_expr",
|
680
|
+
"and_expr",
|
681
|
+
"equality_expr",
|
682
|
+
"relational_expr",
|
683
|
+
"additive_expr",
|
684
|
+
"multiplicative_expr",
|
685
|
+
"unary_expr" ]
|
686
|
+
|
687
|
+
Racc_debug_parser = false
|
688
|
+
|
689
|
+
##### State transition tables end #####
|
690
|
+
|
691
|
+
# reduce 0 omitted
|
692
|
+
|
693
|
+
module_eval(<<'.,.,', 'parser.y', 42)
|
694
|
+
def _reduce_1(val, _values, result)
|
695
|
+
result = val[0]
|
696
|
+
result.absolute = false
|
697
|
+
|
698
|
+
result
|
699
|
+
end
|
700
|
+
.,.,
|
701
|
+
|
702
|
+
module_eval(<<'.,.,', 'parser.y', 46)
|
703
|
+
def _reduce_2(val, _values, result)
|
704
|
+
result = val[0]
|
705
|
+
result.absolute = true
|
706
|
+
|
707
|
+
result
|
708
|
+
end
|
709
|
+
.,.,
|
710
|
+
|
711
|
+
module_eval(<<'.,.,', 'parser.y', 51)
|
712
|
+
def _reduce_3(val, _values, result)
|
713
|
+
result = AST::LocationPath.new
|
714
|
+
result
|
715
|
+
end
|
716
|
+
.,.,
|
717
|
+
|
718
|
+
module_eval(<<'.,.,', 'parser.y', 52)
|
719
|
+
def _reduce_4(val, _values, result)
|
720
|
+
result = val[1]
|
721
|
+
result
|
722
|
+
end
|
723
|
+
.,.,
|
724
|
+
|
725
|
+
module_eval(<<'.,.,', 'parser.y', 54)
|
726
|
+
def _reduce_5(val, _values, result)
|
727
|
+
result = val[1]
|
728
|
+
result.insert_first_step(val[0])
|
729
|
+
|
730
|
+
result
|
731
|
+
end
|
732
|
+
.,.,
|
733
|
+
|
734
|
+
module_eval(<<'.,.,', 'parser.y', 60)
|
735
|
+
def _reduce_6(val, _values, result)
|
736
|
+
result = AST::LocationPath.new
|
737
|
+
result.append_step(val[0])
|
738
|
+
|
739
|
+
result
|
740
|
+
end
|
741
|
+
.,.,
|
742
|
+
|
743
|
+
module_eval(<<'.,.,', 'parser.y', 64)
|
744
|
+
def _reduce_7(val, _values, result)
|
745
|
+
result = val[0]
|
746
|
+
result.append_step(val[2])
|
747
|
+
|
748
|
+
result
|
749
|
+
end
|
750
|
+
.,.,
|
751
|
+
|
752
|
+
module_eval(<<'.,.,', 'parser.y', 68)
|
753
|
+
def _reduce_8(val, _values, result)
|
754
|
+
result = val[0]
|
755
|
+
result.append_step(val[1])
|
756
|
+
result.append_step(val[2])
|
757
|
+
|
758
|
+
result
|
759
|
+
end
|
760
|
+
.,.,
|
761
|
+
|
762
|
+
module_eval(<<'.,.,', 'parser.y', 75)
|
763
|
+
def _reduce_9(val, _values, result)
|
764
|
+
result = AST::Axis::Child.new(node_test: val[0], predicates: val[1])
|
765
|
+
|
766
|
+
result
|
767
|
+
end
|
768
|
+
.,.,
|
769
|
+
|
770
|
+
module_eval(<<'.,.,', 'parser.y', 78)
|
771
|
+
def _reduce_10(val, _values, result)
|
772
|
+
axis_base_class = val[0]
|
773
|
+
axis_base_class = AST::Axis.fetch(axis_base_class.gsub(/-/, '_')) if axis_base_class.instance_of?(String)
|
774
|
+
result = axis_base_class.new(node_test: val[1], predicates: val[2])
|
775
|
+
|
776
|
+
result
|
777
|
+
end
|
778
|
+
.,.,
|
779
|
+
|
780
|
+
# reduce 11 omitted
|
781
|
+
|
782
|
+
# reduce 12 omitted
|
783
|
+
|
784
|
+
module_eval(<<'.,.,', 'parser.y', 85)
|
785
|
+
def _reduce_13(val, _values, result)
|
786
|
+
result = AST::Axis::Attribute
|
787
|
+
result
|
788
|
+
end
|
789
|
+
.,.,
|
790
|
+
|
791
|
+
module_eval(<<'.,.,', 'parser.y', 89)
|
792
|
+
def _reduce_14(val, _values, result)
|
793
|
+
local, namespace = expand_qname(val[0])
|
794
|
+
result = AST::NodeTest::Name.new(local: local, namespace: namespace)
|
795
|
+
|
796
|
+
result
|
797
|
+
end
|
798
|
+
.,.,
|
799
|
+
|
800
|
+
module_eval(<<'.,.,', 'parser.y', 93)
|
801
|
+
def _reduce_15(val, _values, result)
|
802
|
+
result = AST::NodeTest.fetch(val[0]).new
|
803
|
+
|
804
|
+
result
|
805
|
+
end
|
806
|
+
.,.,
|
807
|
+
|
808
|
+
module_eval(<<'.,.,', 'parser.y', 98)
|
809
|
+
def _reduce_16(val, _values, result)
|
810
|
+
result = AST::Axis::DescendantOrSelf.new(node_test: AST::NodeTest::Any.new)
|
811
|
+
|
812
|
+
result
|
813
|
+
end
|
814
|
+
.,.,
|
815
|
+
|
816
|
+
module_eval(<<'.,.,', 'parser.y', 105)
|
817
|
+
def _reduce_17(val, _values, result)
|
818
|
+
result = [AST::Predicate.new(val[0])]
|
819
|
+
result
|
820
|
+
end
|
821
|
+
.,.,
|
822
|
+
|
823
|
+
module_eval(<<'.,.,', 'parser.y', 107)
|
824
|
+
def _reduce_18(val, _values, result)
|
825
|
+
result = val[0]
|
826
|
+
result << val[1]
|
827
|
+
|
828
|
+
result
|
829
|
+
end
|
830
|
+
.,.,
|
831
|
+
|
832
|
+
# reduce 19 omitted
|
833
|
+
|
834
|
+
module_eval(<<'.,.,', 'parser.y', 112)
|
835
|
+
def _reduce_20(val, _values, result)
|
836
|
+
result = val[0]
|
837
|
+
result
|
838
|
+
end
|
839
|
+
.,.,
|
840
|
+
|
841
|
+
module_eval(<<'.,.,', 'parser.y', 114)
|
842
|
+
def _reduce_21(val, _values, result)
|
843
|
+
result = val[1]
|
844
|
+
result
|
845
|
+
end
|
846
|
+
.,.,
|
847
|
+
|
848
|
+
# reduce 22 omitted
|
849
|
+
|
850
|
+
module_eval(<<'.,.,', 'parser.y', 118)
|
851
|
+
def _reduce_23(val, _values, result)
|
852
|
+
result = AST::Axis::Self.new(node_test: AST::NodeTest::Any.new)
|
853
|
+
result
|
854
|
+
end
|
855
|
+
.,.,
|
856
|
+
|
857
|
+
module_eval(<<'.,.,', 'parser.y', 119)
|
858
|
+
def _reduce_24(val, _values, result)
|
859
|
+
result = AST::Axis::Parent.new(node_test: AST::NodeTest::Any.new)
|
860
|
+
result
|
861
|
+
end
|
862
|
+
.,.,
|
863
|
+
|
864
|
+
# reduce 25 omitted
|
865
|
+
|
866
|
+
module_eval(<<'.,.,', 'parser.y', 124)
|
867
|
+
def _reduce_26(val, _values, result)
|
868
|
+
result = AST::Value::VariableReference.new(val[0])
|
869
|
+
result
|
870
|
+
end
|
871
|
+
.,.,
|
872
|
+
|
873
|
+
module_eval(<<'.,.,', 'parser.y', 125)
|
874
|
+
def _reduce_27(val, _values, result)
|
875
|
+
result = val[1]
|
876
|
+
result
|
877
|
+
end
|
878
|
+
.,.,
|
879
|
+
|
880
|
+
module_eval(<<'.,.,', 'parser.y', 126)
|
881
|
+
def _reduce_28(val, _values, result)
|
882
|
+
result = AST::Value::String.new(val[0].to_s)
|
883
|
+
result
|
884
|
+
end
|
885
|
+
.,.,
|
886
|
+
|
887
|
+
module_eval(<<'.,.,', 'parser.y', 127)
|
888
|
+
def _reduce_29(val, _values, result)
|
889
|
+
result = AST::Value::Number.new(val[0].include?(?.) ? val[0].to_f : val[0].to_i)
|
890
|
+
result
|
891
|
+
end
|
892
|
+
.,.,
|
893
|
+
|
894
|
+
# reduce 30 omitted
|
895
|
+
|
896
|
+
module_eval(<<'.,.,', 'parser.y', 132)
|
897
|
+
def _reduce_31(val, _values, result)
|
898
|
+
result = AST::Function.fetch(val[0]).new(*val[2])
|
899
|
+
|
900
|
+
result
|
901
|
+
end
|
902
|
+
.,.,
|
903
|
+
|
904
|
+
module_eval(<<'.,.,', 'parser.y', 135)
|
905
|
+
def _reduce_32(val, _values, result)
|
906
|
+
result = AST::Function.fetch(val[0]).new
|
907
|
+
|
908
|
+
result
|
909
|
+
end
|
910
|
+
.,.,
|
911
|
+
|
912
|
+
# reduce 33 omitted
|
913
|
+
|
914
|
+
module_eval(<<'.,.,', 'parser.y', 145)
|
915
|
+
def _reduce_34(val, _values, result)
|
916
|
+
result = []
|
917
|
+
result << val[0]
|
918
|
+
|
919
|
+
result
|
920
|
+
end
|
921
|
+
.,.,
|
922
|
+
|
923
|
+
module_eval(<<'.,.,', 'parser.y', 149)
|
924
|
+
def _reduce_35(val, _values, result)
|
925
|
+
result = val[0]
|
926
|
+
result << val[2]
|
927
|
+
|
928
|
+
result
|
929
|
+
end
|
930
|
+
.,.,
|
931
|
+
|
932
|
+
# reduce 36 omitted
|
933
|
+
|
934
|
+
module_eval(<<'.,.,', 'parser.y', 156)
|
935
|
+
def _reduce_37(val, _values, result)
|
936
|
+
result = AST::UnionExpr.new(val[0], val[2])
|
937
|
+
|
938
|
+
result
|
939
|
+
end
|
940
|
+
.,.,
|
941
|
+
|
942
|
+
# reduce 38 omitted
|
943
|
+
|
944
|
+
# reduce 39 omitted
|
945
|
+
|
946
|
+
module_eval(<<'.,.,', 'parser.y', 163)
|
947
|
+
def _reduce_40(val, _values, result)
|
948
|
+
val[2].absolute = true
|
949
|
+
result = AST::Path.new(val[0], val[2])
|
950
|
+
|
951
|
+
result
|
952
|
+
end
|
953
|
+
.,.,
|
954
|
+
|
955
|
+
module_eval(<<'.,.,', 'parser.y', 167)
|
956
|
+
def _reduce_41(val, _values, result)
|
957
|
+
val[2].insert_first_step(val[1])
|
958
|
+
val[2].absolute = true
|
959
|
+
result = AST::Path.new(val[0], val[2])
|
960
|
+
|
961
|
+
result
|
962
|
+
end
|
963
|
+
.,.,
|
964
|
+
|
965
|
+
# reduce 42 omitted
|
966
|
+
|
967
|
+
module_eval(<<'.,.,', 'parser.y', 175)
|
968
|
+
def _reduce_43(val, _values, result)
|
969
|
+
result = AST::Filter.new(val[0], predicates: val[1])
|
970
|
+
|
971
|
+
result
|
972
|
+
end
|
973
|
+
.,.,
|
974
|
+
|
975
|
+
# reduce 44 omitted
|
976
|
+
|
977
|
+
module_eval(<<'.,.,', 'parser.y', 180)
|
978
|
+
def _reduce_45(val, _values, result)
|
979
|
+
result = AST::OrExpr.new(a: val[0], b: val[2])
|
980
|
+
result
|
981
|
+
end
|
982
|
+
.,.,
|
983
|
+
|
984
|
+
# reduce 46 omitted
|
985
|
+
|
986
|
+
module_eval(<<'.,.,', 'parser.y', 184)
|
987
|
+
def _reduce_47(val, _values, result)
|
988
|
+
result = AST::AndExpr.new(a: val[0], b: val[2])
|
989
|
+
result
|
990
|
+
end
|
991
|
+
.,.,
|
992
|
+
|
993
|
+
# reduce 48 omitted
|
994
|
+
|
995
|
+
module_eval(<<'.,.,', 'parser.y', 188)
|
996
|
+
def _reduce_49(val, _values, result)
|
997
|
+
result = AST::EqExpr.new(val[0], val[2])
|
998
|
+
result
|
999
|
+
end
|
1000
|
+
.,.,
|
1001
|
+
|
1002
|
+
module_eval(<<'.,.,', 'parser.y', 189)
|
1003
|
+
def _reduce_50(val, _values, result)
|
1004
|
+
result = AST::NeqExpr.new(val[0], val[2])
|
1005
|
+
result
|
1006
|
+
end
|
1007
|
+
.,.,
|
1008
|
+
|
1009
|
+
# reduce 51 omitted
|
1010
|
+
|
1011
|
+
module_eval(<<'.,.,', 'parser.y', 193)
|
1012
|
+
def _reduce_52(val, _values, result)
|
1013
|
+
result = AST::LtExpr.new(val[0], val[2])
|
1014
|
+
result
|
1015
|
+
end
|
1016
|
+
.,.,
|
1017
|
+
|
1018
|
+
module_eval(<<'.,.,', 'parser.y', 194)
|
1019
|
+
def _reduce_53(val, _values, result)
|
1020
|
+
result = AST::GtExpr.new(val[0], val[2])
|
1021
|
+
result
|
1022
|
+
end
|
1023
|
+
.,.,
|
1024
|
+
|
1025
|
+
module_eval(<<'.,.,', 'parser.y', 195)
|
1026
|
+
def _reduce_54(val, _values, result)
|
1027
|
+
result = AST::LteExpr.new(val[0], val[2])
|
1028
|
+
result
|
1029
|
+
end
|
1030
|
+
.,.,
|
1031
|
+
|
1032
|
+
module_eval(<<'.,.,', 'parser.y', 196)
|
1033
|
+
def _reduce_55(val, _values, result)
|
1034
|
+
result = AST::GteExpr.new(val[0], val[2])
|
1035
|
+
result
|
1036
|
+
end
|
1037
|
+
.,.,
|
1038
|
+
|
1039
|
+
# reduce 56 omitted
|
1040
|
+
|
1041
|
+
module_eval(<<'.,.,', 'parser.y', 201)
|
1042
|
+
def _reduce_57(val, _values, result)
|
1043
|
+
result = AST::PlusExpr.new(val[0], val[2])
|
1044
|
+
|
1045
|
+
result
|
1046
|
+
end
|
1047
|
+
.,.,
|
1048
|
+
|
1049
|
+
module_eval(<<'.,.,', 'parser.y', 204)
|
1050
|
+
def _reduce_58(val, _values, result)
|
1051
|
+
result = AST::MinusExpr.new(val[0], val[2])
|
1052
|
+
|
1053
|
+
result
|
1054
|
+
end
|
1055
|
+
.,.,
|
1056
|
+
|
1057
|
+
# reduce 59 omitted
|
1058
|
+
|
1059
|
+
module_eval(<<'.,.,', 'parser.y', 210)
|
1060
|
+
def _reduce_60(val, _values, result)
|
1061
|
+
result = AST::MultiplyExpr.new(val[0], val[2])
|
1062
|
+
|
1063
|
+
result
|
1064
|
+
end
|
1065
|
+
.,.,
|
1066
|
+
|
1067
|
+
module_eval(<<'.,.,', 'parser.y', 213)
|
1068
|
+
def _reduce_61(val, _values, result)
|
1069
|
+
result = AST::DividedExpr.new(val[0], val[2])
|
1070
|
+
|
1071
|
+
result
|
1072
|
+
end
|
1073
|
+
.,.,
|
1074
|
+
|
1075
|
+
module_eval(<<'.,.,', 'parser.y', 216)
|
1076
|
+
def _reduce_62(val, _values, result)
|
1077
|
+
result = AST::ModuloExpr.new(val[0], val[2])
|
1078
|
+
|
1079
|
+
result
|
1080
|
+
end
|
1081
|
+
.,.,
|
1082
|
+
|
1083
|
+
# reduce 63 omitted
|
1084
|
+
|
1085
|
+
module_eval(<<'.,.,', 'parser.y', 222)
|
1086
|
+
def _reduce_64(val, _values, result)
|
1087
|
+
result = AST::Negative.new(val[1])
|
1088
|
+
|
1089
|
+
result
|
1090
|
+
end
|
1091
|
+
.,.,
|
1092
|
+
|
1093
|
+
def _reduce_none(val, _values, result)
|
1094
|
+
val[0]
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
end # class Parser
|
1098
|
+
end # module XPath
|
1099
|
+
end # module Gammo
|