nokogiri 1.2.3 → 1.3.0

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.

Files changed (200) hide show
  1. data/.autotest +14 -2
  2. data/CHANGELOG.ja.rdoc +38 -0
  3. data/CHANGELOG.rdoc +43 -0
  4. data/Manifest.txt +80 -5
  5. data/README.ja.rdoc +12 -11
  6. data/README.rdoc +4 -2
  7. data/Rakefile +103 -173
  8. data/bin/nokogiri +47 -0
  9. data/ext/nokogiri/extconf.rb +19 -13
  10. data/ext/nokogiri/html_document.c +39 -3
  11. data/ext/nokogiri/html_document.h +1 -1
  12. data/ext/nokogiri/html_element_description.c +272 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.h +1 -1
  15. data/ext/nokogiri/html_sax_parser.h +1 -1
  16. data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
  17. data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
  18. data/ext/nokogiri/xml_attr.c +14 -5
  19. data/ext/nokogiri/xml_attr.h +1 -1
  20. data/ext/nokogiri/xml_cdata.c +15 -6
  21. data/ext/nokogiri/xml_cdata.h +1 -1
  22. data/ext/nokogiri/xml_comment.c +13 -4
  23. data/ext/nokogiri/xml_comment.h +1 -1
  24. data/ext/nokogiri/xml_document.c +50 -41
  25. data/ext/nokogiri/xml_document.h +1 -1
  26. data/ext/nokogiri/xml_document_fragment.c +12 -4
  27. data/ext/nokogiri/xml_document_fragment.h +1 -1
  28. data/ext/nokogiri/xml_dtd.c +1 -1
  29. data/ext/nokogiri/xml_dtd.h +1 -1
  30. data/ext/nokogiri/xml_entity_reference.c +13 -4
  31. data/ext/nokogiri/xml_entity_reference.h +1 -1
  32. data/ext/nokogiri/xml_io.h +1 -1
  33. data/ext/nokogiri/xml_namespace.c +69 -0
  34. data/ext/nokogiri/xml_namespace.h +12 -0
  35. data/ext/nokogiri/xml_node.c +232 -124
  36. data/ext/nokogiri/xml_node.h +3 -4
  37. data/ext/nokogiri/xml_node_set.c +206 -19
  38. data/ext/nokogiri/xml_node_set.h +1 -1
  39. data/ext/nokogiri/xml_processing_instruction.c +14 -4
  40. data/ext/nokogiri/xml_processing_instruction.h +1 -1
  41. data/ext/nokogiri/xml_reader.c +87 -7
  42. data/ext/nokogiri/xml_reader.h +1 -1
  43. data/ext/nokogiri/xml_relax_ng.c +106 -0
  44. data/ext/nokogiri/xml_relax_ng.h +9 -0
  45. data/ext/nokogiri/xml_sax_parser.c +122 -2
  46. data/ext/nokogiri/xml_sax_parser.h +1 -1
  47. data/ext/nokogiri/xml_sax_push_parser.c +1 -0
  48. data/ext/nokogiri/xml_sax_push_parser.h +1 -1
  49. data/ext/nokogiri/xml_schema.c +107 -0
  50. data/ext/nokogiri/xml_schema.h +9 -0
  51. data/ext/nokogiri/xml_syntax_error.h +1 -1
  52. data/ext/nokogiri/xml_text.c +10 -3
  53. data/ext/nokogiri/xml_text.h +1 -1
  54. data/ext/nokogiri/xml_xpath.h +1 -1
  55. data/ext/nokogiri/xml_xpath_context.h +1 -1
  56. data/ext/nokogiri/xslt_stylesheet.c +29 -16
  57. data/ext/nokogiri/xslt_stylesheet.h +1 -1
  58. data/lib/action-nokogiri.rb +7 -1
  59. data/lib/nokogiri.rb +21 -5
  60. data/lib/nokogiri/css/generated_parser.rb +49 -14
  61. data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
  62. data/lib/nokogiri/css/node.rb +13 -3
  63. data/lib/nokogiri/css/parser.rb +8 -0
  64. data/lib/nokogiri/css/parser.y +7 -7
  65. data/lib/nokogiri/css/tokenizer.rb +2 -0
  66. data/lib/nokogiri/css/xpath_visitor.rb +10 -6
  67. data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
  68. data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
  69. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
  70. data/lib/nokogiri/decorators/slop.rb +3 -1
  71. data/lib/nokogiri/ffi/html/document.rb +37 -0
  72. data/lib/nokogiri/ffi/html/element_description.rb +85 -0
  73. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  74. data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
  75. data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
  76. data/lib/nokogiri/ffi/libxml.rb +314 -0
  77. data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
  78. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  79. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  80. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  81. data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
  82. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  83. data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
  84. data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
  85. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  86. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  87. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  88. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  89. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  90. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  91. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
  92. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  93. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  94. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  95. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
  96. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  97. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  98. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  99. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  100. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  101. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  102. data/lib/nokogiri/ffi/xml/document.rb +107 -0
  103. data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
  104. data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
  105. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  106. data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
  107. data/lib/nokogiri/ffi/xml/node.rb +380 -0
  108. data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
  109. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  110. data/lib/nokogiri/ffi/xml/reader.rb +217 -0
  111. data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
  112. data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
  113. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
  114. data/lib/nokogiri/ffi/xml/schema.rb +55 -0
  115. data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
  116. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  117. data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
  118. data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
  119. data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
  120. data/lib/nokogiri/hpricot.rb +14 -3
  121. data/lib/nokogiri/html.rb +11 -46
  122. data/lib/nokogiri/html/builder.rb +27 -1
  123. data/lib/nokogiri/html/document.rb +62 -6
  124. data/lib/nokogiri/html/document_fragment.rb +15 -0
  125. data/lib/nokogiri/html/element_description.rb +23 -0
  126. data/lib/nokogiri/html/entity_lookup.rb +2 -0
  127. data/lib/nokogiri/html/sax/parser.rb +27 -1
  128. data/lib/nokogiri/version.rb +26 -1
  129. data/lib/nokogiri/version_warning.rb +11 -0
  130. data/lib/nokogiri/xml.rb +25 -51
  131. data/lib/nokogiri/xml/builder.rb +166 -10
  132. data/lib/nokogiri/xml/cdata.rb +3 -1
  133. data/lib/nokogiri/xml/document.rb +39 -6
  134. data/lib/nokogiri/xml/document_fragment.rb +41 -1
  135. data/lib/nokogiri/xml/dtd.rb +3 -1
  136. data/lib/nokogiri/xml/entity_declaration.rb +3 -1
  137. data/lib/nokogiri/xml/fragment_handler.rb +24 -3
  138. data/lib/nokogiri/xml/namespace.rb +7 -0
  139. data/lib/nokogiri/xml/node.rb +314 -65
  140. data/lib/nokogiri/xml/node/save_options.rb +12 -2
  141. data/lib/nokogiri/xml/node_set.rb +58 -8
  142. data/lib/nokogiri/xml/parse_options.rb +80 -0
  143. data/lib/nokogiri/xml/processing_instruction.rb +2 -0
  144. data/lib/nokogiri/xml/reader.rb +42 -3
  145. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  146. data/lib/nokogiri/xml/sax.rb +0 -7
  147. data/lib/nokogiri/xml/sax/document.rb +84 -0
  148. data/lib/nokogiri/xml/sax/parser.rb +38 -2
  149. data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
  150. data/lib/nokogiri/xml/schema.rb +65 -0
  151. data/lib/nokogiri/xml/syntax_error.rb +11 -0
  152. data/lib/nokogiri/xml/xpath.rb +1 -1
  153. data/lib/nokogiri/xml/xpath_context.rb +2 -0
  154. data/lib/nokogiri/xslt.rb +21 -1
  155. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  156. data/lib/xsd/xmlparser/nokogiri.rb +12 -2
  157. data/tasks/test.rb +42 -19
  158. data/test/css/test_parser.rb +29 -0
  159. data/test/ffi/test_document.rb +35 -0
  160. data/test/files/address_book.rlx +12 -0
  161. data/test/files/address_book.xml +10 -0
  162. data/test/files/po.xml +32 -0
  163. data/test/files/po.xsd +66 -0
  164. data/test/helper.rb +38 -8
  165. data/test/html/sax/test_parser.rb +12 -0
  166. data/test/html/test_builder.rb +25 -2
  167. data/test/html/test_document.rb +91 -20
  168. data/test/html/test_document_fragment.rb +97 -0
  169. data/test/html/test_element_description.rb +95 -0
  170. data/test/html/test_node.rb +66 -3
  171. data/test/test_convert_xpath.rb +1 -1
  172. data/test/test_memory_leak.rb +57 -18
  173. data/test/test_nokogiri.rb +24 -2
  174. data/test/test_reader.rb +77 -0
  175. data/test/test_xslt_transforms.rb +120 -82
  176. data/test/xml/node/test_subclass.rb +44 -0
  177. data/test/xml/sax/test_parser.rb +9 -0
  178. data/test/xml/sax/test_push_parser.rb +24 -0
  179. data/test/xml/test_attr.rb +7 -0
  180. data/test/xml/test_builder.rb +48 -0
  181. data/test/xml/test_cdata.rb +19 -0
  182. data/test/xml/test_comment.rb +6 -0
  183. data/test/xml/test_document.rb +101 -2
  184. data/test/xml/test_document_fragment.rb +55 -3
  185. data/test/xml/test_entity_reference.rb +4 -0
  186. data/test/xml/test_namespace.rb +43 -0
  187. data/test/xml/test_node.rb +255 -8
  188. data/test/xml/test_node_attributes.rb +34 -0
  189. data/test/xml/test_node_encoding.rb +9 -2
  190. data/test/xml/test_node_set.rb +197 -1
  191. data/test/xml/test_parse_options.rb +52 -0
  192. data/test/xml/test_processing_instruction.rb +5 -0
  193. data/test/xml/test_relax_ng.rb +60 -0
  194. data/test/xml/test_schema.rb +65 -0
  195. data/test/xml/test_text.rb +5 -0
  196. data/test/xml/test_unparented_node.rb +3 -3
  197. metadata +128 -12
  198. data/lib/nokogiri/xml/comment.rb +0 -6
  199. data/lib/nokogiri/xml/element.rb +0 -6
  200. data/lib/nokogiri/xml/text.rb +0 -6
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_TEXT
2
2
  #define NOKOGIRI_XML_TEXT
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_text();
7
7
 
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_XPATH
2
2
  #define NOKOGIRI_XML_XPATH
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_xpath();
7
7
  VALUE Nokogiri_wrap_xml_xpath(xmlXPathObjectPtr xpath);
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_XPATH_CONTEXT
2
2
  #define NOKOGIRI_XML_XPATH_CONTEXT
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_xpath_context();
7
7
 
@@ -12,6 +12,18 @@ static void dealloc(xsltStylesheetPtr doc)
12
12
  NOKOGIRI_DEBUG_END(doc);
13
13
  }
14
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
+
15
27
  /*
16
28
  * call-seq:
17
29
  * parse_stylesheet_doc(document)
@@ -24,7 +36,13 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
24
36
  xsltStylesheetPtr ss ;
25
37
  Data_Get_Struct(xmldocobj, xmlDoc, xml);
26
38
  exsltRegisterAll();
39
+
40
+ xsltSetGenericErrorFunc(NULL, xslt_generic_error_handler);
41
+
27
42
  ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */
43
+
44
+ xsltSetGenericErrorFunc(NULL, NULL);
45
+
28
46
  return Data_Wrap_Struct(klass, NULL, dealloc, ss);
29
47
  }
30
48
 
@@ -50,13 +68,21 @@ static VALUE serialize(VALUE self, VALUE xmlobj)
50
68
  xmlFree(doc_ptr);
51
69
  return rval ;
52
70
  }
71
+
53
72
  /*
54
73
  * call-seq:
55
- * transform(document, params)
74
+ * transform(document, params = [])
56
75
  *
57
76
  * Apply an XSLT stylesheet to an XML::Document.
58
77
  * +params+ is an array of strings used as XSLT parameters.
59
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
+ *
60
86
  */
61
87
  static VALUE transform(int argc, VALUE* argv, VALUE self)
62
88
  {
@@ -85,21 +111,9 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
85
111
  result = xsltApplyStylesheet(ss, xml, params);
86
112
  free(params);
87
113
 
88
- return Nokogiri_wrap_xml_document(0, result) ;
89
- }
114
+ if (!result) rb_raise(rb_eRuntimeError, "could not perform xslt transform on document");
90
115
 
91
- /*
92
- * call-seq:
93
- * apply_to(document, params)
94
- *
95
- * Apply an XSLT stylesheet to an XML::Document.
96
- * +params+ is an array of strings used as XSLT parameters.
97
- * returns serialized document
98
- */
99
- static VALUE apply_to(int argc, VALUE* argv, VALUE self)
100
- {
101
- return rb_funcall(self, rb_intern("serialize"), 1,
102
- transform(argc, argv, self));
116
+ return Nokogiri_wrap_xml_document(0, result) ;
103
117
  }
104
118
 
105
119
  VALUE cNokogiriXsltStylesheet ;
@@ -113,6 +127,5 @@ void init_xslt_stylesheet()
113
127
 
114
128
  rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
115
129
  rb_define_method(klass, "serialize", serialize, 1);
116
- rb_define_method(klass, "apply_to", apply_to, -1);
117
130
  rb_define_method(klass, "transform", transform, -1);
