Home

Awesome

pod-babashka-parcera

Babashka pod wrapping parcera, a Clojure parser based on Antlr4.

This is work in progress.

Install

The following installation methods are available:

<!-- - With [brew](https://brew.sh/): `brew install borkdude/brew/pod-babashka-parcera` -->

Compatibility

This pod requires babashka v0.0.96 or later.

Run

(require '[babashka.pods :as pods])

;; load from pod registry:
(pods/load-pod 'org.babashka/parcera "0.0.1")
;; or load from system path:
;; (pods/load-pod "pod-babashka-parcera")

(require '[pod.babashka.parcera :as parcera])

(parcera/ast "(ns foo)")
;;=> (:code (:list (:symbol "ns") (:whitespace " ") (:symbol "foo")))

(parcera/code (parcera/ast "(ns foo)"))
;;=> "(ns foo)"

Examples

For the source, see the examples directory.

Sort requires

$ cat foo.clj
(ns foo
  (:require
   [z.foo :as z]
   [a.foo :as a]))

(defn foo [])

$ cat foo.clj | examples/sort_requires.clj
(ns foo
  (:require
   [a.foo :as a]
   [z.foo :as z]))

(defn foo [])

Find comments

$ find /code/app | grep -e "\.clj$" | xargs examples/find_comments.clj | head
/code/app/test/dre/yada/error_renderers_test.clj:87:
(comment
  (schema-validation-error-test)
  (errors-test)
  (t/run-tests))

/code/app/test/dre/yada/util_test.clj:13:
(comment
  (t/run-tests))

Zipper

Walk all the nodes and print the parcera AST + sexpr, except when it's a whitespace node.

$ examples/zipper.clj "^:foo ^:bar {:a 1}"
(:metadata (:metadata_entry (:keyword ":foo")) (:whitespace " ") (:metadata_entry (:keyword ":bar")) (:whitespace " ") (:map (:keyword ":a") (:whitespace " ") (:number "1")))
"^:foo ^:bar {:a 1}"
(:metadata_entry (:keyword ":foo"))
"^:foo"
(:keyword ":foo")
":foo"
(:metadata_entry (:keyword ":bar"))
"^:bar"
(:keyword ":bar")
":bar"
(:map (:keyword ":a") (:whitespace " ") (:number "1"))
"{:a 1}"
(:keyword ":a")
":a"
(:number "1")
"1"

Dev

Build

Run script/compile

Test

Run script/test.

License

Copyright © 2020 Michiel Borkent

Distributed under the EPL License. See LICENSE.

Parcera is licensed under the LGPL-3.0.