Repository navigation
feat!: validators declare the types they apply to - #105
Merged
Merged
Conversation
`validator NAME for TYPE[, TYPE]* { ... }`. The targets freeze onto
FrozenUnit::Validator (`targets`, serde-default), and validation now:
- rejects a validator without `for` (validation::validator-missing-
target). The grammar keeps `for` optional only so this can say what's
missing instead of the parser's generic error;
- rejects a field whose type isn't one of its validator's targets
(validation::validator-target-mismatch), matching exactly after
resolving aliases - a validator on `string[]` checks the array, not
each element; `optional` is already outside the frozen type;
- rejects `value.length` on a target without a length, and any `value`
accessor other than `length`/`name` (validation::validator-accessor-
unsupported).
Imported validators and aliases are checked too, through a caller-
supplied ImportLookup (validate_with): the build answers from its
ProjectContext via ProjectImports, which follows the schema's `use`
statements (std included); plain validate() knows no imports, as before.
std's StringBounds is now `for string`.
Refs #97
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.
Core part of #97. Stacked on #104 (std's validators need
string); GitHub retargets this tomasterwhen #104 merges.Syntax
Checks (all build errors)
validation::validator-missing-targetfor. The grammar keepsforoptional only so this can name what's missing, with a fix-it hint.validation::validator-target-mismatchstring, nots32". Exact match after resolving aliases ("notCount(u32)"). A validator onstring[]checks the array, not each element.optionaldoesn't matter.validation::validator-accessor-unsupportedvalue.lengthon a target without a length, or avalueaccessor other thanlength/nameImported validators and aliases
These were skipped entirely before: the declaring schema isn't among the importing schema's units.
validate_with(units, &dyn ImportLookup)lets the caller answer, following the same split assize.rs'sSizeLookup:ProjectImportsfollows the schema'susestatements through theProjectContext, std included.validate(): knows no imports, so behaviour there is unchanged.declared_validator_targets/declared_alias_target.Also
foris a keyword (vocabulary: 25 keywords).StringBoundsis nowfor string.for string.optionaland aliased fields that match; both accessor errors; and the cross-schema cases (std'sStringBounds, plus an alias and a validator from another schema in the same package).