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