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

fix(grainfmt): Fix grouping of expressions on LHS of fn application, record access etc #1562

Merged
merged 8 commits into from
Dec 29, 2022

Conversation

marcusroberts
Copy link
Member

@marcusroberts marcusroberts commented Dec 27, 2022

Look for the special case of expressions on the left hand side of function application, record/array accessors and group with parens as appropriate.

Fixes #1559

@marcusroberts
Copy link
Member Author

@ospencer does this look like it covers all the cases you can think of?

@ospencer
Copy link
Member

I would probably reverse the logic and group everything that isn't one of the things to be grouped. Then you can just follow this: https://github.com/grain-lang/grain/blob/main/compiler/src/parsing/parser.mly#L545

So if it is not a:

  • function call
  • constant
  • tuple
  • identifier
  • array access
  • record access
  • record
  • block
  • list
  • array

Then it needs parens. That'll help us in the future too if we ever add more constructs; it's easier to tell what needs to be updated.

Maybe you might want to make a helper function for the above, so it's easy to modify if we update the parser rules.

@ospencer
Copy link
Member

That'll also err on the side of being ugly but correct in the worst case.

@marcusroberts
Copy link
Member Author

Thanks, that makes sense!

@marcusroberts
Copy link
Member Author

Thanks @ospencer that's done I think.

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great! Just some thoughts around naming.

compiler/src/formatting/format.re Outdated Show resolved Hide resolved
Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small bug (related to the marshal format change)

compiler/src/formatting/format.re Outdated Show resolved Hide resolved
Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, excellent work @marcusroberts!

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@phated phated merged commit 6c46015 into main Dec 29, 2022
@phated phated deleted the marcus/issue1559 branch December 29, 2022 09:56
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

Successfully merging this pull request may close these issues.

Incorrect formatting of grouped expressions
3 participants