nokogiri-fitzsimmons 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +26 -0
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +666 -0
- data/CHANGELOG.rdoc +659 -0
- data/C_CODING_STYLE.rdoc +33 -0
- data/Manifest.txt +295 -0
- data/README.ja.rdoc +106 -0
- data/README.rdoc +178 -0
- data/ROADMAP.md +86 -0
- data/Rakefile +194 -0
- data/STANDARD_RESPONSES.md +47 -0
- data/Y_U_NO_GEMSPEC.md +155 -0
- data/bin/nokogiri +63 -0
- data/build_all +58 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +142 -0
- data/ext/nokogiri/html_document.c +170 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +276 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +133 -0
- data/ext/nokogiri/nokogiri.h +160 -0
- data/ext/nokogiri/xml_attr.c +94 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +56 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +54 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +576 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +56 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +78 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1480 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +467 -0
- data/ext/nokogiri/xml_node_set.h +14 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +684 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +161 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +293 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +222 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +115 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +58 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +319 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +270 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/css.rb +27 -0
- data/lib/nokogiri/css/node.rb +102 -0
- data/lib/nokogiri/css/parser.rb +720 -0
- data/lib/nokogiri/css/parser.y +258 -0
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +152 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +171 -0
- data/lib/nokogiri/decorators/slop.rb +35 -0
- data/lib/nokogiri/html.rb +37 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +254 -0
- data/lib/nokogiri/html/document_fragment.rb +41 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +52 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/html/sax/push_parser.rb +16 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +88 -0
- data/lib/nokogiri/xml.rb +73 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +431 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +267 -0
- data/lib/nokogiri/xml/document_fragment.rb +103 -0
- data/lib/nokogiri/xml/dtd.rb +22 -0
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +946 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node_set.rb +357 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +98 -0
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +112 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +4 -0
- data/lib/nokogiri/xml/sax/document.rb +164 -0
- data/lib/nokogiri/xml/sax/parser.rb +115 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/syntax_error.rb +47 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +56 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +90 -0
- data/tasks/cross_compile.rb +153 -0
- data/tasks/nokogiri.org.rb +24 -0
- data/tasks/test.rb +95 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +341 -0
- data/test/css/test_tokenizer.rb +198 -0
- data/test/css/test_xpath_visitor.rb +91 -0
- data/test/decorators/test_slop.rb +16 -0
- data/test/files/2ch.html +108 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/files/to_be_xincluded.xml +2 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/files/xinclude.xml +4 -0
- data/test/helper.rb +147 -0
- data/test/html/sax/test_parser.rb +138 -0
- data/test/html/sax/test_parser_context.rb +46 -0
- data/test/html/test_builder.rb +164 -0
- data/test/html/test_document.rb +529 -0
- data/test/html/test_document_encoding.rb +138 -0
- data/test/html/test_document_fragment.rb +254 -0
- data/test/html/test_element_description.rb +100 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +188 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +135 -0
- data/test/test_css_cache.rb +45 -0
- data/test/test_encoding_handler.rb +46 -0
- data/test/test_memory_leak.rb +152 -0
- data/test/test_nokogiri.rb +132 -0
- data/test/test_reader.rb +488 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +254 -0
- data/test/xml/node/test_save_options.rb +28 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +338 -0
- data/test/xml/sax/test_parser_context.rb +106 -0
- data/test/xml/sax/test_push_parser.rb +157 -0
- data/test/xml/test_attr.rb +64 -0
- data/test/xml/test_attribute_decl.rb +86 -0
- data/test/xml/test_builder.rb +248 -0
- data/test/xml/test_c14n.rb +151 -0
- data/test/xml/test_cdata.rb +48 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +742 -0
- data/test/xml/test_document_encoding.rb +28 -0
- data/test/xml/test_document_fragment.rb +216 -0
- data/test/xml/test_dtd.rb +103 -0
- data/test/xml/test_dtd_encoding.rb +33 -0
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +122 -0
- data/test/xml/test_entity_reference.rb +235 -0
- data/test/xml/test_namespace.rb +75 -0
- data/test/xml/test_node.rb +1029 -0
- data/test/xml/test_node_attributes.rb +53 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_inheritance.rb +32 -0
- data/test/xml/test_node_reparenting.rb +374 -0
- data/test/xml/test_node_set.rb +755 -0
- data/test/xml/test_parse_options.rb +64 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +142 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +94 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +45 -0
- data/test/xml/test_unparented_node.rb +413 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +295 -0
- data/test/xslt/test_custom_functions.rb +129 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- data/test_all +84 -0
- metadata +534 -0
@@ -0,0 +1,258 @@
|
|
1
|
+
class Nokogiri::CSS::Parser
|
2
|
+
|
3
|
+
token FUNCTION INCLUDES DASHMATCH LBRACE HASH PLUS GREATER S STRING IDENT
|
4
|
+
token COMMA NUMBER PREFIXMATCH SUFFIXMATCH SUBSTRINGMATCH TILDE NOT_EQUAL
|
5
|
+
token SLASH DOUBLESLASH NOT EQUAL RPAREN LSQUARE RSQUARE HAS
|
6
|
+
|
7
|
+
rule
|
8
|
+
selector
|
9
|
+
: selector COMMA simple_selector_1toN {
|
10
|
+
result = [val.first, val.last].flatten
|
11
|
+
}
|
12
|
+
| prefixless_combinator_selector { result = val.flatten }
|
13
|
+
| simple_selector_1toN { result = val.flatten }
|
14
|
+
;
|
15
|
+
combinator
|
16
|
+
: PLUS { result = :DIRECT_ADJACENT_SELECTOR }
|
17
|
+
| GREATER { result = :CHILD_SELECTOR }
|
18
|
+
| TILDE { result = :FOLLOWING_SELECTOR }
|
19
|
+
| S { result = :DESCENDANT_SELECTOR }
|
20
|
+
| DOUBLESLASH { result = :DESCENDANT_SELECTOR }
|
21
|
+
| SLASH { result = :CHILD_SELECTOR }
|
22
|
+
;
|
23
|
+
simple_selector
|
24
|
+
: element_name hcap_0toN {
|
25
|
+
result = if val[1].nil?
|
26
|
+
val.first
|
27
|
+
else
|
28
|
+
Node.new(:CONDITIONAL_SELECTOR, [val.first, val[1]])
|
29
|
+
end
|
30
|
+
}
|
31
|
+
| element_name hcap_1toN negation {
|
32
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
33
|
+
[
|
34
|
+
val.first,
|
35
|
+
Node.new(:COMBINATOR, [val[1], val.last])
|
36
|
+
]
|
37
|
+
)
|
38
|
+
}
|
39
|
+
| element_name negation {
|
40
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
41
|
+
}
|
42
|
+
| function
|
43
|
+
| function pseudo {
|
44
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
45
|
+
}
|
46
|
+
| function attrib {
|
47
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
48
|
+
}
|
49
|
+
| hcap_1toN negation {
|
50
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
51
|
+
[
|
52
|
+
Node.new(:ELEMENT_NAME, ['*']),
|
53
|
+
Node.new(:COMBINATOR, val)
|
54
|
+
]
|
55
|
+
)
|
56
|
+
}
|
57
|
+
| hcap_1toN {
|
58
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
59
|
+
[Node.new(:ELEMENT_NAME, ['*']), val.first]
|
60
|
+
)
|
61
|
+
}
|
62
|
+
;
|
63
|
+
prefixless_combinator_selector
|
64
|
+
: combinator simple_selector_1toN {
|
65
|
+
result = Node.new(val.first, [nil, val.last])
|
66
|
+
}
|
67
|
+
;
|
68
|
+
simple_selector_1toN
|
69
|
+
: simple_selector combinator simple_selector_1toN {
|
70
|
+
result = Node.new(val[1], [val.first, val.last])
|
71
|
+
}
|
72
|
+
| simple_selector
|
73
|
+
;
|
74
|
+
class
|
75
|
+
: '.' IDENT { result = Node.new(:CLASS_CONDITION, [val[1]]) }
|
76
|
+
;
|
77
|
+
element_name
|
78
|
+
: namespaced_ident
|
79
|
+
| '*' { result = Node.new(:ELEMENT_NAME, val) }
|
80
|
+
;
|
81
|
+
namespaced_ident
|
82
|
+
: namespace '|' IDENT {
|
83
|
+
result = Node.new(:ELEMENT_NAME,
|
84
|
+
[[val.first, val.last].compact.join(':')]
|
85
|
+
)
|
86
|
+
}
|
87
|
+
| IDENT {
|
88
|
+
name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
|
89
|
+
result = Node.new(:ELEMENT_NAME, [name])
|
90
|
+
}
|
91
|
+
;
|
92
|
+
namespace
|
93
|
+
: IDENT { result = val[0] }
|
94
|
+
|
|
95
|
+
;
|
96
|
+
attrib
|
97
|
+
: LSQUARE attrib_name attrib_val_0or1 RSQUARE {
|
98
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
99
|
+
[val[1]] + (val[2] || [])
|
100
|
+
)
|
101
|
+
}
|
102
|
+
| LSQUARE function attrib_val_0or1 RSQUARE {
|
103
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
104
|
+
[val[1]] + (val[2] || [])
|
105
|
+
)
|
106
|
+
}
|
107
|
+
| LSQUARE NUMBER RSQUARE {
|
108
|
+
# Non standard, but hpricot supports it.
|
109
|
+
result = Node.new(:PSEUDO_CLASS,
|
110
|
+
[Node.new(:FUNCTION, ['nth-child(', val[1]])]
|
111
|
+
)
|
112
|
+
}
|
113
|
+
;
|
114
|
+
attrib_name
|
115
|
+
: namespace '|' IDENT {
|
116
|
+
result = Node.new(:ELEMENT_NAME,
|
117
|
+
[[val.first, val.last].compact.join(':')]
|
118
|
+
)
|
119
|
+
}
|
120
|
+
| IDENT {
|
121
|
+
# Default namespace is not applied to attributes.
|
122
|
+
# So we don't add prefix "xmlns:" as in namespaced_ident.
|
123
|
+
result = Node.new(:ELEMENT_NAME, [val.first])
|
124
|
+
}
|
125
|
+
;
|
126
|
+
function
|
127
|
+
: FUNCTION RPAREN {
|
128
|
+
result = Node.new(:FUNCTION, [val.first.strip])
|
129
|
+
}
|
130
|
+
| FUNCTION expr RPAREN {
|
131
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
132
|
+
}
|
133
|
+
| FUNCTION an_plus_b RPAREN {
|
134
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
135
|
+
}
|
136
|
+
| NOT expr RPAREN {
|
137
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
138
|
+
}
|
139
|
+
| HAS selector RPAREN {
|
140
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
141
|
+
}
|
142
|
+
;
|
143
|
+
expr
|
144
|
+
: NUMBER COMMA expr { result = [val.first, val.last] }
|
145
|
+
| STRING COMMA expr { result = [val.first, val.last] }
|
146
|
+
| IDENT COMMA expr { result = [val.first, val.last] }
|
147
|
+
| NUMBER
|
148
|
+
| STRING
|
149
|
+
| IDENT # even, odd
|
150
|
+
{
|
151
|
+
if val[0] == 'even'
|
152
|
+
val = ["2","n","+","0"]
|
153
|
+
result = Node.new(:AN_PLUS_B, val)
|
154
|
+
elsif val[0] == 'odd'
|
155
|
+
val = ["2","n","+","1"]
|
156
|
+
result = Node.new(:AN_PLUS_B, val)
|
157
|
+
else
|
158
|
+
# This is not CSS standard. It allows us to support this:
|
159
|
+
# assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
|
160
|
+
# assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
|
161
|
+
# assert_xpath("//a[foo(., a, 10)]", @parser.parse('a:foo(a, 10)'))
|
162
|
+
result = val
|
163
|
+
end
|
164
|
+
}
|
165
|
+
;
|
166
|
+
an_plus_b
|
167
|
+
: NUMBER IDENT PLUS NUMBER # 5n+3 -5n+3
|
168
|
+
{
|
169
|
+
if val[1] == 'n'
|
170
|
+
result = Node.new(:AN_PLUS_B, val)
|
171
|
+
else
|
172
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
173
|
+
end
|
174
|
+
}
|
175
|
+
| IDENT PLUS NUMBER { # n+3, -n+3
|
176
|
+
if val[0] == 'n'
|
177
|
+
val.unshift("1")
|
178
|
+
result = Node.new(:AN_PLUS_B, val)
|
179
|
+
elsif val[0] == '-n'
|
180
|
+
val[0] = 'n'
|
181
|
+
val.unshift("-1")
|
182
|
+
result = Node.new(:AN_PLUS_B, val)
|
183
|
+
else
|
184
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
185
|
+
end
|
186
|
+
}
|
187
|
+
| NUMBER IDENT # 5n, -5n
|
188
|
+
{
|
189
|
+
if val[1] == 'n'
|
190
|
+
val << "+"
|
191
|
+
val << "0"
|
192
|
+
result = Node.new(:AN_PLUS_B, val)
|
193
|
+
else
|
194
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
195
|
+
end
|
196
|
+
}
|
197
|
+
;
|
198
|
+
pseudo
|
199
|
+
: ':' function {
|
200
|
+
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
201
|
+
}
|
202
|
+
| ':' IDENT { result = Node.new(:PSEUDO_CLASS, [val[1]]) }
|
203
|
+
;
|
204
|
+
hcap_0toN
|
205
|
+
: hcap_1toN
|
206
|
+
|
|
207
|
+
;
|
208
|
+
hcap_1toN
|
209
|
+
: attribute_id hcap_1toN {
|
210
|
+
result = Node.new(:COMBINATOR, val)
|
211
|
+
}
|
212
|
+
| class hcap_1toN {
|
213
|
+
result = Node.new(:COMBINATOR, val)
|
214
|
+
}
|
215
|
+
| attrib hcap_1toN {
|
216
|
+
result = Node.new(:COMBINATOR, val)
|
217
|
+
}
|
218
|
+
| pseudo hcap_1toN {
|
219
|
+
result = Node.new(:COMBINATOR, val)
|
220
|
+
}
|
221
|
+
| attribute_id
|
222
|
+
| class
|
223
|
+
| attrib
|
224
|
+
| pseudo
|
225
|
+
;
|
226
|
+
attribute_id
|
227
|
+
: HASH { result = Node.new(:ID, val) }
|
228
|
+
;
|
229
|
+
attrib_val_0or1
|
230
|
+
: eql_incl_dash IDENT { result = [val.first, val[1]] }
|
231
|
+
| eql_incl_dash STRING { result = [val.first, val[1]] }
|
232
|
+
|
|
233
|
+
;
|
234
|
+
eql_incl_dash
|
235
|
+
: EQUAL { result = :equal }
|
236
|
+
| PREFIXMATCH { result = :prefix_match }
|
237
|
+
| SUFFIXMATCH { result = :suffix_match }
|
238
|
+
| SUBSTRINGMATCH { result = :substring_match }
|
239
|
+
| NOT_EQUAL { result = :not_equal }
|
240
|
+
| INCLUDES { result = :includes }
|
241
|
+
| DASHMATCH { result = :dash_match }
|
242
|
+
;
|
243
|
+
negation
|
244
|
+
: NOT negation_arg RPAREN {
|
245
|
+
result = Node.new(:NOT, [val[1]])
|
246
|
+
}
|
247
|
+
;
|
248
|
+
negation_arg
|
249
|
+
: element_name
|
250
|
+
| element_name hcap_1toN
|
251
|
+
| hcap_1toN
|
252
|
+
;
|
253
|
+
end
|
254
|
+
|
255
|
+
---- header
|
256
|
+
|
257
|
+
require 'nokogiri/css/parser_extras'
|
258
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module CSS
|
5
|
+
class Parser < Racc::Parser
|
6
|
+
@cache_on = true
|
7
|
+
@cache = {}
|
8
|
+
@mutex = Mutex.new
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# Turn on CSS parse caching
|
12
|
+
attr_accessor :cache_on
|
13
|
+
alias :cache_on? :cache_on
|
14
|
+
alias :set_cache :cache_on=
|
15
|
+
|
16
|
+
# Get the css selector in +string+ from the cache
|
17
|
+
def [] string
|
18
|
+
return unless @cache_on
|
19
|
+
@mutex.synchronize { @cache[string] }
|
20
|
+
end
|
21
|
+
|
22
|
+
# Set the css selector in +string+ in the cache to +value+
|
23
|
+
def []= string, value
|
24
|
+
return value unless @cache_on
|
25
|
+
@mutex.synchronize { @cache[string] = value }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Clear the cache
|
29
|
+
def clear_cache
|
30
|
+
@mutex.synchronize { @cache = {} }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Execute +block+ without cache
|
34
|
+
def without_cache &block
|
35
|
+
tmp = @cache_on
|
36
|
+
@cache_on = false
|
37
|
+
block.call
|
38
|
+
@cache_on = tmp
|
39
|
+
end
|
40
|
+
|
41
|
+
###
|
42
|
+
# Parse this CSS selector in +selector+. Returns an AST.
|
43
|
+
def parse selector
|
44
|
+
@warned ||= false
|
45
|
+
unless @warned
|
46
|
+
$stderr.puts('Nokogiri::CSS::Parser.parse is deprecated, call Nokogiri::CSS.parse(), this will be removed August 1st or version 1.4.0 (whichever is first)')
|
47
|
+
@warned = true
|
48
|
+
end
|
49
|
+
new.parse selector
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Create a new CSS parser with respect to +namespaces+
|
54
|
+
def initialize namespaces = {}
|
55
|
+
@tokenizer = Tokenizer.new
|
56
|
+
@namespaces = namespaces
|
57
|
+
super()
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse string
|
61
|
+
@tokenizer.scan_setup string
|
62
|
+
do_parse
|
63
|
+
end
|
64
|
+
|
65
|
+
def next_token
|
66
|
+
@tokenizer.next_token
|
67
|
+
end
|
68
|
+
|
69
|
+
# Get the xpath for +string+ using +options+
|
70
|
+
def xpath_for string, options={}
|
71
|
+
key = "#{string}#{options[:ns]}#{options[:prefix]}"
|
72
|
+
v = self.class[key]
|
73
|
+
return v if v
|
74
|
+
|
75
|
+
args = [
|
76
|
+
options[:prefix] || '//',
|
77
|
+
options[:visitor] || XPathVisitor.new
|
78
|
+
]
|
79
|
+
self.class[key] = parse(string).map { |ast|
|
80
|
+
ast.to_xpath(*args)
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
# On CSS parser error, raise an exception
|
85
|
+
def on_error error_token_id, error_value, value_stack
|
86
|
+
after = value_stack.compact.last
|
87
|
+
raise SyntaxError.new("unexpected '#{error_value}' after '#{after}'")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
#--
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by rex 1.0.5
|
4
|
+
# from lexical definition file "lib/nokogiri/css/tokenizer.rex".
|
5
|
+
#++
|
6
|
+
|
7
|
+
module Nokogiri
|
8
|
+
module CSS
|
9
|
+
class Tokenizer # :nodoc:
|
10
|
+
require 'strscan'
|
11
|
+
|
12
|
+
class ScanError < StandardError ; end
|
13
|
+
|
14
|
+
attr_reader :lineno
|
15
|
+
attr_reader :filename
|
16
|
+
attr_accessor :state
|
17
|
+
|
18
|
+
def scan_setup(str)
|
19
|
+
@ss = StringScanner.new(str)
|
20
|
+
@lineno = 1
|
21
|
+
@state = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def action
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
|
28
|
+
def scan_str(str)
|
29
|
+
scan_setup(str)
|
30
|
+
do_parse
|
31
|
+
end
|
32
|
+
alias :scan :scan_str
|
33
|
+
|
34
|
+
def load_file( filename )
|
35
|
+
@filename = filename
|
36
|
+
open(filename, "r") do |f|
|
37
|
+
scan_setup(f.read)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def scan_file( filename )
|
42
|
+
load_file(filename)
|
43
|
+
do_parse
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def next_token
|
48
|
+
return if @ss.eos?
|
49
|
+
|
50
|
+
# skips empty actions
|
51
|
+
until token = _next_token or @ss.eos?; end
|
52
|
+
token
|
53
|
+
end
|
54
|
+
|
55
|
+
def _next_token
|
56
|
+
text = @ss.peek(1)
|
57
|
+
@lineno += 1 if text == "\n"
|
58
|
+
token = case @state
|
59
|
+
when nil
|
60
|
+
case
|
61
|
+
when (text = @ss.scan(/has\([\s]*/))
|
62
|
+
action { [:HAS, text] }
|
63
|
+
|
64
|
+
when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*\([\s]*/))
|
65
|
+
action { [:FUNCTION, text] }
|
66
|
+
|
67
|
+
when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*/))
|
68
|
+
action { [:IDENT, text] }
|
69
|
+
|
70
|
+
when (text = @ss.scan(/\#([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/))
|
71
|
+
action { [:HASH, text] }
|
72
|
+
|
73
|
+
when (text = @ss.scan(/[\s]*~=[\s]*/))
|
74
|
+
action { [:INCLUDES, text] }
|
75
|
+
|
76
|
+
when (text = @ss.scan(/[\s]*\|=[\s]*/))
|
77
|
+
action { [:DASHMATCH, text] }
|
78
|
+
|
79
|
+
when (text = @ss.scan(/[\s]*\^=[\s]*/))
|
80
|
+
action { [:PREFIXMATCH, text] }
|
81
|
+
|
82
|
+
when (text = @ss.scan(/[\s]*\$=[\s]*/))
|
83
|
+
action { [:SUFFIXMATCH, text] }
|
84
|
+
|
85
|
+
when (text = @ss.scan(/[\s]*\*=[\s]*/))
|
86
|
+
action { [:SUBSTRINGMATCH, text] }
|
87
|
+
|
88
|
+
when (text = @ss.scan(/[\s]*!=[\s]*/))
|
89
|
+
action { [:NOT_EQUAL, text] }
|
90
|
+
|
91
|
+
when (text = @ss.scan(/[\s]*=[\s]*/))
|
92
|
+
action { [:EQUAL, text] }
|
93
|
+
|
94
|
+
when (text = @ss.scan(/[\s]*\)/))
|
95
|
+
action { [:RPAREN, text] }
|
96
|
+
|
97
|
+
when (text = @ss.scan(/[\s]*\[[\s]*/))
|
98
|
+
action { [:LSQUARE, text] }
|
99
|
+
|
100
|
+
when (text = @ss.scan(/[\s]*\]/))
|
101
|
+
action { [:RSQUARE, text] }
|
102
|
+
|
103
|
+
when (text = @ss.scan(/[\s]*\+[\s]*/))
|
104
|
+
action { [:PLUS, text] }
|
105
|
+
|
106
|
+
when (text = @ss.scan(/[\s]*>[\s]*/))
|
107
|
+
action { [:GREATER, text] }
|
108
|
+
|
109
|
+
when (text = @ss.scan(/[\s]*,[\s]*/))
|
110
|
+
action { [:COMMA, text] }
|
111
|
+
|
112
|
+
when (text = @ss.scan(/[\s]*~[\s]*/))
|
113
|
+
action { [:TILDE, text] }
|
114
|
+
|
115
|
+
when (text = @ss.scan(/\:not\([\s]*/))
|
116
|
+
action { [:NOT, text] }
|
117
|
+
|
118
|
+
when (text = @ss.scan(/-?([0-9]+|[0-9]*\.[0-9]+)/))
|
119
|
+
action { [:NUMBER, text] }
|
120
|
+
|
121
|
+
when (text = @ss.scan(/[\s]*\/\/[\s]*/))
|
122
|
+
action { [:DOUBLESLASH, text] }
|
123
|
+
|
124
|
+
when (text = @ss.scan(/[\s]*\/[\s]*/))
|
125
|
+
action { [:SLASH, text] }
|
126
|
+
|
127
|
+
when (text = @ss.scan(/U\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?/))
|
128
|
+
action {[:UNICODE_RANGE, text] }
|
129
|
+
|
130
|
+
when (text = @ss.scan(/[\s]+/))
|
131
|
+
action { [:S, text] }
|
132
|
+
|
133
|
+
when (text = @ss.scan(/"([^\n\r\f"]|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*"|'([^\n\r\f']|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*'/))
|
134
|
+
action { [:STRING, text] }
|
135
|
+
|
136
|
+
when (text = @ss.scan(/./))
|
137
|
+
action { [text, text] }
|
138
|
+
|
139
|
+
else
|
140
|
+
text = @ss.string[@ss.pos .. -1]
|
141
|
+
raise ScanError, "can not match: '" + text + "'"
|
142
|
+
end # if
|
143
|
+
|
144
|
+
else
|
145
|
+
raise ScanError, "undefined state: '" + state.to_s + "'"
|
146
|
+
end # case state
|
147
|
+
token
|
148
|
+
end # def _next_token
|
149
|
+
|
150
|
+
end # class
|
151
|
+
end
|
152
|
+
end
|