nokogiri 1.5.0 → 1.5.1.rc1
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.
- data/CHANGELOG.ja.rdoc +39 -12
- data/CHANGELOG.rdoc +28 -0
- data/C_CODING_STYLE.rdoc +27 -0
- data/Manifest.txt +4 -0
- data/README.rdoc +11 -7
- data/Rakefile +42 -29
- data/bin/nokogiri +10 -2
- data/ext/nokogiri/extconf.rb +9 -1
- data/ext/nokogiri/html_document.c +16 -0
- data/ext/nokogiri/html_sax_parser_context.c +59 -37
- 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 +6 -8
- data/ext/nokogiri/nokogiri.h +3 -0
- data/ext/nokogiri/xml_document.c +101 -3
- data/ext/nokogiri/xml_document.h +3 -3
- data/ext/nokogiri/xml_node.c +150 -58
- data/ext/nokogiri/xml_node_set.c +169 -120
- data/ext/nokogiri/xml_node_set.h +5 -0
- data/ext/nokogiri/xml_sax_parser_context.c +64 -41
- data/ext/nokogiri/xml_text.c +2 -0
- data/ext/nokogiri/xml_xpath_context.c +30 -24
- data/ext/nokogiri/xslt_stylesheet.c +62 -16
- data/ext/nokogiri/xslt_stylesheet.h +5 -0
- data/lib/nokogiri/css/parser.rb +165 -159
- data/lib/nokogiri/css/parser.y +6 -3
- data/lib/nokogiri/css/tokenizer.rb +1 -1
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +82 -42
- data/lib/nokogiri/html/sax/push_parser.rb +16 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml.rb +6 -0
- data/lib/nokogiri/xml/builder.rb +7 -1
- data/lib/nokogiri/xml/document.rb +32 -17
- data/lib/nokogiri/xml/document_fragment.rb +6 -1
- data/lib/nokogiri/xml/node.rb +40 -9
- data/lib/nokogiri/xslt.rb +5 -1
- data/tasks/cross_compile.rb +1 -0
- data/tasks/nokogiri.org.rb +6 -0
- data/tasks/test.rb +1 -0
- data/test/css/test_xpath_visitor.rb +6 -0
- data/test/helper.rb +1 -0
- data/test/html/test_document.rb +26 -0
- data/test/html/test_document_fragment.rb +1 -2
- data/test/test_memory_leak.rb +81 -1
- data/test/test_xslt_transforms.rb +152 -123
- data/test/xml/test_builder.rb +24 -2
- data/test/xml/test_c14n.rb +151 -0
- data/test/xml/test_document.rb +48 -0
- data/test/xml/test_namespace.rb +5 -0
- data/test/xml/test_node.rb +82 -1
- data/test/xml/test_node_attributes.rb +19 -0
- data/test/xml/test_node_inheritance.rb +32 -0
- data/test/xml/test_node_reparenting.rb +32 -0
- data/test/xml/test_node_set.rb +16 -8
- data/test/xml/test_reader_encoding.rb +16 -0
- data/test/xml/test_unparented_node.rb +24 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +22 -0
- metadata +208 -241
@@ -19,20 +19,22 @@ static void deallocate(xmlParserCtxtPtr ctxt)
|
|
19
19
|
*
|
20
20
|
* Parse +io+ object with +encoding+
|
21
21
|
*/
|
22
|
-
static VALUE
|
22
|
+
static VALUE
|
23
|
+
parse_io(VALUE klass, VALUE io, VALUE encoding)
|
23
24
|
{
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
xmlParserCtxtPtr ctxt;
|
26
|
+
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
27
|
+
|
28
|
+
ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
29
|
+
(xmlInputReadCallback)io_read_callback,
|
30
|
+
(xmlInputCloseCallback)io_close_callback,
|
31
|
+
(void *)io, enc);
|
32
|
+
if (ctxt->sax) {
|
33
|
+
xmlFree(ctxt->sax);
|
34
|
+
ctxt->sax = NULL;
|
35
|
+
}
|
36
|
+
|
37
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
36
38
|
}
|
37
39
|
|
38
40
|
/*
|
@@ -53,20 +55,44 @@ static VALUE parse_file(VALUE klass, VALUE filename)
|
|
53
55
|
*
|
54
56
|
* Parse the XML stored in memory in +data+
|
55
57
|
*/
|
56
|
-
static VALUE
|
58
|
+
static VALUE
|
59
|
+
parse_memory(VALUE klass, VALUE data)
|
57
60
|
{
|
58
|
-
|
61
|
+
xmlParserCtxtPtr ctxt;
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
if (NIL_P(data))
|
64
|
+
rb_raise(rb_eArgError, "data cannot be nil");
|
65
|
+
if (!(int)RSTRING_LEN(data))
|
66
|
+
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data),
|
69
|
+
(int)RSTRING_LEN(data));
|
70
|
+
if (ctxt->sax) {
|
71
|
+
xmlFree(ctxt->sax);
|
72
|
+
ctxt->sax = NULL;
|
73
|
+
}
|
68
74
|
|
69
|
-
|
75
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
parse_doc(VALUE ctxt_val)
|
80
|
+
{
|
81
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
82
|
+
xmlParseDocument(ctxt);
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
parse_doc_finalize(VALUE ctxt_val)
|
88
|
+
{
|
89
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
90
|
+
|
91
|
+
if (NULL != ctxt->myDoc)
|
92
|
+
xmlFreeDoc(ctxt->myDoc);
|
93
|
+
|
94
|
+
NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
|
95
|
+
return Qnil;
|
70
96
|
}
|
71
97
|
|
72
98
|
/*
|
@@ -75,31 +101,28 @@ static VALUE parse_memory(VALUE klass, VALUE data)
|
|
75
101
|
*
|
76
102
|
* Use +sax_handler+ and parse the current document
|
77
103
|
*/
|
78
|
-
static VALUE
|
104
|
+
static VALUE
|
105
|
+
parse_with(VALUE self, VALUE sax_handler)
|
79
106
|
{
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if(!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
|
84
|
-
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
|
85
|
-
|
86
|
-
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
87
|
-
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
|
107
|
+
xmlParserCtxtPtr ctxt;
|
108
|
+
xmlSAXHandlerPtr sax;
|
88
109
|
|
89
|
-
|
90
|
-
|
91
|
-
xmlFree(ctxt->sax);
|
110
|
+
if (!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
|
111
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
|
92
112
|
|
93
|
-
|
94
|
-
|
113
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
114
|
+
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
|
95
115
|
|
96
|
-
|
116
|
+
/* Free the sax handler since we'll assign our own */
|
117
|
+
if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
|
118
|
+
xmlFree(ctxt->sax);
|
97
119
|
|
98
|
-
|
120
|
+
ctxt->sax = sax;
|
121
|
+
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
|
99
122
|
|
100
|
-
|
123
|
+
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
|
101
124
|
|
102
|
-
|
125
|
+
return Qnil;
|
103
126
|
}
|
104
127
|
|
105
128
|
/*
|
data/ext/nokogiri/xml_text.c
CHANGED
@@ -22,6 +22,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
22
22
|
node = xmlNewText((xmlChar *)StringValuePtr(string));
|
23
23
|
node->doc = doc->doc;
|
24
24
|
|
25
|
+
NOKOGIRI_ROOT_NODE(node);
|
26
|
+
|
25
27
|
rb_node = Nokogiri_wrap_xml_node(klass, node) ;
|
26
28
|
rb_obj_call_init(rb_node, argc, argv);
|
27
29
|
|
@@ -59,6 +59,7 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
59
59
|
xmlNodeSetPtr xml_node_set = NULL;
|
60
60
|
xmlXPathObjectPtr obj;
|
61
61
|
int i;
|
62
|
+
nokogiriNodeSetTuple *node_set_tuple;
|
62
63
|
|
63
64
|
assert(ctx);
|
64
65
|
assert(ctx->context);
|
@@ -75,27 +76,29 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
75
76
|
|
76
77
|
doc = DOC_RUBY_OBJECT(ctx->context->doc);
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
79
|
+
if (nargs > 0) {
|
80
|
+
i = nargs - 1;
|
81
|
+
do {
|
82
|
+
obj = valuePop(ctx);
|
83
|
+
switch(obj->type) {
|
84
|
+
case XPATH_STRING:
|
85
|
+
argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
|
86
|
+
break;
|
87
|
+
case XPATH_BOOLEAN:
|
88
|
+
argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
|
89
|
+
break;
|
90
|
+
case XPATH_NUMBER:
|
91
|
+
argv[i] = rb_float_new(obj->floatval);
|
92
|
+
break;
|
93
|
+
case XPATH_NODESET:
|
94
|
+
argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
|
95
|
+
break;
|
96
|
+
default:
|
97
|
+
argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
|
98
|
+
}
|
99
|
+
xmlXPathFreeNodeSetList(obj);
|
100
|
+
} while(i-- > 0);
|
101
|
+
}
|
99
102
|
|
100
103
|
result = rb_funcall2(
|
101
104
|
xpath_handler,
|
@@ -118,7 +121,7 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
118
121
|
case T_STRING:
|
119
122
|
xmlXPathReturnString(
|
120
123
|
ctx,
|
121
|
-
(
|
124
|
+
xmlCharStrdup(StringValuePtr(result))
|
122
125
|
);
|
123
126
|
break;
|
124
127
|
case T_TRUE:
|
@@ -135,13 +138,15 @@ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
|
|
135
138
|
args[0] = doc;
|
136
139
|
args[1] = result;
|
137
140
|
node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
|
138
|
-
Data_Get_Struct(node_set,
|
141
|
+
Data_Get_Struct(node_set, nokogiriNodeSetTuple, node_set_tuple);
|
142
|
+
xml_node_set = node_set_tuple->node_set;
|
139
143
|
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
140
144
|
}
|
141
145
|
break;
|
142
146
|
case T_DATA:
|
143
147
|
if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
|
144
|
-
Data_Get_Struct(result,
|
148
|
+
Data_Get_Struct(result, nokogiriNodeSetTuple, node_set_tuple);
|
149
|
+
xml_node_set = node_set_tuple->node_set;
|
145
150
|
/* Copy the node set, otherwise it will get GC'd. */
|
146
151
|
xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
|
147
152
|
break;
|
@@ -236,6 +241,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
|
|
236
241
|
switch(xpath->type) {
|
237
242
|
case XPATH_STRING:
|
238
243
|
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
|
244
|
+
xmlFree(xpath->stringval);
|
239
245
|
break;
|
240
246
|
case XPATH_NODESET:
|
241
247
|
if(NULL == xpath->nodesetval) {
|
@@ -10,27 +10,49 @@ VALUE xslt;
|
|
10
10
|
int vasprintf (char **strp, const char *fmt, va_list ap);
|
11
11
|
void vasprintf_free (void *p);
|
12
12
|
|
13
|
-
static void
|
13
|
+
static void mark(nokogiriXsltStylesheetTuple *wrapper)
|
14
14
|
{
|
15
|
+
rb_gc_mark(wrapper->func_instances);
|
16
|
+
}
|
17
|
+
|
18
|
+
static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
|
19
|
+
{
|
20
|
+
xsltStylesheetPtr doc = wrapper->ss;
|
21
|
+
|
15
22
|
NOKOGIRI_DEBUG_START(doc);
|
16
23
|
xsltFreeStylesheet(doc); /* commented out for now. */
|
17
24
|
NOKOGIRI_DEBUG_END(doc);
|
25
|
+
|
26
|
+
free(wrapper);
|
18
27
|
}
|
19
28
|
|
20
|
-
NORETURN(static void xslt_generic_error_handler(void * ctx, const char *msg, ...));
|
21
29
|
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
22
30
|
{
|
23
31
|
char * message;
|
24
|
-
VALUE exception;
|
25
32
|
|
26
33
|
va_list args;
|
27
34
|
va_start(args, msg);
|
28
35
|
vasprintf(&message, msg, args);
|
29
36
|
va_end(args);
|
30
37
|
|
31
|
-
|
38
|
+
rb_str_cat2((VALUE)ctx, message);
|
39
|
+
|
32
40
|
vasprintf_free(message);
|
33
|
-
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
|
44
|
+
{
|
45
|
+
VALUE self;
|
46
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
47
|
+
|
48
|
+
self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
|
49
|
+
mark, dealloc, wrapper);
|
50
|
+
|
51
|
+
ss->_private = (void *)self;
|
52
|
+
wrapper->ss = ss;
|
53
|
+
wrapper->func_instances = rb_ary_new();
|
54
|
+
|
55
|
+
return self;
|
34
56
|
}
|
35
57
|
|
36
58
|
/*
|
@@ -41,18 +63,27 @@ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
|
41
63
|
*/
|
42
64
|
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
43
65
|
{
|
44
|
-
xmlDocPtr xml ;
|
66
|
+
xmlDocPtr xml, xml_cpy;
|
67
|
+
VALUE errstr, exception;
|
45
68
|
xsltStylesheetPtr ss ;
|
46
69
|
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
47
70
|
exsltRegisterAll();
|
48
71
|
|
49
|
-
|
72
|
+
errstr = rb_str_new(0, 0);
|
73
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
50
74
|
|
51
|
-
|
75
|
+
xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
|
76
|
+
ss = xsltParseStylesheetDoc(xml_cpy);
|
52
77
|
|
53
78
|
xsltSetGenericErrorFunc(NULL, NULL);
|
54
79
|
|
55
|
-
|
80
|
+
if (!ss) {
|
81
|
+
xmlFreeDoc(xml_cpy);
|
82
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
83
|
+
rb_exc_raise(exception);
|
84
|
+
}
|
85
|
+
|
86
|
+
return Nokogiri_wrap_xslt_stylesheet(ss);
|
56
87
|
}
|
57
88
|
|
58
89
|
|
@@ -65,14 +96,14 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
|
65
96
|
static VALUE serialize(VALUE self, VALUE xmlobj)
|
66
97
|
{
|
67
98
|
xmlDocPtr xml ;
|
68
|
-
|
99
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
69
100
|
xmlChar* doc_ptr ;
|
70
101
|
int doc_len ;
|
71
102
|
VALUE rval ;
|
72
103
|
|
73
104
|
Data_Get_Struct(xmlobj, xmlDoc, xml);
|
74
|
-
Data_Get_Struct(self,
|
75
|
-
xsltSaveResultToString(&doc_ptr, &doc_len, xml, ss);
|
105
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
106
|
+
xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
|
76
107
|
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
|
77
108
|
xmlFree(doc_ptr);
|
78
109
|
return rval ;
|
@@ -98,7 +129,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
|
|
98
129
|
VALUE xmldoc, paramobj ;
|
99
130
|
xmlDocPtr xml ;
|
100
131
|
xmlDocPtr result ;
|
101
|
-
|
132
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
102
133
|
const char** params ;
|
103
134
|
long param_len, j ;
|
104
135
|
|
@@ -116,7 +147,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
|
|
116
147
|
Check_Type(paramobj, T_ARRAY);
|
117
148
|
|
118
149
|
Data_Get_Struct(xmldoc, xmlDoc, xml);
|
119
|
-
Data_Get_Struct(self,
|
150
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
120
151
|
|
121
152
|
param_len = RARRAY_LEN(paramobj);
|
122
153
|
params = calloc((size_t)param_len+1, sizeof(char*));
|
@@ -127,7 +158,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
|
|
127
158
|
}
|
128
159
|
params[param_len] = 0 ;
|
129
160
|
|
130
|
-
result = xsltApplyStylesheet(ss, xml, params);
|
161
|
+
result = xsltApplyStylesheet(wrapper->ss, xml, params);
|
131
162
|
free(params);
|
132
163
|
|
133
164
|
if (!result) rb_raise(rb_eRuntimeError, "could not perform xslt transform on document");
|
@@ -178,8 +209,10 @@ static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
|
|
178
209
|
rb_raise(rb_eRuntimeError, "do not handle type: %d", xpath->type);
|
179
210
|
}
|
180
211
|
args[i] = thing;
|
212
|
+
xmlFree(xpath);
|
181
213
|
}
|
182
214
|
result = rb_funcall3(obj, rb_intern((const char *)function), (int)count, args);
|
215
|
+
free(args);
|
183
216
|
switch(TYPE(result)) {
|
184
217
|
case T_FLOAT:
|
185
218
|
case T_BIGNUM:
|
@@ -211,6 +244,8 @@ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
|
|
211
244
|
VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
|
212
245
|
VALUE args = { Qfalse };
|
213
246
|
VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
|
247
|
+
VALUE inst;
|
248
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
214
249
|
int i;
|
215
250
|
|
216
251
|
for(i = 0; i < RARRAY_LEN(methods); i++) {
|
@@ -219,12 +254,23 @@ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
|
|
219
254
|
(unsigned char *)StringValuePtr(method_name), uri, method_caller);
|
220
255
|
}
|
221
256
|
|
222
|
-
|
257
|
+
Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
258
|
+
wrapper);
|
259
|
+
inst = rb_class_new_instance(0, NULL, obj);
|
260
|
+
rb_ary_push(wrapper->func_instances, inst);
|
261
|
+
|
262
|
+
return (void *)inst;
|
223
263
|
}
|
224
264
|
|
225
265
|
static void shutdownFunc(xsltTransformContextPtr ctxt,
|
226
266
|
const xmlChar *uri, void *data)
|
227
267
|
{
|
268
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
269
|
+
|
270
|
+
Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
271
|
+
wrapper);
|
272
|
+
|
273
|
+
rb_ary_clear(wrapper->func_instances);
|
228
274
|
}
|
229
275
|
|
230
276
|
/*
|
data/lib/nokogiri/css/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# DO NOT MODIFY!!!!
|
3
|
-
# This file is automatically generated by Racc 1.4.
|
3
|
+
# This file is automatically generated by Racc 1.4.7
|
4
4
|
# from Racc grammer file "".
|
5
5
|
#
|
6
6
|
|
@@ -14,90 +14,92 @@ module Nokogiri
|
|
14
14
|
##### State transition tables begin ###
|
15
15
|
|
16
16
|
racc_action_table = [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
12, 9,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
13, 22, 47, 48, 21, 46, 84, 23, 13, 11,
|
18
|
+
12, 83, 21, 23, 66, 43, 16, 11, 86, 14,
|
19
|
+
21, 79, 12, 77, 15, 7, 9, 14, 16, 82,
|
20
|
+
12, 13, 15, 7, 9, 21, 16, 78, 12, 13,
|
21
|
+
11, 7, 85, 21, 16, 80, 47, 51, 11, 50,
|
22
|
+
14, 83, 21, 12, 21, 15, 7, 9, 14, 16,
|
23
|
+
27, 12, 21, 15, 7, 9, 21, 16, 87, 27,
|
24
|
+
12, 11, 12, 7, 21, 7, 16, 59, 16, 21,
|
25
|
+
12, 89, 13, 7, 12, 13, 16, 7, 9, -24,
|
26
|
+
16, 11, 12, 42, 54, 7, 92, 12, 16, 39,
|
27
|
+
7, 14, 94, 16, 14, 38, 15, 74, 75, 15,
|
28
|
+
91, 90, 74, 75, 47, 51, 27, 50, 70, 71,
|
29
|
+
72, 97, 73, 70, 71, 72, 69, 73, 31, 32,
|
30
|
+
34, 69, 47, 51, 98, 50, 47, 51, 33, 50,
|
31
|
+
36, 35, 81, 80 ]
|
32
32
|
|
33
33
|
racc_action_check = [
|
34
|
-
0,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
34
|
+
0, 1, 13, 13, 0, 13, 48, 52, 37, 0,
|
35
|
+
4, 48, 37, 1, 39, 13, 4, 37, 52, 0,
|
36
|
+
63, 45, 0, 42, 0, 0, 0, 37, 0, 47,
|
37
|
+
37, 23, 37, 37, 37, 23, 37, 44, 63, 15,
|
38
|
+
23, 63, 49, 15, 63, 50, 14, 14, 15, 14,
|
39
|
+
23, 51, 19, 23, 3, 23, 23, 23, 15, 23,
|
40
|
+
25, 15, 18, 15, 15, 15, 27, 15, 62, 3,
|
41
|
+
19, 27, 3, 19, 17, 3, 19, 22, 3, 20,
|
42
|
+
18, 67, 12, 18, 27, 16, 18, 27, 27, 11,
|
43
|
+
27, 12, 17, 12, 16, 17, 76, 20, 17, 10,
|
44
|
+
20, 12, 81, 20, 16, 7, 12, 40, 40, 16,
|
45
|
+
68, 68, 41, 41, 83, 83, 5, 83, 40, 40,
|
46
|
+
40, 84, 40, 41, 41, 41, 40, 41, 6, 6,
|
47
|
+
6, 41, 82, 82, 94, 82, 80, 80, 6, 80,
|
48
|
+
6, 6, 46, 46 ]
|
49
49
|
|
50
50
|
racc_action_pointer = [
|
51
|
-
-2,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
nil, nil, nil,
|
57
|
-
|
58
|
-
nil, nil, nil,
|
59
|
-
|
60
|
-
nil, nil, nil, nil, nil, nil, nil, nil ]
|
51
|
+
-2, 1, nil, 48, -14, 95, 121, 94, nil, nil,
|
52
|
+
70, 60, 80, -8, 36, 37, 83, 68, 56, 46,
|
53
|
+
73, nil, 77, 29, nil, 39, nil, 60, nil, nil,
|
54
|
+
nil, nil, nil, nil, nil, nil, nil, 6, nil, 3,
|
55
|
+
104, 109, -2, nil, 14, -2, 131, 17, -1, 19,
|
56
|
+
33, 39, -5, nil, nil, nil, nil, nil, nil, nil,
|
57
|
+
nil, nil, 45, 14, nil, nil, nil, 56, 100, nil,
|
58
|
+
nil, nil, nil, nil, nil, nil, 71, nil, nil, nil,
|
59
|
+
126, 95, 122, 104, 108, nil, nil, nil, nil, nil,
|
60
|
+
nil, nil, nil, nil, 121, nil, nil, nil, nil ]
|
61
61
|
|
62
62
|
racc_action_default = [
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
63
|
+
-25, -70, -2, -46, -12, -16, -18, -70, -20, -21,
|
64
|
+
-70, -23, -25, -70, -70, -25, -70, -51, -52, -53,
|
65
|
+
-54, -55, -70, -25, -9, -45, -11, -25, -13, -14,
|
66
|
+
-15, -3, -4, -5, -6, -7, -8, -25, -19, -70,
|
67
|
+
-58, -58, -70, -29, -70, -70, -37, -38, -39, -70,
|
68
|
+
-37, -39, -70, -43, -44, -47, -48, -49, -50, 99,
|
69
|
+
-1, -10, -70, -67, -69, -17, -22, -70, -70, -59,
|
70
|
+
-60, -61, -62, -63, -64, -65, -70, -28, -30, -31,
|
71
|
+
-70, -42, -70, -70, -70, -32, -33, -66, -68, -26,
|
72
|
+
-56, -57, -27, -34, -70, -35, -36, -41, -40 ]
|
73
73
|
|
74
74
|
racc_goto_table = [
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
85, nil, nil, nil, 80, 78, nil, nil, nil, nil,
|
75
|
+
44, 49, 25, 26, 40, 30, 1, 41, 60, 67,
|
76
|
+
76, 53, 28, 29, 63, 24, 55, 56, 57, 58,
|
77
|
+
37, 52, 65, 45, 62, 61, 64, nil, nil, nil,
|
79
78
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
80
|
-
nil, nil, nil, nil, nil, nil, nil,
|
81
|
-
|
82
|
-
nil, nil, 95
|
79
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
80
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
81
|
+
nil, nil, 88, nil, nil, nil, nil, 93, nil, 95,
|
82
|
+
96 ]
|
83
83
|
|
84
84
|
racc_goto_check = [
|
85
|
-
7,
|
86
|
-
|
87
|
-
3,
|
88
|
-
|
85
|
+
16, 16, 7, 8, 13, 8, 1, 9, 2, 15,
|
86
|
+
15, 9, 10, 11, 5, 6, 7, 7, 7, 7,
|
87
|
+
3, 1, 2, 17, 20, 8, 7, nil, nil, nil,
|
88
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
89
89
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
90
|
-
nil, nil, nil, nil, nil, nil, nil,
|
91
|
-
|
92
|
-
|
90
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
91
|
+
nil, nil, 7, nil, nil, nil, nil, 16, nil, 16,
|
92
|
+
16 ]
|
93
93
|
|
94
94
|
racc_goto_pointer = [
|
95
|
-
nil, 6, -
|
96
|
-
|
95
|
+
nil, 6, -15, 14, nil, -13, 12, -1, 0, -5,
|
96
|
+
8, 9, nil, -8, nil, -31, -13, 10, nil, nil,
|
97
|
+
-3 ]
|
97
98
|
|
98
99
|
racc_goto_default = [
|
99
|
-
nil, nil,
|
100
|
-
|
100
|
+
nil, nil, 2, nil, 6, 3, nil, 5, nil, 4,
|
101
|
+
20, 19, 18, 8, 10, nil, nil, nil, 17, 68,
|
102
|
+
nil ]
|
101
103
|
|
102
104
|
racc_reduce_table = [
|
103
105
|
0, 0, :racc_error,
|
@@ -120,59 +122,60 @@ racc_reduce_table = [
|
|
120
122
|
3, 33, :_reduce_17,
|
121
123
|
1, 33, :_reduce_none,
|
122
124
|
2, 43, :_reduce_19,
|
123
|
-
|
125
|
+
1, 36, :_reduce_none,
|
124
126
|
1, 36, :_reduce_21,
|
125
|
-
|
127
|
+
3, 44, :_reduce_22,
|
126
128
|
1, 44, :_reduce_23,
|
127
|
-
|
128
|
-
|
129
|
+
1, 45, :_reduce_24,
|
130
|
+
0, 45, :_reduce_none,
|
129
131
|
4, 42, :_reduce_26,
|
130
|
-
|
131
|
-
|
132
|
-
|
132
|
+
4, 42, :_reduce_27,
|
133
|
+
3, 42, :_reduce_28,
|
134
|
+
2, 40, :_reduce_29,
|
133
135
|
3, 40, :_reduce_30,
|
134
136
|
3, 40, :_reduce_31,
|
135
137
|
3, 40, :_reduce_32,
|
136
|
-
3,
|
137
|
-
3,
|
138
|
-
3,
|
139
|
-
|
140
|
-
1,
|
141
|
-
1,
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
2,
|
138
|
+
3, 40, :_reduce_33,
|
139
|
+
3, 47, :_reduce_34,
|
140
|
+
3, 47, :_reduce_35,
|
141
|
+
3, 47, :_reduce_36,
|
142
|
+
1, 47, :_reduce_none,
|
143
|
+
1, 47, :_reduce_none,
|
144
|
+
1, 47, :_reduce_39,
|
145
|
+
4, 48, :_reduce_40,
|
146
|
+
3, 48, :_reduce_41,
|
147
|
+
2, 48, :_reduce_42,
|
146
148
|
2, 41, :_reduce_43,
|
149
|
+
2, 41, :_reduce_44,
|
147
150
|
1, 37, :_reduce_none,
|
148
151
|
0, 37, :_reduce_none,
|
149
|
-
2, 38, :_reduce_46,
|
150
152
|
2, 38, :_reduce_47,
|
151
153
|
2, 38, :_reduce_48,
|
152
154
|
2, 38, :_reduce_49,
|
155
|
+
2, 38, :_reduce_50,
|
153
156
|
1, 38, :_reduce_none,
|
154
157
|
1, 38, :_reduce_none,
|
155
158
|
1, 38, :_reduce_none,
|
156
159
|
1, 38, :_reduce_none,
|
157
|
-
1,
|
158
|
-
2,
|
159
|
-
2,
|
160
|
-
0,
|
161
|
-
1,
|
162
|
-
1,
|
163
|
-
1,
|
164
|
-
1,
|
165
|
-
1,
|
166
|
-
1,
|
167
|
-
1,
|
168
|
-
3, 39, :
|
169
|
-
1,
|
170
|
-
2,
|
171
|
-
1,
|
172
|
-
|
173
|
-
racc_reduce_n =
|
174
|
-
|
175
|
-
racc_shift_n =
|
160
|
+
1, 49, :_reduce_55,
|
161
|
+
2, 46, :_reduce_56,
|
162
|
+
2, 46, :_reduce_57,
|
163
|
+
0, 46, :_reduce_none,
|
164
|
+
1, 50, :_reduce_59,
|
165
|
+
1, 50, :_reduce_60,
|
166
|
+
1, 50, :_reduce_61,
|
167
|
+
1, 50, :_reduce_62,
|
168
|
+
1, 50, :_reduce_63,
|
169
|
+
1, 50, :_reduce_64,
|
170
|
+
1, 50, :_reduce_65,
|
171
|
+
3, 39, :_reduce_66,
|
172
|
+
1, 51, :_reduce_none,
|
173
|
+
2, 51, :_reduce_none,
|
174
|
+
1, 51, :_reduce_none ]
|
175
|
+
|
176
|
+
racc_reduce_n = 70
|
177
|
+
|
178
|
+
racc_shift_n = 99
|
176
179
|
|
177
180
|
racc_token_table = {
|
178
181
|
false => 0,
|
@@ -203,8 +206,8 @@ racc_token_table = {
|
|
203
206
|
:RSQUARE => 25,
|
204
207
|
:HAS => 26,
|
205
208
|
"." => 27,
|
206
|
-
"
|
207
|
-
"
|
209
|
+
"*" => 28,
|
210
|
+
"|" => 29,
|
208
211
|
":" => 30 }
|
209
212
|
|
210
213
|
racc_nt_base = 31
|
@@ -256,8 +259,8 @@ Racc_token_to_s_table = [
|
|
256
259
|
"RSQUARE",
|
257
260
|
"HAS",
|
258
261
|
"\".\"",
|
259
|
-
"\"|\"",
|
260
262
|
"\"*\"",
|
263
|
+
"\"|\"",
|
261
264
|
"\":\"",
|
262
265
|
"$start",
|
263
266
|
"selector",
|
@@ -272,6 +275,7 @@ Racc_token_to_s_table = [
|
|
272
275
|
"pseudo",
|
273
276
|
"attrib",
|
274
277
|
"class",
|
278
|
+
"namespaced_ident",
|
275
279
|
"namespace",
|
276
280
|
"attrib_val_0or1",
|
277
281
|
"expr",
|
@@ -400,7 +404,14 @@ def _reduce_19(val, _values, result)
|
|
400
404
|
result
|
401
405
|
end
|
402
406
|
|
403
|
-
|
407
|
+
# reduce 20 omitted
|
408
|
+
|
409
|
+
def _reduce_21(val, _values, result)
|
410
|
+
result = Node.new(:ELEMENT_NAME, val)
|
411
|
+
result
|
412
|
+
end
|
413
|
+
|
414
|
+
def _reduce_22(val, _values, result)
|
404
415
|
result = Node.new(:ELEMENT_NAME,
|
405
416
|
[[val.first, val.last].compact.join(':')]
|
406
417
|
)
|
@@ -408,34 +419,29 @@ def _reduce_20(val, _values, result)
|
|
408
419
|
result
|
409
420
|
end
|
410
421
|
|
411
|
-
def
|
422
|
+
def _reduce_23(val, _values, result)
|
412
423
|
name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
|
413
424
|
result = Node.new(:ELEMENT_NAME, [name])
|
414
425
|
|
415
426
|
result
|
416
427
|
end
|
417
428
|
|
418
|
-
def
|
419
|
-
result = Node.new(:ELEMENT_NAME, val)
|
420
|
-
result
|
421
|
-
end
|
422
|
-
|
423
|
-
def _reduce_23(val, _values, result)
|
429
|
+
def _reduce_24(val, _values, result)
|
424
430
|
result = val[0]
|
425
431
|
result
|
426
432
|
end
|
427
433
|
|
428
|
-
# reduce
|
434
|
+
# reduce 25 omitted
|
429
435
|
|
430
|
-
def
|
436
|
+
def _reduce_26(val, _values, result)
|
431
437
|
result = Node.new(:ATTRIBUTE_CONDITION,
|
432
|
-
[
|
438
|
+
[val[1]] + (val[2] || [])
|
433
439
|
)
|
434
440
|
|
435
441
|
result
|
436
442
|
end
|
437
443
|
|
438
|
-
def
|
444
|
+
def _reduce_27(val, _values, result)
|
439
445
|
result = Node.new(:ATTRIBUTE_CONDITION,
|
440
446
|
[val[1]] + (val[2] || [])
|
441
447
|
)
|
@@ -443,7 +449,7 @@ def _reduce_26(val, _values, result)
|
|
443
449
|
result
|
444
450
|
end
|
445
451
|
|
446
|
-
def
|
452
|
+
def _reduce_28(val, _values, result)
|
447
453
|
# Non standard, but hpricot supports it.
|
448
454
|
result = Node.new(:PSEUDO_CLASS,
|
449
455
|
[Node.new(:FUNCTION, ['nth-child(', val[1]])]
|
@@ -452,14 +458,8 @@ def _reduce_27(val, _values, result)
|
|
452
458
|
result
|
453
459
|
end
|
454
460
|
|
455
|
-
def _reduce_28(val, _values, result)
|
456
|
-
result = Node.new(:FUNCTION, [val.first.strip])
|
457
|
-
|
458
|
-
result
|
459
|
-
end
|
460
|
-
|
461
461
|
def _reduce_29(val, _values, result)
|
462
|
-
result = Node.new(:FUNCTION, [val.first.strip
|
462
|
+
result = Node.new(:FUNCTION, [val.first.strip])
|
463
463
|
|
464
464
|
result
|
465
465
|
end
|
@@ -483,7 +483,8 @@ def _reduce_32(val, _values, result)
|
|
483
483
|
end
|
484
484
|
|
485
485
|
def _reduce_33(val, _values, result)
|
486
|
-
|
486
|
+
result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
|
487
|
+
|
487
488
|
result
|
488
489
|
end
|
489
490
|
|
@@ -497,11 +498,16 @@ def _reduce_35(val, _values, result)
|
|
497
498
|
result
|
498
499
|
end
|
499
500
|
|
500
|
-
|
501
|
+
def _reduce_36(val, _values, result)
|
502
|
+
result = [val.first, val.last]
|
503
|
+
result
|
504
|
+
end
|
501
505
|
|
502
506
|
# reduce 37 omitted
|
503
507
|
|
504
|
-
|
508
|
+
# reduce 38 omitted
|
509
|
+
|
510
|
+
def _reduce_39(val, _values, result)
|
505
511
|
if val[0] == 'even'
|
506
512
|
val = ["2","n","+","0"]
|
507
513
|
result = Node.new(:AN_PLUS_B, val)
|
@@ -519,7 +525,7 @@ def _reduce_38(val, _values, result)
|
|
519
525
|
result
|
520
526
|
end
|
521
527
|
|
522
|
-
def
|
528
|
+
def _reduce_40(val, _values, result)
|
523
529
|
if val[1] == 'n'
|
524
530
|
result = Node.new(:AN_PLUS_B, val)
|
525
531
|
else
|
@@ -529,7 +535,7 @@ def _reduce_39(val, _values, result)
|
|
529
535
|
result
|
530
536
|
end
|
531
537
|
|
532
|
-
def
|
538
|
+
def _reduce_41(val, _values, result)
|
533
539
|
# n+3, -n+3
|
534
540
|
if val[0] == 'n'
|
535
541
|
val.unshift("1")
|
@@ -545,7 +551,7 @@ def _reduce_40(val, _values, result)
|
|
545
551
|
result
|
546
552
|
end
|
547
553
|
|
548
|
-
def
|
554
|
+
def _reduce_42(val, _values, result)
|
549
555
|
if val[1] == 'n'
|
550
556
|
val << "+"
|
551
557
|
val << "0"
|
@@ -557,26 +563,20 @@ def _reduce_41(val, _values, result)
|
|
557
563
|
result
|
558
564
|
end
|
559
565
|
|
560
|
-
def
|
566
|
+
def _reduce_43(val, _values, result)
|
561
567
|
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
562
568
|
|
563
569
|
result
|
564
570
|
end
|
565
571
|
|
566
|
-
def
|
572
|
+
def _reduce_44(val, _values, result)
|
567
573
|
result = Node.new(:PSEUDO_CLASS, [val[1]])
|
568
574
|
result
|
569
575
|
end
|
570
576
|
|
571
|
-
# reduce 44 omitted
|
572
|
-
|
573
577
|
# reduce 45 omitted
|
574
578
|
|
575
|
-
|
576
|
-
result = Node.new(:COMBINATOR, val)
|
577
|
-
|
578
|
-
result
|
579
|
-
end
|
579
|
+
# reduce 46 omitted
|
580
580
|
|
581
581
|
def _reduce_47(val, _values, result)
|
582
582
|
result = Node.new(:COMBINATOR, val)
|
@@ -596,7 +596,11 @@ def _reduce_49(val, _values, result)
|
|
596
596
|
result
|
597
597
|
end
|
598
598
|
|
599
|
-
|
599
|
+
def _reduce_50(val, _values, result)
|
600
|
+
result = Node.new(:COMBINATOR, val)
|
601
|
+
|
602
|
+
result
|
603
|
+
end
|
600
604
|
|
601
605
|
# reduce 51 omitted
|
602
606
|
|
@@ -604,70 +608,72 @@ end
|
|
604
608
|
|
605
609
|
# reduce 53 omitted
|
606
610
|
|
607
|
-
|
611
|
+
# reduce 54 omitted
|
612
|
+
|
613
|
+
def _reduce_55(val, _values, result)
|
608
614
|
result = Node.new(:ID, val)
|
609
615
|
result
|
610
616
|
end
|
611
617
|
|
612
|
-
def
|
618
|
+
def _reduce_56(val, _values, result)
|
613
619
|
result = [val.first, val[1]]
|
614
620
|
result
|
615
621
|
end
|
616
622
|
|
617
|
-
def
|
623
|
+
def _reduce_57(val, _values, result)
|
618
624
|
result = [val.first, val[1]]
|
619
625
|
result
|
620
626
|
end
|
621
627
|
|
622
|
-
# reduce
|
628
|
+
# reduce 58 omitted
|
623
629
|
|
624
|
-
def
|
630
|
+
def _reduce_59(val, _values, result)
|
625
631
|
result = :equal
|
626
632
|
result
|
627
633
|
end
|
628
634
|
|
629
|
-
def
|
635
|
+
def _reduce_60(val, _values, result)
|
630
636
|
result = :prefix_match
|
631
637
|
result
|
632
638
|
end
|
633
639
|
|
634
|
-
def
|
640
|
+
def _reduce_61(val, _values, result)
|
635
641
|
result = :suffix_match
|
636
642
|
result
|
637
643
|
end
|
638
644
|
|
639
|
-
def
|
645
|
+
def _reduce_62(val, _values, result)
|
640
646
|
result = :substring_match
|
641
647
|
result
|
642
648
|
end
|
643
649
|
|
644
|
-
def
|
650
|
+
def _reduce_63(val, _values, result)
|
645
651
|
result = :not_equal
|
646
652
|
result
|
647
653
|
end
|
648
654
|
|
649
|
-
def
|
655
|
+
def _reduce_64(val, _values, result)
|
650
656
|
result = :includes
|
651
657
|
result
|
652
658
|
end
|
653
659
|
|
654
|
-
def
|
660
|
+
def _reduce_65(val, _values, result)
|
655
661
|
result = :dash_match
|
656
662
|
result
|
657
663
|
end
|
658
664
|
|
659
|
-
def
|
665
|
+
def _reduce_66(val, _values, result)
|
660
666
|
result = Node.new(:NOT, [val[1]])
|
661
667
|
|
662
668
|
result
|
663
669
|
end
|
664
670
|
|
665
|
-
# reduce 66 omitted
|
666
|
-
|
667
671
|
# reduce 67 omitted
|
668
672
|
|
669
673
|
# reduce 68 omitted
|
670
674
|
|
675
|
+
# reduce 69 omitted
|
676
|
+
|
671
677
|
def _reduce_none(val, _values, result)
|
672
678
|
val[0]
|
673
679
|
end
|