Struct LexemeDescriptor

Source
pub struct LexemeDescriptor<LexemeType> {
    pub lexeme_type: LexemeType,
    pub pattern: Regex,
}
Expand description

Describes a category of lexemes with similar syntactic meanings.

This is used as part of a lexical-analyzer’s specification, as it is built to recognize different types of lexemes.

Fields§

§lexeme_type: LexemeType

The type of lexemes being described.

§pattern: Regex

A regular-expression pattern that matches the lexemes of the specified type.

Implementations§

Source§

impl<LexemeType> LexemeDescriptor<LexemeType>

Source

pub fn new(lexeme_type: LexemeType, pattern: Regex) -> Self

Creates a LexemeDescriptor describing the specified lexeme_type with the specified pattern.

Source

pub fn keyword(lexeme_type: LexemeType, name: &str) -> Self

Creates a new LexemeDescriptor that describes a keyword.

A keyword is a type of lexeme that only matches some hard-coded string (such as if or int). This function can be used to efficiently describe such keywords.

§Example
enum MyLexemeType { If, While }
let my_lexeme_descriptors = vec![
    LexemeDescriptor::keyword(MyLexemeType::If, "if"),
    LexemeDescriptor::keyword(MyLexemeType::While, "while"),
];
Source

pub fn special_char(lexeme_type: LexemeType, value: char) -> Self

Creates a new LexemeDescriptor that describes a special character.

A special character is a type of lexeme that only matches some hard-coded character (such as operators: +, *). This function can be used to efficiently describe such characters.

§Example
enum MyLexemeType { Addition, Subtraction }
let my_lexeme_descriptors = vec![
    LexemeDescriptor::special_char(MyLexemeType::Addition, '+'),
    LexemeDescriptor::special_char(MyLexemeType::Subtraction, '-'),
];

Auto Trait Implementations§

§

impl<LexemeType> Freeze for LexemeDescriptor<LexemeType>
where LexemeType: Freeze,

§

impl<LexemeType> RefUnwindSafe for LexemeDescriptor<LexemeType>
where LexemeType: RefUnwindSafe,

§

impl<LexemeType> Send for LexemeDescriptor<LexemeType>
where LexemeType: Send,

§

impl<LexemeType> Sync for LexemeDescriptor<LexemeType>
where LexemeType: Sync,

§

impl<LexemeType> Unpin for LexemeDescriptor<LexemeType>
where LexemeType: Unpin,

§

impl<LexemeType> UnwindSafe for LexemeDescriptor<LexemeType>
where LexemeType: UnwindSafe,

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.