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

Allow newlines after match condition commas without requiring backslashes at end of each line #2201

Open
Tracked by #40488
AnmAtAnm opened this issue Jan 29, 2021 · 3 comments

Comments

@AnmAtAnm
Copy link

AnmAtAnm commented Jan 29, 2021

Describe the project you are working on

I want the following statement to be more legible

match x:
    MyClass.EnumType.CONSTANT_A,MyClass.EnumType.CONSTANT_B,MyClass.EnumType.CONSTANT_C,MyClass.EnumType.CONSTANT_D:
        do_this()
    MyClass.EnumType.CONSTANT_E,MyClass.EnumType.CONSTANT_F,MyClass.EnumType.CONSTANT_G,MyClass.EnumType.CONSTANT_H:
        do_that()

Describe the problem or limitation you are having in your project

It is difficult to read each of the possible match conditions when they are forced to be on the same line.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

GDScript should allow a newline after the comma in a match case with multiple conditions. Compare the above example this this one:

match x:
    MyClass.EnumType.CONSTANT_A,
    MyClass.EnumType.CONSTANT_B,
    MyClass.EnumType.CONSTANT_C,
    MyClass.EnumType.CONSTANT_D:
        do_this()
    MyClass.EnumType.CONSTANT_E,
    MyClass.EnumType.CONSTANT_F,
    MyClass.EnumType.CONSTANT_G,
    MyClass.EnumType.CONSTANT_H:
        do_that()

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

If the match condition has a comma followed by a newline, the parser should process the next line as another condition of the same case (expecting the indent to be the same).

If this enhancement will not be used often, can it be worked around with a few lines of script?

The legibility cannot be worked around.

A blackslash after each comma will allow the parser to treat them as if they are on the same line, but this may not be obvious to or expected by all developers

Is there a reason why this should be core and not an add-on in the asset library?

Not applicable. This is a language parsing issue.

@Calinou Calinou changed the title GDScript: Allow newlines after match condition commas Allow newlines after match condition commas Jan 29, 2021
@Calinou Calinou changed the title Allow newlines after match condition commas Allow newlines after match condition commas Jan 29, 2021
@Calinou
Copy link
Member

Calinou commented Jan 29, 2021

The legibility cannot be worked around.

I think you can add a backslash before each line break in the comma expression.

@AnmAtAnm
Copy link
Author

I think you can add a backslash before each line break in the comma expression.

Tested and confirmed. I think the request is valid, but much less pressing. It becomes a discoverability issue more than a legibility issue.

Do you want me to rewrite the issue?

@Calinou
Copy link
Member

Calinou commented Jan 29, 2021

Do you want me to rewrite the issue?

No, I think it's fine as-is 🙂 I edited the title accordingly.

@Calinou Calinou changed the title Allow newlines after match condition commas Allow newlines after match condition commas without requiring backslashes at end of each line Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants