Generalised some lexer functions
This commit is contained in:
parent
d229c3d3c3
commit
1a5d2edee1
|
@ -117,7 +117,7 @@ pub enum Token {
|
||||||
|
|
||||||
// Literals
|
// Literals
|
||||||
/// True, False
|
/// True, False
|
||||||
#[regex("true|false", get_bool)]
|
#[regex("true|false", get_value)]
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
|
||||||
/// Always, Sometimes, Never
|
/// Always, Sometimes, Never
|
||||||
|
@ -133,7 +133,7 @@ pub enum Token {
|
||||||
String(String),
|
String(String),
|
||||||
|
|
||||||
/// Integer
|
/// Integer
|
||||||
#[regex(r"-?[0-9]+", get_int)]
|
#[regex(r"-?[0-9]+", get_value)]
|
||||||
Integer(i32),
|
Integer(i32),
|
||||||
|
|
||||||
/// A C-complaint identifier
|
/// A C-complaint identifier
|
||||||
|
@ -151,11 +151,7 @@ pub enum Token {
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_bool(lexer: &mut Lexer<Token>) -> Option<bool> {
|
fn get_value<T: std::str::FromStr>(lexer: &mut Lexer<Token>) -> Option<T> {
|
||||||
lexer.slice().parse().ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_int(lexer: &mut Lexer<Token>) -> Option<i32> {
|
|
||||||
lexer.slice().parse().ok()
|
lexer.slice().parse().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue