Skip to content

Commit

Permalink
Merge pull request #175 from CertainLach/feat/chomped-string-block
Browse files Browse the repository at this point in the history
Chomped string blocks
  • Loading branch information
CertainLach authored Oct 12, 2024
2 parents a31a8ef + c01145a commit 7160d47
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/jrsonnet-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,21 @@ parser! {
pub rule whole_line() -> &'input str
= str:$((!['\n'][_])* "\n") {str}
pub rule string_block() -> String
= "|||" (!['\n']single_whitespace())* "\n"
empty_lines:$(['\n']*)
prefix:[' ' | '\t']+ first_line:whole_line()
lines:("\n" {"\n"} / [' ' | '\t']*<{prefix.len()}> s:whole_line() {s})*
[' ' | '\t']*<, {prefix.len() - 1}> "|||"
{let mut l = empty_lines.to_owned(); l.push_str(first_line); l.extend(lines); l}
= "|||" chomped:"-"? (!['\n']single_whitespace())* "\n"
empty_lines:$(['\n']*)
prefix:[' ' | '\t']+ first_line:whole_line()
lines:("\n" {"\n"} / [' ' | '\t']*<{prefix.len()}> s:whole_line() {s})*
[' ' | '\t']*<, {prefix.len() - 1}> "|||"
{
let mut l = empty_lines.to_owned();
l.push_str(first_line);
l.extend(lines);
if chomped.is_some() {
debug_assert!(l.ends_with('\n'));
l.truncate(l.len() - 1);
}
l
}

rule hex_char()
= quiet! { ['0'..='9' | 'a'..='f' | 'A'..='F'] } / expected!("<hex char>")
Expand Down

0 comments on commit 7160d47

Please sign in to comment.