overturetool / vdm-vscode

Visual Studio Code extension for VDM language support
GNU General Public License v3.0
21 stars 6 forks source link

Allow nested comments #32

Closed paulch42 closed 3 years ago

paulch42 commented 3 years ago

The VDM-10 Language Reference Manual allows inline comments (--) and block comments (/* ... */).

it does not stipulate whether nested comments should be recognised. If allowed, the following is valid

/*
  /*
  */
*/

If not allowed the above sequence is invalid since the first */ closes the first (not the second) /*.

The current implementation does not allow nested comments. That becomes a problem when you want to comment out a block of code containing embedded comments, for the above reason. You can't just put a /* at the start and a */ at the end.

Propose enhancement to allow nested comments.

nickbattle commented 3 years ago

This is really a VDMJ issue rather than VDM VSCode itself, but I agree it would be a "nice to have". As you say, it makes commenting out large blocks of code easier, and a nested interpretation is not incompatible with the LRM.

I have a version (apparently) working on my "development" branch. Do you want to try it out, or are you happy to wait till 1.0.6?

nickbattle commented 3 years ago

@paulch42 I made the same change over in Overture, which is causing a bit of controversy. See https://github.com/overturetool/overture/issues/774.

@jonaskrask The UI colouring rules for comments don't quite match this new change. Is that easy to fix?

jonaskrask commented 3 years ago

It seems like there is no simple way to add this to VSCode, it has been requested a few times in: https://github.com/Microsoft/vscode/issues/3993 and https://github.com/microsoft/vscode/issues/97996. But it has not got any traction and some argue it should not be added. I tried looking up why you would not want this, and people argue that it encourages bad programming practice to allow it. Since you would never intentionally have a nested comment in release code.

We might be able to add it to the extension with a syntax regular expression, but with my limited know-how on regular expressions it will require a significant amount of time that I would rather put into other syntax highlighting fixes.

FYI. an easy way to comment out a bit part of code in VSCode is to highlight the code you want commented and press: ctrl + '

nickbattle commented 3 years ago

I've raised the issue of whether we want VDMJ/Overture to allow nested comments with the Language Board. The feature is in there at the moment, though it's easy to disable, perhaps with a property setting (and even as it stands, most users won't notice).

https://github.com/overturetool/language/issues/52

nickbattle commented 3 years ago

Nested comments are allowed in other languages, like Haskell, Frege, Scala, Rexx, Modula-2, Modula-3 and Oberon. Some of these must be available as VSCode extensions, I would have thought? Could we see how (whether) they correctly highlight comment nesting? Though if you say that there are MS issues raised about the "problem", perhaps they have the same limitations. Is it easy to check?

jonaskrask commented 3 years ago

Inspired by the Scala extension it was fairly easy. So now the syntax highlighting permits nested comments. (Available on development branch)

nickbattle commented 3 years ago

Great work! Thanks :)