Parse exactly the given string, without any regard to what comes next.
A potential pitfall when parsing keywords is getting tricked by variables that
start with a keyword, like let in letters or import in important. This
is especially likely if you have a whitespace parser that can consume zero
characters. So the keyword parser is defined with token and a
trick to peek ahead a bit:
This definition is specially designed so that (1) if you really see let you
commit to that path and (2) if you see letters instead you can backtrack and
try other options. If I had just put a backtrackable around the whole thing
you would not get (1) anymore.
Parse exactly the given string, without any regard to what comes next.
A potential pitfall when parsing
keywordsis getting tricked by variables that start with a keyword, likeletinlettersorimportinimportant. This is especially likely if you have a whitespace parser that can consume zero characters. So the keyword parser is defined withtokenand a trick to peek ahead a bit:This definition is specially designed so that (1) if you really see
letyou commit to that path and (2) if you seelettersinstead you can backtrack and try other options. If I had just put abacktrackablearound the whole thing you would not get (1) anymore.