-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcst-from-expression.lisp
30 lines (26 loc) · 1.02 KB
/
cst-from-expression.lisp
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
(cl:in-package #:concrete-syntax-tree)
(defvar *table*)
(defun cst-from-element (expression source)
(cond ((cl:atom expression)
(make-instance 'atom-cst
:raw expression
:source source))
(t
(cst-from-list-expression expression source))))
(defun cst-from-list-expression (expression source)
(cond ((nth-value 1 (gethash expression *table*))
(gethash expression *table*))
((cl:atom expression)
(make-instance 'atom-cst
:raw expression
:source source))
(t
(let ((result (make-instance 'cons-cst
:raw expression :source source)))
(setf (gethash expression *table*) result)
(reinitialize-instance result
:first (cst-from-element (car expression) source)
:rest (cst-from-list-expression (cdr expression) source))))))
(defun cst-from-expression (expression &key source)
(let ((*table* (make-hash-table :test #'eq)))
(cst-from-element expression source)))