Merge pull request #4220 from charliermarsh/charlie/str-loc

Start string location at kind or quote prefix
This commit is contained in:
Jeong YunWon authored and GitHub committed 2022-10-16 00:48:49 +09:00
commit 4be533ac60
8 files changed
+57 -18

No files matched your search

+3 -1
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));
}
}
@@ -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 {
@@ -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 {
@@ -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",
),
},
},
},
},
]
@@ -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 {
@@ -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 {
@@ -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 {
+7
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);
}
}