rubyjedi-nokogiri_java 1.4.0.20100513161003-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +26 -0
- data/CHANGELOG.ja.rdoc +330 -0
- data/CHANGELOG.rdoc +341 -0
- data/Manifest.txt +277 -0
- data/README.ja.rdoc +105 -0
- data/README.rdoc +125 -0
- data/Rakefile +307 -0
- data/bin/nokogiri +49 -0
- data/deps.rip +5 -0
- data/ext/nokogiri/extconf.rb +149 -0
- data/ext/nokogiri/html_document.c +145 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +272 -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 +92 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +96 -0
- data/ext/nokogiri/nokogiri.h +148 -0
- data/ext/nokogiri/xml_attr.c +92 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +67 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +54 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +52 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +386 -0
- data/ext/nokogiri/xml_document.h +24 -0
- data/ext/nokogiri/xml_document_fragment.c +46 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +192 -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 +97 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +31 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_namespace.c +82 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1080 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +405 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +593 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +159 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +283 -0
- data/ext/nokogiri/xml_sax_parser.h +43 -0
- data/ext/nokogiri/xml_sax_parser_context.c +157 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +114 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +156 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +52 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +239 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +131 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +123 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +659 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +145 -0
- data/lib/nokogiri/css/node.rb +99 -0
- data/lib/nokogiri/css/parser.rb +82 -0
- data/lib/nokogiri/css/parser.y +230 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +164 -0
- data/lib/nokogiri/decorators/slop.rb +33 -0
- data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
- data/lib/nokogiri/ffi/html/document.rb +28 -0
- data/lib/nokogiri/ffi/html/element_description.rb +81 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +42 -0
- data/lib/nokogiri/ffi/libxml.rb +372 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
- data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +124 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +135 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +21 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +67 -0
- data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
- data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +44 -0
- data/lib/nokogiri/ffi/xml/node.rb +465 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +146 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +227 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +85 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +135 -0
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +55 -0
- data/lib/nokogiri/ffi/xml/schema.rb +92 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +98 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +50 -0
- data/lib/nokogiri/html.rb +36 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +88 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -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 +48 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +33 -0
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +405 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +163 -0
- data/lib/nokogiri/xml/document_fragment.rb +73 -0
- data/lib/nokogiri/xml/dtd.rb +11 -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 +15 -0
- data/lib/nokogiri/xml/fragment_handler.rb +73 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +730 -0
- data/lib/nokogiri/xml/node/save_options.rb +42 -0
- data/lib/nokogiri/xml/node_set.rb +318 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +85 -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 +74 -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 +160 -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 +61 -0
- data/lib/nokogiri/xml/syntax_error.rb +43 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +48 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xsd/xmlparser/nokogiri.rb +90 -0
- data/tasks/test.rb +100 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +282 -0
- data/test/css/test_tokenizer.rb +190 -0
- data/test/css/test_xpath_visitor.rb +76 -0
- data/test/ffi/test_document.rb +35 -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/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -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/valid_bar.xml +2 -0
- data/test/helper.rb +137 -0
- data/test/html/sax/test_parser.rb +83 -0
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +164 -0
- data/test/html/test_document.rb +385 -0
- data/test/html/test_document_encoding.rb +77 -0
- data/test/html/test_document_fragment.rb +157 -0
- data/test/html/test_element_description.rb +98 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +242 -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_jruby.rb +40 -0
- data/test/test_memory_leak.rb +87 -0
- data/test/test_nokogiri.rb +140 -0
- data/test/test_reader.rb +358 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +150 -0
- data/test/xml/node/test_save_options.rb +20 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +314 -0
- data/test/xml/sax/test_parser_context.rb +63 -0
- data/test/xml/sax/test_push_parser.rb +135 -0
- data/test/xml/test_attr.rb +38 -0
- data/test/xml/test_attribute_decl.rb +90 -0
- data/test/xml/test_builder.rb +167 -0
- data/test/xml/test_cdata.rb +38 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +638 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +149 -0
- data/test/xml/test_dtd.rb +92 -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 +83 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +70 -0
- data/test/xml/test_node.rb +740 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_reparenting.rb +279 -0
- data/test/xml/test_node_set.rb +577 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +89 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +30 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +169 -0
- metadata +477 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
#include <xslt_stylesheet.h>
|
2
|
+
|
3
|
+
#include <libxslt/xsltInternals.h>
|
4
|
+
#include <libxslt/xsltutils.h>
|
5
|
+
#include <libxslt/transform.h>
|
6
|
+
#include <libexslt/exslt.h>
|
7
|
+
|
8
|
+
static void dealloc(xsltStylesheetPtr doc)
|
9
|
+
{
|
10
|
+
NOKOGIRI_DEBUG_START(doc);
|
11
|
+
xsltFreeStylesheet(doc); // commented out for now.
|
12
|
+
NOKOGIRI_DEBUG_END(doc);
|
13
|
+
}
|
14
|
+
|
15
|
+
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
16
|
+
{
|
17
|
+
char * message;
|
18
|
+
|
19
|
+
va_list args;
|
20
|
+
va_start(args, msg);
|
21
|
+
vasprintf(&message, msg, args);
|
22
|
+
va_end(args);
|
23
|
+
|
24
|
+
rb_raise(rb_eRuntimeError, message);
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* call-seq:
|
29
|
+
* parse_stylesheet_doc(document)
|
30
|
+
*
|
31
|
+
* Parse a stylesheet from +document+.
|
32
|
+
*/
|
33
|
+
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
34
|
+
{
|
35
|
+
xmlDocPtr xml ;
|
36
|
+
xsltStylesheetPtr ss ;
|
37
|
+
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
38
|
+
exsltRegisterAll();
|
39
|
+
|
40
|
+
xsltSetGenericErrorFunc(NULL, xslt_generic_error_handler);
|
41
|
+
|
42
|
+
ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */
|
43
|
+
|
44
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
45
|
+
|
46
|
+
return Data_Wrap_Struct(klass, NULL, dealloc, ss);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/*
|
51
|
+
* call-seq:
|
52
|
+
* serialize(document)
|
53
|
+
*
|
54
|
+
* Serialize +document+ to an xml string.
|
55
|
+
*/
|
56
|
+
static VALUE serialize(VALUE self, VALUE xmlobj)
|
57
|
+
{
|
58
|
+
xmlDocPtr xml ;
|
59
|
+
xsltStylesheetPtr ss ;
|
60
|
+
xmlChar* doc_ptr ;
|
61
|
+
int doc_len ;
|
62
|
+
VALUE rval ;
|
63
|
+
|
64
|
+
Data_Get_Struct(xmlobj, xmlDoc, xml);
|
65
|
+
Data_Get_Struct(self, xsltStylesheet, ss);
|
66
|
+
xsltSaveResultToString(&doc_ptr, &doc_len, xml, ss);
|
67
|
+
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
|
68
|
+
xmlFree(doc_ptr);
|
69
|
+
return rval ;
|
70
|
+
}
|
71
|
+
|
72
|
+
/*
|
73
|
+
* call-seq:
|
74
|
+
* transform(document, params = [])
|
75
|
+
*
|
76
|
+
* Apply an XSLT stylesheet to an XML::Document.
|
77
|
+
* +params+ is an array of strings used as XSLT parameters.
|
78
|
+
* returns Nokogiri::XML::Document
|
79
|
+
*
|
80
|
+
* Example:
|
81
|
+
*
|
82
|
+
* doc = Nokogiri::XML(File.read(ARGV[0]))
|
83
|
+
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
|
84
|
+
* puts xslt.transform(doc, ['key', 'value'])
|
85
|
+
*
|
86
|
+
*/
|
87
|
+
static VALUE transform(int argc, VALUE* argv, VALUE self)
|
88
|
+
{
|
89
|
+
VALUE xmldoc, paramobj ;
|
90
|
+
xmlDocPtr xml ;
|
91
|
+
xmlDocPtr result ;
|
92
|
+
xsltStylesheetPtr ss ;
|
93
|
+
const char** params ;
|
94
|
+
int param_len, j ;
|
95
|
+
|
96
|
+
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
|
97
|
+
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0) ; }
|
98
|
+
|
99
|
+
Data_Get_Struct(xmldoc, xmlDoc, xml);
|
100
|
+
Data_Get_Struct(self, xsltStylesheet, ss);
|
101
|
+
|
102
|
+
param_len = RARRAY_LEN(paramobj);
|
103
|
+
params = calloc((size_t)param_len+1, sizeof(char*));
|
104
|
+
for (j = 0 ; j < param_len ; j++) {
|
105
|
+
VALUE entry = rb_ary_entry(paramobj, j);
|
106
|
+
const char * ptr = StringValuePtr(entry);
|
107
|
+
params[j] = ptr;
|
108
|
+
}
|
109
|
+
params[param_len] = 0 ;
|
110
|
+
|
111
|
+
result = xsltApplyStylesheet(ss, xml, params);
|
112
|
+
free(params);
|
113
|
+
|
114
|
+
if (!result) rb_raise(rb_eRuntimeError, "could not perform xslt transform on document");
|
115
|
+
|
116
|
+
return Nokogiri_wrap_xml_document(0, result) ;
|
117
|
+
}
|
118
|
+
|
119
|
+
VALUE cNokogiriXsltStylesheet ;
|
120
|
+
void init_xslt_stylesheet()
|
121
|
+
{
|
122
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
123
|
+
VALUE xslt = rb_define_module_under(nokogiri, "XSLT");
|
124
|
+
VALUE klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
|
125
|
+
|
126
|
+
cNokogiriXsltStylesheet = klass;
|
127
|
+
|
128
|
+
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
129
|
+
rb_define_method(klass, "serialize", serialize, 1);
|
130
|
+
rb_define_method(klass, "transform", transform, -1);
|
131
|
+
}
|
data/lib/isorelax.jar
ADDED
Binary file
|
data/lib/jing.jar
ADDED
Binary file
|
data/lib/nekodtd.jar
ADDED
Binary file
|
data/lib/nekohtml.jar
ADDED
Binary file
|
data/lib/nokogiri.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Modify the PATH on windows so that the external DLLs will get loaded.
|
3
|
+
|
4
|
+
require 'rbconfig'
|
5
|
+
ENV['PATH'] = [File.expand_path(
|
6
|
+
File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
|
7
|
+
), ENV['PATH']].compact.join(';') if RbConfig::CONFIG['host_os'] =~ /(mswin|mingw)/i
|
8
|
+
|
9
|
+
if ENV['NOKOGIRI_FFI']
|
10
|
+
require 'ffi'
|
11
|
+
require 'nokogiri/ffi/libxml'
|
12
|
+
elsif defined? RUBY_ENGINE && RUBY_ENGINE == "jruby"
|
13
|
+
require 'isorelax.jar'
|
14
|
+
require 'jing.jar'
|
15
|
+
require 'nekohtml.jar'
|
16
|
+
require 'nekodtd.jar'
|
17
|
+
require 'xercesImpl.jar'
|
18
|
+
require 'nokogiri/nokogiri'
|
19
|
+
else
|
20
|
+
require 'nokogiri/nokogiri'
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'nokogiri/version'
|
24
|
+
require 'nokogiri/version_warning'
|
25
|
+
require 'nokogiri/syntax_error'
|
26
|
+
require 'nokogiri/xml'
|
27
|
+
require 'nokogiri/xslt'
|
28
|
+
require 'nokogiri/html'
|
29
|
+
require 'nokogiri/decorators/slop'
|
30
|
+
require 'nokogiri/css'
|
31
|
+
require 'nokogiri/html/builder'
|
32
|
+
|
33
|
+
# Nokogiri parses and searches XML/HTML very quickly, and also has
|
34
|
+
# correctly implemented CSS3 selector support as well as XPath support.
|
35
|
+
#
|
36
|
+
# Parsing a document returns either a Nokogiri::XML::Document, or a
|
37
|
+
# Nokogiri::HTML::Document depending on the kind of document you parse.
|
38
|
+
#
|
39
|
+
# Here is an example:
|
40
|
+
#
|
41
|
+
# require 'nokogiri'
|
42
|
+
# require 'open-uri'
|
43
|
+
#
|
44
|
+
# # Get a Nokogiri::HTML:Document for the page we’re interested in...
|
45
|
+
#
|
46
|
+
# doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
|
47
|
+
#
|
48
|
+
# # Do funky things with it using Nokogiri::XML::Node methods...
|
49
|
+
#
|
50
|
+
# ####
|
51
|
+
# # Search for nodes by css
|
52
|
+
# doc.css('h3.r a.l').each do |link|
|
53
|
+
# puts link.content
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# See Nokogiri::XML::Node#css for more information about CSS searching.
|
57
|
+
# See Nokogiri::XML::Node#xpath for more information about XPath searching.
|
58
|
+
module Nokogiri
|
59
|
+
class << self
|
60
|
+
###
|
61
|
+
# Parse an HTML or XML document. +string+ contains the document.
|
62
|
+
def parse string, url = nil, encoding = nil, options = nil
|
63
|
+
doc =
|
64
|
+
if string.respond_to?(:read) ||
|
65
|
+
string =~ /^\s*<[^Hh>]*html/i # Probably html
|
66
|
+
Nokogiri::HTML(
|
67
|
+
string,
|
68
|
+
url,
|
69
|
+
encoding, options || XML::ParseOptions::DEFAULT_HTML
|
70
|
+
)
|
71
|
+
else
|
72
|
+
Nokogiri::XML(string, url, encoding,
|
73
|
+
options || XML::ParseOptions::DEFAULT_XML)
|
74
|
+
end
|
75
|
+
yield doc if block_given?
|
76
|
+
doc
|
77
|
+
end
|
78
|
+
|
79
|
+
###
|
80
|
+
# Create a new Nokogiri::XML::DocumentFragment
|
81
|
+
def make input = nil, opts = {}, &blk
|
82
|
+
if input
|
83
|
+
Nokogiri::HTML.fragment(input).children.first
|
84
|
+
else
|
85
|
+
Nokogiri(&blk)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
###
|
90
|
+
# Parse a document and add the Slop decorator. The Slop decorator
|
91
|
+
# implements method_missing such that methods may be used instead of CSS
|
92
|
+
# or XPath. For example:
|
93
|
+
#
|
94
|
+
# doc = Nokogiri::Slop(<<-eohtml)
|
95
|
+
# <html>
|
96
|
+
# <body>
|
97
|
+
# <p>first</p>
|
98
|
+
# <p>second</p>
|
99
|
+
# </body>
|
100
|
+
# </html>
|
101
|
+
# eohtml
|
102
|
+
# assert_equal('second', doc.html.body.p[1].text)
|
103
|
+
#
|
104
|
+
def Slop(*args, &block)
|
105
|
+
Nokogiri(*args, &block).slop!
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
###
|
111
|
+
# Parser a document contained in +args+. Nokogiri will try to guess what
|
112
|
+
# type of document you are attempting to parse. For more information, see
|
113
|
+
# Nokogiri.parse
|
114
|
+
#
|
115
|
+
# To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
|
116
|
+
def Nokogiri(*args, &block)
|
117
|
+
if block_given?
|
118
|
+
builder = Nokogiri::HTML::Builder.new(&block)
|
119
|
+
return builder.doc.root
|
120
|
+
else
|
121
|
+
Nokogiri.parse(*args)
|
122
|
+
end
|
123
|
+
end
|
data/lib/nokogiri/css.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri/css/node'
|
2
|
+
require 'nokogiri/css/xpath_visitor'
|
3
|
+
require 'nokogiri/css/generated_parser'
|
4
|
+
require 'nokogiri/css/generated_tokenizer'
|
5
|
+
require 'nokogiri/css/tokenizer'
|
6
|
+
require 'nokogiri/css/parser'
|
7
|
+
require 'nokogiri/css/syntax_error'
|
8
|
+
|
9
|
+
module Nokogiri
|
10
|
+
module CSS
|
11
|
+
class << self
|
12
|
+
###
|
13
|
+
# Parse this CSS selector in +selector+. Returns an AST.
|
14
|
+
def parse selector
|
15
|
+
Parser.new.parse selector
|
16
|
+
end
|
17
|
+
|
18
|
+
###
|
19
|
+
# Get the XPath for +selector+.
|
20
|
+
def xpath_for selector, options={}
|
21
|
+
Parser.new(options[:ns] || {}).xpath_for selector, options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,659 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.6
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
|
10
|
+
module Nokogiri
|
11
|
+
module CSS
|
12
|
+
class GeneratedParser < Racc::Parser
|
13
|
+
##### State transition tables begin ###
|
14
|
+
|
15
|
+
racc_action_table = [
|
16
|
+
3, 55, 26, 21, 12, 24, 56, 3, 57, 1,
|
17
|
+
73, 12, 41, 56, 3, 23, 1, 79, 12, 18,
|
18
|
+
91, 90, 4, 1, 9, 10, 18, 13, 16, 4,
|
19
|
+
12, 9, 10, 18, 13, 16, 4, 12, 9, 10,
|
20
|
+
3, 13, 16, 41, 12, 41, 60, 61, 4, 1,
|
21
|
+
63, 10, 12, 44, 16, 4, 12, 12, 10, 18,
|
22
|
+
3, 16, 4, 3, 9, 10, 80, 13, 16, 27,
|
23
|
+
4, 28, 48, 10, 4, 4, 16, 10, 10, 18,
|
24
|
+
16, 16, 18, 12, 9, 58, 61, 9, 26, 51,
|
25
|
+
57, 53, 26, 51, 81, 53, 82, 66, 68, -22,
|
26
|
+
62, 4, 66, 68, 10, 85, 86, 16, 67, 69,
|
27
|
+
70, 59, 72, 67, 69, 70, 64, 72, 32, 34,
|
28
|
+
36, 64, 26, 51, 54, 53, 26, 51, 31, 53,
|
29
|
+
33, 35, 89, 4, 92, 93, 94 ]
|
30
|
+
|
31
|
+
racc_action_check = [
|
32
|
+
0, 20, 3, 3, 0, 3, 43, 56, 51, 0,
|
33
|
+
28, 56, 39, 20, 9, 3, 56, 43, 9, 0,
|
34
|
+
71, 71, 0, 9, 0, 0, 56, 0, 0, 56,
|
35
|
+
7, 56, 56, 9, 56, 56, 9, 6, 9, 9,
|
36
|
+
30, 9, 9, 11, 30, 7, 24, 24, 7, 30,
|
37
|
+
26, 7, 8, 10, 7, 6, 41, 17, 6, 30,
|
38
|
+
4, 6, 30, 16, 30, 30, 52, 30, 30, 4,
|
39
|
+
8, 4, 16, 8, 41, 17, 8, 41, 17, 4,
|
40
|
+
41, 17, 16, 15, 4, 21, 53, 16, 61, 61,
|
41
|
+
21, 61, 18, 18, 54, 18, 55, 29, 29, 1,
|
42
|
+
25, 15, 27, 27, 15, 58, 60, 15, 29, 29,
|
43
|
+
29, 22, 29, 27, 27, 27, 29, 27, 5, 5,
|
44
|
+
5, 27, 57, 57, 19, 57, 63, 63, 5, 63,
|
45
|
+
5, 5, 65, 14, 74, 78, 86 ]
|
46
|
+
|
47
|
+
racc_action_pointer = [
|
48
|
+
-2, 71, nil, -8, 58, 111, 31, 24, 46, 12,
|
49
|
+
42, 22, nil, nil, 109, 77, 61, 51, 82, 96,
|
50
|
+
1, 78, 88, nil, 35, 77, 38, 99, -15, 94,
|
51
|
+
38, nil, nil, nil, nil, nil, nil, nil, nil, -9,
|
52
|
+
nil, 50, nil, -6, nil, nil, nil, nil, nil, nil,
|
53
|
+
nil, -4, 43, 74, 83, 96, 5, 112, 92, nil,
|
54
|
+
99, 78, nil, 116, nil, 107, nil, nil, nil, nil,
|
55
|
+
nil, 10, nil, nil, 109, nil, nil, nil, 112, nil,
|
56
|
+
nil, nil, nil, nil, nil, nil, 123, nil, nil, nil,
|
57
|
+
nil, nil, nil, nil, nil ]
|
58
|
+
|
59
|
+
racc_action_default = [
|
60
|
+
-23, -20, -2, -66, -66, -17, -52, -44, -49, -23,
|
61
|
+
-66, -15, -53, -21, -12, -51, -66, -50, -66, -66,
|
62
|
+
-66, -37, -66, -27, -35, -66, -36, -56, -66, -56,
|
63
|
+
-23, -5, -3, -8, -4, -7, -6, -48, -9, -43,
|
64
|
+
-11, -66, -45, -66, -18, -14, -13, -47, -42, -41,
|
65
|
+
-46, -37, -66, -35, -66, -66, -23, -66, -66, -28,
|
66
|
+
-40, -66, -29, -66, -57, -66, -62, -58, -63, -59,
|
67
|
+
-60, -66, -61, -26, -66, -16, -10, -65, -66, -31,
|
68
|
+
-30, -19, 95, -1, -34, -39, -66, -32, -33, -24,
|
69
|
+
-54, -55, -25, -64, -38 ]
|
70
|
+
|
71
|
+
racc_goto_table = [
|
72
|
+
22, 37, 39, 42, 75, 40, 29, 20, 30, 45,
|
73
|
+
47, 65, 50, 74, 38, 52, 43, 46, 49, 25,
|
74
|
+
78, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
75
|
+
83, nil, nil, nil, nil, nil, 77, 76, nil, nil,
|
76
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
77
|
+
nil, nil, nil, nil, 84, nil, nil, nil, 87, nil,
|
78
|
+
88 ]
|
79
|
+
|
80
|
+
racc_goto_check = [
|
81
|
+
14, 7, 7, 7, 2, 8, 9, 1, 3, 8,
|
82
|
+
7, 13, 7, 13, 6, 14, 1, 10, 9, 15,
|
83
|
+
19, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
84
|
+
2, nil, nil, nil, nil, nil, 7, 8, nil, nil,
|
85
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
86
|
+
nil, nil, nil, nil, 14, nil, nil, nil, 14, nil,
|
87
|
+
14 ]
|
88
|
+
|
89
|
+
racc_goto_pointer = [
|
90
|
+
nil, 7, -26, 3, nil, nil, 7, -5, -2, 2,
|
91
|
+
3, nil, nil, -16, -3, 16, nil, nil, nil, -21 ]
|
92
|
+
|
93
|
+
racc_goto_default = [
|
94
|
+
nil, nil, 2, nil, 5, 7, nil, 11, nil, 14,
|
95
|
+
15, 17, 19, nil, nil, nil, 6, 8, 71, nil ]
|
96
|
+
|
97
|
+
racc_reduce_table = [
|
98
|
+
0, 0, :racc_error,
|
99
|
+
3, 32, :_reduce_1,
|
100
|
+
1, 32, :_reduce_2,
|
101
|
+
1, 34, :_reduce_3,
|
102
|
+
1, 34, :_reduce_4,
|
103
|
+
1, 34, :_reduce_5,
|
104
|
+
1, 34, :_reduce_6,
|
105
|
+
1, 34, :_reduce_7,
|
106
|
+
1, 34, :_reduce_8,
|
107
|
+
2, 35, :_reduce_9,
|
108
|
+
3, 35, :_reduce_10,
|
109
|
+
2, 35, :_reduce_11,
|
110
|
+
1, 35, :_reduce_none,
|
111
|
+
2, 35, :_reduce_13,
|
112
|
+
2, 35, :_reduce_14,
|
113
|
+
1, 35, :_reduce_15,
|
114
|
+
3, 33, :_reduce_16,
|
115
|
+
1, 33, :_reduce_none,
|
116
|
+
2, 42, :_reduce_18,
|
117
|
+
3, 36, :_reduce_19,
|
118
|
+
1, 36, :_reduce_20,
|
119
|
+
1, 36, :_reduce_21,
|
120
|
+
1, 43, :_reduce_22,
|
121
|
+
0, 43, :_reduce_none,
|
122
|
+
4, 41, :_reduce_24,
|
123
|
+
4, 41, :_reduce_25,
|
124
|
+
3, 41, :_reduce_26,
|
125
|
+
2, 40, :_reduce_27,
|
126
|
+
3, 40, :_reduce_28,
|
127
|
+
3, 40, :_reduce_29,
|
128
|
+
3, 40, :_reduce_30,
|
129
|
+
3, 40, :_reduce_31,
|
130
|
+
3, 45, :_reduce_32,
|
131
|
+
3, 45, :_reduce_33,
|
132
|
+
3, 45, :_reduce_34,
|
133
|
+
1, 45, :_reduce_none,
|
134
|
+
1, 45, :_reduce_none,
|
135
|
+
1, 45, :_reduce_37,
|
136
|
+
4, 46, :_reduce_38,
|
137
|
+
3, 46, :_reduce_39,
|
138
|
+
2, 46, :_reduce_40,
|
139
|
+
2, 47, :_reduce_41,
|
140
|
+
2, 47, :_reduce_42,
|
141
|
+
1, 37, :_reduce_none,
|
142
|
+
0, 37, :_reduce_none,
|
143
|
+
2, 38, :_reduce_45,
|
144
|
+
2, 38, :_reduce_46,
|
145
|
+
2, 38, :_reduce_47,
|
146
|
+
2, 38, :_reduce_48,
|
147
|
+
1, 38, :_reduce_none,
|
148
|
+
1, 38, :_reduce_none,
|
149
|
+
1, 38, :_reduce_none,
|
150
|
+
1, 38, :_reduce_none,
|
151
|
+
1, 48, :_reduce_53,
|
152
|
+
2, 44, :_reduce_54,
|
153
|
+
2, 44, :_reduce_55,
|
154
|
+
0, 44, :_reduce_none,
|
155
|
+
1, 49, :_reduce_57,
|
156
|
+
1, 49, :_reduce_58,
|
157
|
+
1, 49, :_reduce_59,
|
158
|
+
1, 49, :_reduce_60,
|
159
|
+
1, 49, :_reduce_61,
|
160
|
+
1, 49, :_reduce_62,
|
161
|
+
1, 49, :_reduce_63,
|
162
|
+
3, 39, :_reduce_64,
|
163
|
+
1, 50, :_reduce_none ]
|
164
|
+
|
165
|
+
racc_reduce_n = 66
|
166
|
+
|
167
|
+
racc_shift_n = 95
|
168
|
+
|
169
|
+
racc_token_table = {
|
170
|
+
false => 0,
|
171
|
+
:error => 1,
|
172
|
+
:FUNCTION => 2,
|
173
|
+
:INCLUDES => 3,
|
174
|
+
:DASHMATCH => 4,
|
175
|
+
:LBRACE => 5,
|
176
|
+
:HASH => 6,
|
177
|
+
:PLUS => 7,
|
178
|
+
:GREATER => 8,
|
179
|
+
:S => 9,
|
180
|
+
:STRING => 10,
|
181
|
+
:IDENT => 11,
|
182
|
+
:COMMA => 12,
|
183
|
+
:NUMBER => 13,
|
184
|
+
:PREFIXMATCH => 14,
|
185
|
+
:SUFFIXMATCH => 15,
|
186
|
+
:SUBSTRINGMATCH => 16,
|
187
|
+
:TILDE => 17,
|
188
|
+
:NOT_EQUAL => 18,
|
189
|
+
:SLASH => 19,
|
190
|
+
:DOUBLESLASH => 20,
|
191
|
+
:NOT => 21,
|
192
|
+
:EQUAL => 22,
|
193
|
+
:RPAREN => 23,
|
194
|
+
:LSQUARE => 24,
|
195
|
+
:RSQUARE => 25,
|
196
|
+
:HAS => 26,
|
197
|
+
"." => 27,
|
198
|
+
"|" => 28,
|
199
|
+
"*" => 29,
|
200
|
+
":" => 30 }
|
201
|
+
|
202
|
+
racc_nt_base = 31
|
203
|
+
|
204
|
+
racc_use_result_var = true
|
205
|
+
|
206
|
+
Racc_arg = [
|
207
|
+
racc_action_table,
|
208
|
+
racc_action_check,
|
209
|
+
racc_action_default,
|
210
|
+
racc_action_pointer,
|
211
|
+
racc_goto_table,
|
212
|
+
racc_goto_check,
|
213
|
+
racc_goto_default,
|
214
|
+
racc_goto_pointer,
|
215
|
+
racc_nt_base,
|
216
|
+
racc_reduce_table,
|
217
|
+
racc_token_table,
|
218
|
+
racc_shift_n,
|
219
|
+
racc_reduce_n,
|
220
|
+
racc_use_result_var ]
|
221
|
+
|
222
|
+
Racc_token_to_s_table = [
|
223
|
+
"$end",
|
224
|
+
"error",
|
225
|
+
"FUNCTION",
|
226
|
+
"INCLUDES",
|
227
|
+
"DASHMATCH",
|
228
|
+
"LBRACE",
|
229
|
+
"HASH",
|
230
|
+
"PLUS",
|
231
|
+
"GREATER",
|
232
|
+
"S",
|
233
|
+
"STRING",
|
234
|
+
"IDENT",
|
235
|
+
"COMMA",
|
236
|
+
"NUMBER",
|
237
|
+
"PREFIXMATCH",
|
238
|
+
"SUFFIXMATCH",
|
239
|
+
"SUBSTRINGMATCH",
|
240
|
+
"TILDE",
|
241
|
+
"NOT_EQUAL",
|
242
|
+
"SLASH",
|
243
|
+
"DOUBLESLASH",
|
244
|
+
"NOT",
|
245
|
+
"EQUAL",
|
246
|
+
"RPAREN",
|
247
|
+
"LSQUARE",
|
248
|
+
"RSQUARE",
|
249
|
+
"HAS",
|
250
|
+
"\".\"",
|
251
|
+
"\"|\"",
|
252
|
+
"\"*\"",
|
253
|
+
"\":\"",
|
254
|
+
"$start",
|
255
|
+
"selector",
|
256
|
+
"simple_selector_1toN",
|
257
|
+
"combinator",
|
258
|
+
"simple_selector",
|
259
|
+
"element_name",
|
260
|
+
"hcap_0toN",
|
261
|
+
"hcap_1toN",
|
262
|
+
"negation",
|
263
|
+
"function",
|
264
|
+
"attrib",
|
265
|
+
"class",
|
266
|
+
"namespace",
|
267
|
+
"attrib_val_0or1",
|
268
|
+
"expr",
|
269
|
+
"an_plus_b",
|
270
|
+
"pseudo",
|
271
|
+
"attribute_id",
|
272
|
+
"eql_incl_dash",
|
273
|
+
"negation_arg" ]
|
274
|
+
|
275
|
+
Racc_debug_parser = false
|
276
|
+
|
277
|
+
##### State transition tables end #####
|
278
|
+
|
279
|
+
# reduce 0 omitted
|
280
|
+
|
281
|
+
def _reduce_1(val, _values, result)
|
282
|
+
result = [val.first, val.last].flatten
|
283
|
+
|
284
|
+
result
|
285
|
+
end
|
286
|
+
|
287
|
+
def _reduce_2(val, _values, result)
|
288
|
+
result = val.flatten
|
289
|
+
result
|
290
|
+
end
|
291
|
+
|
292
|
+
def _reduce_3(val, _values, result)
|
293
|
+
result = :DIRECT_ADJACENT_SELECTOR
|
294
|
+
result
|
295
|
+
end
|
296
|
+
|
297
|
+
def _reduce_4(val, _values, result)
|
298
|
+
result = :CHILD_SELECTOR
|
299
|
+
result
|
300
|
+
end
|
301
|
+
|
302
|
+
def _reduce_5(val, _values, result)
|
303
|
+
result = :PRECEDING_SELECTOR
|
304
|
+
result
|
305
|
+
end
|
306
|
+
|
307
|
+
def _reduce_6(val, _values, result)
|
308
|
+
result = :DESCENDANT_SELECTOR
|
309
|
+
result
|
310
|
+
end
|
311
|
+
|
312
|
+
def _reduce_7(val, _values, result)
|
313
|
+
result = :DESCENDANT_SELECTOR
|
314
|
+
result
|
315
|
+
end
|
316
|
+
|
317
|
+
def _reduce_8(val, _values, result)
|
318
|
+
result = :CHILD_SELECTOR
|
319
|
+
result
|
320
|
+
end
|
321
|
+
|
322
|
+
def _reduce_9(val, _values, result)
|
323
|
+
result = if val[1].nil?
|
324
|
+
val.first
|
325
|
+
else
|
326
|
+
Node.new(:CONDITIONAL_SELECTOR, [val.first, val[1]])
|
327
|
+
end
|
328
|
+
|
329
|
+
result
|
330
|
+
end
|
331
|
+
|
332
|
+
def _reduce_10(val, _values, result)
|
333
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
334
|
+
[
|
335
|
+
val.first,
|
336
|
+
Node.new(:COMBINATOR, [val[1], val.last])
|
337
|
+
]
|
338
|
+
)
|
339
|
+
|
340
|
+
result
|
341
|
+
end
|
342
|
+
|
343
|
+
def _reduce_11(val, _values, result)
|
344
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
345
|
+
|
346
|
+
result
|
347
|
+
end
|
348
|
+
|
349
|
+
# reduce 12 omitted
|
350
|
+
|
351
|
+
def _reduce_13(val, _values, result)
|
352
|
+
result = Node.new(:CONDITIONAL_SELECTOR, val)
|
353
|
+
|
354
|
+
result
|
355
|
+
end
|
356
|
+
|
357
|
+
def _reduce_14(val, _values, result)
|
358
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
359
|
+
[
|
360
|
+
Node.new(:ELEMENT_NAME, ['*']),
|
361
|
+
Node.new(:COMBINATOR, val)
|
362
|
+
]
|
363
|
+
)
|
364
|
+
|
365
|
+
result
|
366
|
+
end
|
367
|
+
|
368
|
+
def _reduce_15(val, _values, result)
|
369
|
+
result = Node.new(:CONDITIONAL_SELECTOR,
|
370
|
+
[Node.new(:ELEMENT_NAME, ['*']), val.first]
|
371
|
+
)
|
372
|
+
|
373
|
+
result
|
374
|
+
end
|
375
|
+
|
376
|
+
def _reduce_16(val, _values, result)
|
377
|
+
result = Node.new(val[1], [val.first, val.last])
|
378
|
+
|
379
|
+
result
|
380
|
+
end
|
381
|
+
|
382
|
+
# reduce 17 omitted
|
383
|
+
|
384
|
+
def _reduce_18(val, _values, result)
|
385
|
+
result = Node.new(:CLASS_CONDITION, [val[1]])
|
386
|
+
result
|
387
|
+
end
|
388
|
+
|
389
|
+
def _reduce_19(val, _values, result)
|
390
|
+
result = Node.new(:ELEMENT_NAME,
|
391
|
+
[[val.first, val.last].compact.join(':')]
|
392
|
+
)
|
393
|
+
|
394
|
+
result
|
395
|
+
end
|
396
|
+
|
397
|
+
def _reduce_20(val, _values, result)
|
398
|
+
name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
|
399
|
+
result = Node.new(:ELEMENT_NAME, [name])
|
400
|
+
|
401
|
+
result
|
402
|
+
end
|
403
|
+
|
404
|
+
def _reduce_21(val, _values, result)
|
405
|
+
result = Node.new(:ELEMENT_NAME, val)
|
406
|
+
result
|
407
|
+
end
|
408
|
+
|
409
|
+
def _reduce_22(val, _values, result)
|
410
|
+
result = val[0]
|
411
|
+
result
|
412
|
+
end
|
413
|
+
|
414
|
+
# reduce 23 omitted
|
415
|
+
|
416
|
+
def _reduce_24(val, _values, result)
|
417
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
418
|
+
[Node.new(:ELEMENT_NAME, [val[1]])] + (val[2] || [])
|
419
|
+
)
|
420
|
+
|
421
|
+
result
|
422
|
+
end
|
423
|
+
|
424
|
+
def _reduce_25(val, _values, result)
|
425
|
+
result = Node.new(:ATTRIBUTE_CONDITION,
|
426
|
+
[val[1]] + (val[2] || [])
|
427
|
+
)
|
428
|
+
|
429
|
+
result
|
430
|
+
end
|
431
|
+
|
432
|
+
def _reduce_26(val, _values, result)
|
433
|
+
# Non standard, but hpricot supports it.
|
434
|
+
result = Node.new(:PSEUDO_CLASS,
|
435
|
+
[Node.new(:FUNCTION, ['nth-child(', val[1]])]
|
436
|
+
)
|
437
|
+
|
438
|
+
result
|
439
|
+
end
|
440
|
+
|
441
|
+
def _reduce_27(val, _values, result)
|
442
|
+
result = Node.new(:FUNCTION, [val.first.strip])
|
443
|
+
|
444
|
+
result
|
445
|
+
end
|
446
|
+
|
447
|
+
def _reduce_28(val, _values, result)
|
448
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
449
|
+
|
450
|
+
result
|
451
|
+
end
|
452
|
+
|
453
|
+
def _reduce_29(val, _values, result)
|
454
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
455
|
+
|
456
|
+
result
|
457
|
+
end
|
458
|
+
|
459
|
+
def _reduce_30(val, _values, result)
|
460
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
461
|
+
|
462
|
+
result
|
463
|
+
end
|
464
|
+
|
465
|
+
def _reduce_31(val, _values, result)
|
466
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
467
|
+
|
468
|
+
result
|
469
|
+
end
|
470
|
+
|
471
|
+
def _reduce_32(val, _values, result)
|
472
|
+
result = [val.first, val.last]
|
473
|
+
result
|
474
|
+
end
|
475
|
+
|
476
|
+
def _reduce_33(val, _values, result)
|
477
|
+
result = [val.first, val.last]
|
478
|
+
result
|
479
|
+
end
|
480
|
+
|
481
|
+
def _reduce_34(val, _values, result)
|
482
|
+
result = [val.first, val.last]
|
483
|
+
result
|
484
|
+
end
|
485
|
+
|
486
|
+
# reduce 35 omitted
|
487
|
+
|
488
|
+
# reduce 36 omitted
|
489
|
+
|
490
|
+
def _reduce_37(val, _values, result)
|
491
|
+
if val[0] == 'even'
|
492
|
+
val = ["2","n","+","0"]
|
493
|
+
result = Node.new(:AN_PLUS_B, val)
|
494
|
+
elsif val[0] == 'odd'
|
495
|
+
val = ["2","n","+","1"]
|
496
|
+
result = Node.new(:AN_PLUS_B, val)
|
497
|
+
else
|
498
|
+
# This is not CSS standard. It allows us to support this:
|
499
|
+
# assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
|
500
|
+
# assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
|
501
|
+
# assert_xpath("//a[foo(., a, 10)]", @parser.parse('a:foo(a, 10)'))
|
502
|
+
result = val
|
503
|
+
end
|
504
|
+
|
505
|
+
result
|
506
|
+
end
|
507
|
+
|
508
|
+
def _reduce_38(val, _values, result)
|
509
|
+
if val[1] == 'n'
|
510
|
+
result = Node.new(:AN_PLUS_B, val)
|
511
|
+
else
|
512
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
513
|
+
end
|
514
|
+
|
515
|
+
result
|
516
|
+
end
|
517
|
+
|
518
|
+
def _reduce_39(val, _values, result)
|
519
|
+
# n+3, -n+3
|
520
|
+
if val[0] == 'n'
|
521
|
+
val.unshift("1")
|
522
|
+
result = Node.new(:AN_PLUS_B, val)
|
523
|
+
elsif val[0] == '-n'
|
524
|
+
val[0] = 'n'
|
525
|
+
val.unshift("-1")
|
526
|
+
result = Node.new(:AN_PLUS_B, val)
|
527
|
+
else
|
528
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
529
|
+
end
|
530
|
+
|
531
|
+
result
|
532
|
+
end
|
533
|
+
|
534
|
+
def _reduce_40(val, _values, result)
|
535
|
+
if val[1] == 'n'
|
536
|
+
val << "+"
|
537
|
+
val << "0"
|
538
|
+
result = Node.new(:AN_PLUS_B, val)
|
539
|
+
else
|
540
|
+
raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
|
541
|
+
end
|
542
|
+
|
543
|
+
result
|
544
|
+
end
|
545
|
+
|
546
|
+
def _reduce_41(val, _values, result)
|
547
|
+
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
548
|
+
|
549
|
+
result
|
550
|
+
end
|
551
|
+
|
552
|
+
def _reduce_42(val, _values, result)
|
553
|
+
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
554
|
+
result
|
555
|
+
end
|
556
|
+
|
557
|
+
# reduce 43 omitted
|
558
|
+
|
559
|
+
# reduce 44 omitted
|
560
|
+
|
561
|
+
def _reduce_45(val, _values, result)
|
562
|
+
result = Node.new(:COMBINATOR, val)
|
563
|
+
|
564
|
+
result
|
565
|
+
end
|
566
|
+
|
567
|
+
def _reduce_46(val, _values, result)
|
568
|
+
result = Node.new(:COMBINATOR, val)
|
569
|
+
|
570
|
+
result
|
571
|
+
end
|
572
|
+
|
573
|
+
def _reduce_47(val, _values, result)
|
574
|
+
result = Node.new(:COMBINATOR, val)
|
575
|
+
|
576
|
+
result
|
577
|
+
end
|
578
|
+
|
579
|
+
def _reduce_48(val, _values, result)
|
580
|
+
result = Node.new(:COMBINATOR, val)
|
581
|
+
|
582
|
+
result
|
583
|
+
end
|
584
|
+
|
585
|
+
# reduce 49 omitted
|
586
|
+
|
587
|
+
# reduce 50 omitted
|
588
|
+
|
589
|
+
# reduce 51 omitted
|
590
|
+
|
591
|
+
# reduce 52 omitted
|
592
|
+
|
593
|
+
def _reduce_53(val, _values, result)
|
594
|
+
result = Node.new(:ID, val)
|
595
|
+
result
|
596
|
+
end
|
597
|
+
|
598
|
+
def _reduce_54(val, _values, result)
|
599
|
+
result = [val.first, val[1]]
|
600
|
+
result
|
601
|
+
end
|
602
|
+
|
603
|
+
def _reduce_55(val, _values, result)
|
604
|
+
result = [val.first, val[1]]
|
605
|
+
result
|
606
|
+
end
|
607
|
+
|
608
|
+
# reduce 56 omitted
|
609
|
+
|
610
|
+
def _reduce_57(val, _values, result)
|
611
|
+
result = :equal
|
612
|
+
result
|
613
|
+
end
|
614
|
+
|
615
|
+
def _reduce_58(val, _values, result)
|
616
|
+
result = :prefix_match
|
617
|
+
result
|
618
|
+
end
|
619
|
+
|
620
|
+
def _reduce_59(val, _values, result)
|
621
|
+
result = :suffix_match
|
622
|
+
result
|
623
|
+
end
|
624
|
+
|
625
|
+
def _reduce_60(val, _values, result)
|
626
|
+
result = :substring_match
|
627
|
+
result
|
628
|
+
end
|
629
|
+
|
630
|
+
def _reduce_61(val, _values, result)
|
631
|
+
result = :not_equal
|
632
|
+
result
|
633
|
+
end
|
634
|
+
|
635
|
+
def _reduce_62(val, _values, result)
|
636
|
+
result = :includes
|
637
|
+
result
|
638
|
+
end
|
639
|
+
|
640
|
+
def _reduce_63(val, _values, result)
|
641
|
+
result = :dash_match
|
642
|
+
result
|
643
|
+
end
|
644
|
+
|
645
|
+
def _reduce_64(val, _values, result)
|
646
|
+
result = Node.new(:NOT, [val[1]])
|
647
|
+
|
648
|
+
result
|
649
|
+
end
|
650
|
+
|
651
|
+
# reduce 65 omitted
|
652
|
+
|
653
|
+
def _reduce_none(val, _values, result)
|
654
|
+
val[0]
|
655
|
+
end
|
656
|
+
|
657
|
+
end # class GeneratedParser
|
658
|
+
end # module CSS
|
659
|
+
end # module Nokogiri
|