YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.3k stars 201 forks source link

Proposal: Multi-line comments #380

Closed Bryan-Legend closed 9 months ago

Bryan-Legend commented 9 months ago

/* Yarnspinner is often used for intensive writing tasks, so it should support multi-line comments for writing outlines and other story documentation.

Also, they can be handy to comment out entire nodes. */

McJones commented 9 months ago

I am going to close this issue as something we don't intend on adding to the language, but I'd like to give you our reasoning as this is something that we've discussed a fair bit before internally way back in the pre v1 release days of Yarn Spinner.

So the first and major issue is adding multi-line comments actually adds a surprisingly large amount of complexity to the parsing of yarn (or any language tbh). In that correctly handling all the nesting of comments and mixing elements that aren't comments but look the same is particularly brutal to the parser grammar. As an example of this:

/*
Calculator: hello, I am a calculator
Player: What can you do?
Calculator: I can perform the following +-*/
*/

Sure this example is one I made up on the spot but how should this be handled? And this is true with also just nesting the multi-line comments in general. So take the following example:

/*
Here is some regular text
/*
Here is some more text inside a nested comment
*/
Here is some text outside the nested comment
*/

In this current form should the parser have seen two comment blocks or one? And where should the top level comment end? If we delete the top comment opening terminal is there now an error?

So the options are to:

Secondly in our recommended editor of VSCode if you select a block of text and press Ctrl (or Command on macOS) and / it will automatically append the // comment terminal to the front of the line. Pressing Ctrl + / again will remove the //, giving an easy way to comment and uncomment lines in bulk.

Overall we decided that the quick line comment feature of VSCode gives enough of the benefits of multi-line comments, without any of the edge cases, so we haven't implemented them. I hope this clears up why we don't see any real benefit to multi-line comments.