Monorepo management for opam overlays
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(monopam): handle dune multi-line string syntax in dune-project parser

Dune uses "\| and "\> prefixes for multi-line strings, which are not
standard S-expressions. Preprocess these into regular quoted strings
before parsing with parsexp, fixing "unterminated quoted string" errors
on projects like crowbar.

+45
+45
lib/dune_project.ml
··· 88 88 | _ -> None) 89 89 sexps 90 90 91 + (** Preprocess dune multi-line string syntax. 92 + 93 + Dune uses ["\|] and ["\>] prefixes for multi-line strings (see 94 + {{:https://dune.readthedocs.io/en/stable/concepts/variables.html}Dune docs}). 95 + These are not standard S-expressions, so we convert them to regular quoted 96 + strings before parsing. *) 97 + let preprocess_dune_strings content = 98 + let lines = String.split_on_char '\n' content in 99 + let buf = Buffer.create (String.length content) in 100 + let in_multiline = ref false in 101 + List.iter 102 + (fun line -> 103 + let trimmed = String.trim line in 104 + if 105 + String.length trimmed >= 3 106 + && trimmed.[0] = '"' 107 + && trimmed.[1] = '\\' 108 + && (trimmed.[2] = '|' || trimmed.[2] = '>') 109 + then begin 110 + if not !in_multiline then begin 111 + Buffer.add_char buf '"'; 112 + in_multiline := true 113 + end; 114 + let text = String.sub trimmed 3 (String.length trimmed - 3) in 115 + let text = String.trim text in 116 + if Buffer.length buf > 1 && text <> "" then Buffer.add_char buf ' '; 117 + Buffer.add_string buf text 118 + end 119 + else begin 120 + if !in_multiline then begin 121 + Buffer.add_char buf '"'; 122 + Buffer.add_char buf '\n'; 123 + in_multiline := false 124 + end; 125 + Buffer.add_string buf line; 126 + Buffer.add_char buf '\n' 127 + end) 128 + lines; 129 + if !in_multiline then begin 130 + Buffer.add_char buf '"'; 131 + Buffer.add_char buf '\n' 132 + end; 133 + Buffer.contents buf 134 + 91 135 let parse content = 136 + let content = preprocess_dune_strings content in 92 137 match Parsexp.Many.parse_string content with 93 138 | Error err -> 94 139 Error