railroad_dsl icon indicating copy to clipboard operation
railroad_dsl copied to clipboard

wrong order of elements on the right of repeat operator "*"

Open birkenfeld opened this issue 6 years ago • 1 comments

See the 10_create-table-stmt_diagram.txt example: it has

[!*[['table-constraint', ","]#`primary key and stuff`]]#`Zero or more table-constraints

but the generated diagram is

image

Following the railroad, the comma comes before the table-constraint.

I'm not sure if that is an issue in this code, or railroad itself.

birkenfeld avatar Oct 17 '18 16:10 birkenfeld

The diagram itself is correct according to syntax AFAICS: There has to be at least one column-def; if a table-constraint follows, a comma separates the two. If more table-constraint follow, more commas are needed; the last table-constraint has no comma following it. The language is reversed, though.

The underlying issue here goes deeper: The Repeat-element is completely ignorant about it's separator-element, it just renders it in place (in this case a Sequence([NonTerminal("table-constraint"), Terminal(",")]). As RailroadNode has no way of communicating in .draw() what the reading-direction will be, we have to logically reverse elements in the separator of Repeat (which could be more complex, e.g. involving Choice).

I'm unsure about what to do here: The underlying library assumes reading direction being left-to-right, top-to-bottom everywhere. We (currently) only have this problem in Repeat and only if the separator is a compunded element, which it rarely is. See https://github.com/lukaslueg/railroad/issues/7.

lukaslueg avatar Oct 17 '18 17:10 lukaslueg