32 lines
775 B
Rust
32 lines
775 B
Rust
|
use crate::ErrorHandler;
|
||
|
|
||
|
use super::tokens::Token;
|
||
|
|
||
|
/// The scanner's state, including the source it is scanning.
|
||
|
pub struct Scanner {
|
||
|
source: String,
|
||
|
tokens: Vec<Token>,
|
||
|
start: usize,
|
||
|
current: usize,
|
||
|
line: usize,
|
||
|
}
|
||
|
|
||
|
impl Scanner {
|
||
|
/// Initialize a scanner by specifying the source code to scan.
|
||
|
pub fn new(source: String) -> Scanner {
|
||
|
Scanner{
|
||
|
source: source,
|
||
|
tokens: Vec::new(),
|
||
|
start: 0,
|
||
|
current: 0,
|
||
|
line: 1,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// Scan the source code, generating the list of tokens and returning it.
|
||
|
/// The scanner itself is destroyed once the process is complete.
|
||
|
pub fn scan_tokens(self, err_hdl: &mut ErrorHandler) -> Vec<Token> {
|
||
|
self.tokens
|
||
|
}
|
||
|
}
|