Open gsnedders opened 8 years ago
Something like:
def notFollowedBy(p):
@Parser
def _notFollowedBy(tokens, s):
try:
p.run(tokens, s)
except NoParseError, e:
return skip(pure(None)).run(tokens, State(s.pos, e.state.max))
else:
raise NoParseError(u'is followed by', s)
_notFollowedBy.name = u'(notFollowedBy %s)' % (p,)
return _notFollowedBy
Seems to work. I'm sure I'm failing to do something right here, though, with that function! I'll open some PR with that soonish, I guess.
If I'm not mistaken, we have no need for try
because |
never consumes anything on the LHS, right?
I've ended up with something like:
This ends up with an unexpected token error for the second HEADER token with a token stream like
HEADER BODY EMPTY HEADER BODY
as the EMPTY gets consumed bybody
and hence it cannot be consumed bysegments
.In Haskell I'd solve this with something like
body = data <|> (try ( do { empty_line ; notFollowedBy header } ))
. As far as I can tell, there's nothing comparable totry
ornotFollowedBy
. Is there any sensible way to define such a grammar?