You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dead-simple grammar that can read natural numbers [funcparserlib]
Funcparserlib is a parser combinator, which means it doesn't use a
text-based grammar. Instead, you combine small parsers into larger ones,
eventually arriving at a parser that can handle your whole language.
The basic unit of funcparserlib is `some`, which takes a function that
receives a character and returns a boolean, to determine whether that
character is a match. Our `digits` rule is a parser that requires its
sub-parser to match one or more times; its sub-parser is a parser that
matches if its input is a digit.
funcparserlib parsers have an __rshift__ function, which means they can
be used with the `>>` operator. However, instead of being a right
bit-shift like an int's __rshift__, this function receives a function
that takes the output of the parser and returns some munged version of
that output. In this case, we're supplying a function that takes the
parsed list-of-digit-characters, joins it into a string, and then casts
it as an int.
0 commit comments