Preserve escape sequence after formatting

Bumped into this randomly. We do correctly parse escape sequence, but
  the format would simply but the unescaped string back on save. Now it
  properly re-escapes strings before flushing them back. I also removed
  the escape sequence for 'backspace' and 'new page' form feed as I
  don't see any use case for those in an Aiken program really...
This commit is contained in:
KtorZ
2023-09-08 12:12:11 +02:00
parent 5cfc3de7bf
commit 8ba5946c32
7 changed files with 74 additions and 6 deletions

View File

@@ -28,4 +28,9 @@ mod tests {
fn bytearray_utf8_encoded() {
assert_expr!("\"aiken\"");
}
#[test]
fn bytearray_utf8_escaped() {
assert_expr!("\"\\\"aiken\\\"\"");
}
}

View File

@@ -0,0 +1,17 @@
---
source: crates/aiken-lang/src/parser/expr/bytearray.rs
description: "Code:\n\n\"\\\"aiken\\\"\""
---
ByteArray {
location: 0..11,
bytes: [
34,
97,
105,
107,
101,
110,
34,
],
preferred_format: Utf8String,
}

View File

@@ -196,10 +196,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
let escape = just('\\').ignore_then(
just('\\')
.or(just('/'))
.or(just('"'))
.or(just('b').to('\x08'))
.or(just('f').to('\x0C'))
.or(just('n').to('\n'))
.or(just('r').to('\r'))
.or(just('t').to('\t')),