From 0f6b269020748a0fd2f8cd6077e91a6a312d413e Mon Sep 17 00:00:00 2001 From: Lach Date: Wed, 26 Aug 2020 12:56:18 +0500 Subject: [PATCH] fix(parser): handle empty lines in text block --- crates/jrsonnet-parser/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/jrsonnet-parser/src/lib.rs b/crates/jrsonnet-parser/src/lib.rs index 03bd5bb3..35e97ee7 100644 --- a/crates/jrsonnet-parser/src/lib.rs +++ b/crates/jrsonnet-parser/src/lib.rs @@ -79,10 +79,11 @@ parser! { = str:$((!['\n'][_])* "\n") {str} pub rule string_block() -> String = "|||" (!['\n']single_whitespace())* "\n" + empty_lines:$(['\n']*) prefix:[' ' | '\t']+ first_line:whole_line() - lines:([' ' | '\t']*<{prefix.len()}> s:whole_line() {s})* + lines:("\n" {"\n"} / [' ' | '\t']*<{prefix.len()}> s:whole_line() {s})* [' ' | '\t']*<, {prefix.len() - 1}> "|||" - {let mut l = first_line.to_owned(); l.extend(lines); l} + {let mut l = empty_lines.to_owned(); l.push_str(first_line); l.extend(lines); l} pub rule string() -> String = "\"" str:$(("\\\"" / "\\\\" / (!['"'][_]))*) "\"" {unescape::unescape(str).unwrap()} / "'" str:$(("\\'" / "\\\\" / (!['\''][_]))*) "'" {unescape::unescape(str).unwrap()}