3 ms·
I don't think I'd call that a parser combinator, it's a regex DSL - it's just a more verbose way of writing out a regular expression, with a 1:1 translation bet
by codebje 8y ago
I don't think I'd call that a parser combinator, it's a regex DSL - it's just a more verbose way of writing out a regular expression, with a 1:1 translation between the DSL and a regex.
- pygy_ 8y agoA parser combinator is a function that takes one or more parser as argument and returns a parser with the same API as result. 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.
- 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)`.