Support \u escapes in strings
This commit is contained in:
parent
884c8e515f
commit
4b11a6622a
@ -841,8 +841,15 @@ fn string_literal(input: Span) -> ParseResult<ExpressionKind> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bare_string_literal(input: Span) -> ParseResult<String> {
|
fn bare_string_literal(input: Span) -> ParseResult<String> {
|
||||||
let string_escape_transforms =
|
let string_escape_transforms = alt((
|
||||||
alt((value("\\", tag("\\")), value("\"", tag("\"")), value("\n", tag("n")), value("\t", tag("t"))));
|
value('\\', tag("\\")),
|
||||||
|
value('"', tag("\"")),
|
||||||
|
value('\n', tag("n")),
|
||||||
|
value('\t', tag("t")),
|
||||||
|
map(delimited(tag(r#"u{"#), recognize(digit_group_hex), tag("}")), |value| {
|
||||||
|
char::from_u32(u32::from_str_radix(value.fragment(), 16).unwrap()).unwrap()
|
||||||
|
}),
|
||||||
|
));
|
||||||
alt((
|
alt((
|
||||||
map(tag(r#""""#), |_| String::new()),
|
map(tag(r#""""#), |_| String::new()),
|
||||||
preceded(
|
preceded(
|
||||||
|
@ -190,6 +190,7 @@ fn string_literals() {
|
|||||||
expr(StringLiteral { s: rc("some bytestring"), prefix: Some(rc("b")) })
|
expr(StringLiteral { s: rc("some bytestring"), prefix: Some(rc("b")) })
|
||||||
);
|
);
|
||||||
assert_expr!(r#""Do \n \" escapes work\t""#, expr(strlit("Do \n \" escapes work\t")));
|
assert_expr!(r#""Do \n \" escapes work\t""#, expr(strlit("Do \n \" escapes work\t")));
|
||||||
|
assert_expr!(r#""Georgian letter jani \u{10ef}""#, expr(strlit("Georgian letter jani ჯ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user