GuntherRademacher / rr

RR - Railroad Diagram Generator
Apache License 2.0
467 stars 51 forks source link

Direct recursion elimination produces duplicate path #43

Closed PhilippSalvisberg closed 1 month ago

PhilippSalvisberg commented 1 month ago

Thanks for this excellent tool. I use it to visualize a SQL grammar. Here's a small excerpt of the grammar to reproduce the problem:

dataType ::=
      oracleBuiltInDatatype
    | ansiSupportedDatatype
    | postgresqlDatatype
    | userDefinedType
    | dataType (LSQB RSQB)+

LSQB ::=  '['
RSQB ::=  ']'

I use the following settings with the current version (8773d49e0d0dff4767ac094bfeb28c56d4a35e25) of the master branch.

image

The result looks like this:

image

I highlighted the duplicate path.

The result looks good when I disable the "Direct recursion elimination" option. Like this:

image

Disabling the option as a workaround is good enough for me.

mingodad commented 1 month ago

It seems that you do not need the + in | dataType (LSQB RSQB)+.

PhilippSalvisberg commented 1 month ago

It seems that you do not need the + in | dataType (LSQB RSQB)+.

No, the + is required. The result looks good when "Direct recursion elimination" is disabled. I'd expect a single path also when enabling "Direct recursion elimination".

mingodad commented 1 month ago

The + is not required the left recursive rule | dataType LSQB RSQB already mean a dataType followd by one or more LSQB RSQB.

PhilippSalvisberg commented 1 month ago

The + is not required the left recursive rule | dataType LSQB RSQB already mean a dataType followd by one or more LSQB RSQB.

Oh you are correct @mingodad. I haven't seen that.

PhilippSalvisberg commented 1 month ago

Based on the comment of @mingodad I think the visualization is correct. Enabling "Direct recursion elimination" just showed a flaw in the grammar.

I'm closing this issue. Thanks @mingodad.