awwx.ws

Creating a parser combinator library to parse JSON

Prev: Choosing a combinator interfaceContentsNext: Matching JSON literals

Displaying the parse result

Next is a convenience function to convert a string into a list of characters, run a parser against it, and display the result:

(def show-parse (parser str)
  (let p (coerce str 'cons)
    (iflet (p2 r) (parser p)
      (do (pr "returning: ")
          (write r)
          (prn " remaining: " (coerce p2 'string)))
      (prn "no match")))
  nil)
arc> (show-parse match-a "abc")
returning: "found A!" remaining: bc
nil
arc> (show-parse match-a "def")
no match
nil

Prev: Choosing a combinator interfaceContentsNext: Matching JSON literals


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