Skip to content

Commit

Permalink
feat: chomped string block
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Oct 12, 2024
1 parent a31a8ef commit c01145a
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 c01145a

Please sign in to comment.