Skip to content
EDN parser with location metadata and pluggable dispatch table.
Clojure Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci initial commit Aug 27, 2019
.github initial commit Aug 27, 2019
resources bump version Sep 1, 2019
script/test initial commit Aug 27, 2019
src/edamame Use tools.reader as dependency (#8) Sep 12, 2019
test/edamame fix regex (#6) Sep 11, 2019
.gitignore initial commit Aug 27, 2019
LICENSE initial commit Aug 27, 2019
README.md Use tools.reader as dependency (#8) Sep 12, 2019
deps.edn Use tools.reader as dependency (#8) Sep 12, 2019
project.clj Use tools.reader as dependency (#8) Sep 12, 2019

README.md

Edamame

EDN parser with location metadata and pluggable dispatch table.

CircleCI Clojars Project cljdoc badge

Rationale

This library can be useful when:

  • You want to include locations in feedback about EDN files.
  • You want to parse Clojure-like expressions and want to add support for unsupported EDN characters.

This library came out of sci, a small Clojure interpreter.

Features

  • Parse EDN values with location as metadata.
  • Pluggable dispatch table to extend EDN.

This library works with:

  • Clojure on the JVM
  • ClojureScript

Usage

(require '[edamame.core :refer [parse-string]])

Locations are attached as metadata:

(def s "
[{:a 1}
 {:b 2}]")
(map meta (parse-string s))
;;=>
({:row 2, :col 2}
 {:row 3, :col 2})

(->> "{:a {:b {:c [a b c]}}}"
     parse-string
     (tree-seq coll? #(if (map? %) (vals %) %))
     (map meta))
;;=>
({:row 1, :col 1}
 {:row 1, :col 5}
 {:row 1, :col 9}
 {:row 1, :col 13}
 {:row 1, :col 14}
 {:row 1, :col 16}
 {:row 1, :col 18})

Dispatch on a character, even if it's unsupported in EDN:

(parse-string "@foo" {:dispatch {\@ (fn [val] (list 'deref val))}})
;;=> (deref foo)

Dispatch on dispatch characters:

(parse-string "#\"foo\"" {:dispatch {\# {\" #(re-pattern %)}}})
;;=> #"foo"

(parse-string "#(inc 1 2 %)" {:dispatch {\# {\( (fn [expr] (read-string (str "#" expr)))}}})
;;=> (fn* [p1__11574#] (inc 1 2 p1__11574#))

Test

script/test/jvm
script/test/node
script/test/all

Status

Experimental. Breaking changes are expected to happen at this phase.

Installation

Use as a dependency:

Clojars Project

Credits

The code is largely inspired by rewrite-clj and derived projects.

License

Copyright © 2019 Michiel Borkent

Distributed under the Eclipse Public License 1.0. This project contains code from Clojure and ClojureScript which are also licensed under the EPL 1.0. See LICENSE.

You can’t perform that action at this time.