nerdcommenter
nerdcommenter copied to clipboard
incorrect comment in ocaml code line starting with close brace or ending with open brace
Sample code:
if my_cond then (
print_int 123;
print_newline ();
) else ()
Commented code at first line and last line show syntax errors (* my_cond then (*) and (*) else ()*)
Solution: please open 1 space before the comment closing and after the comment opening in appropriate cases
This sounds like a problem with the syntax highlighting or your linter, not the commenter. As far as I can tell (* is a a valid comment leader and it doesn't really depend on other context such as what's inside the line being commented. If this is not the case can you point to OCAML documentation about this?
If, for the sake of readability, you would like to turn on adding extra spaces after (and before) comment characters there is an option for this in the config (see the Readme) but unless we're violating the strict definition of what a comment is how it displays should be up to the user which is what the config option is for.
I don't think there is any problem with my linter or the syntax highlighting.
Ocaml supports nested comment, which explains why the plugin cannot close the comment in the following case
Before comment:
if foo then (
After comment:
(*if foo then(*)
Compile the commented code gots this error
File "./tmp.ml", line 1, characters 14-16:
Error: Comment not terminated
My ocaml version via ocaml --version
The OCaml toplevel, version 4.04.0
OCaml counts nested (* ... *) blocks, and this allows you to comment out regions of code very easily:
(* This code is broken ...
(* Primality test. ) let is_prime n = ( note to self: ask about this on the mailing lists *) XXX;;
*)
i agree with op. (* ......... (*) is parsed from the left as one comment opening then another nested comment opening (where the inner comment text starts with )).