mod errors; mod tokens; use std::collections::VecDeque; use std::fs::File; use std::path::Path; use std::str::Chars; use tokens::Token; use crate::lexer::errors::LexerErrors; use crate::lexer::errors::LexerErrors::EmptyTextSequenceError; pub type Result = std::result::Result; pub struct Lexer<'a> { input: String, chars: Chars<'a>, } impl Lexer<'_> { /// Create a new Lexer for the given String /// Example: /// ``` /// use cb_calculator::lexer; /// let text = "some text"; /// lexer::Lexer::new(String::from(text)); /// ``` #[inline] pub fn new(input: String) -> Lexer { Lexer { input, chars: input.chars() } } // Get the next token pub fn next(&mut self) -> Result> { let mut buffer: Vec = Vec::new(); loop { if let Some(c) = self.chars.next() { buffer.push(c); } } } }