pub struct Builder { /* private fields */ }Expand description
Hash-consing arena builder. Structurally equal subtrees collapse to one NodeId because every
side blob is content-interned, so equal children yield equal Node values.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(options: CompileOptions) -> Self
pub fn new(options: CompileOptions) -> Self
A new builder with the given options.
Sourcepub fn null(&mut self) -> Result<NodeId, CompileError>
pub fn null(&mut self) -> Result<NodeId, CompileError>
Interns a null node.
Sourcepub fn boolean(&mut self) -> Result<NodeId, CompileError>
pub fn boolean(&mut self) -> Result<NodeId, CompileError>
Interns a boolean node.
Sourcepub fn never(&mut self) -> Result<NodeId, CompileError>
pub fn never(&mut self) -> Result<NodeId, CompileError>
Interns a node matching no value at all (the bare false schema).
Sourcepub fn string_const(&mut self, value: &str) -> Result<NodeId, CompileError>
pub fn string_const(&mut self, value: &str) -> Result<NodeId, CompileError>
Interns a string-const node.
Sourcepub fn string_pattern(
&mut self,
regex: &str,
min_len: Option<u32>,
max_len: Option<u32>,
charset: Charset,
) -> Result<NodeId, CompileError>
pub fn string_pattern( &mut self, regex: &str, min_len: Option<u32>, max_len: Option<u32>, charset: Charset, ) -> Result<NodeId, CompileError>
Interns a string-pattern node.
Sourcepub fn integer(
&mut self,
minimum: Option<i64>,
maximum: Option<i64>,
) -> Result<NodeId, CompileError>
pub fn integer( &mut self, minimum: Option<i64>, maximum: Option<i64>, ) -> Result<NodeId, CompileError>
Interns an integer node.
Sourcepub fn integer_multiple_of(
&mut self,
minimum: Option<i64>,
maximum: Option<i64>,
multiple_of: Option<u64>,
) -> Result<NodeId, CompileError>
pub fn integer_multiple_of( &mut self, minimum: Option<i64>, maximum: Option<i64>, multiple_of: Option<u64>, ) -> Result<NodeId, CompileError>
Interns an integer node with an exact multipleOf divisor.
Sourcepub fn number(&mut self) -> Result<NodeId, CompileError>
pub fn number(&mut self) -> Result<NodeId, CompileError>
Interns an unbounded number node (the full JSON numeric grammar).
Sourcepub fn number_range(
&mut self,
minimum: Option<(i128, u32, bool)>,
maximum: Option<(i128, u32, bool)>,
multiple_of: Option<(u64, u32)>,
) -> Result<NodeId, CompileError>
pub fn number_range( &mut self, minimum: Option<(i128, u32, bool)>, maximum: Option<(i128, u32, bool)>, multiple_of: Option<(u64, u32)>, ) -> Result<NodeId, CompileError>
Interns a number node with an integer-valued inclusive/exclusive bound and/or a decimal
multipleOf (coef * 10^-exp).
Sourcepub fn integer_number_range(
&mut self,
minimum: Option<(i128, u32, bool)>,
maximum: Option<(i128, u32, bool)>,
multiple_of: Option<(u64, u32)>,
) -> Result<NodeId, CompileError>
pub fn integer_number_range( &mut self, minimum: Option<(i128, u32, bool)>, maximum: Option<(i128, u32, bool)>, multiple_of: Option<(u64, u32)>, ) -> Result<NodeId, CompileError>
Interns exact decimal constraints whose accepted values must be mathematically integral.
Sourcepub fn lexical_number(&mut self, regex: &str) -> Result<NodeId, CompileError>
pub fn lexical_number(&mut self, regex: &str) -> Result<NodeId, CompileError>
Interns a lexical JSON-number constraint.
Sourcepub fn enum_values(
&mut self,
values: Vec<ScalarLit>,
) -> Result<NodeId, CompileError>
pub fn enum_values( &mut self, values: Vec<ScalarLit>, ) -> Result<NodeId, CompileError>
Interns an enum node. Values are canonically sorted; a duplicate value is rejected.
Sourcepub fn array(
&mut self,
items: NodeId,
min_items: u32,
max_items: Option<u32>,
) -> Result<NodeId, CompileError>
pub fn array( &mut self, items: NodeId, min_items: u32, max_items: Option<u32>, ) -> Result<NodeId, CompileError>
Interns an array node.
Sourcepub fn array_unique(
&mut self,
items: NodeId,
min_items: u32,
max_items: Option<u32>,
unique_items: bool,
) -> Result<NodeId, CompileError>
pub fn array_unique( &mut self, items: NodeId, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>
Interns an array node with an explicit uniqueItems flag.
Sourcepub fn array_open(
&mut self,
min_items: u32,
max_items: Option<u32>,
unique_items: bool,
) -> Result<NodeId, CompileError>
pub fn array_open( &mut self, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>
Interns an array node with unconstrained (items: true or absent) elements.
Sourcepub fn array_full(
&mut self,
items: ItemsPolicy,
min_items: u32,
max_items: Option<u32>,
unique_items: bool,
contains: Option<ContainsConstraint>,
items_annotates: bool,
) -> Result<NodeId, CompileError>
pub fn array_full( &mut self, items: ItemsPolicy, min_items: u32, max_items: Option<u32>, unique_items: bool, contains: Option<ContainsConstraint>, items_annotates: bool, ) -> Result<NodeId, CompileError>
Interns an array node with every keyword explicit, including contains and whether items
was textually present (items_annotates, for unevaluatedItems).
Sourcepub fn tuple(
&mut self,
prefix: Vec<NodeId>,
tail: Option<NodeId>,
min_items: u32,
max_items: Option<u32>,
) -> Result<NodeId, CompileError>
pub fn tuple( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, ) -> Result<NodeId, CompileError>
Interns a tuple array with positional prefix schemas and an optional tail schema.
Closed tuples whose minimum exceeds the prefix length are rejected.
Sourcepub fn tuple_unique(
&mut self,
prefix: Vec<NodeId>,
tail: Option<NodeId>,
min_items: u32,
max_items: Option<u32>,
unique_items: bool,
) -> Result<NodeId, CompileError>
pub fn tuple_unique( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, unique_items: bool, ) -> Result<NodeId, CompileError>
Interns a positional (tuple) array node with an explicit uniqueItems flag.
Sourcepub fn tuple_full(
&mut self,
prefix: Vec<NodeId>,
tail: Option<NodeId>,
min_items: u32,
max_items: Option<u32>,
unique_items: bool,
contains: Option<ContainsConstraint>,
tail_annotates: bool,
) -> Result<NodeId, CompileError>
pub fn tuple_full( &mut self, prefix: Vec<NodeId>, tail: Option<NodeId>, min_items: u32, max_items: Option<u32>, unique_items: bool, contains: Option<ContainsConstraint>, tail_annotates: bool, ) -> Result<NodeId, CompileError>
Interns a positional (tuple) array node with every keyword explicit, including contains and
whether the tail was textually present (tail_annotates, for unevaluatedItems).
Sourcepub fn union_of(
&mut self,
branches: Vec<NodeId>,
) -> Result<NodeId, CompileError>
pub fn union_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>
Interns a type-union node. branches are child nodes in declaration order; a single branch
collapses to that branch directly rather than a one-element union.
Sourcepub fn alloc_def_slot(&mut self) -> Result<u32, CompileError>
pub fn alloc_def_slot(&mut self) -> Result<u32, CompileError>
Reserves a def slot for a recursive definition and returns its index. The slot is filled by
Builder::set_def_target once the body is lowered; a Node::Ref may point at it meanwhile.
Sourcepub fn set_def_target(
&mut self,
slot: u32,
body: NodeId,
) -> Result<(), CompileError>
pub fn set_def_target( &mut self, slot: u32, body: NodeId, ) -> Result<(), CompileError>
Points a reserved def slot at its lowered body root. Fails on an out-of-range slot or one already assigned, rather than silently overwriting or indexing out of bounds.
Sourcepub fn ref_node(&mut self, def: u32) -> Result<NodeId, CompileError>
pub fn ref_node(&mut self, def: u32) -> Result<NodeId, CompileError>
Interns a Node::Ref naming a reserved def slot (a recursion cut point).
Sourcepub fn dynamic_ref(
&mut self,
initial_target: NodeId,
anchor: AnchorId,
) -> Result<NodeId, CompileError>
pub fn dynamic_ref( &mut self, initial_target: NodeId, anchor: AnchorId, ) -> Result<NodeId, CompileError>
Interns an already-statically-resolved dynamic reference.
Sourcepub fn unevaluated(
&mut self,
kind: UnevaluatedKind,
scope: NodeId,
unevaluated: NodeId,
) -> Result<NodeId, CompileError>
pub fn unevaluated( &mut self, kind: UnevaluatedKind, scope: NodeId, unevaluated: NodeId, ) -> Result<NodeId, CompileError>
Interns an unevaluatedProperties/unevaluatedItems obligation over scope, with
unevaluated applied to each member scope did not annotate.
Sourcepub fn intersection_of(
&mut self,
branches: Vec<NodeId>,
) -> Result<NodeId, CompileError>
pub fn intersection_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>
Interns an allOf intersection in declaration order.
A single branch collapses to itself.
Sourcepub fn exactly_one_of(
&mut self,
branches: Vec<NodeId>,
) -> Result<NodeId, CompileError>
pub fn exactly_one_of( &mut self, branches: Vec<NodeId>, ) -> Result<NodeId, CompileError>
Interns a oneOf exactly-one node in declaration order.
A single branch collapses to itself because exactly-one preserves its language.
Sourcepub fn not(&mut self, inner: NodeId) -> Result<NodeId, CompileError>
pub fn not(&mut self, inner: NodeId) -> Result<NodeId, CompileError>
Interns a not: matches any complete JSON value inner does not.
Sourcepub fn object(
&mut self,
fields: Vec<(String, NodeId)>,
required: &[bool],
closure: ObjectClosure,
) -> Result<NodeId, CompileError>
pub fn object( &mut self, fields: Vec<(String, NodeId)>, required: &[bool], closure: ObjectClosure, ) -> Result<NodeId, CompileError>
Interns an object node. fields are (name, child) in source order; required is aligned
to fields by position. A duplicate field name is rejected.
Sourcepub fn object_full(
&mut self,
fields: Vec<(String, NodeId)>,
required: &[bool],
closure: ObjectClosure,
dependent: Vec<(String, NodeId)>,
dependent_required: Vec<(String, Vec<String>)>,
) -> Result<NodeId, CompileError>
pub fn object_full( &mut self, fields: Vec<(String, NodeId)>, required: &[bool], closure: ObjectClosure, dependent: Vec<(String, NodeId)>, dependent_required: Vec<(String, Vec<String>)>, ) -> Result<NodeId, CompileError>
Interns an object with dependentSchemas: (key, schema) pairs where key’s presence in
the instance additionally requires the whole instance to satisfy schema.
Sourcepub fn open_object(
&mut self,
known: Vec<(String, NodeId)>,
known_required: &[bool],
patterns: Vec<(String, NodeId)>,
additional: AdditionalPolicy,
property_names: Option<NodeId>,
min_properties: Option<u32>,
max_properties: Option<u32>,
) -> Result<NodeId, CompileError>
pub fn open_object( &mut self, known: Vec<(String, NodeId)>, known_required: &[bool], patterns: Vec<(String, NodeId)>, additional: AdditionalPolicy, property_names: Option<NodeId>, min_properties: Option<u32>, max_properties: Option<u32>, ) -> Result<NodeId, CompileError>
Interns an order-independent open object. known/known_required behave like object’s
fields/required; patterns are (regex, child) patternProperties entries.
Sourcepub fn open_object_full(
&mut self,
known: Vec<(String, NodeId)>,
known_required: &[bool],
patterns: Vec<(String, NodeId)>,
additional: AdditionalPolicy,
property_names: Option<NodeId>,
min_properties: Option<u32>,
max_properties: Option<u32>,
dependent: Vec<(String, NodeId)>,
dependent_required: Vec<(String, Vec<String>)>,
) -> Result<NodeId, CompileError>
pub fn open_object_full( &mut self, known: Vec<(String, NodeId)>, known_required: &[bool], patterns: Vec<(String, NodeId)>, additional: AdditionalPolicy, property_names: Option<NodeId>, min_properties: Option<u32>, max_properties: Option<u32>, dependent: Vec<(String, NodeId)>, dependent_required: Vec<(String, Vec<String>)>, ) -> Result<NodeId, CompileError>
Interns an order-independent open object with dependentSchemas, same semantics as
object_full’s.
Sourcepub fn unsupported(
&mut self,
keyword: &str,
reason: UnsupportedReason,
json_pointer: &str,
) -> Result<NodeId, CompileError>
pub fn unsupported( &mut self, keyword: &str, reason: UnsupportedReason, json_pointer: &str, ) -> Result<NodeId, CompileError>
Interns an Unsupported node and records a diagnostic for this occurrence. Returns the
node id, or TooManyDiagnostics once the bounded buffer is full.