Allow digits in identifiers in simplexpr

This commit is contained in:
elkowar 2021-08-10 14:30:33 +02:00
parent 142894c3ce
commit ec8b12d206
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
5 changed files with 17 additions and 2 deletions

View file

@ -99,7 +99,7 @@ regex_rules! {
r"[ \n\n\f]+" => |_| Token::Skip,
r";.*"=> |_| Token::Comment,
r"[a-zA-Z_-]+" => |x| Token::Ident(x.to_string()),
r"[a-zA-Z_][a-zA-Z0-9_-]*" => |x| Token::Ident(x.to_string()),
r"[+-]?(?:[0-9]+[.])?[0-9]+" => |x| Token::NumLit(x.to_string())
}
@ -278,6 +278,8 @@ mod test {
snapshot_string! {
basic => v!(r#"bar "foo""#),
digit => v!(r#"12"#),
number_in_ident => v!(r#"foo_1_bar"#),
interpolation_1 => v!(r#" "foo ${2 * 2} bar" "#),
interpolation_nested => v!(r#" "foo ${(2 * 2) + "${5 + 5}"} bar" "#),
escaping => v!(r#" "a\"b\{}" "#),

View file

@ -0,0 +1,6 @@
---
source: crates/simplexpr/src/parser/lexer.rs
expression: "v!(r#\"12\"#)"
---
(0, NumLit("12"), 2)

View file

@ -0,0 +1,6 @@
---
source: crates/simplexpr/src/parser/lexer.rs
expression: "v!(r#\"foo_1_bar\"#)"
---
(0, Ident("foo_1_bar"), 9)

View file

@ -4,6 +4,7 @@
//};
fn main() {
println!("hi");
// let mut files = codespan_reporting::files::SimpleFiles::new();
// let input = r#"

View file

@ -69,7 +69,7 @@ impl YuckFiles {
}
impl YuckFiles {
fn get_file(&self, id: usize) -> Result<&YuckFile, codespan_reporting::files::Error> {
pub fn get_file(&self, id: usize) -> Result<&YuckFile, codespan_reporting::files::Error> {
self.files.get(&id).ok_or(codespan_reporting::files::Error::FileMissing)
}