nokogiri 1.6.2.rc1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.autotest +26 -0
- data/.editorconfig +17 -0
- data/.gemtest +0 -0
- data/.travis.yml +25 -0
- data/CHANGELOG.ja.rdoc +857 -0
- data/CHANGELOG.rdoc +880 -0
- data/C_CODING_STYLE.rdoc +33 -0
- data/Gemfile +21 -0
- data/Manifest.txt +371 -0
- data/README.ja.rdoc +112 -0
- data/README.rdoc +180 -0
- data/ROADMAP.md +89 -0
- data/Rakefile +351 -0
- data/STANDARD_RESPONSES.md +47 -0
- data/Y_U_NO_GEMSPEC.md +155 -0
- data/bin/nokogiri +78 -0
- data/build_all +130 -0
- data/dependencies.yml +4 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +453 -0
- data/ext/nokogiri/html_document.c +170 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -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 +148 -0
- data/ext/nokogiri/nokogiri.h +164 -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 +577 -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 +1541 -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 +681 -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 +312 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -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 +63 -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 +307 -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 +137 -0
- data/lib/nokogiri/2.0/nokogiri.so +0 -0
- data/lib/nokogiri/2.1/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +27 -0
- data/lib/nokogiri/css/node.rb +52 -0
- data/lib/nokogiri/css/parser.rb +715 -0
- data/lib/nokogiri/css/parser.y +249 -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 +219 -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 +333 -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 +106 -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 +443 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +279 -0
- data/lib/nokogiri/xml/document_fragment.rb +112 -0
- data/lib/nokogiri/xml/dtd.rb +32 -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 +982 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node_set.rb +355 -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 +171 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -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 +102 -0
- data/suppressions/README.txt +1 -0
- data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
- data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
- data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
- data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
- data/tasks/nokogiri.org.rb +24 -0
- data/tasks/test.rb +95 -0
- data/test/css/test_nthiness.rb +222 -0
- data/test/css/test_parser.rb +358 -0
- data/test/css/test_tokenizer.rb +198 -0
- data/test/css/test_xpath_visitor.rb +96 -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/atom.xml +344 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/bogus.xml +0 -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/saml/saml20assertion_schema.xsd +283 -0
- data/test/files/saml/saml20protocol_schema.xsd +302 -0
- data/test/files/saml/xenc_schema.xsd +146 -0
- data/test/files/saml/xmldsig_schema.xsd +318 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/shift_jis_no_charset.html +9 -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/test_document_url/bar.xml +2 -0
- data/test/files/test_document_url/document.dtd +4 -0
- data/test/files/test_document_url/document.xml +6 -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 +164 -0
- data/test/html/sax/test_parser.rb +141 -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 +619 -0
- data/test/html/test_document_encoding.rb +148 -0
- data/test/html/test_document_fragment.rb +261 -0
- data/test/html/test_element_description.rb +105 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +196 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
- data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
- data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +66 -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 +156 -0
- data/test/test_nokogiri.rb +138 -0
- data/test/test_reader.rb +558 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +279 -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 +382 -0
- data/test/xml/sax/test_parser_context.rb +115 -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 +315 -0
- data/test/xml/test_c14n.rb +161 -0
- data/test/xml/test_cdata.rb +48 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +934 -0
- data/test/xml/test_document_encoding.rb +28 -0
- data/test/xml/test_document_fragment.rb +228 -0
- data/test/xml/test_dtd.rb +187 -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 +245 -0
- data/test/xml/test_namespace.rb +95 -0
- data/test/xml/test_node.rb +1155 -0
- data/test/xml/test_node_attributes.rb +113 -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 +129 -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 +422 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +376 -0
- data/test/xslt/test_custom_functions.rb +133 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- data/test_all +81 -0
- metadata +601 -0
@@ -0,0 +1,249 @@
|
|
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
|
+
| function
|
32
|
+
| function pseudo {
|
33
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
34
|
+
}
|
35
|
+
| function attrib {
|
36
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
37
|
+
}
|
38
|
+
| hcap_1toN {
|
39
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
40
|
+
[Node.new(:ELEMENT_NAME, ['*']), val.first]
|
41
|
+
)
|
42
|
+
}
|
43
|
+
;
|
44
|
+
prefixless_combinator_selector
|
45
|
+
: combinator simple_selector_1toN {
|
46
|
+
result = Node.new(val.first, [nil, val.last])
|
47
|
+
}
|
48
|
+
;
|
49
|
+
simple_selector_1toN
|
50
|
+
: simple_selector combinator simple_selector_1toN {
|
51
|
+
result = Node.new(val[1], [val.first, val.last])
|
52
|
+
}
|
53
|
+
| simple_selector
|
54
|
+
;
|
55
|
+
class
|
56
|
+
: '.' IDENT { result = Node.new(:CLASS_CONDITION, [val[1]]) }
|
57
|
+
;
|
58
|
+
element_name
|
59
|
+
: namespaced_ident
|
60
|
+
| '*' { result = Node.new(:ELEMENT_NAME, val) }
|
61
|
+
;
|
62
|
+
namespaced_ident
|
63
|
+
: namespace '|' IDENT {
|
64
|
+
result = Node.new(:ELEMENT_NAME,
|
65
|
+
[[val.first, val.last].compact.join(':')]
|
66
|
+
)
|
67
|
+
}
|
68
|
+
| IDENT {
|
69
|
+
name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
|
70
|
+
result = Node.new(:ELEMENT_NAME, [name])
|
71
|
+
}
|
72
|
+
;
|
73
|
+
namespace
|
74
|
+
: IDENT { result = val[0] }
|
75
|
+
|
|
76
|
+
;
|
77
|
+
attrib
|
78
|
+
: LSQUARE attrib_name attrib_val_0or1 RSQUARE {
|
79
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
80
|
+
[val[1]] + (val[2] || [])
|
81
|
+
)
|
82
|
+
}
|
83
|
+
| LSQUARE function attrib_val_0or1 RSQUARE {
|
84
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
85
|
+
[val[1]] + (val[2] || [])
|
86
|
+
)
|
87
|
+
}
|
88
|
+
| LSQUARE NUMBER RSQUARE {
|
89
|
+
# Non standard, but hpricot supports it.
|
90
|
+
result = Node.new(:PSEUDO_CLASS,
|
91
|
+
[Node.new(:FUNCTION, ['nth-child(', val[1]])]
|
92
|
+
)
|
93
|
+
}
|
94
|
+
;
|
95
|
+
attrib_name
|
96
|
+
: namespace '|' IDENT {
|
97
|
+
result = Node.new(:ELEMENT_NAME,
|
98
|
+
[[val.first, val.last].compact.join(':')]
|
99
|
+
)
|
100
|
+
}
|
101
|
+
| IDENT {
|
102
|
+
# Default namespace is not applied to attributes.
|
103
|
+
# So we don't add prefix "xmlns:" as in namespaced_ident.
|
104
|
+
result = Node.new(:ELEMENT_NAME, [val.first])
|
105
|
+
}
|
106
|
+
;
|
107
|
+
function
|
108
|
+
: FUNCTION RPAREN {
|
109
|
+
result = Node.new(:FUNCTION, [val.first.strip])
|
110
|
+
}
|
111
|
+
| FUNCTION expr RPAREN {
|
112
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
113
|
+
}
|
114
|
+
| FUNCTION nth RPAREN {
|
115
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
116
|
+
}
|
117
|
+
| NOT expr RPAREN {
|
118
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
119
|
+
}
|
120
|
+
| HAS selector RPAREN {
|
121
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
122
|
+
}
|
123
|
+
;
|
124
|
+
expr
|
125
|
+
: NUMBER COMMA expr { result = [val.first, val.last] }
|
126
|
+
| STRING COMMA expr { result = [val.first, val.last] }
|
127
|
+
| IDENT COMMA expr { result = [val.first, val.last] }
|
128
|
+
| NUMBER
|
129
|
+
| STRING
|
130
|
+
| IDENT # even, odd
|
131
|
+
{
|
132
|
+
if val[0] == 'even'
|
133
|
+
val = ["2","n","+","0"]
|
134
|
+
result = Node.new(:NTH, val)
|
135
|
+
elsif val[0] == 'odd'
|
136
|
+
val = ["2","n","+","1"]
|
137
|
+
result = Node.new(:NTH, val)
|
138
|
+
else
|
139
|
+
# This is not CSS standard. It allows us to support this:
|
140
|
+
# assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
|
141
|
+
# assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
|
142
|
+
# assert_xpath("//a[foo(., a, 10)]", @parser.parse('a:foo(a, 10)'))
|
143
|
+
result = val
|
144
|
+
end
|
145
|
+
}
|
146
|
+
;
|
147
|
+
nth
|
148
|
+
: NUMBER IDENT PLUS NUMBER # 5n+3 -5n+3
|
149
|
+
{
|
150
|
+
if val[1] == 'n'
|
151
|
+
result = Node.new(:NTH, val)
|
152
|
+
else
|
153
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
154
|
+
end
|
155
|
+
}
|
156
|
+
| IDENT PLUS NUMBER { # n+3, -n+3
|
157
|
+
if val[0] == 'n'
|
158
|
+
val.unshift("1")
|
159
|
+
result = Node.new(:NTH, val)
|
160
|
+
elsif val[0] == '-n'
|
161
|
+
val[0] = 'n'
|
162
|
+
val.unshift("-1")
|
163
|
+
result = Node.new(:NTH, val)
|
164
|
+
else
|
165
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
166
|
+
end
|
167
|
+
}
|
168
|
+
| NUMBER IDENT { # 5n, -5n, 10n-1
|
169
|
+
n = val[1]
|
170
|
+
if n[0, 2] == 'n-'
|
171
|
+
val[1] = 'n'
|
172
|
+
val << "-"
|
173
|
+
# b is contained in n as n is the string "n-b"
|
174
|
+
val << n[2, n.size]
|
175
|
+
result = Node.new(:NTH, val)
|
176
|
+
elsif n == 'n'
|
177
|
+
val << "+"
|
178
|
+
val << "0"
|
179
|
+
result = Node.new(:NTH, val)
|
180
|
+
else
|
181
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
182
|
+
end
|
183
|
+
}
|
184
|
+
;
|
185
|
+
pseudo
|
186
|
+
: ':' function {
|
187
|
+
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
188
|
+
}
|
189
|
+
| ':' IDENT { result = Node.new(:PSEUDO_CLASS, [val[1]]) }
|
190
|
+
;
|
191
|
+
hcap_0toN
|
192
|
+
: hcap_1toN
|
193
|
+
|
|
194
|
+
;
|
195
|
+
hcap_1toN
|
196
|
+
: attribute_id hcap_1toN {
|
197
|
+
result = Node.new(:COMBINATOR, val)
|
198
|
+
}
|
199
|
+
| class hcap_1toN {
|
200
|
+
result = Node.new(:COMBINATOR, val)
|
201
|
+
}
|
202
|
+
| attrib hcap_1toN {
|
203
|
+
result = Node.new(:COMBINATOR, val)
|
204
|
+
}
|
205
|
+
| pseudo hcap_1toN {
|
206
|
+
result = Node.new(:COMBINATOR, val)
|
207
|
+
}
|
208
|
+
| negation hcap_1toN {
|
209
|
+
result = Node.new(:COMBINATOR, val)
|
210
|
+
}
|
211
|
+
| attribute_id
|
212
|
+
| class
|
213
|
+
| attrib
|
214
|
+
| pseudo
|
215
|
+
| negation
|
216
|
+
;
|
217
|
+
attribute_id
|
218
|
+
: HASH { result = Node.new(:ID, val) }
|
219
|
+
;
|
220
|
+
attrib_val_0or1
|
221
|
+
: eql_incl_dash IDENT { result = [val.first, val[1]] }
|
222
|
+
| eql_incl_dash STRING { result = [val.first, val[1]] }
|
223
|
+
|
|
224
|
+
;
|
225
|
+
eql_incl_dash
|
226
|
+
: EQUAL { result = :equal }
|
227
|
+
| PREFIXMATCH { result = :prefix_match }
|
228
|
+
| SUFFIXMATCH { result = :suffix_match }
|
229
|
+
| SUBSTRINGMATCH { result = :substring_match }
|
230
|
+
| NOT_EQUAL { result = :not_equal }
|
231
|
+
| INCLUDES { result = :includes }
|
232
|
+
| DASHMATCH { result = :dash_match }
|
233
|
+
;
|
234
|
+
negation
|
235
|
+
: NOT negation_arg RPAREN {
|
236
|
+
result = Node.new(:NOT, [val[1]])
|
237
|
+
}
|
238
|
+
;
|
239
|
+
negation_arg
|
240
|
+
: element_name
|
241
|
+
| element_name hcap_1toN
|
242
|
+
| hcap_1toN
|
243
|
+
;
|
244
|
+
end
|
245
|
+
|
246
|
+
---- header
|
247
|
+
|
248
|
+
require 'nokogiri/css/parser_extras'
|
249
|
+
|
@@ -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
|