Use quoted strings for chunks of code (multiline strings)#13162
Conversation
|
This looks reasonable and the LaTeX code in particular benefits greatly. I try to find avenues for nitpicks that are strictly less important than the topic of the PR itself, and at first I thought that I would be stuck on a PR about lexical conventions. Fear not, we can talk about whitespace! The use of quoted string literals introduces a dedentation of the content -- we cannot indent to the current indentation level inside the string. This is visually jarring but a reasonable cost to pay for the increased readability of the content. However, I would like to suggest a rule when this happens, that you do not always respect: when string-literal content is going to dedented at the very beginning of a line, I think that the input delimiter that introduces this content should also be dedented at the very beginning of a line. So this: if ctx.has_refill then
pr ctx {|
let rec __ocaml_lex_refill_buf lexbuf _buf _len _curr _last
_last_action state k =
...
|}should rather be written as if ctx.has_refill then
pr ctx
{|
let rec __ocaml_lex_refill_buf lexbuf _buf _len _curr _last
_last_action state k =
...
|}so that it is clear what is going on. (There are several other instances in this PR.) |
|
Thanks for the review, I've applied your suggestion. As a side note, I was tempted to introduce a new function handling the indentation of the generated code in let pr' ~pref ctx =
Printf.ksprintf (fun str ->
let i = ref 0 in
String.iteri (fun j -> function
| '\n' when !i = j ->
Out_channel.output_char ctx.oc '\n';
incr i;
| '\n' ->
Out_channel.output_string ctx.oc pref;
Out_channel.output_substring ctx.oc str !i (j - !i + 1);
i := j + 1
| _ -> ()) str;
if !i <> String.length str then begin
Out_channel.output_string ctx.oc pref;
Out_channel.output_substring ctx.oc str !i (String.length str - !i)
end)…but maybe that's something more suited for the |
|
Your |
|
Thanks, I've applied your suggestions to keep whitespace identical.
I'll keep it as-is for now and see later if I can come up with a satisfying design. |
Now that #12514 is merged, we can take advantage of OCaml 4.02's quoted strings, making both the code being emitted, and the formatting of the lines, somewhat less obscure.