-
Notifications
You must be signed in to change notification settings - Fork 16
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
Formatter removes parts of the grammar and is not idempotent #25
Comments
@matthiasbalke I'm fine with this, and with PR's. I'll make an effort when I can find time. |
@teverett I created a minimal unit test to reproduce the removal of inline comments (not sure if they are called like that), this seems to be the root of the described problem. If you like take a look at the test: https://github.com/matthiasbalke/Antlr4Formatter/blob/issue-25-idempotent/antlr4-formatter/src/test/java/com/khubla/antlr4formatter/Antlr4FormatterTest.java#L29 I think it might be an easy one for you to fix. In the meantime I try to find the cause of it myself, but as I'm very new to ANTLR I 'm not sure if I find it. Anyway it's a very interesting topic and I never meant to push you. |
Ya, I'm looking it now, and it has to do with hidden comments that are to
the *right* of the current context. Good times!
…On Fri, Dec 28, 2018 at 2:59 PM Matthias Balke ***@***.***> wrote:
@teverett <https://github.com/teverett> I created a minimal unit test to
reproduce the removal of inline comments (not sure if they are called like
that), this seems to be the root of the described problem.
If you like take a look at the test:
https://github.com/matthiasbalke/Antlr4Formatter/blob/issue-25-idempotent/antlr4-formatter/src/test/java/com/khubla/antlr4formatter/Antlr4FormatterTest.java#L29
I think it might be an easy one for you to fix. In the meantime I try to
find the cause of it myself, but as I'm very new to ANTLR I 'm not sure if
I find it.
Anyway it's a very interesting topic and I never meant to push you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#25 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABK1Zv4fBiniloFZFe2YV2MGf5Q_Gi5wks5u9pRagaJpZM4ZkHUN>
.
|
@matthiasbalke ok i have a fix, I think, for the comments issue. Will commit tomorrow. |
@teverett I'm exited. Have a good night. |
@teverett I saw your code fix and updated my tests accordingly. Now the missing comments gets duplicated. I also identified another code fragment, including comments which gets broken by the formatter and added another test for complex fragments. Also I added the Java8 grammar as a kind of integration test for a real grammar. |
Are there any updates on formatting comments correctly? I think last time I checked, the comments got duplicated. |
Sorry, work has been very busy. |
I would like to merge the spotless integration PR diffplug/spotless#328, what do you think? Do you think you find some time to fix the issue the next weeks, or should we merge the integration and fix the formatter afterwards? |
Hiya! Very excited to have Antlr support in Spotless. A rare corner case that duplicates comments is fine, and our paddedCell functionality can actually work around a bug of this sort. But if code gets deleted, that's a pretty serious bug that we can't work around at our level. Happy to merge your PR and release to the public anytime, but I'd like to make sure there isn't a known "code-delete" bug when we do. |
Work has been exceptionally busy, and I just haven't had time to dive in. I apologize for any inconvenience this has caused. |
No apologies! Volunteer open source ought to be fun, not an obligation, and the point of it being open is that any of us who want the feature can jump in and do it ourselves. Thanks for making and maintaining the formatter! We're excited to share your work with the spotless audience whenever somebody gets around to figuring out this issue. |
@nedtwigg thanks |
@teverett I'll check it out! Thanks for the effort! |
@teverett I have tested the know edge cases (duplicating the comments) and it seem to be fine now. But I have found another non idempotent formatting, which is adding spaces each formatting run. To test this I modified csharp/CSharpPreprocessorParser.g4 by running the formatter once and the reverting the buggy part. I've added this as a test case in #33. diff --git a/src/main/antlr4/CSharpPreprocessorParser.g4 b/src/main/antlr4/CSharpPreprocessorParser.g4
index 297e5ca..bb84c19 100644
--- a/src/main/antlr4/CSharpPreprocessorParser.g4
+++ b/src/main/antlr4/CSharpPreprocessorParser.g4
@@ -25,7 +25,7 @@ private boolean allConditions() {
return true;
}
}
-preprocessor_directive returns [boolean value]
+preprocessor_directive returns [ b o o l e a n v a l u e ]
: DEFINE CONDITIONAL_SYMBOL directive_new_line_or_sharp
{ ConditionalSymbols.add($CONDITIONAL_SYMBOL.text);
$value = allConditions(); } # preprocessorDeclaration
@@ -61,7 +61,7 @@ directive_new_line_or_sharp
| EOF
;
-preprocessor_expression returns [String value]
+preprocessor_expression returns [ S t r i n g v a l u e ]
: TRUE
{ $value = "true"; }
| FALSE
@nedtwigg Maybe this could be handled by using |
Since we don't have a known data loss bug any more, Spotless would be happy to merge and release your work (once this has been published to mavenCentral). If you run the formatter a second time, does it add more spaces again? e.g.
If so, then |
@nedtwigg it keeps adding spaces each run. @teverett My only question remaining is, does the misformated grammar part work as expected? Or will it cause errors? But as @nedtwigg said, users could exclude files using syntax like that, in case it leads to unexpected issues. Feel free to release this version to Maven Central. As soon as it is published, I will update my PR to use it, as default version. |
@matthiasbalke @nedtwigg we can't pull this quite yet. The grammar resulting from formatting the latest put isn't invalid. |
Hiya! Just wanted to take a shot at getting this useful piece of code into some more users hands :)
Is the only known problem:
If so, Spotless with |
@nedtwigg I didn't manage to get this fixed using |
I'm just curious, but is anybody from the @antlr org able and willing to help out to fix this - as it seems to be the last - formatting bug before we can release the first working version? @teverett, @parrt do you know have anybody in mind or don't mind taking a look into it yourself? |
I don't have time to look into this sorry |
@matthiasbalke I have been very busy and unable to find time for this. Thank-you for this. I will take a look. |
workaround for broken formatting of action blocks (#25)
@teverett thx for merging. can you release a new version including this bug fix to maven central, in the near future? |
Release 1.2.1 done.
… Matthias Balke ***@***.***>
March 15, 2020 at 10:28 AM
@teverett <https://github.com/teverett> thx for merging. can you
release a new version including this bug fix to maven central, in the
near future?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#25 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJLKZULL7RGVYWUR5DJHZTRHT63JANCNFSM4GMQOUGQ>.
--
Tom Everett
tom@khubla.com <mailto:tom@khubla.com>
<https://www.postbox-inc.com>
|
@matthiasbalke thanks again for the fix. |
Now that 1.2.1 is on mavencentral, can we close out this little tree of issues? |
@matthiasbalke any objection to closing this issue? |
@teverett no not at all. Thx |
….9.1 Bump antlr.version from 4.9 to 4.9.1
I just applied a local build of my spotless antlr4 formatter on antlr/grammars-v4 several times in a row and everytime the sources changed. To me It looks like the formatter is removing stuff. So I did the same using the standalone JAR to check if it is a bug in my spotless integration, but the result was the same.
Here's what I did:
java -jar antlr4-formatter-standalone-1.1.0.jar -dir .
java -jar antlr4-formatter-standalone-1.1.0.jar -dir .
But afterwards the following files where modified:
Taking a look at
java8/Java8.g4
the first formatting removes some comments (which I think it shouldn't)Shortened Diff:
but the second formatting removes parts of the grammar:
Complete Diff:
I think we should extract the non working grammar parts and write unit tests for each. This way we are testing
Antlr4ParseTreeListenerImpl.java
which is anyway very complex and could use some refactoring afterwards.The text was updated successfully, but these errors were encountered: