Liking cljdoc? Tell your friends :D


Build Status Clojars Project

Grammar-based Clojure parser.

Parcera can safely read any Clojure file without any code evaluation.

Parcera uses the wonderful Antlr4 as its parsing engine and focuses entirely on the grammar definition instead.


Add [org.antlr/antlr4-runtime "4.7.1"] to your dependencies in addition to parcera. Parcera assumes that this dependency will be in the classpath to avoid collisions.

(ns example.core
  (:require [parcera.core :as parcera]))

;;parse clojure code from a string
(parcera/ast (str '(ns parcera.core
                     (:require [ :as bar]
                               [ :as data]
                               [clojure.string :as str]))))

;; => returns a data structure with the result from the parser
  (:symbol "ns")
  (:whitespace " ")
  (:symbol "parcera.core")
  (:whitespace " ")
   (:simple_keyword "require")
   (:whitespace " ")
    (:symbol "")
    (:whitespace " ")
    (:simple_keyword "as")
    (:whitespace " ")
    (:symbol "bar"))
   (:whitespace " ")
   (:vector (:symbol "") (:whitespace " ") (:simple_keyword "as") (:whitespace " ") (:symbol "data"))
   (:whitespace " ")
   (:vector (:symbol "clojure.string") (:whitespace " ") (:simple_keyword "as") (:whitespace " ") (:symbol "str")))))

;; get meta data from the parsed code
(meta (second (parcera/ast (str :hello))))
#:parcera.core{:start {:row 1, :column 0}, :end {:row 1, :column 6}}

;; convert an AST back into a string
(parcera/code [:symbol "ns"])
;; "ns"


  • To get you setup check the travis file which already contains a full setup from scratch.
  • The project contains a benchmark which should be the decision factor for performance issues inside parcera.
  • Please follow Clojure's Etiquete for issues and pull requests

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close