* A JSON parser written with =parzival= This file introduces the =parzival= Common Lisp library by building a simple JSON parser. The parser that is completed will not be a "full" JSON parser in that it won't parse the full range of number forms in the JSON spec, nor will it parse escaped quote characters inside of strings. The code is for educational purposes only. While as [[https://en.wikipedia.org/wiki/Parzival][Parzival]] sought the Holy Grail through much trial and folly, =parzival= searches the space of context free languages while avoiding the unholy = (parse-string ;; failing to match a space, input starts with an #\x character |json-parzival|> (parse-string ;; matching and returning a newline |json-parzival|> (parse-string (< ;; failing to match either, empty string |json-parzival|> (parse-string (< ;; finally, matching a bunch of spaces or newlines and returning them as a list |json-parzival|> (parse-string (<<* (< ;; equivalently, just use your newly minted (parse-string #+end_src Looking at the above, you already begin to see how new parsers can be built up from old. We can go from a parser that accepts a single character, to one that accepts either of two characters, to one that accepts a list of zero or more of either of those two characters in a single clean line of code. Nice stuff! **** Ignoring Whitespace Now that you can match strings of whitespace you will create a parser to ignore whitespace. Specifially, you'll write a parser that effectively "strips" the whitespace around some other parser. The combinator doing the heavy lifting is called =< (parse-string (< |json-parzival|> (parse-string (< #+end_src So what's happening here? First, the parser = (defvar json-txt "{\"name\" : \"Boutade\", \"languages\" : [ {\"lang\" : \"Common Lisp\", \"proficiency\" : null, \"lovesIt\" : true } , {\"lang\" : \"Rust\", \"proficiency\" : 0.8, \"isAshamedToLoveIt\" : true} , {\"lang\" : \"Haskell\", \"proficiency\" : 0.5, \"lovesIt\" : \"sometimes, in some ways\"} ], \"religion\" : \"Goofism\", \"pizzaOrder\" : [\"Tempeh Italian Sausage\", \"Spinach\", \"Mushrooms\", \"Red Pepper Flakes\"], \"isCool\" : false, \"isFunny\" : false, \"thinksPeopleAreLaughing\" : true, \"beHonest_thinksPeopleAreLaughing\" : false }") JSON-TXT |json-parzival|> (parse json-txt #+end_src