use alkale::{
format_notification, notification::NotificationSeverity, token::Token, FinalizedLexerResult,
LexerResult, SourceCodeScanner,
};
type Word<'a> = &'a str;
fn lexer(source: &str) -> FinalizedLexerResult<Word<'_>> {
let scanner = SourceCodeScanner::new(source);
let mut result = LexerResult::new();
while scanner.has_next() {
if let Some(identifier) = scanner.try_consume_standard_identifier() {
result.push_token(Token::from_spanned(identifier));
continue;
}
if let Some(char) = scanner.next_span() {
if !char.is_whitespace() {
format_notification!("Unrecognized character '{}'", char.data)
.span(char.span)
.severity(NotificationSeverity::Error)
.report(&mut result);
}
}
}
result.finalize()
}
fn main() {
let data = "word word another word % that was not a word what!!";
let result = lexer(data);
println!("{:#?}", result);
}