Crates.io | literify |
lib.rs | literify |
version | 0.2.0 |
source | src |
created_at | 2023-07-11 20:50:45.710763 |
updated_at | 2023-10-03 21:27:22.135431 |
description | Stringifies tokens inside token stream |
homepage | |
repository | https://git.ablecorp.us/ondra05/literify |
max_upload_size | |
id | 914094 |
size | 6,176 |
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.
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)),
)