Compare commits
No commits in common. "4b11a6622a4a17a8c13af2f1d6289326b7d46b6e" and "d2b5deb802a576e086f5a57da0782f7a89d0b689" have entirely different histories.
4b11a6622a
...
d2b5deb802
@ -841,15 +841,8 @@ fn string_literal(input: Span) -> ParseResult<ExpressionKind> {
|
||||
}
|
||||
|
||||
fn bare_string_literal(input: Span) -> ParseResult<String> {
|
||||
let string_escape_transforms = alt((
|
||||
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()
|
||||
}),
|
||||
));
|
||||
let string_escape_transforms =
|
||||
alt((value("\\", tag("\\")), value("\"", tag("\"")), value("\n", tag("n")), value("\t", tag("t"))));
|
||||
alt((
|
||||
map(tag(r#""""#), |_| String::new()),
|
||||
preceded(
|
||||
|
@ -423,7 +423,7 @@ peg::parser! {
|
||||
rule pattern_literal() -> Pattern =
|
||||
"true" { Pattern::Literal(PatternLiteral::BoolPattern(true)) } /
|
||||
"false" { Pattern::Literal(PatternLiteral::BoolPattern(false)) } /
|
||||
s:bare_string_literal() { Pattern::Literal(PatternLiteral::StringPattern(Rc::new(s))) } /
|
||||
s:bare_string_literal() { Pattern::Literal(PatternLiteral::StringPattern(Rc::new(s.to_string()))) } /
|
||||
sign:("-"?) num:(float_literal() / nat_literal()) {
|
||||
let neg = sign.is_some();
|
||||
Pattern::Literal(PatternLiteral::NumPattern { neg, num })
|
||||
@ -447,18 +447,19 @@ peg::parser! {
|
||||
}
|
||||
|
||||
rule string_literal() -> ExpressionKind =
|
||||
prefix:identifier()? s:bare_string_literal(){ ExpressionKind::StringLiteral{ s: Rc::new(s),
|
||||
prefix:identifier()? s:bare_string_literal(){ ExpressionKind::StringLiteral{ s: Rc::new(s.to_string()),
|
||||
prefix: prefix.map(rc_string)
|
||||
} }
|
||||
|
||||
rule bare_string_literal() -> String =
|
||||
"\"" chars:string_component()* "\"" { chars.into_iter().collect::<String>() }
|
||||
rule bare_string_literal() -> &'input str =
|
||||
"\"" s:$(string_component()*) "\"" { s }
|
||||
|
||||
rule string_component() -> char =
|
||||
!(r#"""# / r#"\"#) ch:$([_]) { ch.chars().next().unwrap() } /
|
||||
r#"\u{"# value:$(['0'..='9' | 'a'..='f' | 'A'..='F']+) "}" { char::from_u32(u32::from_str_radix(value, 16).unwrap()).unwrap() } /
|
||||
r#"\n"# { '\n' } / r#"\t"# { '\t' } / r#"\""# { '"' } / r#"\\"# { '\\' } /
|
||||
expected!("Valid escape sequence")
|
||||
rule string_component() -> &'input str =
|
||||
r#"\\"# { "\\" } /
|
||||
r#"\""# { "\"" } /
|
||||
r#"\t"# { "\t" } /
|
||||
r#"\n"# { "\n" } /
|
||||
ch:$([^ '"' ]) { ch }
|
||||
|
||||
rule bool_literal() -> ExpressionKind =
|
||||
"true" { ExpressionKind::BoolLiteral(true) } / "false" { ExpressionKind::BoolLiteral(false) }
|
||||
|
@ -189,8 +189,8 @@ fn string_literals() {
|
||||
r#"b"some bytestring""#,
|
||||
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#""Georgian letter jani \u{10ef}""#, expr(strlit("Georgian letter jani ჯ")));
|
||||
//NOTE I'm not 100% sure this case is correct, but I'll deal with it later
|
||||
//assert_expr!(r#""Do \n \" escapes work\t""#, expr(StringLiteral(rc("Do \n \" escapes work\t"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user