A good enough EBNF instaparser to parse simple python maps to clojure data structures
Often there are cases when python maps have been dumped directly to a file. This is a simple parser to parse that data in to clojure data structures.
>>> {u'age': 25}
>>> {u'bar': { u'baz': ['a', 'ab', 'abc']}, u'foo': [1, 2, 3, 4]}
(require [io.scotthaleen.instaparse-python.core :refer [parser]])
(parser "{u'age': 25}")
;;=> ([:object [:pair [:keyword "age"] [:value [:number "25"]]]])
(parser "{u'bar': { u'baz': ['a', 'ab', 'abc']}, u'foo': [1, 2, 3, 4]}")
;;=> ([:object [:pair [:keyword "foo"] [:value [:array [:value [:number "1"]] [:value [:number "2"]] [:value [:number "3"]] [:value [:number "4"]]]]] [:pair [:keyword "bar"] [:value [:object [:pair [:keyword "baz"] [:value [:array [:value [:string "a"]] [:value [:string "ab"]] [:value [:string "abc"]]]]]]]]])
- escaped characters in strings
- reconstruct clojure maps from parser output
Copyright © 2017 ☕
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.