Changed way of String lexing

This commit is contained in:
Erin 2022-03-13 13:18:51 +01:00 committed by ondra05
parent 8ad10e132b
commit 77c201476b

View file

@ -112,7 +112,7 @@ pub enum Token {
// Literals // Literals
/// String /// String
#[regex(r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]*\*/)", get_string)] #[token("/*", get_string)]
String(String), String(String),
/// Integer /// Integer
@ -135,12 +135,12 @@ fn get_value<T: std::str::FromStr>(lexer: &mut Lexer<Token>) -> Option<T> {
lexer.slice().parse().ok() lexer.slice().parse().ok()
} }
fn get_string(lexer: &mut Lexer<Token>) -> String { fn get_string(lexer: &mut Lexer<Token>) -> Option<String> {
lexer lexer.bump(lexer.remainder().find("*/")?);
.slice() let string = lexer.slice()[2..].to_owned();
.trim_start_matches("/*") lexer.bump(2);
.trim_end_matches("*/")
.to_owned() Some(string)
} }
fn get_ident(lexer: &mut Lexer<Token>) -> String { fn get_ident(lexer: &mut Lexer<Token>) -> String {