-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add support for formatting .yrl and .xrl files #41
Comments
Jumping on this task, I have some questions:
|
Each erlang form ends with a Here are some things we will need to add:
|
@michalmuskala I think I saw a specification for |
It's in here a bit lower: https://erlang.org/doc/man/yecc.html#more-examples I agree adding first-class support for yecc forms would be probably the "nicest" solution |
It can be done gradually. - There is the explicit "Erlang code." part of |
Amazing thank you, I somehow missed that. |
Looks like this actually mostly works today - just issues a lot of warnings. #289 |
Yes, this task is about also formatting the |
But technically, like Ilya maybe meant, this can also be done gradually, by for example, first only supporting |
Until everything is supported, I think a good compromise could be to warn once that the file wasn't entirely formatted. |
Then, is there a reference on how it should be formatted?
attribute -> '-' 'if' attr_val : build_attribute('$1', '$2', '$3').
attribute -> '-' atom : build_attribute('$1', '$2', no_parens).
attribute -> '-' atom attr_val : build_attribute('$1', '$2', '$3'). Potential worse result: attribute -> '-' 'if' attr_val : build_attribute('$1', '$2', '$3').
attribute -> '-' atom : build_attribute('$1', '$2', no_parens).
attribute -> '-' atom attr_val : build_attribute('$1', '$2', '$3').
type -> type '::' type : ?mkop2('$1', '$2', '$3').
type -> type '|' type : ?mkop2('$1', '$2', '$3').
type -> type '..' type : ?mkop2('$1', '$2', '$3'). Potential worse result: type -> type '::' type :
?mkop2('$1', '$2', '$3').
type -> type '|' type :
?mkop2('$1', '$2', '$3').
type -> type '..' type :
?mkop2('$1', '$2', '$3'). Or type ->
type '::' type : ?mkop2('$1', '$2', '$3').
type ->
type '|' type : ?mkop2('$1', '$2', '$3').
type ->
type '..' type : ?mkop2('$1', '$2', '$3'). |
Great question and thank you for bringing examples in the ask, this points out great things to consider and is making me think. Of the ideas here, I would prefer
The reason is that erlfmt does not align things anywhere else. I have looked at how I have manually formatted a bnf for another grammar I worked on and I naturally conformed to this style sometimes. Although we had opening and closing braces for the SDT rule. So it was a bit of an easier style choice. Trying out some other styles:
After that I think I still prefer your idea
But we can discuss this for a while. But great to start thinking about this already. |
I'm a big fan of vertical alignment. Helps to see the structure / patterns (either it's repeated, or on the contrary the variations are more easily seen). It's also helpful to spot copy-paste mistake. Some people cannot stand it, so it would be both complicated and controversial to make a pretty printer generate that. |
Jumping out of this task! (Exercise is good for you). Rationale:
|
cc @ilya-klyuchnikov
The text was updated successfully, but these errors were encountered: