项目作者: carocad

项目描述 :
Grammar-based Clojure(script) parser
高级语言: Clojure
项目地址: git://github.com/carocad/parcera.git
创建时间: 2019-09-28T11:42:51Z
项目社区:https://github.com/carocad/parcera

开源协议:GNU Lesser General Public License v3.0

下载


parcera

Build Status
Clojars Project
CljDoc

Grammar-based Clojure(script) parser.

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

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

If you are interested in the grammar definition check Clojure.g4.

setup

  • Java

Add [org.antlr/antlr4-runtime "4.7.1"] to your dependencies in addition to parcera.
This is to avoid adding an unnecessary dependency for the JavaScript users.

  • Javascript

All necessary files are delivered with parcera. However, currently only Browser support
has been tested.

  • Babashka

Check out babashka’s pod for parcera. Made by @borkdude

usage

  1. (ns example.core
  2. (:require [parcera.core :as parcera]))
  3. ;;parse clojure code from a string
  4. (parcera/ast (str '(ns parcera.core
  5. (:require [clojure.data :as data]
  6. [clojure.string :as str]))))
  7. ;; => returns a data structure with the result from the parser
  8. (:code
  9. (:list
  10. (:symbol "ns")
  11. (:whitespace " ")
  12. (:symbol "parcera.core")
  13. (:whitespace " ")
  14. (:list
  15. (:keyword ":require")
  16. (:whitespace " ")
  17. (:vector (:symbol "clojure.data") (:whitespace " ") (:keyword ":as") (:whitespace " ") (:symbol "data"))
  18. (:whitespace " ")
  19. (:vector (:symbol "clojure.string") (:whitespace " ") (:keyword ":as") (:whitespace " ") (:symbol "str")))))
  20. ;; get meta data from the parsed code
  21. (meta (second (parcera/ast (str :hello))))
  22. #:parcera.core{:start {:row 1, :column 0}, :end {:row 1, :column 6}}
  23. ;; convert an AST back into a string
  24. (parcera/code [:symbol "ns"])
  25. ;; "ns"

contributing

  • 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.
  • please follow Clojure’s Etiquete
    for issues and pull requests