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