2016-12-19 22:23:27 -08:00
|
|
|
//! # Lexer
|
|
|
|
|
2016-12-20 17:38:44 -08:00
|
|
|
use characters;
|
2016-12-19 22:23:27 -08:00
|
|
|
|
2016-12-20 17:52:29 -08:00
|
|
|
pub enum Kind {
|
2016-12-19 22:23:27 -08:00
|
|
|
LeftParen,
|
|
|
|
RightParen,
|
|
|
|
Identifier,
|
|
|
|
}
|
|
|
|
|
2016-12-20 17:52:29 -08:00
|
|
|
pub struct Token {
|
2016-12-19 22:23:27 -08:00
|
|
|
kind: Kind,
|
|
|
|
value: String,
|
|
|
|
}
|
|
|
|
|
2016-12-20 17:52:29 -08:00
|
|
|
pub struct Lexer {
|
|
|
|
input: String,
|
|
|
|
index: usize,
|
2016-12-20 17:38:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Lexer {
|
2016-12-20 17:52:29 -08:00
|
|
|
pub fn new(input: String) -> Lexer {
|
|
|
|
Lexer { input: input, index: 0 }
|
|
|
|
}
|
2016-12-20 17:38:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for Lexer {
|
|
|
|
type Item = Token;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Token> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 22:23:27 -08:00
|
|
|
pub fn hello(person: &str) {
|
|
|
|
println!("Hello, {}!", person);
|
|
|
|
for (idx, c) in person.char_indices() {
|
2016-12-20 17:51:43 -08:00
|
|
|
println!(" {}, {} -> {}", c, idx, characters::identifier_initials().contains(&c));
|
2016-12-19 22:23:27 -08:00
|
|
|
}
|
|
|
|
}
|