by codebje · 8y ago · 0 comments
combine-regexp is a parser combinator lib backed by regexps.
Traditional parser combinators are just a recursive descent parser DSL, with a 1:1 translation between both representations.
> 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.
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)`.