2 unstable releases

0.2.0 Oct 3, 2023
0.1.0 Jul 11, 2023

#1231 in Procedural macros

MIT license

6KB
57 lines

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

Dependencies

~250KB