Types of Parser Combinators
sgt.hootr.club
sgt.hootr.club
What I love about parser combinators is that they are just code, in your language. They are also highly composable.
What I hate about parser combinators is how easy it is to accidental generate infinite loops or miss a crucial backtracking point.
Are there any parser combinators libraries that avoid these traps, particularly around recursion?
[0] https://github.com/hexops/zorex/tree/main/src/combn#combn-ru...
From what I read the author seems to abstract the idea of parsing to "transforming data with the possibility of failure". Not sure if I missed the point here
A parser for things
is a function from strings
to lists of pairs of
strings and things.I'm more or less using Alexis King's definition of "parsing" here, as described in this post: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
Parsing text (a sequence of characters) or binary files (a sequence of bytes) are well known.
The author mentions the case where a JSON parser has generated a bunch of JSON objects, but you want your own object types. (Deserialization libraries can do this automatically if all that is required is setting fields or properties, but for more complex cases you need custom code.)
Similar for XML parsing: all you get is a stream of element events, or a tree of generic XML objects, and you have to transform that further.
Another case would be when you get import data in the form of an Excel or CSV file. Your code starts with a 2D array of generic cells/values, and has to transform it into your own table/object types.