Creating a parser combinator library to parse JSON

Prev: Skipping whitespaceContentsNext: many1

JSON numbers

Like the match-literal parser that manually looks forward in the input stream to see if it matches a literal string, I could write a parser that manually matches JSON number characters in the input stream. What I’d like to do instead is make a many1 parser combinator, which matches one or more instances of something:

(= json-number
  (many1 json-number-char))

where json-number-char is a parser that matches one JSON number character:

(= json-number-char
  (match [find _ ".-+eE1234567890"]))

and match takes a predicate function. It succeeds, returning the next item in the input, if the function returns true when called with that item:

(def match (f)
  (only (fn (p)
          (let x car.p
            (if (f x)
                 (return cdr.p x))))))

Prev: Skipping whitespaceContentsNext: many1

Questions? Comments? Email me andrew.wilcox [at]