Make sure to escape formatting of char literals

Closes #4682
This commit is contained in:
Ayaz Hafiz 2022-12-05 14:07:30 -06:00
parent 3399fe10a0
commit aab509c5c1
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 29 additions and 15 deletions

View file

@ -298,17 +298,7 @@ impl<'a> Formattable for Expr<'a> {
}
SingleQuote(string) => {
buf.indent(indent);
buf.push('\'');
for c in string.chars() {
if c == '"' {
buf.push_char_literal('"')
} else {
for escaped in c.escape_default() {
buf.push_char_literal(escaped);
}
}
}
buf.push('\'');
format_sq_literal(buf, string);
}
&NonBase10Int {
base,
@ -438,6 +428,20 @@ impl<'a> Formattable for Expr<'a> {
}
}
pub(crate) fn format_sq_literal(buf: &mut Buf, s: &str) {
buf.push('\'');
for c in s.chars() {
if c == '"' {
buf.push_char_literal('"')
} else {
for escaped in c.escape_default() {
buf.push_char_literal(escaped);
}
}
}
buf.push('\'');
}
fn starts_with_newline(expr: &Expr) -> bool {
use roc_parse::ast::Expr::*;