-
Notifications
You must be signed in to change notification settings - Fork 5
/
clojure-ast.el
40 lines (36 loc) · 1.31 KB
/
clojure-ast.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(require 'cl)
(defun wisent-clojure-find-project-tag
()
"Returns the tag describing the Clojure project. Must be called
within the project.clj buffer."
(do* ((tags (semantic-fetch-tags) (cdr tags))
(tag (car tags) (car tags)))
((string= (car tag) "project")
tag)))
(defun wisent-clojure-find-project-deps
(ptag)
"Returns the list of tags describing the project dependencies vector."
(let ((properties (car (cdaddr ptag))))
(do* ((tags properties (cdr tags))
(tag (car tags) (car tags)))
((and (listp tag) (string= (car tag) ":dependencies"))
(cadr tags)))))
(defun wisent-clojure-ast-parse
(ast)
"Parse the semantic AST and returns the content of
the Clojure data as an ELisp object."
(let ((type (cadr ast)))
(cond ((eq type 'vector)
(mapcar 'wisent-clojure-ast-parse (cadr (caddr ast))))
((eq type 'symbol)
(car ast))
((eq type 'string)
(car ast)))))
(defun wisent-clojure-project-dependencies
()
"Returns a list of lists representing the project dependencies."
(when (string-match "project.clj$" (buffer-file-name))
(let* ((ptag (wisent-clojure-find-project-tag))
(depsdef (wisent-clojure-find-project-deps ptag))
(deps (wisent-clojure-ast-parse depsdef)))
deps)))