Check for "FirstOf alternative prefix of later one" problem
The mistake of having a FirstOf alternative be a prefix of a subsequent one is common and sometimes hard to see. It'd be great if parboiled could automatically detect these grammar problems and report them. Actually this would likely be a byproduct of implementing #19
Are you saying that the user should be advised by the parboiled to reorder choices with a leading substring in a particular manner ? I often thought that if you have a grammar like foo and foobar; the user should declare foobar first to avoid backtracking.
If you have a rule like this in your grammar:
FirstOf("foo", "foobar")
The second alternative will never match! Ever! In fact this rule is equivalent to one just directly matching "foo". Backtracking is not going to help (see the parboiled mailing list for a recent discussion on this). So parboiled can and should warn you, when you write things like this. It is almost always an error.
This would be a very helpful improvement. I would like to see validation of a grammar for:
- left recursion
- *a a ; +a a #=> always fails
- optional(a) | optional(b) #=> never matches the alternative
- *ANY x #=> this only makes sense if x == EOI i think
- a | a
- *optional(a) ; +optional(a) #=> endless loop?
- probably more
Yes, all these things would be nice if they were available. However, IMHO the "FirstOf alternative prefix of later one" error is the most important one, since it can be hard to "see" and difficult to find, whereas all the ones you listed are somewhat easier to spot and fix manually...
Maybe a LongestOf()?
I have a similar problem with CSS where, for instance, font-size has "small" as a possible value, and font-variant has "small-caps". My plan was to implement LongestOf() somehow, I just don't know how :/