rubyjedi-oga 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/LICENSE +362 -0
- data/README.md +317 -0
- data/doc/css/common.css +77 -0
- data/doc/css_selectors.md +935 -0
- data/doc/manually_creating_documents.md +67 -0
- data/doc/migrating_from_nokogiri.md +169 -0
- data/doc/xml_namespaces.md +63 -0
- data/ext/c/extconf.rb +11 -0
- data/ext/c/lexer.c +2595 -0
- data/ext/c/lexer.h +16 -0
- data/ext/c/lexer.rl +198 -0
- data/ext/c/liboga.c +6 -0
- data/ext/c/liboga.h +11 -0
- data/ext/java/Liboga.java +14 -0
- data/ext/java/org/liboga/xml/Lexer.java +1363 -0
- data/ext/java/org/liboga/xml/Lexer.rl +223 -0
- data/ext/ragel/base_lexer.rl +633 -0
- data/lib/oga.rb +57 -0
- data/lib/oga/blacklist.rb +40 -0
- data/lib/oga/css/lexer.rb +743 -0
- data/lib/oga/css/parser.rb +976 -0
- data/lib/oga/entity_decoder.rb +21 -0
- data/lib/oga/html/entities.rb +2150 -0
- data/lib/oga/html/parser.rb +25 -0
- data/lib/oga/html/sax_parser.rb +18 -0
- data/lib/oga/lru.rb +160 -0
- data/lib/oga/oga.rb +57 -0
- data/lib/oga/version.rb +3 -0
- data/lib/oga/whitelist.rb +20 -0
- data/lib/oga/xml/attribute.rb +136 -0
- data/lib/oga/xml/cdata.rb +17 -0
- data/lib/oga/xml/character_node.rb +37 -0
- data/lib/oga/xml/comment.rb +17 -0
- data/lib/oga/xml/default_namespace.rb +13 -0
- data/lib/oga/xml/doctype.rb +82 -0
- data/lib/oga/xml/document.rb +108 -0
- data/lib/oga/xml/element.rb +428 -0
- data/lib/oga/xml/entities.rb +122 -0
- data/lib/oga/xml/html_void_elements.rb +15 -0
- data/lib/oga/xml/lexer.rb +550 -0
- data/lib/oga/xml/namespace.rb +48 -0
- data/lib/oga/xml/node.rb +219 -0
- data/lib/oga/xml/node_set.rb +333 -0
- data/lib/oga/xml/parser.rb +631 -0
- data/lib/oga/xml/processing_instruction.rb +37 -0
- data/lib/oga/xml/pull_parser.rb +175 -0
- data/lib/oga/xml/querying.rb +56 -0
- data/lib/oga/xml/sax_parser.rb +192 -0
- data/lib/oga/xml/text.rb +66 -0
- data/lib/oga/xml/traversal.rb +50 -0
- data/lib/oga/xml/xml_declaration.rb +65 -0
- data/lib/oga/xpath/evaluator.rb +1798 -0
- data/lib/oga/xpath/lexer.rb +1958 -0
- data/lib/oga/xpath/parser.rb +622 -0
- data/oga.gemspec +45 -0
- metadata +227 -0
@@ -0,0 +1,622 @@
|
|
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.
|
11
|
+
#
|
12
|
+
# Unlike {Oga::XML::Parser} this parser only takes String instances as input.
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
#
|
16
|
+
class Parser < LL::Driver
|
17
|
+
CONFIG = LL::DriverConfig.new
|
18
|
+
|
19
|
+
CONFIG.terminals = [
|
20
|
+
:$EOF, # 0
|
21
|
+
:T_AXIS, # 1
|
22
|
+
:T_COLON, # 2
|
23
|
+
:T_COMMA, # 3
|
24
|
+
:T_FLOAT, # 4
|
25
|
+
:T_INT, # 5
|
26
|
+
:T_IDENT, # 6
|
27
|
+
:T_TYPE_TEST, # 7
|
28
|
+
:T_LBRACK, # 8
|
29
|
+
:T_RBRACK, # 9
|
30
|
+
:T_LPAREN, # 10
|
31
|
+
:T_RPAREN, # 11
|
32
|
+
:T_SLASH, # 12
|
33
|
+
:T_STRING, # 13
|
34
|
+
:T_PIPE, # 14
|
35
|
+
:T_AND, # 15
|
36
|
+
:T_OR, # 16
|
37
|
+
:T_ADD, # 17
|
38
|
+
:T_DIV, # 18
|
39
|
+
:T_MOD, # 19
|
40
|
+
:T_EQ, # 20
|
41
|
+
:T_NEQ, # 21
|
42
|
+
:T_LT, # 22
|
43
|
+
:T_GT, # 23
|
44
|
+
:T_LTE, # 24
|
45
|
+
:T_GTE, # 25
|
46
|
+
:T_SUB, # 26
|
47
|
+
:T_MUL, # 27
|
48
|
+
:T_VAR, # 28
|
49
|
+
].freeze
|
50
|
+
|
51
|
+
CONFIG.rules = [
|
52
|
+
[3, 0, 8, 34], # 0
|
53
|
+
[3, 1, 4, 35, 6, 0, 0, 3], # 1
|
54
|
+
[3, 2, 0, 3, 1, 16], # 2
|
55
|
+
[3, 3, 4, 36, 6, 0, 0, 5], # 3
|
56
|
+
[3, 4, 0, 5, 1, 15], # 4
|
57
|
+
[3, 5, 4, 37, 6, 0, 0, 7], # 5
|
58
|
+
[3, 6, 0, 7, 1, 20], # 6
|
59
|
+
[3, 7, 0, 7, 1, 21], # 7
|
60
|
+
[3, 8, 4, 38, 6, 0, 0, 9], # 8
|
61
|
+
[3, 9, 0, 9, 1, 22], # 9
|
62
|
+
[3, 10, 0, 9, 1, 23], # 10
|
63
|
+
[3, 11, 0, 9, 1, 24], # 11
|
64
|
+
[3, 12, 0, 9, 1, 25], # 12
|
65
|
+
[3, 13, 4, 39, 6, 0, 0, 11], # 13
|
66
|
+
[3, 14, 0, 11, 1, 17], # 14
|
67
|
+
[3, 15, 0, 11, 1, 26], # 15
|
68
|
+
[3, 16, 8, 40, 0, 13], # 16
|
69
|
+
[3, 17, 0, 11, 1, 18], # 17
|
70
|
+
[3, 18, 0, 11, 1, 19], # 18
|
71
|
+
[3, 19, 0, 11, 1, 27], # 19
|
72
|
+
[3, 20, 4, 41, 6, 0, 0, 15], # 20
|
73
|
+
[3, 21, 0, 15, 1, 14], # 21
|
74
|
+
[3, 22, 0, 16], # 22
|
75
|
+
[3, 23, 0, 19], # 23
|
76
|
+
[3, 24, 0, 31], # 24
|
77
|
+
[3, 25, 0, 32], # 25
|
78
|
+
[3, 26, 0, 33], # 26
|
79
|
+
[3, 27, 1, 11, 0, 1, 1, 10], # 27
|
80
|
+
[3, 28, 0, 17], # 28
|
81
|
+
[3, 29, 4, 42, 6, 0, 0, 20], # 29
|
82
|
+
[3, 30, 0, 20, 1, 12], # 30
|
83
|
+
[3, 31, 8, 43, 1, 12], # 31
|
84
|
+
[3, 32, 0, 21], # 32
|
85
|
+
[3, 33, 0, 29], # 33
|
86
|
+
[3, 34, 0, 22, 1, 6], # 34
|
87
|
+
[3, 35, 0, 24], # 35
|
88
|
+
[3, 36, 1, 11, 0, 27, 1, 10], # 36
|
89
|
+
[3, 37, 8, 44, 1, 6, 1, 2], # 37
|
90
|
+
[3, 38, 8, 45], # 38
|
91
|
+
[3, 39, 1, 9, 0, 1, 1, 8], # 39
|
92
|
+
[3, 40, 1, 7], # 40
|
93
|
+
[3, 41, 8, 46, 1, 6], # 41
|
94
|
+
[3, 42, 1, 6, 1, 2], # 42
|
95
|
+
[3, 43, 4, 47, 6, 0, 0, 1], # 43
|
96
|
+
[3, 44, 2, 0], # 44
|
97
|
+
[3, 45, 0, 1, 1, 3], # 45
|
98
|
+
[3, 46, 8, 48, 0, 30, 1, 1], # 46
|
99
|
+
[3, 47, 0, 25], # 47
|
100
|
+
[3, 48, 0, 24], # 48
|
101
|
+
[3, 49, 1, 13], # 49
|
102
|
+
[3, 50, 1, 5], # 50
|
103
|
+
[3, 51, 1, 4], # 51
|
104
|
+
[3, 52, 1, 28], # 52
|
105
|
+
[3, 53, 0, 1], # 53
|
106
|
+
[3, 54, 0, 2], # 54
|
107
|
+
[3, 55, 0, 4], # 55
|
108
|
+
[3, 56, 0, 6], # 56
|
109
|
+
[3, 57, 0, 8], # 57
|
110
|
+
[3, 58, 0, 10], # 58
|
111
|
+
[3, 59, 0, 12], # 59
|
112
|
+
[3, 60, 0, 14], # 60
|
113
|
+
[3, 61, 0, 18], # 61
|
114
|
+
[3, 62, 0, 17], # 62
|
115
|
+
[3, 63, 0, 23], # 63
|
116
|
+
[3, 64, 0, 23], # 64
|
117
|
+
[3, 65, 0, 26], # 65
|
118
|
+
[3, 66, 0, 28], # 66
|
119
|
+
[3, 67, 0, 23], # 67
|
120
|
+
].freeze
|
121
|
+
|
122
|
+
CONFIG.table = [
|
123
|
+
[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
|
124
|
+
[-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
|
125
|
+
[-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
|
126
|
+
[-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
|
127
|
+
[-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
|
128
|
+
[-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
|
129
|
+
[-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
|
130
|
+
[-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
|
131
|
+
[-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
|
132
|
+
[-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
|
133
|
+
[-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
|
134
|
+
[-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
|
135
|
+
[-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
|
136
|
+
[-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
|
137
|
+
[-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
|
138
|
+
[-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
|
139
|
+
[-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
|
140
|
+
[-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
|
141
|
+
[-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
|
142
|
+
[-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
|
143
|
+
[-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
|
144
|
+
[-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
|
145
|
+
[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
|
146
|
+
[-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
|
147
|
+
[-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
|
148
|
+
[-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
|
149
|
+
[-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
|
150
|
+
[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
|
151
|
+
[-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
|
152
|
+
[-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
|
153
|
+
[-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
|
154
|
+
[-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
|
155
|
+
[-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
|
156
|
+
[-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
|
157
|
+
[-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
|
158
|
+
[-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
|
159
|
+
[-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
|
160
|
+
[-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
|
161
|
+
[-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
|
162
|
+
[-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
|
163
|
+
[-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
|
164
|
+
[-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
|
165
|
+
[-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
|
166
|
+
[-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
|
167
|
+
[-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
|
168
|
+
[-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
|
169
|
+
[-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
|
170
|
+
[-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
|
171
|
+
[-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
|
172
|
+
].freeze
|
173
|
+
|
174
|
+
CONFIG.actions = [
|
175
|
+
[:_rule_0, 1], # 0
|
176
|
+
[:_rule_1, 2], # 1
|
177
|
+
[:_rule_2, 2], # 2
|
178
|
+
[:_rule_3, 2], # 3
|
179
|
+
[:_rule_4, 2], # 4
|
180
|
+
[:_rule_5, 2], # 5
|
181
|
+
[:_rule_6, 2], # 6
|
182
|
+
[:_rule_7, 2], # 7
|
183
|
+
[:_rule_8, 2], # 8
|
184
|
+
[:_rule_9, 2], # 9
|
185
|
+
[:_rule_10, 2], # 10
|
186
|
+
[:_rule_11, 2], # 11
|
187
|
+
[:_rule_12, 2], # 12
|
188
|
+
[:_rule_13, 2], # 13
|
189
|
+
[:_rule_14, 2], # 14
|
190
|
+
[:_rule_15, 2], # 15
|
191
|
+
[:_rule_16, 2], # 16
|
192
|
+
[:_rule_17, 2], # 17
|
193
|
+
[:_rule_18, 2], # 18
|
194
|
+
[:_rule_19, 2], # 19
|
195
|
+
[:_rule_20, 2], # 20
|
196
|
+
[:_rule_21, 2], # 21
|
197
|
+
[:_rule_22, 1], # 22
|
198
|
+
[:_rule_23, 1], # 23
|
199
|
+
[:_rule_24, 1], # 24
|
200
|
+
[:_rule_25, 1], # 25
|
201
|
+
[:_rule_26, 1], # 26
|
202
|
+
[:_rule_27, 3], # 27
|
203
|
+
[:_rule_28, 1], # 28
|
204
|
+
[:_rule_29, 2], # 29
|
205
|
+
[:_rule_30, 2], # 30
|
206
|
+
[:_rule_31, 2], # 31
|
207
|
+
[:_rule_32, 1], # 32
|
208
|
+
[:_rule_33, 1], # 33
|
209
|
+
[:_rule_34, 2], # 34
|
210
|
+
[:_rule_35, 1], # 35
|
211
|
+
[:_rule_36, 3], # 36
|
212
|
+
[:_rule_37, 3], # 37
|
213
|
+
[:_rule_38, 1], # 38
|
214
|
+
[:_rule_39, 3], # 39
|
215
|
+
[:_rule_40, 1], # 40
|
216
|
+
[:_rule_41, 2], # 41
|
217
|
+
[:_rule_42, 2], # 42
|
218
|
+
[:_rule_43, 2], # 43
|
219
|
+
[:_rule_44, 0], # 44
|
220
|
+
[:_rule_45, 2], # 45
|
221
|
+
[:_rule_46, 3], # 46
|
222
|
+
[:_rule_47, 1], # 47
|
223
|
+
[:_rule_48, 1], # 48
|
224
|
+
[:_rule_49, 1], # 49
|
225
|
+
[:_rule_50, 1], # 50
|
226
|
+
[:_rule_51, 1], # 51
|
227
|
+
[:_rule_52, 1], # 52
|
228
|
+
[:_rule_53, 1], # 53
|
229
|
+
[:_rule_54, 1], # 54
|
230
|
+
[:_rule_55, 1], # 55
|
231
|
+
[:_rule_56, 1], # 56
|
232
|
+
[:_rule_57, 1], # 57
|
233
|
+
[:_rule_58, 1], # 58
|
234
|
+
[:_rule_59, 1], # 59
|
235
|
+
[:_rule_60, 1], # 60
|
236
|
+
[:_rule_61, 1], # 61
|
237
|
+
[:_rule_62, 1], # 62
|
238
|
+
[:_rule_63, 1], # 63
|
239
|
+
[:_rule_64, 1], # 64
|
240
|
+
[:_rule_65, 1], # 65
|
241
|
+
[:_rule_66, 1], # 66
|
242
|
+
[:_rule_67, 1], # 67
|
243
|
+
].freeze
|
244
|
+
|
245
|
+
##
|
246
|
+
# @return [Oga::LRU]
|
247
|
+
#
|
248
|
+
CACHE = LRU.new
|
249
|
+
|
250
|
+
##
|
251
|
+
# @param [String] data
|
252
|
+
# @return [AST::Node]
|
253
|
+
#
|
254
|
+
def self.parse_with_cache(data)
|
255
|
+
return CACHE.get_or_set(data) { new(data).parse }
|
256
|
+
end
|
257
|
+
|
258
|
+
##
|
259
|
+
# @param [String] data The input to parse.
|
260
|
+
#
|
261
|
+
def initialize(data)
|
262
|
+
@lexer = Lexer.new(data)
|
263
|
+
end
|
264
|
+
|
265
|
+
##
|
266
|
+
# Creates a new XPath node.
|
267
|
+
#
|
268
|
+
# @param [Symbol] type
|
269
|
+
# @param [Array] children
|
270
|
+
# @return [AST::Node]
|
271
|
+
#
|
272
|
+
def s(type, *children)
|
273
|
+
return AST::Node.new(type, children)
|
274
|
+
end
|
275
|
+
|
276
|
+
##
|
277
|
+
# Yields the next token from the lexer.
|
278
|
+
#
|
279
|
+
# @yieldparam [Array]
|
280
|
+
#
|
281
|
+
def each_token
|
282
|
+
@lexer.advance do |type, value, line|
|
283
|
+
@line = line if line
|
284
|
+
|
285
|
+
yield [type, value]
|
286
|
+
end
|
287
|
+
|
288
|
+
yield [-1, -1]
|
289
|
+
end
|
290
|
+
|
291
|
+
##
|
292
|
+
# @param [Array] val
|
293
|
+
#
|
294
|
+
def combine_operators(val)
|
295
|
+
ret = val[0]
|
296
|
+
|
297
|
+
val[1].each do |expr|
|
298
|
+
ret = s(expr[0], ret, expr[1])
|
299
|
+
end
|
300
|
+
|
301
|
+
return ret
|
302
|
+
end
|
303
|
+
|
304
|
+
##
|
305
|
+
# @param [Array] val
|
306
|
+
#
|
307
|
+
def combine_optional_operator(val)
|
308
|
+
ret = val[0]
|
309
|
+
|
310
|
+
if val[1]
|
311
|
+
ret = s(val[1][0], ret, val[1][1])
|
312
|
+
end
|
313
|
+
|
314
|
+
ret
|
315
|
+
end
|
316
|
+
|
317
|
+
def _rule_0(val)
|
318
|
+
val[0]
|
319
|
+
end
|
320
|
+
|
321
|
+
def _rule_1(val)
|
322
|
+
combine_operators(val)
|
323
|
+
end
|
324
|
+
|
325
|
+
def _rule_2(val)
|
326
|
+
[:or, val[1]]
|
327
|
+
end
|
328
|
+
|
329
|
+
def _rule_3(val)
|
330
|
+
combine_operators(val)
|
331
|
+
end
|
332
|
+
|
333
|
+
def _rule_4(val)
|
334
|
+
[:and, val[1]]
|
335
|
+
end
|
336
|
+
|
337
|
+
def _rule_5(val)
|
338
|
+
combine_operators(val)
|
339
|
+
end
|
340
|
+
|
341
|
+
def _rule_6(val)
|
342
|
+
[:eq, val[1]]
|
343
|
+
end
|
344
|
+
|
345
|
+
def _rule_7(val)
|
346
|
+
[:neq, val[1]]
|
347
|
+
end
|
348
|
+
|
349
|
+
def _rule_8(val)
|
350
|
+
combine_operators(val)
|
351
|
+
end
|
352
|
+
|
353
|
+
def _rule_9(val)
|
354
|
+
[:lt, val[1]]
|
355
|
+
end
|
356
|
+
|
357
|
+
def _rule_10(val)
|
358
|
+
[:gt, val[1]]
|
359
|
+
end
|
360
|
+
|
361
|
+
def _rule_11(val)
|
362
|
+
[:lte, val[1]]
|
363
|
+
end
|
364
|
+
|
365
|
+
def _rule_12(val)
|
366
|
+
[:gte, val[1]]
|
367
|
+
end
|
368
|
+
|
369
|
+
def _rule_13(val)
|
370
|
+
combine_operators(val)
|
371
|
+
end
|
372
|
+
|
373
|
+
def _rule_14(val)
|
374
|
+
[:add, val[1]]
|
375
|
+
end
|
376
|
+
|
377
|
+
def _rule_15(val)
|
378
|
+
[:sub, val[1]]
|
379
|
+
end
|
380
|
+
|
381
|
+
def _rule_16(val)
|
382
|
+
combine_optional_operator(val)
|
383
|
+
end
|
384
|
+
|
385
|
+
def _rule_17(val)
|
386
|
+
[:div, val[1]]
|
387
|
+
end
|
388
|
+
|
389
|
+
def _rule_18(val)
|
390
|
+
[:mod, val[1]]
|
391
|
+
end
|
392
|
+
|
393
|
+
def _rule_19(val)
|
394
|
+
[:mul, val[1]]
|
395
|
+
end
|
396
|
+
|
397
|
+
def _rule_20(val)
|
398
|
+
combine_operators(val)
|
399
|
+
end
|
400
|
+
|
401
|
+
def _rule_21(val)
|
402
|
+
[:pipe, val[1]]
|
403
|
+
end
|
404
|
+
|
405
|
+
def _rule_22(val)
|
406
|
+
val[0]
|
407
|
+
end
|
408
|
+
|
409
|
+
def _rule_23(val)
|
410
|
+
val[0]
|
411
|
+
end
|
412
|
+
|
413
|
+
def _rule_24(val)
|
414
|
+
val[0]
|
415
|
+
end
|
416
|
+
|
417
|
+
def _rule_25(val)
|
418
|
+
val[0]
|
419
|
+
end
|
420
|
+
|
421
|
+
def _rule_26(val)
|
422
|
+
val[0]
|
423
|
+
end
|
424
|
+
|
425
|
+
def _rule_27(val)
|
426
|
+
val[1]
|
427
|
+
end
|
428
|
+
|
429
|
+
def _rule_28(val)
|
430
|
+
val[0].length > 1 ? s(:path, *val[0]) : val[0][0]
|
431
|
+
end
|
432
|
+
|
433
|
+
def _rule_29(val)
|
434
|
+
[val[0], *val[1]]
|
435
|
+
end
|
436
|
+
|
437
|
+
def _rule_30(val)
|
438
|
+
val[1]
|
439
|
+
end
|
440
|
+
|
441
|
+
def _rule_31(val)
|
442
|
+
s(:absolute_path, *val[1])
|
443
|
+
end
|
444
|
+
|
445
|
+
def _rule_32(val)
|
446
|
+
val[0]
|
447
|
+
end
|
448
|
+
|
449
|
+
def _rule_33(val)
|
450
|
+
val[0]
|
451
|
+
end
|
452
|
+
|
453
|
+
def _rule_34(val)
|
454
|
+
|
455
|
+
type = val[1][0]
|
456
|
+
args = val[1][1]
|
457
|
+
pred = val[1][2]
|
458
|
+
|
459
|
+
if type.equal?(:test)
|
460
|
+
# Whenever a bare test is used (e.g. just "A") this actually means
|
461
|
+
# "child::A". Handling this on parser level is the easiest.
|
462
|
+
if args
|
463
|
+
node = s(:axis, 'child', s(:test, val[0], args))
|
464
|
+
else
|
465
|
+
node = s(:axis, 'child', s(:test, nil, val[0]))
|
466
|
+
end
|
467
|
+
else
|
468
|
+
node = s(type, val[0], *args)
|
469
|
+
end
|
470
|
+
|
471
|
+
if pred
|
472
|
+
node = s(:predicate, node, pred)
|
473
|
+
end
|
474
|
+
|
475
|
+
node
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
def _rule_35(val)
|
480
|
+
s(:axis, 'child', val[0])
|
481
|
+
end
|
482
|
+
|
483
|
+
def _rule_36(val)
|
484
|
+
[:call, val[1]]
|
485
|
+
end
|
486
|
+
|
487
|
+
def _rule_37(val)
|
488
|
+
[:test, val[1], val[2]]
|
489
|
+
end
|
490
|
+
|
491
|
+
def _rule_38(val)
|
492
|
+
[:test, nil, val[0]]
|
493
|
+
end
|
494
|
+
|
495
|
+
def _rule_39(val)
|
496
|
+
val[1]
|
497
|
+
end
|
498
|
+
|
499
|
+
def _rule_40(val)
|
500
|
+
s(:type_test, val[0])
|
501
|
+
end
|
502
|
+
|
503
|
+
def _rule_41(val)
|
504
|
+
|
505
|
+
val[1] ? s(:test, val[0], val[1]) : s(:test, nil, val[0])
|
506
|
+
|
507
|
+
end
|
508
|
+
|
509
|
+
def _rule_42(val)
|
510
|
+
val[1]
|
511
|
+
end
|
512
|
+
|
513
|
+
def _rule_43(val)
|
514
|
+
[val[0], *val[1]]
|
515
|
+
end
|
516
|
+
|
517
|
+
def _rule_44(val)
|
518
|
+
val
|
519
|
+
end
|
520
|
+
|
521
|
+
def _rule_45(val)
|
522
|
+
val[1]
|
523
|
+
end
|
524
|
+
|
525
|
+
def _rule_46(val)
|
526
|
+
|
527
|
+
ret = s(:axis, val[0], val[1])
|
528
|
+
|
529
|
+
if val[2]
|
530
|
+
ret = s(:predicate, ret, val[2])
|
531
|
+
end
|
532
|
+
|
533
|
+
ret
|
534
|
+
|
535
|
+
end
|
536
|
+
|
537
|
+
def _rule_47(val)
|
538
|
+
val[0]
|
539
|
+
end
|
540
|
+
|
541
|
+
def _rule_48(val)
|
542
|
+
val[0]
|
543
|
+
end
|
544
|
+
|
545
|
+
def _rule_49(val)
|
546
|
+
s(:string, val[0])
|
547
|
+
end
|
548
|
+
|
549
|
+
def _rule_50(val)
|
550
|
+
s(:int, val[0])
|
551
|
+
end
|
552
|
+
|
553
|
+
def _rule_51(val)
|
554
|
+
s(:float, val[0])
|
555
|
+
end
|
556
|
+
|
557
|
+
def _rule_52(val)
|
558
|
+
s(:var, val[0])
|
559
|
+
end
|
560
|
+
|
561
|
+
def _rule_53(val)
|
562
|
+
val[0]
|
563
|
+
end
|
564
|
+
|
565
|
+
def _rule_54(val)
|
566
|
+
val[0]
|
567
|
+
end
|
568
|
+
|
569
|
+
def _rule_55(val)
|
570
|
+
val[0]
|
571
|
+
end
|
572
|
+
|
573
|
+
def _rule_56(val)
|
574
|
+
val[0]
|
575
|
+
end
|
576
|
+
|
577
|
+
def _rule_57(val)
|
578
|
+
val[0]
|
579
|
+
end
|
580
|
+
|
581
|
+
def _rule_58(val)
|
582
|
+
val[0]
|
583
|
+
end
|
584
|
+
|
585
|
+
def _rule_59(val)
|
586
|
+
val[0]
|
587
|
+
end
|
588
|
+
|
589
|
+
def _rule_60(val)
|
590
|
+
val[0]
|
591
|
+
end
|
592
|
+
|
593
|
+
def _rule_61(val)
|
594
|
+
val[0]
|
595
|
+
end
|
596
|
+
|
597
|
+
def _rule_62(val)
|
598
|
+
val[0]
|
599
|
+
end
|
600
|
+
|
601
|
+
def _rule_63(val)
|
602
|
+
val[0]
|
603
|
+
end
|
604
|
+
|
605
|
+
def _rule_64(val)
|
606
|
+
val[0]
|
607
|
+
end
|
608
|
+
|
609
|
+
def _rule_65(val)
|
610
|
+
val[0]
|
611
|
+
end
|
612
|
+
|
613
|
+
def _rule_66(val)
|
614
|
+
val[0]
|
615
|
+
end
|
616
|
+
|
617
|
+
def _rule_67(val)
|
618
|
+
val[0]
|
619
|
+
end
|
620
|
+
end
|
621
|
+
end
|
622
|
+
end
|