substrait/parse/
context.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! A parse context.
4
5use thiserror::Error;
6
7use crate::parse::proto::extensions::SimpleExtensionUrn;
8use crate::parse::{Anchor, Parse};
9
10/// A parse context.
11///
12/// Parsing Substrait data is context-sensitive. This trait provides methods
13/// that can be used by parser implementations to parse Substrait data.
14pub(crate) trait Context {
15    /// Parse an item with this context.
16    ///
17    /// See [Parse::parse].
18    fn parse<T: Parse<Self>>(&mut self, item: T) -> Result<T::Parsed, T::Error>
19    where
20        Self: Sized,
21    {
22        item.parse(self)
23    }
24}
25
26/// Parse context errors.
27#[derive(Debug, Error, PartialEq)]
28pub enum ContextError {
29    /// Undefined reference to simple extension.
30    #[error("undefined reference to simple extension with anchor `{0}`")]
31    UndefinedSimpleExtension(Anchor<SimpleExtensionUrn>),
32
33    /// Duplicate anchor for simple extension.
34    #[error("duplicate anchor `{0}` for simple extension")]
35    DuplicateSimpleExtension(Anchor<SimpleExtensionUrn>),
36
37    /// Unsupported simple extension urn.
38    #[error("unsupported simple extension urn: {0}")]
39    UnsupportedUrn(String),
40}