Start string location at kind or quote prefix

This commit is contained in:
Charlie Marsh 2022-10-15 11:03:45 -04:00
parent eede189959
commit 15e2ac3fd7
8 changed files with 57 additions and 18 deletions

View file

@ -205,7 +205,9 @@ where
// Check if we have a string:
if self.chr0 == Some('"') || self.chr0 == Some('\'') {
return self.lex_string(saw_b, saw_r, saw_u, saw_f);
return self
.lex_string(saw_b, saw_r, saw_u, saw_f)
.map(|(_, tok, end_pos)| (start_pos, tok, end_pos));
}
}

View file

@ -1,19 +1,19 @@
---
source: parser/src/parser.rs
source: compiler/parser/src/parser.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Expr {
value: Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: JoinedStr {
@ -21,7 +21,7 @@ expression: parse_ast
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Constant {

View file

@ -1,5 +1,5 @@
---
source: parser/src/string.rs
source: compiler/parser/src/string.rs
expression: parse_ast
---
[
@ -34,7 +34,7 @@ expression: parse_ast
Located {
location: Location {
row: 1,
column: 12,
column: 10,
},
custom: (),
node: FormattedValue {

View file

@ -0,0 +1,30 @@
---
source: compiler/parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Expr {
value: Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Constant {
value: Str(
"Hello, world!",
),
kind: Some(
"u",
),
},
},
},
},
]

View file

@ -1,19 +1,19 @@
---
source: parser/src/string.rs
source: compiler/parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Expr {
value: Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: JoinedStr {
@ -21,7 +21,7 @@ expression: parse_ast
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Constant {

View file

@ -1,19 +1,19 @@
---
source: parser/src/string.rs
source: compiler/parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Expr {
value: Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: JoinedStr {
@ -21,7 +21,7 @@ expression: parse_ast
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Constant {

View file

@ -1,19 +1,19 @@
---
source: parser/src/string.rs
source: compiler/parser/src/string.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Expr {
value: Located {
location: Location {
row: 1,
column: 3,
column: 1,
},
custom: (),
node: Constant {

View file

@ -131,4 +131,11 @@ mod tests {
let parse_ast = parse_program(&source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
#[test]
fn test_parse_string_triple_quotes_with_kind() {
let source = String::from("u'''Hello, world!'''");
let parse_ast = parse_program(&source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
}