118
131
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XSLT_STYLESHEET
2
2
  #define NOKOGIRI_XSLT_STYLESHEET
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xslt_stylesheet();
7
7
 
@@ -12,8 +12,11 @@ require 'nokogiri'
12
12
  # end
13
13
  #
14
14
  module ActionController
15
- module TestResponseBehavior
15
+ module TestResponseBehavior # :nodoc:
16
16
 
17
+ ###
18
+ # Get your response as a Nokogiri::XML::Document using the
19
+ # Nokogiri.HTML parser
17
20
  def html(flavor=nil)
18
21
  if flavor == :hpricot
19
22
  @_nokogiri_html_hpricot ||= Nokogiri::Hpricot(body)
@@ -22,6 +25,9 @@ module ActionController
22
25
  end
23
26
  end
24
27
 
28
+ ###
29
+ # Get your response as a Nokogiri::XML::Document using the
30
+ # Nokogiri.XML parser
25
31
  def xml
26
32
  @_nokogiri_xml ||= Nokogiri::XML(body)
27
33
  end
@@ -1,11 +1,19 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Modify the PATH on windows so that the external DLLs will get loaded.
2
3
  ENV['PATH'] = [File.expand_path(
3
4
  File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
4
- ), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /mswin/i
5
+ ), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /(mswin|mingw)/i
5
6
 
6
- require 'nokogiri/native' unless RUBY_PLATFORM =~ /java/
7
+ if ENV['NOKOGIRI_FFI'] || RUBY_PLATFORM =~ /java/
8
+ gem 'ffi', '>=0.4.0' unless RUBY_PLATFORM =~ /java/
9
+ require 'ffi'
10
+ require 'nokogiri/ffi/libxml'
11
+ else
12
+ require 'nokogiri/nokogiri'
13
+ end
7
14
 
8
15
  require 'nokogiri/version'
16
+ require 'nokogiri/version_warning'
9
17
  require 'nokogiri/syntax_error'
10
18
  require 'nokogiri/xml'
11
19
  require 'nokogiri/xslt'
@@ -47,14 +55,16 @@ module Nokogiri
47
55
  def parse string, url = nil, encoding = nil, options = nil
48
56
  doc =
49
57
  if string =~ /^\s*<[^Hh>]*html/i # Probably html
50
- Nokogiri::HTML.parse(string, url, encoding, options || 2145)
58
+ Nokogiri::HTML::Document.parse(string, url, encoding, options || 2145)
51
59
  else
52
- Nokogiri::XML.parse(string, url, encoding, options || 2159)
60
+ Nokogiri::XML::Document.parse(string, url, encoding, options || 2159)
53
61
  end
54
62
  yield doc if block_given?
55
63
  doc
56
64
  end
57
65
 
66
+ ###
67
+ # Create a new Nokogiri::XML::DocumentFragment
58
68
  def make input = nil, opts = {}, &blk
59
69
  if input
60
70
  Nokogiri::HTML.fragment(input).children.first
@@ -62,7 +72,7 @@ module Nokogiri
62
72
  Nokogiri(&blk)
63
73
  end
64
74
  end
65
-
75
+
66
76
  ###
67
77
  # Parse a document and add the Slop decorator. The Slop decorator
68
78
  # implements method_missing such that methods may be used instead of CSS
@@ -84,6 +94,12 @@ module Nokogiri
84
94
  end
85
95
  end
86
96
 
97
+ ###
98
+ # Parser a document contained in +args+. Nokogiri will try to guess what
99
+ # type of document you are attempting to parse. For more information, see
100
+ # Nokogiri.parse
101
+ #
102
+ # To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
87
103
  def Nokogiri(*args, &block)
88
104
  if block_given?
89
105
  builder = Nokogiri::HTML::Builder.new(&block)
@@ -147,13 +147,13 @@ racc_reduce_table = [
147
147
  2, 43, :_reduce_53,
148
148
  2, 43, :_reduce_54,
149
149
  0, 43, :_reduce_none,
150
- 1, 48, :_reduce_none,
151
- 1, 48, :_reduce_none,
152
- 1, 48, :_reduce_none,
153
- 1, 48, :_reduce_none,
154
- 1, 48, :_reduce_none,
155
- 1, 48, :_reduce_none,
156
- 1, 48, :_reduce_none,
150
+ 1, 48, :_reduce_56,
151
+ 1, 48, :_reduce_57,
152
+ 1, 48, :_reduce_58,
153
+ 1, 48, :_reduce_59,
154
+ 1, 48, :_reduce_60,
155
+ 1, 48, :_reduce_61,
156
+ 1, 48, :_reduce_62,
157
157
  3, 38, :_reduce_63,
158
158
  1, 49, :_reduce_none ]
159
159
 
@@ -680,19 +680,54 @@ module_eval(<<'.,.,', 'parser.y', 203)
680
680
 
681
681
  # reduce 55 omitted
682
682
 
683
- # reduce 56 omitted
683
+ module_eval(<<'.,.,', 'parser.y', 207)
684
+ def _reduce_56(val, _values, result)
685
+ result = :equal
686
+ result
687
+ end
688
+ .,.,
684
689
 
685
- # reduce 57 omitted
690
+ module_eval(<<'.,.,', 'parser.y', 208)
691
+ def _reduce_57(val, _values, result)
692
+ result = :prefix_match
693
+ result
694
+ end
695
+ .,.,
686
696
 
687
- # reduce 58 omitted
697
+ module_eval(<<'.,.,', 'parser.y', 209)
698
+ def _reduce_58(val, _values, result)
699
+ result = :suffix_match
700
+ result
701
+ end
702
+ .,.,
688
703
 
689
- # reduce 59 omitted
704
+ module_eval(<<'.,.,', 'parser.y', 210)
705
+ def _reduce_59(val, _values, result)
706
+ result = :substring_match
707
+ result
708
+ end
709
+ .,.,
690
710
 
691
- # reduce 60 omitted
711
+ module_eval(<<'.,.,', 'parser.y', 211)
712
+ def _reduce_60(val, _values, result)
713
+ result = :not_equal
714
+ result
715
+ end
716
+ .,.,
692
717
 
693
- # reduce 61 omitted
718
+ module_eval(<<'.,.,', 'parser.y', 212)
719
+ def _reduce_61(val, _values, result)
720
+ result = :includes
721
+ result
722
+ end
723
+ .,.,
694
724
 
695
- # reduce 62 omitted
725
+ module_eval(<<'.,.,', 'parser.y', 213)
726
+ def _reduce_62(val, _values, result)
727
+ result = :dash_match
728
+ result
729
+ end
730
+ .,.,
696
731
 
697
732
  module_eval(<<'.,.,', 'parser.y', 217)
698
733
  def _reduce_63(val, _values, result)
@@ -1,8 +1,8 @@
1
- #--
1
+ #
2
2
  # DO NOT MODIFY!!!!
3
3
  # This file is automatically generated by rex 1.0.1
4
4
  # from lexical definition file "lib/nokogiri/css/tokenizer.rex".
5
- #++
5
+ #
6
6
 
7
7
  module Nokogiri
8
8
  module CSS
@@ -1,12 +1,18 @@
1
1
  module Nokogiri
2
2
  module CSS
3
3
  class Node
4
- attr_accessor :type, :value
4
+ # Get the type of this node
5
+ attr_accessor :type
6
+ # Get the value of this node
7
+ attr_accessor :value
8
+
9
+ # Create a new Node with +type+ and +value+
5
10
  def initialize type, value
6
11
  @type = type
7
12
  @value = value
8
13
  end
9
14
 
15
+ # Accept +visitor+
10
16
  def accept visitor
11
17
  visitor.send(:"visit_#{type.to_s.downcase}", self)
12
18
  end
@@ -18,6 +24,7 @@ module Nokogiri
18
24
  prefix + visitor.accept(self)
19
25
  end
20
26
 
27
+ # Preprocess this node tree
21
28
  def preprocess!
22
29
  ### Deal with nth-child
23
30
  matches = find_by_type(
@@ -67,14 +74,15 @@ module Nokogiri
67
74
  match.value[1] = Node.new(:COMBINATOR, [
68
75
  Node.new(:FUNCTION, ["#{match.value[1].value.first}("]),
69
76
  Node.new(:FUNCTION, ['self(', tag_name])
70
- ])
77
+ ])
71
78
  end
72
79
  end
73
80
 
74
81
  self
75
82
  end
76
83
 
77
- def find_by_type(types)
84
+ # Find a node by type using +types+
85
+ def find_by_type types
78
86
  matches = []
79
87
  matches << self if to_type == types
80
88
  @value.each do |v|
@@ -83,12 +91,14 @@ module Nokogiri
83
91
  matches
84
92
  end
85
93
 
94
+ # Convert to_type
86
95
  def to_type
87
96
  [@type] + @value.map { |n|
88
97
  n.to_type if n.respond_to?(:to_type)
89
98
  }.compact
90
99
  end
91
100
 
101
+ # Convert to array
92
102
  def to_a
93
103
  [@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] }
94
104
  end
@@ -8,24 +8,29 @@ module Nokogiri
8
8
  @mutex = Mutex.new
9
9
 
10
10
  class << self
11
+ # Turn on CSS parse caching
11
12
  attr_accessor :cache_on
12
13
  alias :cache_on? :cache_on
13
14
  alias :set_cache :cache_on=
14
15
 
16
+ # Get the css selector in +string+ from the cache
15
17
  def [] string
16
18
  return unless @cache_on
17
19
  @mutex.synchronize { @cache[string] }
18
20
  end
19
21
 
22
+ # Set the css selector in +string+ in the cache to +value+
20
23
  def []= string, value
21
24
  return value unless @cache_on
22
25
  @mutex.synchronize { @cache[string] = value }
23
26
  end
24
27
 
28
+ # Clear the cache
25
29
  def clear_cache
26
30
  @mutex.synchronize { @cache = {} }
27
31
  end
28
32
 
33
+ # Execute +block+ without cache
29
34
  def without_cache &block
30
35
  tmp = @cache_on
31
36
  @cache_on = false
@@ -45,12 +50,14 @@ module Nokogiri
45
50
  end
46
51
  end
47
52
 
53
+ # Create a new CSS parser with respect to +namespaces+
48
54
  def initialize namespaces = {}
49
55
  @namespaces = namespaces
50
56
  super()
51
57
  end
52
58
  alias :parse :scan_str
53
59
 
60
+ # Get the xpath for +string+ using +options+
54
61
  def xpath_for string, options={}
55
62
  key = string + options[:ns].to_s
56
63
  v = self.class[key]
@@ -65,6 +72,7 @@ module Nokogiri
65
72
  }
66
73
  end
67
74
 
75
+ # On CSS parser error, raise an exception
68
76
  def on_error error_token_id, error_value, value_stack
69
77
  after = value_stack.compact.last
70
78
  raise SyntaxError.new("unexpected '#{error_value}' after '#{after}'")
@@ -205,13 +205,13 @@ rule
205
205
  |
206
206
  ;
207
207
  eql_incl_dash
208
- : EQUAL
209
- | PREFIXMATCH
210
- | SUFFIXMATCH
211
- | SUBSTRINGMATCH
212
- | NOT_EQUAL
213
- | INCLUDES
214
- | DASHMATCH
208
+ : EQUAL { result = :equal }
209
+ | PREFIXMATCH { result = :prefix_match }
210
+ | SUFFIXMATCH { result = :suffix_match }
211
+ | SUBSTRINGMATCH { result = :substring_match }
212
+ | NOT_EQUAL { result = :not_equal }
213
+ | INCLUDES { result = :includes }
214
+ | DASHMATCH { result = :dash_match }
215
215
  ;
216
216
  negation
217
217
  : NOT negation_arg RPAREN {
@@ -1,6 +1,8 @@
1
1
  module Nokogiri
2
2
  module CSS
3
3
  class Tokenizer < GeneratedTokenizer
4
+ ###
5
+ # Scan and tokenize +str+
4
6
  def scan(str)
5
7
  scan_evaluate(str)
6
8
  end