4 ms·
"A parser for a thing is a function from a string to a list of pairs of strings and things." > Traditional parser combinators are just a recursive descent pars
by codebje 8y ago
"A parser for a thing is a function from a string to a list of pairs of strings and things."
> Traditional parser combinators are just a recursive descent parser DSL, with a 1:1 translation between both representations.
Yes, exactly - a recursive descent _parser_ recognises a grammar and produces the parse result for the grammar. Parser combinators take little parsers and make bigger parsers.
combine-regexp doesn't make parsers, it makes regular expression grammars, that you then feed to some _other_ parser that actually does the parsing based on that grammar.
- pygy_ 8y agoThe line is blurrier in my eyes. The library combines regular grammars that need an interpreter (the `match` method, which is bundled with the regexp object), whereas parser combinators work on code written in the same language (that is ultimately interpreted by the CPU). Edit: the parser in this case is a `(Regexp.prototype.match, regex.source)` tuple, whereas in the case of a praser combinator lib in a language that compiles to machine code, it would be `(call instruction, instructions list)`.