-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment scope inconsistent in the presence of subtheories #537
Comments
It's actually perfectly consistent, but unintuitive if you think of it as "commenting out a theory". A comment is delimited by the approriate delimiter for where the comment occurs. A comment outside of a module is delimited by a module delimiter, because it appears on the "module level". A comment inside a module is delimited by a declaration delimiter, because it appears on the "declaration level". A theory - even inside another theory - is delimited by a module delimiter. However, if you now comment out such a theory, and it is nested, then the comment is inside a theory and hence delimited by a declaration delimiter. If a module delimiter appears instead, I would expect that the whole module is being closed, which explains the type-checking error in Test_two - (the delimiter that is supposed to close the (commented out) theory Sub_test closes Test_two instead, hence test_function is outside of a module). I have no idea why the theory Test does not throw a type checking error, though. Inconsistencies between MMT's parser and IntelliJ's syntax highlighting (which I guess you mean by Syntax Highlighting) are quite possible. If we can identify what exactly the discrepancies are they might be fixable, but since IntelliJ uses a fixed BNF grammar whereas MMT does not, there's a decent chance that they aren't fixable at all. Given the above, it's not entirely clear what the supposed bug is - except for a possible bug in the INtelliJ plugin, which doesn't belong here though ;) |
Ah, I now understand why theory Test works, but theory Test_two doesn't: The comment inside the first theory is closed by a module delimiter, but that one does not close the whole module. In the second theory however, the comment is closed by the declaration delimiter following "a : test", and then another module delimiter appears, which closes the whole module. Consequently, a comment inside a theory being delimited by a module delimiter seems to be allowed and not close the surrounding module. EDIT: I think I can adapt the BNF in the IntelliJ Plugin accordingly |
Here's an actual weirdness though:
Some further experimentation shows, that constants can also be closed by module delimiters without closing the module. So the actual rules seems to be:
This means: Objects are always closed with their containing declarations, but declarations need to always be explicitly closed before their containing module can be closed. |
Here is the behaviour I would expect:
|
In other words, whatever theory and view declarations do to "figure out" which level they are on/which delimiter pertains to them, comments should do the same thing. |
I assume the problem is that comment keywords are not level-specific like module keywords which makes this difficult to implement. |
That's fundamentally counter to what comments are though. Firstly: Apparently comments in modules can be delimited by module delimiters - see my previous comment. The solution you propose would require for comments to be actively parsed to look for e.g. the keyword "theory" in order to actively skip declaration delimiters that would otherwise close the comment. And I maintain that that would yield entirely different problems. For example: theory Bla = ^ this theory would now be empty, because the comment contains the keyword "theory" and hence only ends at the MD at the bottom. |
They do, that's exactly your problem ;) |
This is indeed a problem. Then it seems the only option to achieve what I want would be level-specific comment key words.
This would also work, then one would just wrap the submodule with a comment and a declaration-level delimiter, right? |
...this already works. That's exactly how comments work ;) Your problem is exactly that that is how it works. If you comment out a non-empty theory, this theory will contain declaration delimiters. These dellimiters close a comment. What you want is for a comment to not be closed by those declaration delimiters, and instead only close when encountering the module delimiter that closes the theory that you comment out. But as I said, for that to work, the parser would have to actively parse the comment to realize that it contains a theory, and then skip the declaration delimiters. I maintain that that is counter to the whole point of comments; which is that they're not actively being parsed ;) And no other language does that - imagine that in Scala a comment that would contain a "{" would only close if the correponding "}" is encountered... that would cause a lot more confusion than it would solve.
That would be possible, but also horrible. Nobody wants to memorize three distinct comment keywords and which level which belongs to. |
I think we have to distinguish between "comments" and "commenting out". Both are legitimate, and they are related. |
Another "solution" would be always having to escape keywords in comments. But that is horrible too. |
Would this correspond to having dedicated keyword/delimiter pair for those? |
All comments in MMT are paired, the problem is that the ending element of the pair changes depending on the level. I vaguely remember there being a "good" reason why that is the case, but maybe that reason is now obsolete...? Or one picks a separate comment delimiter (also horrible)? Anyway, all of this is something that can/should be discussed |
There is also the issue of "semantic" and "syntactic" comments, ... MMT comments are more on the semantic side. |
Shouldn't the "//"-comments be syntactic in that sense and the "/T" comments semantic? Or is there a semantic use for "//"-comments? |
When I designed the // comment syntax, I liked how it lets users comment out multi-line declarations with a change in a single place. Later I realized it doesn't work well for commenting out the outer one of nested theory/structure declarations. |
Tangential: If there are concrete working/intended-to-fail test cases for syntax highlighters, I'd be more than happy to integrate them into the highlighters I've written. |
Commenting out subtheories does not currently work. Neither commenting out a whole theory that contains substheories. Sometimes things appear to break only in syntax-highlighting. Sometimes during type-checking as well.
Panoptikum-Repo: https://gl.kwarc.info/rappatoni/panoptikum
Code example:
The text was updated successfully, but these errors were encountered: