Open zygoloid opened 6 years ago
Hmm, yeah, there really is no good way to do this. If you allowed any sequence of identifiers and * characters, this is easy - I apparently haven't updated the parser yet to work with this, but I added a MultipleChoice node to the official repo (https://github.com/tabatkins/railroad-diagrams) that makes this simple:
Plus:
AnyOf:
T: *
N: identifier
But if you have to explicitly alternate, and can start and end with either one, it's definitely harder. Another new node I've added to the official repo but apparently not mirrored over here (jeez...) is OptionalSequence, which does exactly reproduce what you want and reduces the duplication a little bit, at least:
OptionalSeq:
T: *
Plus:
N: identifier
T: *
T: *
This seems reasonable overall, and I'm willing to add a new node. Can you give me a sketch of what you think it would look like?
Maybe something like this:
Ah, that's cute and I like it. Yeah, I'll happily add this - I've just ported it over to an issue on the right repo https://github.com/tabatkins/railroad-diagrams/issues/50
Okay, JS version of the new node is complete - check it out at https://tabatkins.github.io/railroad-diagrams/example.html#glob. Just need to write the Python version, copy it over here, then write the parsing code for it (and the other two new constructs that I haven't ported over to Bikeshed).
Thank you, that looks great.
Suppose we want to describe a grammar that recognizes an alternating sequence of identifiers and
*
s (describing a glob pattern). The natural way to render this in a railroad diagram would be to have two nodes, with the entry path going to both, the exit path coming from both, and each connected to the other.(Can provide diagram if the above is not sufficient.) There appears to be no way to represent this in bikeshed's railroad diagram language without significant node duplication. Here a couple of bad ways of expressing this: