Code Monkey home page Code Monkey logo

walkclj's Introduction

walkclj

Walkclj is a complimentary library to parseclj and parseedn. These Clojure/EDN parsing libraries return a parse tree, this library lets you navigate that parse tree as if it was a regular clojure/edn data structure.

For example when parsing (foo bar) you get

(setq parse-tree
      ;; (parseclj-parse-clojure "(foo bar)")
      '((:node-type . :root)
        (:position . 1)
        (:children ((:node-type . :list)
                    (:position . 1)
                    (:children ((:node-type . :symbol)
                                (:position . 2)
                                (:form . "foo")
                                (:value . foo))
                               ((:node-type . :symbol)
                                (:position . 6)
                                (:form . "bar")
                                (:value . bar)))))))

;; There's an extra wrapping because parseclj accepts multiple top-level forms

(walkclj-ffirst parse-tree)
;;=> ((:node-type . :symbol) (:position . 2) (:form . "foo") (:value . foo))

(walkclj-list-p (walkclj-first parse-tree)) ;;=> t

(walkclj-name (walkclj-ffirst parse-tree)) ;;=>"foo"

We currently implement the following functions, all match their Clojure equivalent:

  • (walkclj-ffirst form)
  • (walkclj-first form)
  • (walkclj-list-p form)
  • (walkclj-meta form)
  • (walkclj-name form)
  • (walkclj-second form)
  • (walkclj-symbol-p form)

There's a macro walkclj-do which lets you omit the walkclj- prefix, and also allows writing Clojure-style keyword lookups:

(macroexpand-1 '
 (walkclj-do
  (:foo (list? (first parse-tree))))) 
;; => (a-get (walkclj-list-p (walkclj-first parse-tree)) :foo)

Two special helpers:

  • (walkclj-unwrap-meta form): Optionally unwrap a :meta type parse node. Any Clojure literal that has metadata will get an extra wrapper in the parse tree, this unwraps that, if it's there.

  • (walkclj-current-ns): Get the namespace name of the current buffer, assumes the first form in the buffer is an ns form

Patches are welcome! Any function that mimics a clojure.core function is fair game.

License

Copyright © 2018-2022 Arne Brasseur and Contributors

Licensed under the term of the GNU General Public License, version 3.

walkclj's People

Contributors

plexus avatar syohex avatar

Stargazers

Russell Matney avatar  avatar

Watchers

 avatar Marco Rolappe avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.