Skip to main content

ParserRegistry

Struct ParserRegistry 

Source
pub struct ParserRegistry { /* private fields */ }
Expand description

A pluggable dispatch table mapping language keys to LanguageParsers.

The registry starts with the BuiltInLanguageParser as a fallback, so an unmodified registry behaves exactly like LinkNetwork::parse: lino is handled by the links-notation parser and every other key is routed through the tree-sitter adapter with a lossless text fallback.

Users register parsers for new language keys or override an existing one. Following TXL’s grammar-override model and SWC’s plugin lesson, a user registration shadows the built-in dispatch for the same key rather than forking the pipeline: any key without an explicit registration still falls through to the built-in set.

Language keys are matched case-insensitively, mirroring the built-in dispatch (LINO, Lino, and lino resolve to the same parser).

§Examples

use std::sync::Arc;
use meta_language::{
    LanguageParser, LinkNetwork, ParseConfiguration, ParserRegistry,
};

#[derive(Debug)]
struct ShoutParser;

impl LanguageParser for ShoutParser {
    fn parse_source(
        &self,
        text: &str,
        language: &str,
        configuration: ParseConfiguration,
    ) -> LinkNetwork {
        LinkNetwork::parse_lossless_text(&text.to_uppercase(), language, configuration)
    }
}

let registry = ParserRegistry::new().with_parser("shout", Arc::new(ShoutParser));
let network = registry.parse("hi", "shout", ParseConfiguration::default());
assert_eq!(network.reconstruct_text(), "HI");

Implementations§

Source§

impl ParserRegistry

Source

pub fn new() -> Self

Creates a registry backed by the BuiltInLanguageParser fallback and no user registrations.

Source

pub fn register( &mut self, language: impl Into<String>, parser: Arc<dyn LanguageParser>, ) -> &mut Self

Registers parser for language, shadowing any prior registration or built-in dispatch for the same (case-insensitive) key.

Returns &mut Self so registrations can be chained.

Source

pub fn with_parser( self, language: impl Into<String>, parser: Arc<dyn LanguageParser>, ) -> Self

Builder-style variant of register that consumes and returns the registry.

Source

pub fn parser_for(&self, language: &str) -> Option<&Arc<dyn LanguageParser>>

Returns the parser explicitly registered for language, if any.

Keys served by the built-in fallback report None; use parse to dispatch including the fallback.

Source

pub fn is_registered(&self, language: &str) -> bool

Whether language has an explicit (non-fallback) registration.

Source

pub fn len(&self) -> usize

The number of explicit registrations, excluding the built-in fallback.

Source

pub fn is_empty(&self) -> bool

Whether the registry holds no explicit registrations.

An empty registry still parses every key through the built-in fallback.

Source

pub fn parse( &self, text: &str, language: &str, configuration: ParseConfiguration, ) -> LinkNetwork

Parses text for language, dispatching to a registered parser when one shadows the key and otherwise to the built-in fallback.

Trait Implementations§

Source§

impl Clone for ParserRegistry

Source§

fn clone(&self) -> ParserRegistry

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 Debug for ParserRegistry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ParserRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
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.