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

Revisit the recommended formatting of nom macro invocations #829

Closed
dtolnay opened this issue Aug 22, 2018 · 3 comments
Closed

Revisit the recommended formatting of nom macro invocations #829

dtolnay opened this issue Aug 22, 2018 · 3 comments

Comments

@dtolnay
Copy link

dtolnay commented Aug 22, 2018

Over the past two years, the style team has settled on a Rust style that uses exclusively four-space indentation

Each level of indentation must be four spaces (that is, all indentation
outside of string literals and comments must be a multiple of four).

and discourages any form of "visual" alignment meaning whitespace within a line to align tokens on vertical column boundaries. Please find the complete formatting guidelines RFC in rust-lang/rfcs#2436.

I find that the heavily visually aligned style in nom's documentation looks very out of place in modern Rust code formatted according to the style team guidelines. Notice the two-space indentation, the one line indented by 11 spaces to achieve visual alignment, and the visual alignment of the hex_primary and >> tokens in the following snippet from the readme.

named!(hex_color<&str, Color>,
  do_parse!(
           tag!("#")   >>
    red:   hex_primary >>
    green: hex_primary >>
    blue:  hex_primary >>
    (Color { red, green, blue })
  )
);

It would be valuable to redesign how we intend for nom macro invocations to be formatted in modern Rust code, adjusting the input syntax of macros as necessary to arrive at a style that is harmonious with the one being pushed by the style team.

@Geal
Copy link
Collaborator

Geal commented Oct 6, 2018

it would probably be useful to define a proper style for nom macros. I see two issues for now:

@dtolnay
Copy link
Author

dtolnay commented Oct 6, 2018

  • The documentation should display a well thought-out style regardless of whether that style is implemented in rustfmt.
  • Yes, I believe any DSL embedded in Rust should follow a style that is harmonious with the Rust style to the extent possible. I believe it is possible to come up with a style for nom parsers that does this better.

@Geal
Copy link
Collaborator

Geal commented Oct 25, 2021

closing this as macros have been removed

@Geal Geal closed this as completed Oct 25, 2021
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

2 participants