Janet 1.39.1-e9c6678 Documentation
(Other Versions:
1.38.0
1.37.1
1.36.0
1.35.0
1.34.0
1.31.0
1.29.1
1.28.0
1.27.0
1.26.0
1.25.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.1
1.17.1
1.16.1
1.15.0
1.13.1
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
schema
Simple schema validation library. Specify structure declaratively, and get functions that will check that structure and either raise an error or return a boolean. While reasonably general, use is intended for data such as one would find in configuration files or network protocols.
Currently does not support more advanced features such as:
- Recursive schemas
- Full error reporting (only a single error is reported)
- PEG style grammars (used to enable recursion in PEGs)
- Unification (such as in the
(match)
macro) - Parsing/data extraction
Syntax:
:keyword
- match any value of that type- Tuples are used to match various combinators:
(any)
- match any one value(enum & options)
- match any of the option values(or & schemas)
- similar to enum, but each option is considered a schema.(and & schemas)
- Only matches if all clauses match(values schema)
- Matches only if schema matches all values in a data structure.(keys schema)
- Matches only if schema matches all keys in a data structure.(props & k v)
- Takes a sequence of keys and values (alternating in order). Only matches
the data if, for a key, the corresponding schema `v` matches.
(length l)
- Only match if the data has a length of l. Uses of the length combinator should assert the data type before doing a length check.(length min max)
- Only match lengths between min and max inclusive(peg pattern)
- Matches only if the peg matches(not pattern)
- Only matches if pattern does not match(pred predicate)
- Use a predicate function (function of 1 argument) to check if the data is valid.
- anything else - match that value literally
Reference
schema/make-predicate schema/make-validator schema/predicate schema/validator
schema/make-predicate function source
(make-predicate schema) Generate a function that can be used to validate a data structure. This is the function form of `predicate`.
schema/make-validator function source
(make-validator schema) Generate a function that can be used to validate a data structure. This is the function form of `validator`.
schema/predicate macro source
(predicate pattern) Make a validation predicate given a certain schema.
schema/validator macro source
(validator pattern) Make a validation function of one argument. A validation function will throw an error on validation failure, otherwise, it will return the argument.