ParseContext

Struct ParseContext 

Source
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>

Source

pub fn new(doc: &'doc EureDocument, node_id: NodeId) -> Self

Create a new parse context at the given node.

Source

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.

Source

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() and deny_unknown_extensions() become no-ops
  • All field/extension accesses are recorded in the shared FlattenContext
Source

pub fn flatten_ctx(&self) -> Option<&FlattenContext>

Get the flatten context, if present.

Source

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.

Source

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.

Source

pub fn node_id(&self) -> NodeId

Get the current node ID.

Source

pub fn node(&self) -> &'doc Node

Get the current node.

Source

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.

§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 extensions
Source

pub fn union_tag_mode(&self) -> UnionTagMode

Get the union tag mode.

Source

pub fn parse<T: ParseDocument<'doc>>(&self) -> Result<T, T::Error>

Parse the current node as type T.

Source

pub fn parse_with<T: DocumentParser<'doc>>( &self, parser: T, ) -> Result<T::Output, T::Error>

Source

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. Use VariantRepr::default() for Untagged.
Source

pub fn parse_record(&self) -> Result<RecordParser<'doc>, ParseError>

Parse the current node as a record.

Returns error if variant path is not empty.

Source

pub fn parse_tuple(&self) -> Result<TupleParser<'doc>, ParseError>

Parse the current node as a tuple.

Returns error if variant path is not empty.

Source

pub fn parse_primitive(&self) -> Result<&'doc PrimitiveValue, ParseError>

Parse the current node as a primitive value.

Returns error if variant path is not empty.

Source

pub fn parse_ext<T>(&self, name: &str) -> Result<T, T::Error>
where T: ParseDocument<'doc>, T::Error: From<ParseError>,

Get a required extension field.

Returns ParseErrorKind::MissingExtension if the extension is not present.

Source

pub fn parse_ext_with<T>( &self, name: &str, parser: T, ) -> Result<T::Output, T::Error>
where T: DocumentParser<'doc>, T::Error: From<ParseError>,

Get a required extension field with a custom parser.

Source

pub fn parse_ext_optional<T>(&self, name: &str) -> Result<Option<T>, T::Error>
where T: ParseDocument<'doc>, T::Error: From<ParseError>,

Get an optional extension field.

Returns Ok(None) if the extension is not present.

Source

pub fn parse_ext_optional_with<T>( &self, name: &str, parser: T, ) -> Result<Option<T::Output>, T::Error>
where T: DocumentParser<'doc>, T::Error: From<ParseError>,

Get an optional extension field with a custom parser.

Returns Ok(None) if the extension is not present.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_null(&self) -> bool

Check if the current node is null.

Trait Implementations§

Source§

impl<'doc> Clone for ParseContext<'doc>

Source§

fn clone(&self) -> ParseContext<'doc>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'doc> Debug for ParseContext<'doc>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'doc> Freeze for ParseContext<'doc>

§

impl<'doc> !RefUnwindSafe for ParseContext<'doc>

§

impl<'doc> !Send for ParseContext<'doc>

§

impl<'doc> !Sync for ParseContext<'doc>

§

impl<'doc> Unpin for ParseContext<'doc>

§

impl<'doc> !UnwindSafe for ParseContext<'doc>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.