Closed papler closed 8 months ago
Hi @papler,
Thanks for submitting the issue. This is a known behaviour of the alternative parser and a way recursive descent parsers generally work. The first match will be the one it uses, so you have to order the alternatives in a way so that the "longest match" comes first.
So, since wsMandatory
matches the ones that start with a space, it won't even bother trying the other alternative.
Thanks for the reply. I strongly considered that this is just me not using it right, since it's such a mature library.
So once it matches some mandatory whitespace, it then doesn't try the alternative, but goes ahead with the "=" or ":". However, doesn't it backtrack? This alternative is unsuccessful - try other ones?
The problem is that it is successful and reached the end of your parser grammar. Eto.Parse is not backtracking in any way currently.
Ah ok, I'll continue writing this grammar with that in mind. Thank you!
thisWayIsBroken = wsMandatory | ( wsOptional & new CharSetTerminal( ':', '=' ) & wsOptional ); butThisWayWorksOK = ( wsOptional & new CharSetTerminal( ':', '=' ) & wsOptional ) | wsMandatory;
This is for a name-value parser, where the name and value can be separated by either just spaces, or a colon or an equal sign. In case of colon or equal sign, spaces in between the name and colon/equalsign and value are optional.
All of the examples should be passing, but I get: