git.delta.rocks / jrsonnet / refs/commits / 7160d47bdfd7

difftreelog

Merge pull request #175 from CertainLach/feat/chomped-string-block

Yaroslav Bolyukin2024-10-12parents: #a31a8ef #c01145a.patch.diff
in: master
Chomped string blocks

1 file changed

modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
143 pub rule whole_line() -> &'input str143 pub rule whole_line() -> &'input str
144 = str:$((!['\n'][_])* "\n") {str}144 = str:$((!['\n'][_])* "\n") {str}
145 pub rule string_block() -> String145 pub rule string_block() -> String
146 = "|||" (!['\n']single_whitespace())* "\n"146 = "|||" chomped:"-"? (!['\n']single_whitespace())* "\n"
147 empty_lines:$(['\n']*)147 empty_lines:$(['\n']*)
148 prefix:[' ' | '\t']+ first_line:whole_line()148 prefix:[' ' | '\t']+ first_line:whole_line()
149 lines:("\n" {"\n"} / [' ' | '\t']*<{prefix.len()}> s:whole_line() {s})*149 lines:("\n" {"\n"} / [' ' | '\t']*<{prefix.len()}> s:whole_line() {s})*
150 [' ' | '\t']*<, {prefix.len() - 1}> "|||"150 [' ' | '\t']*<, {prefix.len() - 1}> "|||"
151 {let mut l = empty_lines.to_owned(); l.push_str(first_line); l.extend(lines); l}151 {
152 let mut l = empty_lines.to_owned();
153 l.push_str(first_line);
154 l.extend(lines);
155 if chomped.is_some() {
156 debug_assert!(l.ends_with('\n'));
157 l.truncate(l.len() - 1);
158 }
159 l
160 }
152161