sibil/src/lexer/char.rs

76 lines
1.6 KiB
Rust
Raw Normal View History

/* char.rs
* Eryn Wells <eryn@erynwells.me>
*/
use lexer::charset;
pub trait Lexable {
fn is_left_paren(&self) -> bool;
fn is_right_paren(&self) -> bool;
2016-12-25 15:03:18 -07:00
fn is_hash(&self) -> bool;
2016-12-25 20:54:47 -07:00
fn is_dot(&self) -> bool;
2016-12-25 15:03:18 -07:00
fn is_string_quote(&self) -> bool;
fn is_newline(&self) -> bool;
fn is_eof(&self) -> bool;
fn is_identifier_initial(&self) -> bool;
fn is_identifier_subsequent(&self) -> bool;
2016-12-24 09:07:38 -07:00
fn is_identifier_single(&self) -> bool;
fn is_boolean_true(&self) -> bool;
fn is_boolean_false(&self) -> bool;
2016-12-25 13:50:34 -07:00
fn is_comment_initial(&self) -> bool;
}
impl Lexable for char {
fn is_left_paren(&self) -> bool {
2016-12-24 09:07:38 -07:00
*self == '('
}
fn is_right_paren(&self) -> bool {
2016-12-24 09:07:38 -07:00
*self == ')'
}
2016-12-24 10:29:10 -07:00
fn is_hash(&self) -> bool {
*self == '#'
}
2016-12-25 20:54:47 -07:00
fn is_dot(&self) -> bool {
*self == '.'
}
2016-12-25 15:03:18 -07:00
fn is_string_quote(&self) -> bool {
*self == '"'
}
2016-12-24 10:29:10 -07:00
fn is_boolean_true(&self) -> bool {
*self == 't'
}
fn is_boolean_false(&self) -> bool {
*self == 'f'
2016-12-24 10:29:10 -07:00
}
2016-12-24 09:17:08 -07:00
fn is_newline(&self) -> bool {
*self == '\n'
}
2016-12-25 13:50:34 -07:00
2016-12-25 14:33:26 -07:00
fn is_eof(&self) -> bool {
*self == '\0'
}
2016-12-25 13:50:34 -07:00
fn is_comment_initial(&self) -> bool {
*self == ';'
}
2016-12-25 15:03:18 -07:00
fn is_identifier_initial(&self) -> bool {
charset::identifier_initials().contains(&self)
}
fn is_identifier_subsequent(&self) -> bool {
charset::identifier_subsequents().contains(&self)
}
fn is_identifier_single(&self) -> bool {
charset::identifier_singles().contains(&self)
}
}