feat(relaxng): compact name-class subtraction (* - name)
The compact-syntax name class * - nameClass now parses as anyName except the subtracted class (the model already had anyNameExcept). ns:* - name would need an nsName-except model case and is left as a refinement. Part of #79
This commit is contained in:
parent
ab4a8661f5
commit
3887b33e4e
@ -308,6 +308,11 @@ private extension RNCParser {
|
||||
switch peek() {
|
||||
case .symbol("*"):
|
||||
advance()
|
||||
// `* - nameClass` is any name except the subtracted class.
|
||||
if peek() == .symbol("-") {
|
||||
advance()
|
||||
return .anyNameExcept(parseSimpleNameClass(attribute: attribute))
|
||||
}
|
||||
return .anyName
|
||||
case .symbol("("):
|
||||
advance()
|
||||
|
||||
22
Tests/RelaxNGNameClassTests.swift
Normal file
22
Tests/RelaxNGNameClassTests.swift
Normal file
@ -0,0 +1,22 @@
|
||||
@testable import PureXML
|
||||
import Testing
|
||||
|
||||
@Suite("RELAX NG compact name-class subtraction")
|
||||
struct RelaxNGNameClassTests {
|
||||
private func valid(_ rnc: String, _ xml: String) throws -> Bool {
|
||||
try PureXML.Schema.RelaxNG(compact: rnc).validate(xml)
|
||||
}
|
||||
|
||||
@Test("* - name admits any element except the subtracted one")
|
||||
func test_subtraction() throws {
|
||||
let rnc = "element root { element * - skip { empty }* }"
|
||||
#expect(try valid(rnc, "<root><a/><b/></root>"))
|
||||
#expect(try !valid(rnc, "<root><skip/></root>"))
|
||||
}
|
||||
|
||||
@Test("A plain wildcard still admits everything")
|
||||
func test_plainWildcard() throws {
|
||||
let rnc = "element root { element * { empty }* }"
|
||||
#expect(try valid(rnc, "<root><skip/><a/></root>"))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user