langium icon indicating copy to clipboard operation
langium copied to clipboard

Check the state of optional unordered group handling

Open dhuebner opened this issue 2 years ago • 4 comments

As described here optional elements inside an unordered group are currently not supported.

We should check how the new Chevrotain implementation affects the current unordered group implementation. Depending on the result remove existing validation, or implement a solution so that unordered groups are handled correctly.

dhuebner avatar Dec 07 '22 07:12 dhuebner

Update: Using an optional unordered group element currently leads to a stack overflow. Same problem exists also when an optional alternative is used inside a many group:

( prop1='prop1'? | prop2='prop2')*

dhuebner avatar Dec 07 '22 14:12 dhuebner

Is it the same stack overflow as in #775?

spoenemann avatar Dec 09 '22 08:12 spoenemann

@spoenemann No. Here it is inside the chevrotain-allstart package. Could we address this issue before v1.0.0?

dhuebner avatar Dec 09 '22 13:12 dhuebner

While experimenting with unordered groups, I found out that Chevrotain (or Langium?) treats all options within an unordered group as optional anyway, i.e., ('a' & b') matches , a, b, a b, b a. Therefore, it acts exactly how I would expect ('a'? & 'b'?) to work, which means both expressions are equivalent. Of course, the same applies to ('a'? | 'b'?)* vs. ('a' | 'b')*, just that these also allow duplicates of a and b.

Maybe you have already known that. If no modification in Chevrotain is made, doesn't that mean that there are the following two options?

  1. Disallow both ('a'? | 'b'?)* and ('a'? & 'b'?) with a validation message that recommends using an expression without ?
  2. Remove the optional modifier internally before passing the grammar rules to Chevrotain

l-ehlers avatar Jan 02 '23 14:01 l-ehlers