Closed tallakt closed 10 years ago
During the result merge phase, parslet encounters this:
[{:main=>"MAINA "@0, :comment=>"COMMENTA"@8}, [{:main=>"MAINB "@17}, {:comment=>"COMMENTB"@25}, {:comment=>"COMMENTC"@36}]]
But a repetition can either contain all hashes or all arrays, with hashes being given the preference. This drops your second line result.
Rephrasing your :comments
rule to
rule :comments do
# I suspect a problem occurs here as there might be several :comment
# generated.
comment >> (newline >> comment).repeat.as(:others)
end
preserves the result in every case. The thing with .as(...)
is: You need to name all the things, everywhere. Don't try to get a minimal output, try to get all your results.
This is not a bug, but a really devious edge case.
It would be nice if there was a warning of sorts, that was what i was thinking...
A warning about normal operation? What would be the wording?
Warning: Duplicated tag name in rule comments
, capture groups may be lost
;-)
The way I see it doing what I did is a bug... it would be a nice feature if parslet would inform you that you have done something wrong.
2014-08-19 9:02 GMT+02:00 Kaspar Schiess notifications@github.com:
A warning about normal operation? What would be the wording?
— Reply to this email directly or view it on GitHub https://github.com/kschiess/parslet/issues/111#issuecomment-52597231.
Warning: Duplicated tag name in rule
comments
, capture groups may be lost
The problem is about giving preference to Hashes over Arrays when flattening results. This is normal operation. Warning about it is probably silly - maybe we should explain flattening better?
Anyhow - the general advice here is: you almost never have enough .as(...) ;)
k