fix: constrain the xml and xlink attributes in mx::core - #461
Merged
Merged
Conversation
The generator now follows the imports the MusicXML schema declares, so the attribute declarations in xml.xsd and xlink.xsd are lowered instead of being passed through as strings: xml:space and xlink:type/show/actuate become closed vocabularies with the schemas' own members, and xml:lang becomes the builtin xs:language primitive, mapped in C++ to a hand-written Language wrapper beside Token. Regenerates all four targets; no mx::api change.
Contributor
gen-quality
|
Owner
Author
|
/coverage |
Contributor
Coverage reportCore-dev coverage
|
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 76.9% | 28961 / 37668 |
| Functions | 73.5% | 6568 / 8935 |
| Branches | 50.8% | 23805 / 46903 |
API coverage src/private/mx/{api,impl,utility}/
| Metric | Coverage | Covered / Total |
|---|---|---|
| Lines | 88.1% | 9836 / 11163 |
| Functions | 81.7% | 3980 / 4870 |
| Branches | 54.9% | 8440 / 15365 |
Core HTML report | API HTML report
Commit be7fca1e4dccb458107fd0954814738b354b65cb.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Summary
This was a relatively unimportant missing validation on the MusicXML. Now we coerce pattern-invalid link attributes and send up a diagnostic when we do.
Summary
MusicXML imports
xml.xsdandxlink.xsd, and the generator passed every attribute declared there through as a plain string. Values those schemas forbid were therefore representable inmx::core, which is the exception #398 reports: the model is supposed to make an invalid MusicXML value impossible.The IR now follows the imports the MusicXML schema declares. The XSD parser reads the imported schemas that sit beside the main one, and the lowering resolves each external attribute ref against the declaration it finds there:
xml:spacebecomes a closed vocabulary (default,preserve).xlink:type,xlink:showandxlink:actuatebecome closed vocabularies whose members are read fromxlink.xsd, so a schema bump cannot leave them drifting.xml:langbecomes thexs:languageprimitive. Its declared type is the builtinxs:language, which no schema declares, so it rides the builtin primitive table the way the identity tokens do; the C++ target maps it to a new hand-writtenLanguagewrapper besideTokenthat validates the builtin pattern and admits the empty tag the attribute's schema unions in. An out-of-grammar tag repairs to the empty tag, the un-declared value.xlink:href,xlink:roleandxlink:titlestaystd::string: they arexs:anyURIandxs:string, which accept nearly any string.An out-of-vocabulary value is repaired and reported through a
Diagnostic, the leniency every other value type applies, so no document that parsed before now fails to parse and no in-vocabulary value changes. 49 corpus files carryxml:lang, 54 carryxml:spaceand 7 carry the xlink attributes; all of their values are in-vocabulary.All four targets are regenerated in the same commit: 4 new value types in C++, Go and C, plus the 18 attribute sites the issue lists.
mx::apiis untouched, because none of these attributes is exposed there.Testing
make test-all: core round trip (841 files), core unit (646 assertions), api-test (5879 assertions), api round trip (414 files)make test-goandmake test-c, the other two targets' suitesmake gen-test(146 tests, including the new imported-vocabulary IR cases)make gen-quality(84.7, floor 84.5) andmake gen-lint(9.29, floor 9.29)make genthengit diff --exit-code: no generated driftmake fmt-checkLanguageKeepsTheBuiltinPatternOrEmptyandImportedXmlAndXlinkVocabularyinValueTest.cpp,RepairsOutOfVocabularyXmlAndXlinkAttributesinDocumentTest.cpp, and four cases ingen/tests/test_ir.pyReferences
xml:*andxlink:*attributes are unconstrained strings inmx::core#398mx::core. #397