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
keywords
is getting tricked by variables that start with a keyword, likelet
inletters
orimport
inimportant
. This is especially likely if you have a whitespace parser that can consume zero characters. So the keyword parser is defined withtoken
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 seeletters
instead you can backtrack and try other options. If I had just put abacktrackable
around the whole thing you would not get (1) anymore.