Skip to main content

Crate trilean_json_shape_pattern

Crate trilean_json_shape_pattern 

Source
Expand description

The regular expressions a pattern constraint may use: the subset of ECMAScript patterns whose meaning is the same in every JSON Schema validator, so the validator of trilean-json-shape and one written for the schema it emits agree. It is a crate of its own so that the derive, which refuses an unsupported pattern at compile time, and the validator, which matches with it, compile one grammar and cannot disagree about which patterns exist. A pattern is unanchored unless it says ^ and $, and is matched over Unicode scalar values, as ECMAScript does with the u flag, which is how Ajv compiles a schema’s patterns.

Supported: literal characters, . (any character except a line terminator), escaped punctuation (\., \\, \/ and the other syntax characters, and \- inside a class), classes with ranges and negation ([a-z0-9._-], [^/]), groups ((...) and (?:...)), alternation, the greedy quantifiers *, + and ?, and the anchors ^ and $. Anything else (counted repetition, lazy quantifiers, \d-style classes, lookaround) is refused, so a pattern that would mean something else in another engine does not compile.

Structs§

Pattern
A compiled pattern, matched by simulating a Thompson automaton: no backtracking and no recursion over the text, so matching costs time linear in the text times the size of the pattern, and constant stack, whatever the text.
PatternError
Why a pattern is not in the supported subset.

Functions§

json_quote
The text as a JSON string literal, which is how every message writes a string. The escapes are the ones JSON.stringify writes: \", \\, the short forms of the control characters that have one, and \u00XX for the rest below U+0020; everything else is written as it is.