swaroopch / edn_format

EDN reader and writer implementation in Python, using PLY (lex, yacc)
https://swaroopch.com/2012/12/24/edn-format-python/
Other
131 stars 31 forks source link

Cannot parse Roam EDN exports #85

Closed jrk closed 3 years ago

jrk commented 3 years ago

I discovered this library looking for a tool to parse Roam EDN exports. (Roam is a Clojure project, so EDN is their most native export format.)

Trying to parse a standard export with this library, I immediately run into:

NotImplementedError: Don't know how to handle tag ImmutableDict(datascript/DB)

Indeed, the Roam export begins with the tag #datascript/DB, but I'm unclear how this is meant to be handled. Am I supposed to register custom types or handlers or something?

swaroopch commented 3 years ago

Yes, those are tagged elements, please see tests on how to handle that.

bfontaine commented 3 years ago

You can either use the tag decorator, or use add_tag(<tag>, <function or class>) directly. The parser calls the function (or class) on the tagged element.

A very simple no-op implementation would be:

from edn_parse import tag, add_tag

@tag("datascript/DB")
def identity(m):
    return m

# alternatively:
add_tag("datascript/DB", lambda m: m)
jrk commented 3 years ago

Excellent, thanks! Closing, with a suggestion to document this more prominently (e.g., in README).