Skip to main content

ParsingContext

Struct ParsingContext 

Source
pub struct ParsingContext<'a> {
    pub text: &'a str,
    pub reference: &'a ReferenceWithTimezone,
    pub tokens: Vec<Token>,
    pub locale: Locale,
    /* private fields */
}
Expand description

Shared state for a single parse request.

Parsers and refiners receive a ParsingContext so they can reuse the input text, reference time, locale, and precomputed token scan.

Fields§

§text: &'a str

Original input text.

§reference: &'a ReferenceWithTimezone

Reference date/time used to resolve relative expressions.

§tokens: Vec<Token>

Tokens discovered during the scanner pre-pass.

§locale: Locale

Active locale for the parse request.

Implementations§

Source§

impl<'a> ParsingContext<'a>

Source

pub fn new(text: &'a str, reference: &'a ReferenceWithTimezone) -> Self

Create a new English parsing context.

Source

pub fn with_locale( text: &'a str, reference: &'a ReferenceWithTimezone, locale: Locale, ) -> Self

Create a parsing context for a specific locale.

Source

pub fn lower_text(&self) -> &str

Return the cached lowercase representation of the input.

Source

pub fn create_components(&self) -> FastComponents

Create a fresh component set seeded from the reference date.

Source

pub fn create_result( &self, index: usize, end_index: usize, start: FastComponents, end: Option<FastComponents>, ) -> ParsedResult

Build a ParsedResult for a matched span.

Source

pub fn has_token_type(&self, token_type: TokenType) -> bool

Return true when the scanner found a token of the given type.

Auto Trait Implementations§

§

impl<'a> Freeze for ParsingContext<'a>

§

impl<'a> RefUnwindSafe for ParsingContext<'a>

§

impl<'a> Send for ParsingContext<'a>

§

impl<'a> Sync for ParsingContext<'a>

§

impl<'a> Unpin for ParsingContext<'a>

§

impl<'a> UnsafeUnpin for ParsingContext<'a>

§

impl<'a> UnwindSafe for ParsingContext<'a>

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> 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, 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.