scotthaleen / instaparse-python-maps-clj

EBNF Python Map parser for Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

instaparse python maps clj

A good enough EBNF instaparser to parse simple python maps to clojure data structures

Build Status

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.

Usage

>>> {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"]]]]]]]]])

TODO

  • escaped characters in strings
  • reconstruct clojure maps from parser output

License

Copyright © 2017 ☕

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

EBNF Python Map parser for Clojure

License:Eclipse Public License 1.0


Languages

Language:Clojure 100.0%