From dd2a73e1fd6b32e2eced59ab698fa179889ad75f Mon Sep 17 00:00:00 2001 From: xqtc Date: Fri, 12 Jul 2024 17:55:43 +0200 Subject: [PATCH] Add lex! macro --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 831ec45..e35631a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,6 +59,20 @@ pub struct Lexer { pub current_char: Option, } +/// 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 {