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 choice indent #16

Merged
merged 1 commit into from
Mar 3, 2023
Merged

Fix choice indent #16

merged 1 commit into from
Mar 3, 2023

Conversation

huacnlee
Copy link
Member

@huacnlee huacnlee commented Mar 3, 2023

Fix #15

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

do you plan to address all those choice indent issues in this PR or only some?

"0" ~ ("1" // a comment
| "2" // another comment
| "3" // longer comment
| "4" // final comment
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if correct to align the comment like that -- the original feedback was that the intention was to put the "final comment" on top of "a" (or "5" in log_line3), but formatting makes it look like that it's attached to the previous line ("4" instead of "a" or "5")

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't try to improve the comment style for this case, but focused on ensuring alignment and avoiding loss.

"1" ~ ("2" // another comment
| "3" // longer comment
| "4" // final comment
| "5" | "a" | "b" | "c" | "d" | "e") // comment
Copy link
Contributor

Choose a reason for hiding this comment

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

will this split up the choices if there was more of them, so that it is not too long vertically?
The original feedback mentioned there may be too many choices:

the line that starts with pair35 in the output doesn't scale if there are lots and lots of rules.
In my real output - I ended up with a vertical formatted input with one of the output lines being 634 characters long (593 up to the comment).

@huacnlee
Copy link
Member Author

huacnlee commented Mar 3, 2023

This PR just fixes serious issues:

A. The first comment inside {} may be lost.

a = { //this will miss
"a"
}

B. When comment after a choice, the indent have a one more space.

a = {
    "a" // comment1
   | "b" // comment2
   | "c"
}

after

a = {
    "a" // comment1
  | "b" // comment2
  | "c"
}

@huacnlee
Copy link
Member Author

huacnlee commented Mar 3, 2023

In original question of he wants.

Raw text:

pair = { string ~ ":" ~ value }

log_line = {
    pair ~ (
        pair
        // a comment
        | pair        // another comment
        | pair   // longer comment
        | pair34
        // final comment
        | pair35
        | pair
        | pair
        | pair
        | pair
    ) 
}

Expected:

pair = { string ~ ":" ~ value }

log_line = {
    pair ~ (
        pair
        // a comment
        | pair // another comment
        | pair // longer comment
        | pair34
        // final comment
        | pair35
        | pair
        | pair
        | pair
        | pair
    ) 
}

Current result:

pair = { string ~ ":" ~ value }

log_line = {
    pair ~ (pair // a comment
  | pair // another comment
  | pair // longer comment
  | pair34 // final comment
  | pair35 | pair | pair | pair | pair)
}

If there are no comment inside the expression, the format result is ok:

pair = { string ~ ":" ~ value }

log_line = {
    pair ~ (pair | pair | pair | pair34 | pair35 | pair | pair | pair | pair)
}

I know that, but we're going to fix this is complex, I need to thinking about how to implement it. Maybe it will take a lot of time.

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

ok, will merge this one first

@tomtau tomtau merged commit a79113b into pest-parser:master Mar 3, 2023
@huacnlee huacnlee deleted the fix-choice-indent branch March 3, 2023 15:48
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.

Comment and choice_operator format bug
2 participants