moxml 0.6.3 → 0.6.5
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.adoc +14 -8
- data/Rakefile +16 -2
- data/benchmark/scoreboard.rb +3 -2
- data/conformance/moxml-conformance.json +214 -2
- data/docs/_pages/conformance.adoc +112 -0
- data/docs/_pages/divergences.adoc +42 -0
- data/docs/_pages/index.adoc +7 -2
- data/docs/_references/processing-model.adoc +7 -0
- data/lib/moxml/adapter/leptris.rb +222 -22
- data/lib/moxml/c14n_cases.rb +38 -0
- data/lib/moxml/context.rb +4 -5
- data/lib/moxml/serialization_cases.rb +42 -0
- data/lib/moxml/version.rb +1 -1
- data/lib/moxml/xsd.rb +436 -2
- data/lib/moxml/xsd_structural_cases.rb +44 -0
- data/lib/moxml.rb +3 -0
- data/spec/consistency/conformance_families_spec.rb +71 -0
- data/spec/consistency/serialization_family_spec.rb +41 -0
- data/spec/moxml/adapter/leptris_children_address_spec.rb +171 -0
- data/spec/moxml/adapter/leptris_spec.rb +0 -6
- data/spec/moxml/adapter/platform_spec.rb +11 -2
- data/spec/moxml/context_spec.rb +9 -1
- data/spec/moxml/xsd_composed_spec.rb +183 -0
- metadata +10 -3
- data/spec/moxml/adapter/leptris_children_columnar_spec.rb +0 -146
|
@@ -31,7 +31,12 @@ module Moxml
|
|
|
31
31
|
# "raise all floors"): the tested pair — every gate below it
|
|
32
32
|
# unwound, and the floor is ENFORCED (the load refuses below it;
|
|
33
33
|
# the README's "older bindings do not load" claim is now true).
|
|
34
|
-
|
|
34
|
+
# Raised 1.9.386.0 -> 1.9.410.0 (2026-11-10, owner directive
|
|
35
|
+
# "update floors"): the namespace-aware strict admission
|
|
36
|
+
# (leptris#1964, 1.9.409) and the schG2 child-typing fix
|
|
37
|
+
# (leptris#1979, 1.9.410) - the XSD conformance answers the
|
|
38
|
+
# dataset and the suite now pin REQUIRE this wave.
|
|
39
|
+
MINIMUM_BINDING_VERSION = "1.9.410.0"
|
|
35
40
|
|
|
36
41
|
# Snapshot-backed attribute listing native (moxml#520): the
|
|
37
42
|
# listing face serves reads from the binding's flat packet face —
|
|
@@ -80,6 +85,28 @@ module Moxml
|
|
|
80
85
|
end
|
|
81
86
|
end
|
|
82
87
|
|
|
88
|
+
# The address-native lane's native (leptris-ruby#587/#589/#591):
|
|
89
|
+
# a node as (binding document, raw C address, parent-reported
|
|
90
|
+
# kind). Plain Ruby — one allocation per node, no TypedData
|
|
91
|
+
# wrap, no binding identity-cache crossing. Reads resolve
|
|
92
|
+
# through the address-keyed C faces; writes bridge through
|
|
93
|
+
# #to_binding (address + document answer the bridge's
|
|
94
|
+
# questions). The per-document token cache (#address_native)
|
|
95
|
+
# hands the SAME token back per address while the document is
|
|
96
|
+
# unmutated, so wrapper identity rides the context registry
|
|
97
|
+
# unchanged. +kind+ is the children_addrs integer (0 element,
|
|
98
|
+
# 1 text, 2 comment, 3 cdata, 4 pi) — VISIT_NODE_TYPES'
|
|
99
|
+
# order.
|
|
100
|
+
class AddressNode
|
|
101
|
+
attr_reader :document, :address, :kind
|
|
102
|
+
|
|
103
|
+
def initialize(document, address, kind)
|
|
104
|
+
@document = document
|
|
105
|
+
@address = address
|
|
106
|
+
@kind = kind
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
83
110
|
if Gem::Version.new(::Leptris::VERSION.to_s) <
|
|
84
111
|
Gem::Version.new(MINIMUM_BINDING_VERSION)
|
|
85
112
|
raise Moxml::AdapterError.new(
|
|
@@ -96,12 +123,10 @@ module Moxml
|
|
|
96
123
|
# Attribute-node xpath results carry proper wrappers since
|
|
97
124
|
# 1.9.105 (leptris-ruby#153: ResultAttr with name/value);
|
|
98
125
|
# before that the native gate routed them to the Ruby engine.
|
|
99
|
-
ATTR_RESULT_NATIVE = true
|
|
100
126
|
|
|
101
127
|
# leptris_node_digest shipped in bindings 1.9.99 (libleptris
|
|
102
128
|
# 1.9.99, engine #869): on-demand Merkle subtree hash, zero
|
|
103
129
|
# cost when unused. Below it, Node#digest answers nil.
|
|
104
|
-
DIGEST_SUPPORTED = true
|
|
105
130
|
|
|
106
131
|
# 1.9.163.7 added the XPath seams (TODO.perf/15+16):
|
|
107
132
|
# Searchable#at_xpath materializes nodeset entry 0 and frees
|
|
@@ -186,6 +211,20 @@ module Moxml
|
|
|
186
211
|
defined?(::Leptris::XML::Native) &&
|
|
187
212
|
::Leptris::XML::Native.respond_to?(:walk_columnar)
|
|
188
213
|
|
|
214
|
+
# The address-keyed shadow faces (leptris-ruby#587/#589/#591):
|
|
215
|
+
# children_addrs(parent) => [addrs, kinds] accepts a raw
|
|
216
|
+
# address Integer, and the fast_* read faces (name, element
|
|
217
|
+
# text, comment/cdata/pi payloads) read by address. The
|
|
218
|
+
# address-native lane mints a plain AddressNode per node
|
|
219
|
+
# instead of the TypedData wrap + identity-cache crossing the
|
|
220
|
+
# columnar lane pays in C. Face-probed, not version-gated.
|
|
221
|
+
ADDRESS_NATIVE =
|
|
222
|
+
defined?(::Leptris::XML::Native) &&
|
|
223
|
+
::Leptris::XML::Native.respond_to?(:children_addrs) &&
|
|
224
|
+
::Leptris::XML::Native.respond_to?(:walk_addresses) &&
|
|
225
|
+
::Leptris::XML::Native.respond_to?(:fast_name) &&
|
|
226
|
+
::Leptris::XML::Native.respond_to?(:fast_text_content)
|
|
227
|
+
|
|
189
228
|
# 1.9.163.2's native layer returns UTF-8, unfrozen strings
|
|
190
229
|
# (1.9.162.x answered ASCII-8BIT — the reads retagged with a
|
|
191
230
|
# dup+force_encoding per call).
|
|
@@ -240,7 +279,6 @@ module Moxml
|
|
|
240
279
|
# 1.9.181 (lockstep): Node#source_position — {line, col_start,
|
|
241
280
|
# col_end} from the engine's source-position API (upstream
|
|
242
281
|
# #1124); created nodes report zeros.
|
|
243
|
-
NATIVE_SOURCE_POSITION = true
|
|
244
282
|
|
|
245
283
|
# Entity-reference preservation (leptris-ruby#212 / upstream
|
|
246
284
|
# #1094): 1.9.177 ships ParseOptions.keep_entity_refs plus
|
|
@@ -268,7 +306,6 @@ module Moxml
|
|
|
268
306
|
# so the gate names the first release where the drain is
|
|
269
307
|
# CORRECT, not merely present. Dev floor pins ~> 1.9.238;
|
|
270
308
|
# older bindings take the callback Parser below.
|
|
271
|
-
NATIVE_SAX_RECORDS = true
|
|
272
309
|
|
|
273
310
|
# Document#absorb (engine #1548): one call transfers a source
|
|
274
311
|
# document's pool ownership into the destination, so
|
|
@@ -429,7 +466,7 @@ module Moxml
|
|
|
429
466
|
native_bulk_fixed: !NATIVE_BULK_FIXED.nil?,
|
|
430
467
|
native_plan_structs: NATIVE_PLAN_STRUCTS,
|
|
431
468
|
native_plan_typed: NATIVE_PLAN_TYPED,
|
|
432
|
-
digest:
|
|
469
|
+
digest: engine_serves?(:digest),
|
|
433
470
|
xsd: XSD_SUPPORTED && engine_serves?(:xsd),
|
|
434
471
|
relaxng: RELAXNG_SUPPORTED && engine_serves?(:relaxng),
|
|
435
472
|
xslt: XSLT_SUPPORTED && engine_serves?(:xslt),
|
|
@@ -664,12 +701,13 @@ module Moxml
|
|
|
664
701
|
|
|
665
702
|
def to_binding(node)
|
|
666
703
|
return node unless NATIVE_READ_LAYER &&
|
|
667
|
-
node.is_a?(::Leptris::XML::NativeNode)
|
|
704
|
+
(node.is_a?(::Leptris::XML::NativeNode) ||
|
|
705
|
+
node.is_a?(AddressNode))
|
|
668
706
|
|
|
669
707
|
bridged = @binding_of[node]
|
|
670
708
|
return bridged if bridged
|
|
671
709
|
|
|
672
|
-
doc = doc_for(node)
|
|
710
|
+
doc = node.is_a?(AddressNode) ? node.document : doc_for(node)
|
|
673
711
|
ptr = ::FFI::Pointer.new(node.address)
|
|
674
712
|
bridged = ::Leptris::XML::Node.wrap(ptr, doc)
|
|
675
713
|
@binding_of = fresh_node_registry if @binding_of.size >= BINDING_OF_CAP
|
|
@@ -918,6 +956,15 @@ module Moxml
|
|
|
918
956
|
# already-minted wrappers, so the adapter crossing
|
|
919
957
|
# (bind_call + to_a + keep-refs probe) drops out, and
|
|
920
958
|
# entity-marker documents take super for the split.
|
|
959
|
+
# NOTE (address-lane verdict, #531): the token arm was
|
|
960
|
+
# tried HERE and measured — tokens cannot serve the
|
|
961
|
+
# wrapper walk without breaking the klass-propagating
|
|
962
|
+
# identity contract (children vs element_children mint
|
|
963
|
+
# different wrapper classes for the same C node) and the
|
|
964
|
+
# wrapper lifecycle (tokens pin the binding document, so
|
|
965
|
+
# dropped documents stop releasing wrappers). The C-side
|
|
966
|
+
# klass-injected native cache is the walk lane; the
|
|
967
|
+
# address faces serve direct adapter consumers.
|
|
921
968
|
if NN.method_defined?(:children_read)
|
|
922
969
|
module ChildReads
|
|
923
970
|
def children
|
|
@@ -1093,8 +1140,10 @@ module Moxml
|
|
|
1093
1140
|
end
|
|
1094
1141
|
|
|
1095
1142
|
if NATIVE_READ_LAYER
|
|
1096
|
-
native_one = one.is_a?(::Leptris::XML::NativeNode)
|
|
1097
|
-
|
|
1143
|
+
native_one = one.is_a?(::Leptris::XML::NativeNode) ||
|
|
1144
|
+
one.is_a?(AddressNode)
|
|
1145
|
+
native_other = other.is_a?(::Leptris::XML::NativeNode) ||
|
|
1146
|
+
other.is_a?(AddressNode)
|
|
1098
1147
|
if native_one || native_other
|
|
1099
1148
|
address_one = native_one ? one.address : one.c_ptr.address
|
|
1100
1149
|
address_other = native_other ? other.address : other.c_ptr.address
|
|
@@ -1109,6 +1158,9 @@ module Moxml
|
|
|
1109
1158
|
# to the root (C-bound reads) and look the doc up in the
|
|
1110
1159
|
# root registry. Detached subtrees answer nil.
|
|
1111
1160
|
def doc_for(node)
|
|
1161
|
+
# Address tokens carry their document (set at mint).
|
|
1162
|
+
return node.document if node.is_a?(AddressNode)
|
|
1163
|
+
|
|
1112
1164
|
# The 1.9.163.5 native layer exposes the owning document
|
|
1113
1165
|
# directly; the root climb serves older bindings.
|
|
1114
1166
|
return NN_DOCUMENT.bind_call(node) if NATIVE_MUTATIONS_COHERENT
|
|
@@ -1572,8 +1624,13 @@ module Moxml
|
|
|
1572
1624
|
def bare_attr_value(element, name)
|
|
1573
1625
|
# Exact-name C read: bare names target no-namespace
|
|
1574
1626
|
# attributes (the documented contract — a bare "y" never
|
|
1575
|
-
# resolves a "p:y" sibling).
|
|
1576
|
-
|
|
1627
|
+
# resolves a "p:y" sibling). Address tokens take the
|
|
1628
|
+
# address-keyed attribute face.
|
|
1629
|
+
value = if element.is_a?(AddressNode)
|
|
1630
|
+
::Leptris::XML::Native.fast_attribute(
|
|
1631
|
+
element.address, name.to_s
|
|
1632
|
+
)
|
|
1633
|
+
elsif NATIVE_READ_LAYER && element.is_a?(NN)
|
|
1577
1634
|
NN_ATTRIBUTE.bind_call(element, name.to_s)
|
|
1578
1635
|
else
|
|
1579
1636
|
element[name.to_s]
|
|
@@ -2326,7 +2383,10 @@ module Moxml
|
|
|
2326
2383
|
end
|
|
2327
2384
|
|
|
2328
2385
|
def processing_instruction_target(node)
|
|
2329
|
-
|
|
2386
|
+
if NATIVE_READ_LAYER &&
|
|
2387
|
+
(node.is_a?(NN) || node.is_a?(AddressNode))
|
|
2388
|
+
return to_binding(node).target
|
|
2389
|
+
end
|
|
2330
2390
|
|
|
2331
2391
|
node.target
|
|
2332
2392
|
end
|
|
@@ -2344,6 +2404,12 @@ module Moxml
|
|
|
2344
2404
|
# complete on the snapshot itself.
|
|
2345
2405
|
return :attribute if node.is_a?(SnapshotAttribute)
|
|
2346
2406
|
|
|
2407
|
+
# Address tokens carry the parent-reported WS kind.
|
|
2408
|
+
if node.is_a?(AddressNode)
|
|
2409
|
+
mapped = VISIT_NODE_TYPES[node.kind]
|
|
2410
|
+
return mapped if mapped
|
|
2411
|
+
end
|
|
2412
|
+
|
|
2347
2413
|
if node.is_a?(::Leptris::XML::Node) &&
|
|
2348
2414
|
node.instance_variable_defined?(:@node_type)
|
|
2349
2415
|
kind = node.instance_variable_get(:@node_type)
|
|
@@ -2388,8 +2454,9 @@ module Moxml
|
|
|
2388
2454
|
# wrappers (declarations, doctypes, entity markers) and the
|
|
2389
2455
|
# lightweight Attr triples answer nil.
|
|
2390
2456
|
def digest(node, drop_ws_text: false)
|
|
2391
|
-
|
|
2392
|
-
|
|
2457
|
+
if NATIVE_READ_LAYER &&
|
|
2458
|
+
(node.is_a?(::Leptris::XML::NativeNode) ||
|
|
2459
|
+
node.is_a?(AddressNode))
|
|
2393
2460
|
return to_binding(node).digest(drop_ws: drop_ws_text)
|
|
2394
2461
|
end
|
|
2395
2462
|
return nil unless node.is_a?(::Leptris::XML::Node) &&
|
|
@@ -2401,6 +2468,18 @@ module Moxml
|
|
|
2401
2468
|
def node_name(node)
|
|
2402
2469
|
return node.root_name if node.is_a?(::Leptris::XML::DocType)
|
|
2403
2470
|
|
|
2471
|
+
# Address tokens: the fast_name face is element-only (nil
|
|
2472
|
+
# otherwise); PIs answer their target.
|
|
2473
|
+
if node.is_a?(AddressNode)
|
|
2474
|
+
if node.kind == 4
|
|
2475
|
+
return ::Leptris::XML::Native.fast_pi_target(
|
|
2476
|
+
node.address,
|
|
2477
|
+
).to_s
|
|
2478
|
+
end
|
|
2479
|
+
|
|
2480
|
+
return ::Leptris::XML::Native.fast_name(node.address).to_s
|
|
2481
|
+
end
|
|
2482
|
+
|
|
2404
2483
|
if NATIVE_READ_LAYER && node.is_a?(::Leptris::XML::NativeNode)
|
|
2405
2484
|
# PIs expose no name through the native layer.
|
|
2406
2485
|
return to_binding(node).target.to_s if NN_NODE_TYPE.bind_call(node) == :pi
|
|
@@ -2475,7 +2554,30 @@ module Moxml
|
|
|
2475
2554
|
return to_binding(node).children.to_a
|
|
2476
2555
|
end
|
|
2477
2556
|
|
|
2557
|
+
# Address tokens: element receivers take the token arm;
|
|
2558
|
+
# terminal kinds answer [] through the case chain below.
|
|
2559
|
+
if NATIVE_READ_LAYER && node.is_a?(AddressNode)
|
|
2560
|
+
doc = node.document
|
|
2561
|
+
return address_children(doc, node) if doc && node.kind.zero?
|
|
2562
|
+
|
|
2563
|
+
return []
|
|
2564
|
+
end
|
|
2565
|
+
|
|
2478
2566
|
if NATIVE_READ_LAYER && node.is_a?(::Leptris::XML::NativeNode)
|
|
2567
|
+
# The address-native arm outranks the columnar lane: the
|
|
2568
|
+
# same child lists, but the tokens are plain
|
|
2569
|
+
# (document, address, kind) AddressNodes — the columnar
|
|
2570
|
+
# crossing mints a TypedData wrap + identity-cache write
|
|
2571
|
+
# per node in C, this arm allocates one plain token per
|
|
2572
|
+
# node in Ruby (ADDRESS_NATIVE above). Element receivers
|
|
2573
|
+
# only: their children's kinds are the WS enum the token
|
|
2574
|
+
# carries; document receivers keep the assembly path
|
|
2575
|
+
# (declaration/doctype kinds are outside the enum).
|
|
2576
|
+
if ADDRESS_NATIVE && !entity_bearing && element_native?(node)
|
|
2577
|
+
doc = doc_for(node)
|
|
2578
|
+
return address_children(doc, node) if doc
|
|
2579
|
+
end
|
|
2580
|
+
|
|
2479
2581
|
# Bulk C children through moxml's own scratch (see
|
|
2480
2582
|
# NATIVE_READ_LAYER note above). Entity-marker documents
|
|
2481
2583
|
# bridge each child for the marker split — the
|
|
@@ -2539,15 +2641,67 @@ module Moxml
|
|
|
2539
2641
|
CustomizedLeptris::EntityReference, CustomizedLeptris::TextSegment,
|
|
2540
2642
|
# Terminal node kinds pay an FFI round trip for an empty
|
|
2541
2643
|
# list; unfiltered recursions visit every text node.
|
|
2644
|
+
# Address tokens of the terminal kinds (text, comment,
|
|
2645
|
+
# cdata, pi) have no children either.
|
|
2542
2646
|
::Leptris::XML::Text, ::Leptris::XML::Comment,
|
|
2543
2647
|
::Leptris::XML::CDATA, ::Leptris::XML::ProcessingInstruction,
|
|
2544
|
-
::Leptris::XML::Attr
|
|
2648
|
+
::Leptris::XML::Attr, AddressNode
|
|
2545
2649
|
[]
|
|
2546
2650
|
else
|
|
2547
2651
|
node.children.to_a
|
|
2548
2652
|
end
|
|
2549
2653
|
end
|
|
2550
2654
|
|
|
2655
|
+
# The address-native arm's child list: one children_addrs
|
|
2656
|
+
# crossing, one token per child (ADDRESS_NATIVES cache for
|
|
2657
|
+
# identity stability).
|
|
2658
|
+
ADDRESS_NATIVES = :address_natives
|
|
2659
|
+
|
|
2660
|
+
def address_children(doc, node)
|
|
2661
|
+
addrs, kinds = ::Leptris::XML::Native.children_addrs(
|
|
2662
|
+
node.is_a?(AddressNode) ? node.address : node,
|
|
2663
|
+
)
|
|
2664
|
+
children = Array.new(addrs.size)
|
|
2665
|
+
i = 0
|
|
2666
|
+
while i < addrs.size
|
|
2667
|
+
children[i] = address_native(doc, addrs[i], kinds[i])
|
|
2668
|
+
i += 1
|
|
2669
|
+
end
|
|
2670
|
+
children
|
|
2671
|
+
end
|
|
2672
|
+
|
|
2673
|
+
# One address token per (document version, address): the
|
|
2674
|
+
# context registry keys wrapper identity on the token, so a
|
|
2675
|
+
# stable token per address keeps the children[0].equal?
|
|
2676
|
+
# semantics across traversals. The document version stamps
|
|
2677
|
+
# the map — any mutation invalidates wholesale, the same
|
|
2678
|
+
# discipline as the columnar map and the binding's own
|
|
2679
|
+
# children memo.
|
|
2680
|
+
ADDRESS_NATIVES_CAP = 1_048_576
|
|
2681
|
+
|
|
2682
|
+
def address_native(doc, address, kind)
|
|
2683
|
+
pair = attachments.get(doc, ADDRESS_NATIVES)
|
|
2684
|
+
unless pair.is_a?(Array) && pair[0] == doc.version
|
|
2685
|
+
pair = [doc.version, {}]
|
|
2686
|
+
attachments.set(doc, ADDRESS_NATIVES, pair)
|
|
2687
|
+
end
|
|
2688
|
+
map = pair[1]
|
|
2689
|
+
map.clear if map.size >= ADDRESS_NATIVES_CAP
|
|
2690
|
+
token = map[address]
|
|
2691
|
+
return token if token
|
|
2692
|
+
|
|
2693
|
+
token = AddressNode.new(doc, address, kind)
|
|
2694
|
+
map[address] = token
|
|
2695
|
+
token
|
|
2696
|
+
end
|
|
2697
|
+
|
|
2698
|
+
# Element-ness of a native receiver, for the address arm's
|
|
2699
|
+
# gate (one kind read; the token lane answers from the
|
|
2700
|
+
# parent-reported kind without a crossing).
|
|
2701
|
+
def element_native?(node)
|
|
2702
|
+
NN_NODE_TYPE.bind_call(node) == :element
|
|
2703
|
+
end
|
|
2704
|
+
|
|
2551
2705
|
# Map hit for a primed node (see COLUMNAR_WALK). Served dup'd so
|
|
2552
2706
|
# no consumer can mutate the cached list in place.
|
|
2553
2707
|
def columnar_children_hit(node)
|
|
@@ -2737,6 +2891,24 @@ module Moxml
|
|
|
2737
2891
|
def root_parent(node)
|
|
2738
2892
|
return node.document if node.is_a?(::Leptris::XML::DocType)
|
|
2739
2893
|
|
|
2894
|
+
# Address tokens carry no parent face: bridge once, then
|
|
2895
|
+
# answer through the binding parent — as a document-cache
|
|
2896
|
+
# twin so the answer stays in the native representation.
|
|
2897
|
+
# The binding reports the root element and document-level
|
|
2898
|
+
# parts parentless; the moxml contract roots them at the
|
|
2899
|
+
# document (same rule as the binding arm below).
|
|
2900
|
+
if node.is_a?(AddressNode)
|
|
2901
|
+
doc = node.document
|
|
2902
|
+
bound = to_binding(node)
|
|
2903
|
+
parent = bound&.parent
|
|
2904
|
+
return native_twin(doc, parent) if parent
|
|
2905
|
+
|
|
2906
|
+
return doc if doc && (doc.root&.c_address == node.address ||
|
|
2907
|
+
bound.is_a?(::Leptris::XML::ProcessingInstruction))
|
|
2908
|
+
|
|
2909
|
+
return nil
|
|
2910
|
+
end
|
|
2911
|
+
|
|
2740
2912
|
parent = node.parent
|
|
2741
2913
|
return parent if parent
|
|
2742
2914
|
|
|
@@ -2750,6 +2922,8 @@ module Moxml
|
|
|
2750
2922
|
end
|
|
2751
2923
|
|
|
2752
2924
|
def next_sibling(node)
|
|
2925
|
+
return next_sibling(to_binding(node)) if node.is_a?(AddressNode)
|
|
2926
|
+
|
|
2753
2927
|
return NN_NEXT_SIBLING.bind_call(node) if NATIVE_READ_LAYER &&
|
|
2754
2928
|
node.is_a?(::Leptris::XML::NativeNode)
|
|
2755
2929
|
|
|
@@ -2766,6 +2940,8 @@ module Moxml
|
|
|
2766
2940
|
end
|
|
2767
2941
|
|
|
2768
2942
|
def document(node)
|
|
2943
|
+
return node.document if node.is_a?(AddressNode)
|
|
2944
|
+
|
|
2769
2945
|
return doc_for(node) if NATIVE_READ_LAYER &&
|
|
2770
2946
|
node.is_a?(::Leptris::XML::NativeNode)
|
|
2771
2947
|
|
|
@@ -2792,8 +2968,6 @@ module Moxml
|
|
|
2792
2968
|
end
|
|
2793
2969
|
|
|
2794
2970
|
def source_position(node)
|
|
2795
|
-
return nil unless NATIVE_SOURCE_POSITION
|
|
2796
|
-
|
|
2797
2971
|
to_binding(node).source_position
|
|
2798
2972
|
end
|
|
2799
2973
|
|
|
@@ -2919,7 +3093,9 @@ module Moxml
|
|
|
2919
3093
|
end
|
|
2920
3094
|
|
|
2921
3095
|
def attr_packet_target(element)
|
|
2922
|
-
if
|
|
3096
|
+
if element.is_a?(AddressNode)
|
|
3097
|
+
[element.document, element.address]
|
|
3098
|
+
elsif NATIVE_READ_LAYER && element.is_a?(NN)
|
|
2923
3099
|
[NN_DOCUMENT.bind_call(element), element.address]
|
|
2924
3100
|
elsif element.respond_to?(:c_address)
|
|
2925
3101
|
[element.document, element.c_address]
|
|
@@ -3738,6 +3914,22 @@ module Moxml
|
|
|
3738
3914
|
end
|
|
3739
3915
|
|
|
3740
3916
|
def text_content(node)
|
|
3917
|
+
# Address tokens dispatch the same kind table the native
|
|
3918
|
+
# layer's #content uses (elements aggregate via
|
|
3919
|
+
# fast_element_text; text/comment/cdata/pi carry their
|
|
3920
|
+
# payload faces).
|
|
3921
|
+
if node.is_a?(AddressNode)
|
|
3922
|
+
native = ::Leptris::XML::Native
|
|
3923
|
+
content = case node.kind
|
|
3924
|
+
when 0 then native.fast_element_text(node.address)
|
|
3925
|
+
when 1 then native.fast_text_content(node.address)
|
|
3926
|
+
when 2 then native.fast_comment_content(node.address)
|
|
3927
|
+
when 3 then native.fast_cdata_content(node.address)
|
|
3928
|
+
when 4 then native.fast_pi_data(node.address)
|
|
3929
|
+
end
|
|
3930
|
+
return content.to_s
|
|
3931
|
+
end
|
|
3932
|
+
|
|
3741
3933
|
if NATIVE_READ_LAYER && node.is_a?(::Leptris::XML::NativeNode)
|
|
3742
3934
|
content = NN_CONTENT.bind_call(node)
|
|
3743
3935
|
return content if NATIVE_STRINGS_UTF8
|
|
@@ -3833,6 +4025,10 @@ module Moxml
|
|
|
3833
4025
|
end
|
|
3834
4026
|
|
|
3835
4027
|
def cdata_content(node)
|
|
4028
|
+
if node.is_a?(AddressNode)
|
|
4029
|
+
return ::Leptris::XML::Native.fast_cdata_content(node.address)
|
|
4030
|
+
end
|
|
4031
|
+
|
|
3836
4032
|
return NN_CONTENT.bind_call(node) if NATIVE_READ_LAYER && node.is_a?(NN)
|
|
3837
4033
|
|
|
3838
4034
|
node.content
|
|
@@ -3844,6 +4040,10 @@ module Moxml
|
|
|
3844
4040
|
end
|
|
3845
4041
|
|
|
3846
4042
|
def comment_content(node)
|
|
4043
|
+
if node.is_a?(AddressNode)
|
|
4044
|
+
return ::Leptris::XML::Native.fast_comment_content(node.address)
|
|
4045
|
+
end
|
|
4046
|
+
|
|
3847
4047
|
if NATIVE_READ_LAYER && node.is_a?(NN)
|
|
3848
4048
|
content = NN_CONTENT.bind_call(node)
|
|
3849
4049
|
# NativeNode#content answers nil for comment-kind nodes
|
|
@@ -4220,7 +4420,7 @@ module Moxml
|
|
|
4220
4420
|
# (leptris-ruby#153: ResultAttr wrappers with name/value);
|
|
4221
4421
|
# older bindings returned generic Node wrappers whose
|
|
4222
4422
|
# #name raised, so the Ruby engine owned them.
|
|
4223
|
-
next true if selects_attribute_results?(ast)
|
|
4423
|
+
next true if selects_attribute_results?(ast)
|
|
4224
4424
|
|
|
4225
4425
|
!selects_attribute_results?(ast)
|
|
4226
4426
|
end
|
|
@@ -4331,14 +4531,14 @@ module Moxml
|
|
|
4331
4531
|
def sax_parse(xml, handler)
|
|
4332
4532
|
bridge = LeptrisSAXBridge.new(handler)
|
|
4333
4533
|
xml_string = xml.is_a?(IO) || xml.is_a?(::StringIO) ? xml.read : xml.to_s
|
|
4334
|
-
# Bulk record drain (leptris#1298
|
|
4534
|
+
# Bulk record drain (leptris#1298):
|
|
4335
4535
|
# one crossing per document. The handler decides the shape
|
|
4336
4536
|
# polymorphically — Handler#on_sax_records answers
|
|
4337
4537
|
# :unhandled, so classic handlers get the exact callback
|
|
4338
4538
|
# stream replayed from the table; hot loops override and
|
|
4339
4539
|
# walk the records (nil table = outside the drain subset
|
|
4340
4540
|
# or pre-1.9.238 binding — callback path).
|
|
4341
|
-
table =
|
|
4541
|
+
table = ::Leptris::XML::SAX::Records.open(xml_string)
|
|
4342
4542
|
if table
|
|
4343
4543
|
begin
|
|
4344
4544
|
return if handler.on_sax_records(table) != :unhandled
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Moxml
|
|
4
|
+
# The c14n conformance family (#490 item 8, family 6): canonical
|
|
5
|
+
# C14N 1.0 vectors (comments dropped — the default digest shape).
|
|
6
|
+
# Every row canonicalizes to IDENTICAL bytes on all seven adapters
|
|
7
|
+
# (the Ruby reference and the leptris native delegation are pinned
|
|
8
|
+
# byte-for-byte by the c14n suite). Consumed by
|
|
9
|
+
# `rake conformance:export` and the cross-language runners.
|
|
10
|
+
module C14nCases
|
|
11
|
+
CONFORMANCE_CASES = [
|
|
12
|
+
["attr-order", '<r b="2" a="1"/>', '<r a="1" b="2"></r>'],
|
|
13
|
+
["ns-rewrite",
|
|
14
|
+
'<n:r xmlns:n="urn:n" xmlns:m="urn:m"><n:a m:k="v"/></n:r>',
|
|
15
|
+
'<n:r xmlns:m="urn:m" xmlns:n="urn:n"><n:a m:k="v"></n:a></n:r>'],
|
|
16
|
+
["ns-hoist", '<r xmlns="urn:x"><a xmlns="urn:y"/></r>',
|
|
17
|
+
'<r xmlns="urn:x"><a xmlns="urn:y"></a></r>'],
|
|
18
|
+
["text-escape", "<r>1 < 2 & 3</r>", "<r>1 < 2 & 3</r>"],
|
|
19
|
+
["cdata-to-text", "<r><![CDATA[raw data]]><b/></r>",
|
|
20
|
+
"<r>raw data<b></b></r>"],
|
|
21
|
+
["comment-dropped", "<r><!--gone--><a/></r>", "<r><a></a></r>"],
|
|
22
|
+
["pi-kept", "<r><?pi data?><a/></r>", "<r><?pi data?><a></a></r>"],
|
|
23
|
+
["entity-expanded", "<r>a<b&c</r>", "<r>a<b&c</r>"],
|
|
24
|
+
["empty-elements", "<r><a/><b></b></r>", "<r><a></a><b></b></r>"],
|
|
25
|
+
["whitespace-preserved", "<r> x <a/> y </r>",
|
|
26
|
+
"<r> x <a></a> y </r>"],
|
|
27
|
+
["attr-quote-norm", '<r a=\'single "double"\'/>',
|
|
28
|
+
'<r a="single "double""></r>'],
|
|
29
|
+
["utf8-high", "<r>café — naïve</r>", "<r>café — naïve</r>"],
|
|
30
|
+
["nested-ns-default",
|
|
31
|
+
'<r xmlns="urn:a"><c:b xmlns:c="urn:c"><d xmlns="urn:d"/></c:b></r>',
|
|
32
|
+
'<r xmlns="urn:a"><c:b xmlns:c="urn:c"><d xmlns="urn:d"></d></c:b></r>'],
|
|
33
|
+
["mixed-attrs-ns",
|
|
34
|
+
'<r xmlns:p="urn:p" p:a="1" b="2" xmlns:q="urn:q" q:c="3"/>',
|
|
35
|
+
'<r xmlns:p="urn:p" xmlns:q="urn:q" b="2" p:a="1" q:c="3"></r>'],
|
|
36
|
+
].map(&:freeze).freeze
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/moxml/context.rb
CHANGED
|
@@ -237,14 +237,13 @@ module Moxml
|
|
|
237
237
|
# Compile an XSD schema from a file path — <xs:include href>
|
|
238
238
|
# resolves relative to the file's directory (the engine
|
|
239
239
|
# resolves it; reading the file into #xsd would lose that).
|
|
240
|
-
# The
|
|
241
|
-
#
|
|
242
|
-
#
|
|
243
|
-
# engine-validated and the index can only under-report.
|
|
240
|
+
# The path is kept on the Schema (moxml#522): #validate resolves
|
|
241
|
+
# the instance's xsi:schemaLocation hints against it and unions
|
|
242
|
+
# the hinted documents into the compiled set.
|
|
244
243
|
def xsd_file(path)
|
|
245
244
|
handle = config.adapter.xsd_compile_file(path.to_s)
|
|
246
245
|
source = File.read(path.to_s)
|
|
247
|
-
Moxml::XSD::Schema.new(handle, self, source)
|
|
246
|
+
Moxml::XSD::Schema.new(handle, self, source, path: path.to_s)
|
|
248
247
|
end
|
|
249
248
|
|
|
250
249
|
# Compile a SET of schema documents (paths) into one schema:
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Moxml
|
|
4
|
+
# The serialization conformance family (#490 item 8, family 5): the
|
|
5
|
+
# committed element-level serialization answers, one row per shape.
|
|
6
|
+
# Each row's output is the round-trip-correct form — admitted only
|
|
7
|
+
# after parse -> serialize -> parse -> serialize byte-equality on
|
|
8
|
+
# both primary engines. Comparison basis: `doc.root.to_xml(indent: 0)`
|
|
9
|
+
# (element level; the document face carries adapter-divergent
|
|
10
|
+
# trailing newlines). Consumed by `rake conformance:export` and the
|
|
11
|
+
# cross-language runners; rows are the model's answers, so a runner
|
|
12
|
+
# mismatch is a finding, not a data question.
|
|
13
|
+
module SerializationCases
|
|
14
|
+
CONFORMANCE_CASES = [
|
|
15
|
+
["empty-root", "<r/>", "<r></r>"],
|
|
16
|
+
["simple-text", "<r>x</r>", "<r>x</r>"],
|
|
17
|
+
["attr-amp", "<r a=\"x & y\"/>", "<r a=\"x & y\"></r>"],
|
|
18
|
+
["attr-lt", "<r a=\"1 < 2\"/>", "<r a=\"1 < 2\"></r>"],
|
|
19
|
+
["attr-quote", "<r a='say \"hi\"'/>",
|
|
20
|
+
"<r a=\"say "hi"\"></r>"],
|
|
21
|
+
["text-escape", "<r>1 < 2 & 3</r>", "<r>1 < 2 & 3</r>"],
|
|
22
|
+
["text-gt", "<r>1 > 2</r>", "<r>1 > 2</r>"],
|
|
23
|
+
["cdata", "<r><![CDATA[a]]><b/></r>",
|
|
24
|
+
"<r><![CDATA[a]]><b></b></r>"],
|
|
25
|
+
["comment", "<r><!--c--></r>", "<r><!--c--></r>"],
|
|
26
|
+
["pi", "<r><?pi data?></r>", "<r><?pi data?></r>"],
|
|
27
|
+
["namespace-default", "<r xmlns=\"urn:x\"><a/></r>",
|
|
28
|
+
"<r xmlns=\"urn:x\"><a></a></r>"],
|
|
29
|
+
["namespace-prefixed-attr", "<r xmlns:p=\"urn:p\" p:a=\"1\"/>",
|
|
30
|
+
"<r xmlns:p=\"urn:p\" p:a=\"1\"></r>"],
|
|
31
|
+
["mixed-content", "<r>a<b/>c</r>", "<r>a<b></b>c</r>"],
|
|
32
|
+
["attr-newline", "<r a=\"x y\"/>", "<r a=\"x y\"></r>"],
|
|
33
|
+
["crlf-text", "<r>a\r\nb</r>", "<r>a\nb</r>"],
|
|
34
|
+
["combo", "<r a='1'>t&t</r>", "<r a=\"1\">t&t</r>"],
|
|
35
|
+
["nested-empty", "<r><a><b/></a></r>",
|
|
36
|
+
"<r><a><b></b></a></r>"],
|
|
37
|
+
["text-apos", "<r>it's</r>", "<r>it's</r>"],
|
|
38
|
+
["numeric-ref", "<r>Aé</r>", "<r>Aé</r>"],
|
|
39
|
+
["high-codepoint-attr", "<r a=\"é\"/>", "<r a=\"é\"></r>"],
|
|
40
|
+
].map(&:freeze).freeze
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/moxml/version.rb
CHANGED