1. 9
  1.  

  2. 2

    Years ago (like, a decade ago) I wrote something similar in glorious pure ECMAScript 3, which was the style at the time. I’ve long since lost the code, but apparently it still exists as part of the sIRCouch project: https://searchcode.com/codesearch/view/78239460/

    And the grammar specification that they used: https://github.com/BigBlueHat/sIRCouch/blob/master/IRC/lib/parser_grammar.js

    Maybe I should resurrect the project…

    1. 1

      The combinators are where it gets cool. In arcsecond a combinator is a higher order parser, which takes one or more parsers as its input and gives back a new parser that combines those in some way. If you’ve used higher order components in react like connect, withRouter, or withStyles, then you’re already familiar with the idea.

      Sorry to nitpick, but the terminology is improper. In this context (coming from the terminology “higher-order function” which is a precise mathematical concept¹) “higher-order foo” means “a foo that itself takes foo as input”. A higher-order function is a function that takes a function as input (a function of “order 1” only takes atomic data as input). I’m not sure what the react people intend with “higher-order component”, but it should be a component that itself gets components plugged in.

      In contrast, what is being described is “an operation that builds new foo from some foos given as input”. (but this operation is not itself “a foo”). This is exactly what we call a combinator: an operation that combines foos into a new foo. sequenceOf is a parser combinator in this sense, but it is not a “higher-order parser”, because it is not itself a parser (sequenceOf does not, by itself, parse anything).

      I think it’s interesting to be a bit precise in the names we use, because they allow us to make distinctions between interesting concepts. “combinator” is a powerful and interesting idea, it doesn’t need to be called “higher-order” to look cooler. “higher-order” is a more complex idea, that is used less often, but also very powerful; it is nice to be able to signal it clearly when it is used, which we will be made more difficult if we muddy the meaning of the names.

      ¹: A function of type A -> B, that takes an A as input and return a B, has the order order(A -> B) defined as max(1+order(A), order(B)). An atomic datatype such as numbers has order 0.
      For example Num -> Num -> Num has order 1, (Num -> Num) -> Num has order 2.