Skip to content
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

Bug: alignColons formatting setting affects semicolon on first line #134

Closed
xpe opened this issue Feb 4, 2021 · 5 comments
Closed

Bug: alignColons formatting setting affects semicolon on first line #134

xpe opened this issue Feb 4, 2021 · 5 comments
Labels
possible bug Could be a bug

Comments

@xpe
Copy link

xpe commented Feb 4, 2021

The alignColons setting, as I understand it, should only impact colons (:). However, I've noticed that it changes the formatting of semicolons (;) on the first line in both my parser grammar and lexer grammar.

For example, here is the result of formatting:

lexer grammar FooLexer
    ;

Just in case there might be some kind of interactions between settings, here are my settings:

    "antlr4.format": {
        "alignTrailingComments": true,
        "allowShortBlocksOnASingleLine": true,
        "breakBeforeBraces": false,
        "columnLimit": 78,
        "continuationIndentWidth": 4,
        "indentWidth": 4,
        "keepEmptyLinesAtTheStartOfBlocks": false,
        "maxEmptyLinesToKeep": 1,
        "reflowComments": false,
        "spaceBeforeAssignmentOperators": true,
        "tabWidth": 4,
        "useTab": false,
        "alignColons": "hanging",
        "singleLineOverrulesHangingColon": true,
        "allowShortRulesOnASingleLine": true,
        "alignSemicolons": "hanging",
        "breakBeforeParens": false,
        "ruleInternalsOnSingleLine": false,
        "minEmptyLines": 1,
        "groupedAlignments": true,
        "alignFirstTokens": true,
        "alignLexerCommands": false,
        "alignActions": false,
        "alignLabels": true,
        "alignTrailers": false
    },
@mike-lischke
Copy link
Owner

You have set "alignSemicolons" to hanging as well. This is probably why you got this result.

@xpe
Copy link
Author

xpe commented Feb 5, 2021

You have set "alignSemicolons" to hanging as well. This is probably why you got this result.

Do you agree with these statements:

  • alignSemicolons should only apply to rule definitions.
  • alignSemicolons should not apply to the first line of a grammar file (e.g. grammar, lexer grammar, or parser grammar).

@xpe
Copy link
Author

xpe commented Feb 5, 2021

My goal is setup the extension to do ANTLR formatting along the lines of common examples provided in TDAR and many examples in the ANTLR4 grammars repo. This means:

  • in rules, align :, |, and ;
  • use semicolons normally in non-rules (such as lexer grammar FooGrammar;)

I don't think this is currently possible given the current setting options, which is why I filed this as a bug.

@mike-lischke
Copy link
Owner

Do you agree with these statements:

* `alignSemicolons` should _only_ apply to rule definitions.

* `alignSemicolons` should _not_ apply to the first line of a grammar file (e.g. `grammar`, `lexer grammar`, or `parser grammar`).

I haven't thought about other occurences than rules, so I cannot answer with yes currently. However, I have not seen output where the semicolon from the introducer line is placed on the next line and I have tests with all 3 semicolon settings. But maybe I just missed that.

@mike-lischke
Copy link
Owner

My goal is setup the extension to do ANTLR formatting along the lines of common examples provided in TDAR and many examples in the ANTLR4 grammars repo. This means:

* in rules, align `:`, `|`, and `;`

* use semicolons normally in non-rules (such as `lexer grammar FooGrammar;`)

I agree. The setting should not affect non-rules.

I don't think this is currently possible given the current setting options, which is why I filed this as a bug.

If that's the case then it should be fixed. Interesting here is that I never got a bug report for this issue, which either means people don't care about it or they never use hanging semicolons. I certainly do not.

@mike-lischke mike-lischke added the possible bug Could be a bug label May 27, 2022
mike-lischke added a commit that referenced this issue Nov 9, 2023
…t line

Signed-off-by: Mike Lischke <mike@lischke-online.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Could be a bug
Projects
None yet
Development

No branches or pull requests

2 participants