leptris 1.9.355.0-arm-linux → 1.9.359.0-arm-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.adoc +13 -5
  4. data/Rakefile +1 -1
  5. data/ext/leptris/native/native.c +383 -5
  6. data/lib/leptris/version.rb +1 -1
  7. data/lib/leptris/xml/cdata.rb +3 -0
  8. data/lib/leptris/xml/comment.rb +3 -0
  9. data/lib/leptris/xml/declaration.rb +59 -0
  10. data/lib/leptris/xml/doc_type.rb +33 -1
  11. data/lib/leptris/xml/document.rb +74 -2
  12. data/lib/leptris/xml/element.rb +21 -1
  13. data/lib/leptris/xml/entity_reference.rb +3 -0
  14. data/lib/leptris/xml/native.so +0 -0
  15. data/lib/leptris/xml/node_set.rb +22 -0
  16. data/lib/leptris/xml/processing_instruction.rb +3 -0
  17. data/lib/leptris/xml/sax/parser.rb +102 -78
  18. data/lib/leptris/xml/text.rb +4 -0
  19. data/lib/leptris/xml.rb +14 -0
  20. data/lib/libleptris.so +0 -0
  21. data/scripts/gem_smoke.rb +6 -3
  22. data/vendor-src/README.md +1 -1
  23. data/vendor-src/libleptris/CHANGELOG.md +134 -0
  24. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  25. data/vendor-src/libleptris/TODO.xslt-full/REMAINING.md +37 -18
  26. data/vendor-src/libleptris/cli/commands/validate.c +15 -2
  27. data/vendor-src/libleptris/src/include/leptris.h +60 -4
  28. data/vendor-src/libleptris/src/leptris/dom/element.c +8 -0
  29. data/vendor-src/libleptris/src/leptris/dtd/content_check.c +280 -144
  30. data/vendor-src/libleptris/src/leptris/dtd/parser.c +17 -4
  31. data/vendor-src/libleptris/src/leptris/rng/parse.c +53 -8
  32. data/vendor-src/libleptris/src/leptris/rng/validate.c +63 -21
  33. data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +304 -12
  34. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +30 -0
  35. data/vendor-src/libleptris/src/leptris/xpath/evaluator.h +11 -0
  36. data/vendor-src/libleptris/src/leptris/xpath/evaluator_axes.c +3 -3
  37. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +4 -20
  38. data/vendor-src/libleptris/src/leptris/xpath/parser.c +4 -1
  39. data/vendor-src/libleptris/src/leptris/xpath/vm.c +41 -11
  40. data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +4 -3
  41. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +2 -1
  42. data/vendor-src/libleptris/src/leptris/xsd/compile.c +981 -38
  43. data/vendor-src/libleptris/src/leptris/xsd/content_model.c +15 -3
  44. data/vendor-src/libleptris/src/leptris/xsd/validate.c +27 -9
  45. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +1 -0
  46. data/vendor-src/libleptris/test/cli/test_cli.cpp +50 -14
  47. data/vendor-src/libleptris/test/dom/test_dom.cpp +27 -0
  48. data/vendor-src/libleptris/test/dtd/test_dtd_validate.cpp +80 -4
  49. data/vendor-src/libleptris/test/rng/include-cases/attr-text-choice.rng +18 -0
  50. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-mid.rng +7 -0
  51. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-shared.rng +5 -0
  52. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-top.rng +6 -0
  53. data/vendor-src/libleptris/test/rng/test_rng.cpp +101 -0
  54. data/vendor-src/libleptris/test/xinclude/test_xinclude.cpp +261 -0
  55. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +169 -0
  56. data/vendor-src/libleptris/test/xpath/test_xpath_conformance.cpp +8 -1
  57. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +128 -11
  58. data/vendor-src/libleptris/vcpkg.json +1 -1
  59. metadata +7 -2
@@ -3,25 +3,54 @@
3
3
  class Leptris::XML::DocType
4
4
  attr_reader :c_ptr, :document
5
5
 
6
- def initialize(c_ptr, document)
6
+ def initialize(c_ptr, document, detached_name: nil,
7
+ detached_public_id: nil, detached_system_id: nil)
7
8
  @c_ptr = c_ptr
8
9
  @document = document
10
+ @detached_name = detached_name
11
+ @detached_public_id = detached_public_id
12
+ @detached_system_id = detached_system_id
13
+ end
14
+
15
+ # Detached token (leptris-ruby#459 ask 2): create first, attach
16
+ # later via Document#add_child — the two-phase facade contract.
17
+ def self.new_detached(document, name, public_id = nil, system_id = nil)
18
+ new(nil, document, detached_name: name.to_s,
19
+ detached_public_id: public_id, detached_system_id: system_id)
20
+ end
21
+
22
+ def attached?
23
+ !@c_ptr.nil?
24
+ end
25
+
26
+ # Installs the C node handle on a detached token (Document#add_child
27
+ # routes the attach). The detached field copies die here.
28
+ def attach!(c_ptr)
29
+ @c_ptr = c_ptr
30
+ @detached_name = nil
31
+ @detached_public_id = nil
32
+ @detached_system_id = nil
33
+ self
9
34
  end
10
35
 
11
36
  def name
37
+ return @detached_name if @c_ptr.nil?
12
38
  Leptris::XML::FFI.leptris_doctype_get_name(c_ptr)
13
39
  end
14
40
  alias_method :node_name, :name
15
41
 
16
42
  def root_name
43
+ return @detached_name if @c_ptr.nil?
17
44
  Leptris::XML::FFI.leptris_doctype_get_root_name(c_ptr)
18
45
  end
19
46
 
20
47
  def public_id
48
+ return @detached_public_id if @c_ptr.nil?
21
49
  Leptris::XML::FFI.leptris_doctype_get_public_id(c_ptr)
22
50
  end
23
51
 
24
52
  def system_id
53
+ return @detached_system_id if @c_ptr.nil?
25
54
  Leptris::XML::FFI.leptris_doctype_get_system_id(c_ptr)
26
55
  end
27
56
 
@@ -51,4 +80,7 @@ class Leptris::XML::DocType
51
80
  def inspect
52
81
  "#<#{self.class.name} name=#{name.inspect} public=#{public_id.inspect} system=#{system_id.inspect}>"
53
82
  end
83
+
84
+ # leptris-ruby#464: DOCTYPE serialization face.
85
+ alias_method :to_xml, :to_s
54
86
  end
@@ -348,7 +348,18 @@ class Leptris::XML::Document
348
348
  # the chain lacks it, so parsed and built documents read the
349
349
  # same. Prolog/epilog placement uses node_compare against the
350
350
  # root.
351
+ # The declaration (leptris-ruby#459) rides in FRONT of the C child
352
+ # chain — it is document state, not a chain node, so the C-facing
353
+ # child logic below never sees it.
351
354
  def children
355
+ base = document_child_nodes
356
+ return base if declaration.nil?
357
+ list = base.to_a
358
+ list.unshift(declaration)
359
+ Leptris::XML::NodeSet.new(self, list)
360
+ end
361
+
362
+ def document_child_nodes
352
363
  doc_node = node
353
364
  return Leptris::XML::NodeSet.new(self, []) if doc_node.nil?
354
365
  kids = doc_node.children.to_a
@@ -507,10 +518,18 @@ class Leptris::XML::Document
507
518
  def doctype
508
519
  ptr = Leptris::XML::FFI.leptris_document_internal_subset(c_ptr)
509
520
  return nil if ptr.null?
510
- Leptris::XML::DocType.new(ptr, self)
521
+ wrap_doctype(ptr)
511
522
  end
512
523
  alias_method :internal_subset, :doctype
513
524
 
525
+ # One DocType wrapper per C node per document (leptris-ruby#459):
526
+ # the attach routes and the readers hand back the SAME Ruby object
527
+ # the consumer created or received before.
528
+ def wrap_doctype(ptr)
529
+ @doctype_wrappers ||= {}
530
+ @doctype_wrappers[ptr.address] ||= Leptris::XML::DocType.new(ptr, self)
531
+ end
532
+
514
533
  # indent_text selects the ext-serializer knob (libleptris 1.9.22):
515
534
  # a STRING is the indent unit with Nokogiri's semantics — the unit
516
535
  # replaces the default spaces, one copy per depth level, standard
@@ -759,6 +778,16 @@ class Leptris::XML::Document
759
778
  value
760
779
  end
761
780
 
781
+ # The declaration as a NODE (leptris-ruby#459 ask 1): reads and
782
+ # writes route to the document state; remove/unlink clears it.
783
+ # nil when the document carries no declaration. One value object
784
+ # per document — repeated reads return the same instance.
785
+ def declaration
786
+ return @declaration_node if @declaration_node
787
+ return nil if xml_version.nil?
788
+ @declaration_node = Leptris::XML::Declaration.new(self)
789
+ end
790
+
762
791
  # Programmatic DOCTYPE (libleptris 1.9.176 / #212): create and
763
792
  # set the document's DOCTYPE (root name + optional PUBLIC/SYSTEM
764
793
  # ids); serializes in document position. Returns the DocType.
@@ -767,7 +796,49 @@ class Leptris::XML::Document
767
796
  c_ptr, name.to_s, public_id, system_id)
768
797
  raise Leptris::XML::Error, "leptris_document_set_doctype failed" if dt.null?
769
798
  @version += 1
770
- Leptris::XML::DocType.new(dt, self)
799
+ wrap_doctype(dt)
800
+ end
801
+
802
+ # Detached DOCTYPE token (leptris-ruby#459 ask 2): create now,
803
+ # inspect while unattached, attach later via add_child. Nothing is
804
+ # written to the document until the attach.
805
+ def new_doctype(name, public_id: nil, system_id: nil)
806
+ Leptris::XML::DocType.new_detached(self, name.to_s, public_id, system_id)
807
+ end
808
+
809
+ # Attach a detached DOCTYPE token (the two-phase facade contract):
810
+ # routes through the engine's set_doctype and adopts the caller's
811
+ # wrapper, so #doctype hands back the same node identity.
812
+ def add_child(node)
813
+ unless node.is_a?(Leptris::XML::DocType) && !node.attached?
814
+ raise ArgumentError,
815
+ "Document#add_child attaches a detached DocType, got #{node.class}"
816
+ end
817
+ dt = Leptris::XML::FFI.leptris_document_set_doctype(
818
+ c_ptr, node.name, node.public_id, node.system_id)
819
+ raise Leptris::XML::Error, "leptris_document_set_doctype failed" if dt.null?
820
+ @version += 1
821
+ node.attach!(dt)
822
+ (@doctype_wrappers ||= {})[dt.address] = node
823
+ node
824
+ end
825
+
826
+ # Recovered-parse diagnostics (leptris-ruby#465): nokogiri parity
827
+ # for the recover lane — the engine's parse diagnostics as
828
+ # SyntaxError entries, empty for a clean parse. The engine
829
+ # reader carries message + kind; position stays nil until the C
830
+ # face exposes the diag line/column.
831
+ def errors
832
+ count = Leptris::XML::FFI.leptris_document_parse_diag_count(c_ptr)
833
+ return [] if count.zero?
834
+ count.times.map do |i|
835
+ msg_buf = ::FFI::MemoryPointer.new(:char, 512)
836
+ kind_buf = ::FFI::MemoryPointer.new(:int)
837
+ ok = Leptris::XML::FFI.leptris_document_parse_diag(
838
+ c_ptr, i, kind_buf, msg_buf, 512)
839
+ next nil if ok.zero?
840
+ Leptris::XML::SyntaxError.new(msg_buf.read_string.force_encoding(Encoding::UTF_8))
841
+ end.compact
771
842
  end
772
843
 
773
844
  # Un-set the XML declaration (libleptris 1.9.204, upstream
@@ -778,6 +849,7 @@ class Leptris::XML::Document
778
849
  def clear_declaration
779
850
  Leptris::XML::FFI.check_status(
780
851
  Leptris::XML::FFI.leptris_document_clear_declaration(c_ptr))
852
+ @declaration_node = nil
781
853
  @version += 1
782
854
  self
783
855
  end
@@ -643,10 +643,30 @@ class Leptris::XML::Element < Leptris::XML::Node
643
643
  end
644
644
 
645
645
  # Replace this element with +new_node+ in the parent's child list.
646
- # +new_node+ must belong to the same document. Returns +new_node+.
646
+ # +new_node+ is a node belonging to the same document, or markup
647
+ # parsed in this document's context (leptris-ruby#457 — nokogiri
648
+ # parity; multiple top-level nodes splice in order). Returns the
649
+ # replacement node, or a NodeSet when the markup produced several.
647
650
  def replace(new_node)
648
651
  parent = self.parent
649
652
  raise Leptris::XML::Error, "cannot replace a node with no parent" unless parent
653
+ if new_node.is_a?(Leptris::XML::DocumentFragment)
654
+ # DOM Core insert semantics: the fragment itself never enters
655
+ # the tree — its children splice in (the #document-fragment
656
+ # pseudo-node would leak into serialization/XPath/C14N).
657
+ nodes = new_node.children.to_a
658
+ raise Leptris::XML::Error, "replacement fragment produced no nodes" if nodes.empty?
659
+ installed = nodes.reverse_each.map { |n| add_next_sibling(n) }.reverse
660
+ parent.remove_child(self)
661
+ return installed.size == 1 ? installed.first : Leptris::XML::NodeSet.new(@document, installed)
662
+ end
663
+ if new_node.is_a?(String)
664
+ nodes = @document.fragment(new_node).children.to_a
665
+ raise Leptris::XML::Error, "replacement markup produced no nodes" if nodes.empty?
666
+ installed = nodes.reverse_each.map { |n| add_next_sibling(n) }.reverse
667
+ parent.remove_child(self)
668
+ return installed.size == 1 ? installed.first : Leptris::XML::NodeSet.new(@document, installed)
669
+ end
650
670
  add_next_sibling(new_node)
651
671
  parent.remove_child(self)
652
672
  new_node
@@ -14,4 +14,7 @@ class Leptris::XML::EntityReference < Leptris::XML::Node
14
14
  def to_s
15
15
  "&#{name};"
16
16
  end
17
+
18
+ # leptris-ruby#464: entity-reference serialization face.
19
+ alias_method :to_xml, :to_s
17
20
  end
Binary file
@@ -187,6 +187,28 @@ class Leptris::XML::NodeSet
187
187
  end
188
188
  alias_method :text, :inner_text
189
189
 
190
+ # Nokogiri parity (leptris-ruby#455): unlink every member from its
191
+ # tree. Members are materialized first — unlinking mutates the
192
+ # sibling chain the lazy result would otherwise be walked against.
193
+ def remove
194
+ to_a.each(&:unlink)
195
+ self
196
+ end
197
+ alias_method :unlink, :remove
198
+
199
+ # Nokogiri parity (leptris-ruby#456): serialize every member in
200
+ # order and concatenate. Elements and attributes ride #to_xml;
201
+ # text/comment/PI answer #to_s with the same bytes.
202
+ def to_xml
203
+ map do |node|
204
+ if node.is_a?(Leptris::XML::Element) || node.is_a?(Leptris::XML::Attr)
205
+ node.to_xml
206
+ else
207
+ node.to_s
208
+ end
209
+ end.join
210
+ end
211
+
190
212
  # Union semantics: ONE engine call evaluates the expression
191
213
  # against every element member and merges the results into a
192
214
  # de-duplicated, document-ordered nodeset (libleptris 1.9.7,
@@ -54,6 +54,9 @@ class Leptris::XML::ProcessingInstruction < Leptris::XML::Node
54
54
  content.to_s.empty? ? "<?#{name}?>" : "<?#{name} #{content}?>"
55
55
  end
56
56
 
57
+ # leptris-ruby#464: PI serialization face.
58
+ alias_method :to_xml, :to_s
59
+
57
60
  # Document-level PIs have no tree parent for leptris_node_unlink
58
61
  # — route through the document-level removal (libleptris 1.9.9,
59
62
  # #612), identity-matched by index so the right same-target PI
@@ -71,8 +71,13 @@ class Leptris::XML::SAX::Parser
71
71
  @document, dispatched_kinds, string)
72
72
  return self
73
73
  end
74
- if bulk_dispatch?
75
- parse_memory_bulk(string)
74
+ if native_fast?
75
+ rc = Leptris::XML::Native.sax_parse(
76
+ @document, native_kinds_mask, string)
77
+ if rc != 0
78
+ raise Leptris::XML::ParseError,
79
+ "leptris_sax_parse failed (rc=#{rc})"
80
+ end
76
81
  else
77
82
  handler_struct = self.handler_struct
78
83
  rc = Leptris::XML::FFI.leptris_sax_parse(
@@ -85,48 +90,78 @@ class Leptris::XML::SAX::Parser
85
90
  self
86
91
  end
87
92
 
88
- # Bulk transport for many-override handlers: record the whole
89
- # document C-side (~12ms per 250k events), then dispatch through
90
- # the recorder's drain — 250k ffi callback trampolines cost
91
- # ~150ms, so this wins outright for handlers that consume most of
92
- # the event stream (and beats Nokogiri's C extension on the same
93
- # shape). The delivered call shapes are IDENTICAL to the callback
94
- # transport (pairs arrays, arity dispatch, UTF-8, PI-data
95
- # normalization) — the transports are interchangeable to the
96
- # handler.
97
- #
98
- # Transport choice, from the round-XXVI crossover measurements:
99
- # ONE overridden hot kind pays less through the callbacks (the
100
- # engine skips C-side emission for unattached kinds entirely:
101
- # text-only 23ms vs 43ms), while two or more hot kinds win through
102
- # the recorder (start+chars 138 -> 99ms, start+end+chars 167 ->
103
- # 122ms vs Nokogiri's 142ms). The weights are document-shape
104
- # priors — text-heavy documents with tagged structure.
105
- HOT_KIND_WEIGHTS = {
106
- characters: 0.6, start_element: 0.2, end_element: 0.2,
107
- }.freeze
108
- private_constant :HOT_KIND_WEIGHTS
109
- DISPATCH_WEIGHT_THRESHOLD = 0.8
110
- private_constant :DISPATCH_WEIGHT_THRESHOLD
111
-
112
- def parse_memory_bulk(string)
113
- recorder = Leptris::XML::SAX::Recorder.open
93
+ def parse_io(io)
94
+ unless @streaming
95
+ parse_memory(io.read)
96
+ return self
97
+ end
98
+ if native_fast?
99
+ parser = Leptris::XML::Native.sax_parser_create(
100
+ @document, native_kinds_mask)
101
+ if parser.nil?
102
+ raise Leptris::XML::Error, "leptris_sax_parser_create failed"
103
+ end
104
+ begin
105
+ Leptris::XML::Native.sax_parser_set_skip_flags(
106
+ parser, @skip_flags || 0)
107
+ while (chunk = io.read(CHUNK_SIZE))
108
+ rc = Leptris::XML::Native.sax_parser_feed(parser, chunk, false)
109
+ if rc != 0
110
+ raise Leptris::XML::ParseError,
111
+ "leptris_sax_parser_feed failed (rc=#{rc})"
112
+ end
113
+ end
114
+ rc = Leptris::XML::Native.sax_parser_feed(parser, "", true)
115
+ if rc != 0
116
+ raise Leptris::XML::ParseError,
117
+ "leptris_sax_parser_feed (final) failed (rc=#{rc})"
118
+ end
119
+ ensure
120
+ Leptris::XML::Native.sax_parser_free(parser)
121
+ end
122
+ return self
123
+ end
124
+ handler_struct = self.handler_struct
125
+ parser_ptr = Leptris::XML::FFI.leptris_sax_parser_create(
126
+ handler_struct.pointer, nil)
127
+ if parser_ptr.null?
128
+ raise Leptris::XML::Error, "leptris_sax_parser_create failed"
129
+ end
130
+ if @skip_flags
131
+ Leptris::XML::FFI.leptris_sax_parser_set_skip_flags(
132
+ parser_ptr, @skip_flags)
133
+ end
114
134
  begin
115
- rc = recorder.feed(string, final: true)
116
- recorder.dispatch(@document, dispatched_kinds)
135
+ while (chunk = io.read(CHUNK_SIZE))
136
+ rc = Leptris::XML::FFI.leptris_sax_parser_feed(
137
+ parser_ptr, chunk, chunk.bytesize, 0)
138
+ if rc != 0
139
+ raise Leptris::XML::ParseError, "leptris_sax_parser_feed failed (rc=#{rc})"
140
+ end
141
+ end
142
+ # Final flush
143
+ rc = Leptris::XML::FFI.leptris_sax_parser_feed(parser_ptr, "", 0, 1)
117
144
  if rc != 0
118
- raise Leptris::XML::ParseError,
119
- "leptris_sax_parse failed (rc=#{rc})"
145
+ raise Leptris::XML::ParseError, "leptris_sax_parser_feed (final) failed (rc=#{rc})"
120
146
  end
121
147
  ensure
122
- recorder.free
148
+ Leptris::XML::FFI.leptris_sax_parser_free(parser_ptr)
123
149
  end
124
150
  self
125
151
  end
126
152
 
127
- # The handler's overridden-kind map — the same decisions
128
- # build_handler_struct makes, in dispatch form. Memoized with the
129
- # handler struct; document= invalidates both.
153
+ def parse_file(path)
154
+ if @streaming
155
+ File.open(path, "r") { |f| parse_io(f) }
156
+ else
157
+ parse_memory(File.read(path))
158
+ end
159
+ end
160
+
161
+ # The handler's overridden-kind map — memoized with the handler
162
+ # struct; document= invalidates both. The native transport derives
163
+ # its kind bitmask from it; the FFI fallback builds its callback
164
+ # struct from the same decisions.
130
165
  def dispatched_kinds
131
166
  @dispatched_kinds ||= begin
132
167
  kinds = {}
@@ -156,54 +191,43 @@ class Leptris::XML::SAX::Parser
156
191
  end
157
192
  end
158
193
 
159
- def bulk_dispatch?
160
- dispatched_kinds.keys.sum do |kind|
161
- HOT_KIND_WEIGHTS.fetch(kind, 0.0)
162
- end >= DISPATCH_WEIGHT_THRESHOLD
163
- end
194
+ private
164
195
 
165
- def parse_io(io)
166
- unless @streaming
167
- parse_memory(io.read)
168
- return self
169
- end
170
- handler_struct = self.handler_struct
171
- parser_ptr = Leptris::XML::FFI.leptris_sax_parser_create(
172
- handler_struct.pointer, nil)
173
- if parser_ptr.null?
174
- raise Leptris::XML::Error, "leptris_sax_parser_create failed"
175
- Leptris::XML::FFI.leptris_sax_parser_set_skip_flags(
176
- parser_ptr, @skip_flags || 0)
177
- end
178
- begin
179
- while (chunk = io.read(CHUNK_SIZE))
180
- rc = Leptris::XML::FFI.leptris_sax_parser_feed(
181
- parser_ptr, chunk, chunk.bytesize, 0)
182
- if rc != 0
183
- raise Leptris::XML::ParseError, "leptris_sax_parser_feed failed (rc=#{rc})"
184
- end
185
- end
186
- # Final flush
187
- rc = Leptris::XML::FFI.leptris_sax_parser_feed(parser_ptr, "", 0, 1)
188
- if rc != 0
189
- raise Leptris::XML::ParseError, "leptris_sax_parser_feed (final) failed (rc=#{rc})"
190
- end
191
- ensure
192
- Leptris::XML::FFI.leptris_sax_parser_free(parser_ptr)
193
- end
194
- self
196
+ def native_fast?
197
+ defined?(Leptris::XML::NATIVE_FAST)
195
198
  end
196
199
 
197
- def parse_file(path)
198
- if @streaming
199
- File.open(path, "r") { |f| parse_io(f) }
200
- else
201
- parse_memory(File.read(path))
200
+ # The C transport's kind bitmask — the same decisions
201
+ # dispatched_kinds makes, in bit form. start_element's arity picks
202
+ # the 1-arg or 2-arg dispatch; only overridden kinds attach (the
203
+ # engine skips NULL callbacks, so cost scales with declared
204
+ # interest, not with the document's event mix).
205
+ NATIVE_KIND_BITS = {
206
+ start_document: 1 << 0,
207
+ end_document: 1 << 1,
208
+ end_element: 1 << 4,
209
+ characters: 1 << 5,
210
+ comment: 1 << 6,
211
+ cdata: 1 << 7,
212
+ pi: 1 << 8,
213
+ start_prefix: 1 << 9,
214
+ end_prefix: 1 << 10,
215
+ error: 1 << 11,
216
+ }.freeze
217
+ private_constant :NATIVE_KIND_BITS
218
+
219
+ def native_kinds_mask
220
+ mask = 0
221
+ dispatched_kinds.each do |kind, mode|
222
+ if kind == :start_element
223
+ mask |= (mode == :one_arg ? (1 << 2) : (1 << 3))
224
+ else
225
+ mask |= NATIVE_KIND_BITS.fetch(kind, 0)
226
+ end
202
227
  end
228
+ mask
203
229
  end
204
230
 
205
- private
206
-
207
231
  # Build a LeptrisSAXHandler struct populated with FFI::Function callbacks
208
232
  # that dispatch to the Ruby handler. Only the callbacks the handler
209
233
  # actually overrides are attached: the C engine skips NULL callbacks,
@@ -40,4 +40,8 @@ class Leptris::XML::Text < Leptris::XML::Node
40
40
  def to_s
41
41
  Leptris::XML::Serialization.escape_text(content)
42
42
  end
43
+
44
+ # leptris-ruby#464: nokogiri's Node#to_xml exists on every kind —
45
+ # text serializes escaped.
46
+ alias_method :to_xml, :to_s
43
47
  end
data/lib/leptris/xml.rb CHANGED
@@ -16,6 +16,7 @@ module Leptris
16
16
  autoload :DocumentFragment, "leptris/xml/document_fragment"
17
17
  autoload :Builder, "leptris/xml/builder"
18
18
  autoload :DocType, "leptris/xml/doc_type"
19
+ autoload :Declaration, "leptris/xml/declaration"
19
20
  autoload :NodeSet, "leptris/xml/node_set"
20
21
  autoload :Searchable, "leptris/xml/searchable"
21
22
  autoload :ParseOptions, "leptris/xml/parse_options"
@@ -104,6 +105,19 @@ module Leptris
104
105
 
105
106
  class Error < StandardError; end
106
107
  class ParseError < Error; end
108
+ # Recovered-parse diagnostics (leptris-ruby#465): nokogiri's
109
+ # SyntaxError shape — a message plus optional position — served
110
+ # by Document#errors.
111
+ class SyntaxError < Error
112
+ attr_reader :message, :line, :column
113
+
114
+ def initialize(message, line: nil, column: nil)
115
+ @message = message
116
+ @line = line
117
+ @column = column
118
+ super(message)
119
+ end
120
+ end
107
121
  class ReadOnlyError < Error; end
108
122
  class XPathError < Error; end
109
123
  class UseAfterFreeError < Error; end
data/lib/libleptris.so CHANGED
Binary file
data/scripts/gem_smoke.rb CHANGED
@@ -14,10 +14,13 @@ puts "leptris #{Leptris::VERSION} on #{RUBY_PLATFORM} (ruby #{RUBY_VERSION})"
14
14
  doc = Leptris::XML.parse("<r id='1'><a x='2'>t1</a><a>t2</a></r>")
15
15
  raise "parse: root" unless doc.root.name == "r"
16
16
  raise "xpath: children" unless doc.root.xpath("a").size == 2
17
- raise "attr read" unless doc.at_xpath("a")["x"] == "2"
17
+ # //a from DOCUMENT level: document-node context (libxml2/nokogiri
18
+ # semantics, engine 1.9.358+) — doc.at_xpath("a") would correctly be
19
+ # nil (the document's child is r, not a).
20
+ raise "attr read" unless doc.at_xpath("//a")["x"] == "2"
18
21
 
19
- doc.at_xpath("a").content = "z"
20
- raise "mutate" unless doc.at_xpath("a").content == "z"
22
+ doc.at_xpath("//a").content = "z"
23
+ raise "mutate" unless doc.at_xpath("//a").content == "z"
21
24
  raise "serialize" unless doc.to_xml.include?('<a x="2">z</a>')
22
25
 
23
26
  rng = Leptris::XML::RelaxNG.parse(
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.355
4
+ - libleptris v1.9.359
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand: