pub struct ParseContext<'doc> { /* private fields */ }Expand description
Context for parsing Eure documents.
Encapsulates the document, current node, and variant path state.
Similar to DocumentConstructor for writing, but for reading.
Implementations§
Source§impl<'doc> ParseContext<'doc>
impl<'doc> ParseContext<'doc>
Sourcepub fn new(doc: &'doc EureDocument, node_id: NodeId) -> Self
pub fn new(doc: &'doc EureDocument, node_id: NodeId) -> Self
Create a new parse context at the given node.
Sourcepub fn with_union_tag_mode(
doc: &'doc EureDocument,
node_id: NodeId,
mode: UnionTagMode,
) -> Self
pub fn with_union_tag_mode( doc: &'doc EureDocument, node_id: NodeId, mode: UnionTagMode, ) -> Self
Create a new parse context with the specified union tag mode.
Sourcepub fn with_flatten_ctx(
doc: &'doc EureDocument,
node_id: NodeId,
flatten_ctx: FlattenContext,
mode: UnionTagMode,
) -> Self
pub fn with_flatten_ctx( doc: &'doc EureDocument, node_id: NodeId, flatten_ctx: FlattenContext, mode: UnionTagMode, ) -> Self
Create a context with a flatten context (for flatten parsing).
When a flatten context is present:
deny_unknown_fields()anddeny_unknown_extensions()become no-ops- All field/extension accesses are recorded in the shared
FlattenContext
Sourcepub fn flatten_ctx(&self) -> Option<&FlattenContext>
pub fn flatten_ctx(&self) -> Option<&FlattenContext>
Get the flatten context, if present.
Sourcepub fn is_flattened(&self) -> bool
pub fn is_flattened(&self) -> bool
Check if this context is flattened (has a flatten context).
When flattened, deny_unknown_fields() and deny_unknown_extensions() are no-ops.
Sourcepub fn parser_scope(&self) -> Option<ParserScope>
pub fn parser_scope(&self) -> Option<ParserScope>
Get the parser scope, if in a flatten context.
Returns Some(ParserScope::Record) if from rec.flatten(),
Some(ParserScope::Extension) if from ext.flatten_ext(),
None if not in a flatten context.
Sourcepub fn flatten(&self) -> Self
pub fn flatten(&self) -> Self
Create a flattened version of this context for shared access tracking.
When you need both record parsing and extension parsing to share access tracking (so deny_unknown_* works correctly), use this method to create a shared context first.
§Scope
This method always sets ParserScope::Record. When alternating between
flatten() and flatten_ext(), the scope is updated each time:
ctx.flatten() // scope = Record
.flatten_ext() // scope = Extension
.flatten() // scope = Record (updated, not inherited)§AccessedSet Sharing
The AccessedSet is shared across all contexts in the flatten chain
(via Rc). This ensures that field/extension accesses are tracked
regardless of which scope they were accessed from, and the root parser
can validate everything with deny_unknown_*.
§Example
// Both record and extension parsers share the same AccessedSet
let ctx = ctx.flatten();
// ... parse extensions with ctx.parse_ext(...) ...
let mut rec = ctx.parse_record()?;
// ... parse fields ...
rec.deny_unknown_fields()?; // Validates both fields and extensionsSourcepub fn union_tag_mode(&self) -> UnionTagMode
pub fn union_tag_mode(&self) -> UnionTagMode
Get the union tag mode.
Sourcepub fn parse<T: FromEure<'doc, T>>(&self) -> Result<T, T::Error>
pub fn parse<T: FromEure<'doc, T>>(&self) -> Result<T, T::Error>
Parse the current node as type T.
Sourcepub fn parse_via<M, T>(&self) -> Result<T, M::Error>where
M: FromEure<'doc, T>,
pub fn parse_via<M, T>(&self) -> Result<T, M::Error>where
M: FromEure<'doc, T>,
Parse the current node as type T using a marker/strategy type M.
This is used for parsing remote types where M implements
FromEure<'doc, T> but T doesn’t implement FromEure itself.
pub fn parse_with<T: DocumentParser<'doc>>( &self, parser: T, ) -> Result<T::Output, T::Error>
Sourcepub fn parse_union<T, E>(
&self,
repr: VariantRepr,
) -> Result<UnionParser<'doc, '_, T, E>, E>where
E: From<ParseError>,
pub fn parse_union<T, E>(
&self,
repr: VariantRepr,
) -> Result<UnionParser<'doc, '_, T, E>, E>where
E: From<ParseError>,
Get a union parser for the current node with the specified variant representation.
Returns error if $variant extension has invalid type or syntax.
§Arguments
repr- The variant representation to use. UseVariantRepr::default()for Untagged.
Sourcepub fn parse_record(&self) -> Result<RecordParser<'doc>, ParseError>
pub fn parse_record(&self) -> Result<RecordParser<'doc>, ParseError>
Parse the current node as a record.
Returns error if variant path is not empty.
Sourcepub fn parse_tuple(&self) -> Result<TupleParser<'doc>, ParseError>
pub fn parse_tuple(&self) -> Result<TupleParser<'doc>, ParseError>
Parse the current node as a tuple.
Returns error if variant path is not empty.
Sourcepub fn parse_primitive(&self) -> Result<&'doc PrimitiveValue, ParseError>
pub fn parse_primitive(&self) -> Result<&'doc PrimitiveValue, ParseError>
Parse the current node as a primitive value.
Returns NotPrimitive error if the node is not a primitive.
Returns UnexpectedVariantPath error if variant path is not empty.
Sourcepub fn node_subtree_to_document_excluding_accessed(&self) -> EureDocument
pub fn node_subtree_to_document_excluding_accessed(&self) -> EureDocument
Create a standalone document from the current node’s subtree, excluding extensions that have been marked as accessed.
This is useful for literal comparison in schema validation, where
extensions like $variant have been consumed by union resolution
and should not be part of the literal value.
Sourcepub fn parse_ext<T>(&self, name: &str) -> Result<T, T::Error>
pub fn parse_ext<T>(&self, name: &str) -> Result<T, T::Error>
Get a required extension field.
Returns ParseErrorKind::MissingExtension if the extension is not present.
Sourcepub fn parse_ext_with<T>(
&self,
name: &str,
parser: T,
) -> Result<T::Output, T::Error>
pub fn parse_ext_with<T>( &self, name: &str, parser: T, ) -> Result<T::Output, T::Error>
Get a required extension field with a custom parser.
Sourcepub fn parse_ext_optional<T>(&self, name: &str) -> Result<Option<T>, T::Error>
pub fn parse_ext_optional<T>(&self, name: &str) -> Result<Option<T>, T::Error>
Get an optional extension field.
Returns Ok(None) if the extension is not present.
Sourcepub fn parse_ext_optional_with<T>(
&self,
name: &str,
parser: T,
) -> Result<Option<T::Output>, T::Error>
pub fn parse_ext_optional_with<T>( &self, name: &str, parser: T, ) -> Result<Option<T::Output>, T::Error>
Get an optional extension field with a custom parser.
Returns Ok(None) if the extension is not present.
Sourcepub fn ext(&self, name: &str) -> Result<ParseContext<'doc>, ParseError>
pub fn ext(&self, name: &str) -> Result<ParseContext<'doc>, ParseError>
Get the parse context for an extension field without parsing it.
Use this when you need access to the extension’s NodeId or want to defer parsing.
Returns ParseErrorKind::MissingExtension if the extension is not present.
Sourcepub fn ext_optional(&self, name: &str) -> Option<ParseContext<'doc>>
pub fn ext_optional(&self, name: &str) -> Option<ParseContext<'doc>>
Get the parse context for an optional extension field without parsing it.
Use this when you need access to the extension’s NodeId or want to defer parsing.
Returns None if the extension is not present.
Sourcepub fn deny_unknown_extensions(&self) -> Result<(), ParseError>
pub fn deny_unknown_extensions(&self) -> Result<(), ParseError>
Finish parsing with Deny policy (error if unknown extensions exist).
Flatten behavior: If this context is in a flatten chain (has flatten_ctx), this is a no-op. Only root parsers validate.
Sourcepub fn unknown_extensions(
&self,
) -> impl Iterator<Item = (&'doc Identifier, ParseContext<'doc>)> + '_
pub fn unknown_extensions( &self, ) -> impl Iterator<Item = (&'doc Identifier, ParseContext<'doc>)> + '_
Get an iterator over unknown extensions (for custom handling).
Returns (identifier, context) pairs for extensions that haven’t been accessed.
Sourcepub fn flatten_ext(&self) -> ParseContext<'doc>
pub fn flatten_ext(&self) -> ParseContext<'doc>
Create a flatten context for child parsers in Extension scope.
This creates a FlattenContext initialized with the current accessed extensions, and returns a ParseContext that children can use. Children created from this context will:
- Add their accessed extensions to the shared FlattenContext
- Have deny_unknown_extensions() be a no-op
The root parser should call deny_unknown_extensions() after all children are done.
§Scope
This method always sets ParserScope::Extension. When alternating between
flatten() and flatten_ext(), the scope is updated each time:
ctx.flatten() // scope = Record
.flatten_ext() // scope = Extension (updated, not inherited)
.flatten() // scope = Record§AccessedSet Sharing
The AccessedSet is shared across all contexts in the flatten chain
(via Rc). See flatten() for details.
Trait Implementations§
Source§impl<'doc> Clone for ParseContext<'doc>
impl<'doc> Clone for ParseContext<'doc>
Source§fn clone(&self) -> ParseContext<'doc>
fn clone(&self) -> ParseContext<'doc>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more