question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add the ability to use parentheses when declaring `TypeAlternatives`

See original GitHub issue

The Langium grammar allows to create the rule X, where the property x is an array of type alternatives, and it has to be possible to declare the corresponding type XType, as in the example. We should support parentheses in TypeAlternatives.

X returns XType:
    x+=(ID | NUMBER)*;

interface XType {
    x: (number | string)[];
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pluraliacommented, May 24, 2022

I would personally prefer an array of strings over mixed strings and numbers, so yes I think the restriction should be ok.

The ability to have an array of strings will remain after the parentheses are added, also I think it’s a “low hanging fruit”, so I’d suggest to implement it.

0reactions
spoenemanncommented, May 24, 2022

Would it be okay?

I would personally prefer an array of strings over mixed strings and numbers, so yes I think the restriction should be ok. This is related to https://github.com/langium/langium/issues/494#issuecomment-1125811597, where I proposed to disallow multiple assignments with different types to the same property. But maybe I’m too strict here and there could be valid use cases to write explicit alternatives to an assignment.

An important point I should mention: property types in the current implementation are able to support brackets, and it won’t be that “expensive” to implement.

If it’s a “low hanging fruit”, we could still implement this, independently of how we decide about validation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Parentheses Cheat Sheet - Edlitera
Master how parentheses work in Python to learn to code faster.
Read more >
Do the parentheses after the type name make a difference ...
NO: The object is default-initialized, which, for non-class types, leaves it with an indeterminate value (it effectively isn't initialized). These rules ...
Read more >
Parentheses | Effective Writing Practices Tutorial
Parentheses are used to explain the statement or provide explanatory information in the sentence.
Read more >
Dashes, Parentheses, Brackets, Ellipses - Swarthmore College
DASHES Use a dash to draw attention to parenthetical information, to prepare ... Brackets are used to enclose words that you add to...
Read more >
Typing assistance | ReSharper Documentation - JetBrains
Wrap code blocks with braces and parentheses ... With ReSharper, you can select a code block or an expression, then type an opening...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found