Struct rustemo::lexer::Context

source ·
pub struct Context<'i, I: Input + ?Sized> {
    pub file: String,
    pub input: &'i I,
    pub position: usize,
    pub range: Range<usize>,
    pub location: Location,
    pub layout: Option<&'i I>,
    pub layout_ahead: Option<&'i I>,
}
Expand description

Lexer context is used to keep the lexing state. It provides necessary information to parsers and actions.

Fields§

§file: String

File path of the parsed content. <str> In case of static string.

§input: &'i I

The input being parsed. Should be set when the context is created.

§position: usize

An absolute position in the input sequence

The input must be indexable type.

§range: Range<usize>

The range of token/non-terminal during shift/reduce operation.

§location: Location

Similar to position but has line/column format for text based inputs.

If this prove to be pricey overhead we might make tracking of this info configurable.

§layout: Option<&'i I>

Layout before the current token (e.g. whitespaces, comments…)

§layout_ahead: Option<&'i I>

Layout before the lookahead token (e.g. whitespaces, comments…)

Implementations§

source§

impl<'i, I: Input + ?Sized> Context<'i, I>

source

pub fn new(file: String, input: &'i I) -> Self

source

pub fn file(&self) -> String

source

pub fn location_str(&self) -> String

Trait Implementations§

source§

impl<'i, I: Debug + Input + ?Sized> Debug for Context<'i, I>

source§

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

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

impl<'i, I: Input + ?Sized> From<&mut Context<'i, I>> for Location

source§

fn from(context: &mut Context<'_, I>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'i, I: ?Sized> RefUnwindSafe for Context<'i, I>where I: RefUnwindSafe,

§

impl<'i, I: ?Sized> Send for Context<'i, I>where I: Sync,

§

impl<'i, I: ?Sized> Sync for Context<'i, I>where I: Sync,

§

impl<'i, I: ?Sized> Unpin for Context<'i, I>

§

impl<'i, I: ?Sized> UnwindSafe for Context<'i, I>where I: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.