mike-lischke / antlr-format

A tool to format ANTLR grammars
MIT License
5 stars 2 forks source link

Spacing after parentheses #13

Open kaby76 opened 1 month ago

kaby76 commented 1 month ago

Here is a grammar with some various spaces in alt indentation, before and after parentheses.

// $antlr-format alignColons hanging, alignSemicolons hanging, alignTrailingComments true, allowShortBlocksOnASingleLine true
// $antlr-format allowShortRulesOnASingleLine false, columnLimit 150, maxEmptyLinesToKeep 1, minEmptyLines 1, reflowComments false, useTab false

parser grammar FortranParser;

options {
    tokenVocab = FortranLexer;
}

binding_attr
  : access_spec
    | DEFERRED
    | NONOVERRIDABLE
    | NOPASS
  | PASS (       LPAREN arg_name RPAREN  )?
    ;

other_binding_attr
  : access_spec
    | DEFERRED
    | NONOVERRIDABLE
    | NOPASS
  | PASS ( LPAREN arg_name RPAREN )?
    ;

another_binding_attr
  : access_spec
    | DEFERRED
    | NONOVERRIDABLE
    | NOPASS
  | PASS (LPAREN arg_name RPAREN)?
    ;

When I reformat the grammar, spacing is adjusted to be consistent for alt indentation, and for spacing before ")". But, the spacing following "(" is only readjusted if there are iniitally some spaces following the "(". If there is no space following a left parenthesis initially, spacing is not readjusted.

I can work around this inconsistency by adding a space after every LPAREN in the Antlr4 grammar (using Trash, trparse -t ANTLRv4 *.g4 | trquery insert after ' //LPAREN' '" "' | trsponge -c) prior to reformatting.

mike-lischke commented 1 month ago

I guess you mean the spacing of the alt that is not adjusted when there's no space after the opening par, like in the another_binding_attr rule?

kaby76 commented 1 month ago

I guess you mean the spacing of the alt that is not adjusted when there's no space after the opening par, like in the another_binding_attr rule?

Yes. in another_bindnig_attr.