Enhanced the LexerError and Documentation of Types
I went and enhanced the LexerError to now wrap a Rust source Error. This makes it so we can wrapup the possible IO errors we get when trying to open a file and read its contents. I also added some documentation for all the implemented functions.
This commit is contained in:
12
src/lexer.rs
12
src/lexer.rs
@ -72,13 +72,12 @@ impl Lexer
|
||||
let mut cursor = Position::default();
|
||||
let mut stream = TokenStream::new();
|
||||
|
||||
let input_file = File::open(&path).map_err(|_error| {
|
||||
let input_file = File::open(&path).map_err(|err| {
|
||||
LexerError::new(
|
||||
"Unable to open file for Lexigraphical Analysis.",
|
||||
"Unable to open file for Lexical Analysis.",
|
||||
Span::default(),
|
||||
Some(path.as_ref().to_string_lossy().to_string()),
|
||||
None,
|
||||
)
|
||||
Some(path.as_ref().to_path_buf()),
|
||||
None).with_source(err)
|
||||
})?;
|
||||
|
||||
let reader = BufReader::with_capacity(BUFFER_SIZE, input_file);
|
||||
@ -138,7 +137,8 @@ impl Lexer
|
||||
}
|
||||
|
||||
/// Internal: scans a single line of text into tokens.
|
||||
fn scan(line: &str, stream: &mut TokenStream<TokenType>, cursor: &mut Position)
|
||||
fn scan(line: &str, stream: &mut TokenStream<TokenType>,
|
||||
cursor: &mut Position)
|
||||
{
|
||||
for c in line.chars()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user