Add lex! macro
This commit is contained in:
parent
ef8e57d6b1
commit
dd2a73e1fd
14
src/lib.rs
14
src/lib.rs
|
@ -59,6 +59,20 @@ pub struct Lexer {
|
||||||
pub current_char: Option<char>,
|
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 {
|
impl Lexer {
|
||||||
/// Instantiates the [`Lexer`]
|
/// Instantiates the [`Lexer`]
|
||||||
pub fn new(input: &str) -> Self {
|
pub fn new(input: &str) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue