Add lex! macro
Some checks failed
/ build (push) Failing after 1m40s
/ clippy (push) Successful in 1m43s

This commit is contained in:
xqtc 2024-07-12 17:55:43 +02:00
parent ef8e57d6b1
commit dd2a73e1fd

View file

@ -59,6 +59,20 @@ pub struct Lexer {
pub current_char: Option<char>,
}
/// Instantiates Lexer and retrieves Tokens of given source.
/// Returns Arc<[Token]>
/// Equivalent to:
/// ```
/// let source = "some source";
/// let lexed = Lexer::new(source).get_tokens();
/// ```
#[macro_export]
macro_rules! lex {
($source:expr) => {{
$crate::Lexer::get_tokens(&mut $crate::Lexer::new($source))
}};
}
impl Lexer {
/// Instantiates the [`Lexer`]
pub fn new(input: &str) -> Self {