From 6099dbd2365d365b522c10e2520fdb8adfc1667b Mon Sep 17 00:00:00 2001 From: Artemy Egorov Date: Mon, 12 Aug 2024 18:21:25 +0300 Subject: [PATCH] fix: escaping in argument and multiline text --- src/daleth/lexer/mod.rs | 4 ++-- src/daleth/parser/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/daleth/lexer/mod.rs b/src/daleth/lexer/mod.rs index 3d1e8e5..1006f90 100644 --- a/src/daleth/lexer/mod.rs +++ b/src/daleth/lexer/mod.rs @@ -86,7 +86,7 @@ fn symbol<'src>() -> impl Parser<'src, &'src str, Token<'src>, extra::Err() -> impl Parser<'src, &'src str, Token<'src>, extra::Err>> { let arg_escape = just('\\') - .ignore_then(just('"')) + .ignore_then(choice((just('"'), just('\\')))) .labelled("Escape sequence for argument"); let number = text::int(10) @@ -109,7 +109,7 @@ fn argument<'src>() -> impl Parser<'src, &'src str, Token<'src>, extra::Err() -> impl Parser<'src, &'src str, Token<'src>, extra::Err>> { let escape = just('\\') - .ignore_then(just('}')) + .ignore_then(choice((just('}'), just('\\')))) .labelled("Multi-line escape sequence"); let text = none_of("\n") diff --git a/src/daleth/parser/mod.rs b/src/daleth/parser/mod.rs index cd3136f..2cac613 100644 --- a/src/daleth/parser/mod.rs +++ b/src/daleth/parser/mod.rs @@ -31,9 +31,9 @@ pub fn tag<'tokens, 'src: 'tokens>( let text_body = select! { Token::TextBody(t) => t.to_owned(), - Token::MLText(t) => trim_indent(t).to_owned(), - Token::MLMSText(n, t) => set_spaces(t, n).to_owned(), - Token::MLRText(t) => t.to_owned() + Token::MLText(t) => trim_indent(t).replace("\\}", "}").replace("\\\\", "\\"), + Token::MLMSText(n, t) => set_spaces(t, n).replace("\\}", "}").replace("\\\\", "\\"), + Token::MLRText(t) => t.replace("\\}", "}").replace("\\\\", "\\") } .labelled("Text body");