Skip to content

Revisit the recommended formatting of nom macro invocations #829

@dtolnay

Description

@dtolnay

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions