literify

Crates.ioliterify
lib.rsliterify
version0.2.0
sourcesrc
created_at2023-07-11 20:50:45.710763
updated_at2023-10-03 21:27:22.135431
descriptionStringifies tokens inside token stream
homepage
repositoryhttps://git.ablecorp.us/ondra05/literify
max_upload_size
id914094
size6,176
(ondra05)

documentation

README

Literify

Stringifies (and concats) literal within the passed token stream inside ~() group. It is also possible to concaternate with other strings inside the group.

This can be useful when you need to stringify a literal for a use in macro, but macro expects a literal token tree, so usage of stringify! is not possible.

Example

use logos::Logos;

literify::literify! {
    #[derive(Debug, PartialEq, Logos)]
    enum Token {
        #[token(~("amog" u s))]
        Amogus,

        #[token(~(.))]
        Dot,
    }
}

let mut lexer = Token::lexer("amogus.");

assert_eq!(
    lexer.next(),
    Some(Ok(Token::Amogus)),
);

assert_eq!(
    lexer.next(),
    Some(Ok(Token::Dot)),
)
Commit count: 0

cargo fmt