Struct CTTokenMapBuilder

Source
pub struct CTTokenMapBuilder<StorageT: Display + ToTokens> { /* private fields */ }
Expand description

Exports all token IDs used by a parser as a separate Rust module.

This builder will create a Rust module named mod_name that can be imported with lrlex_mod!(mod_name). The module will contain one const StorageT per token in token_map, with the token prefixed by T_. In addition, it will contain an array of all token IDs TOK_IDS.

For example, if StorageT is u8, mod_name is x, and token_map is HashMap{"ID": 0, "INT": 1} the generated module will look roughly as follows:

mod x {
  pub const T_ID: u8 = 0;
  pub const T_INT: u8 = 1;
  pub const TOK_IDS: &[u8] = &[T_ID, T_INT];
}

See the custom lexer example for more usage details.

Implementations§

Source§

impl<StorageT: Display + ToTokens> CTTokenMapBuilder<StorageT>

Source

pub fn new( mod_name: impl Into<String>, token_map: impl Borrow<HashMap<String, StorageT>>, ) -> Self

Create a new token map builder.

See the builder documentation for more info.

Source

pub fn rename_map<M, I, K, V>(self, rename_map: Option<M>) -> Self
where M: IntoIterator<Item = I>, I: Borrow<(K, V)>, K: AsRef<str>, V: AsRef<str>,

Set a token rename map.

Rename map is used to specify identifier names for tokens whose names are not valid Rust identifiers. For example, if token_map is HashMap{"+": 0, "ID": 1} and rename_map is HashMap{"+": "PLUS"} then the generated module will look roughly as follows:

mod x {
  pub const T_PLUS: u8 = 0;
  pub const T_ID: u8 = 1;
}
Source

pub fn allow_dead_code(self, allow_dead_code: bool) -> Self

Control whether the builder will add #[allow(dead_code)] to the generated module.

By default, all tokens are #[deny(dead_code)], meaning that you’ll get a warning if your custom lexer doesn’t use any of them. This function can be used to disable this behavior.

Source

pub fn build(&self) -> Result<(), Box<dyn Error>>

Build the token map module.

Trait Implementations§

Source§

impl<StorageT: Clone + Display + ToTokens> Clone for CTTokenMapBuilder<StorageT>

Source§

fn clone(&self) -> CTTokenMapBuilder<StorageT>

Returns a copy 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<StorageT: Debug + Display + ToTokens> Debug for CTTokenMapBuilder<StorageT>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<StorageT> Freeze for CTTokenMapBuilder<StorageT>

§

impl<StorageT> RefUnwindSafe for CTTokenMapBuilder<StorageT>
where StorageT: RefUnwindSafe,

§

impl<StorageT> !Send for CTTokenMapBuilder<StorageT>

§

impl<StorageT> !Sync for CTTokenMapBuilder<StorageT>

§

impl<StorageT> Unpin for CTTokenMapBuilder<StorageT>
where StorageT: Unpin,

§

impl<StorageT> UnwindSafe for CTTokenMapBuilder<StorageT>
where StorageT: 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> 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> 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.