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

Printer patterns are insufficient #40

Open
4 tasks
HawkSK opened this issue Aug 8, 2020 · 1 comment
Open
4 tasks

Printer patterns are insufficient #40

HawkSK opened this issue Aug 8, 2020 · 1 comment

Comments

@HawkSK
Copy link
Contributor

HawkSK commented Aug 8, 2020

The only two currently available printer patterns @NewLine and @Indent are not flexible enough to define the default formatting a language should have. The following features are missing:

  1. Printer pattern for a TokenPart (i.e. from @Before, @After) enabling:
    • leading new line
    • newline bewteen tokens in String[] value
    • trailing new line
    • indentation
  2. Printer pattern enabling trailing new line after BindingNotationPart or OptionalPart. Currently @NewLine can be used to put a leading new line there.
    Suggestions:
    1. add an enum field to @NewLine with values BEFORE, AFTER, BOTH; or
    2. rename @NewLine to @OnNewLine/@FirstOnLine and introduce a new annotation @LastOnLine/@OnEndOfLine
  3. Separator new line style with the following options:
    i. last on line
elem1,
elem2

ii. first on line

elem1
, elem2

iii. no new line
elem1 , elem2

iv. own line

elem1
,
elem2
  • Note: It should be possible to define an empty separator just with the new line style.
  1. "Stickiness" of TokenParts and Separators. It is the ability of the terminal token (usually punctuation) to ignore whitespace from its sides:
    1. not sticky array [ 0 ] . method ( )
    2. left-sticky separator elem1, elem2, elem3
    3. right-sticky lpar if (condition
    4. both sides sticky dot operator obj.method
    • Empty separator should be implicitly sticky from either right or left, so that there is only 1 space

Optionally define more abstract annotations, which replace multiple usages of others. F.e. @Vertical for marking a constructor instead of writing @NewLine before all parameters starting with the second (skipping the first because that should be governed from outside). However, it should be thought through whether the new line applies before the first @Before token or before the actual properties.

Optional: TokenParts do not have a connection with their property currently. That means there is no way to know where the last token from @After ends and where the first token from the next @Before starts. It could maybe be useful to know which tokens are in one "group" for some formatting in the future. F.e. @Vertical could be applied also to one group, meaning each token from @Before, @After and the property are on a new line.

@HawkSK
Copy link
Contributor Author

HawkSK commented Sep 1, 2020

Another feature can be optional TokenParts. Theoretically, this could be achieved with @Flag (#31), but maybe we do not really need the boolean value itself, so that the abstract syntax is not touched, only the concrete syntax. Example: the optional AN keyword in LOLCODE binary operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant