aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--json-template.lisp28
1 files changed, 19 insertions, 9 deletions
diff --git a/json-template.lisp b/json-template.lisp
index 5607004..032714e 100644
--- a/json-template.lisp
+++ b/json-template.lisp
@@ -24,6 +24,12 @@
(in-package #:json-template)
+(defconstant +not-found+
+ (if (boundp '+not-found+)
+ (symbol-value '+not-found+)
+ '#:not-found))
+
+
(defclass template ()
((things :initarg :things :accessor template-things)))
@@ -141,12 +147,15 @@
(expand-template-to-stream template (list context) out)))
(defun getcontext (context key &aux (result context))
- (ignore-errors
- (dolist (key-component key result)
- (setq result
- (getf result
- key-component
- nil)))))
+ (dolist (key-component key result)
+ (handler-case
+ (setq result
+ (getf result
+ key-component
+ +not-found+))
+ (error (condition)
+ (declare (ignore condition))
+ (return-from getcontext +not-found+)))))
(defun listify-key (key &optional (start 0))
(let ((dot (position #\. key :start start)))
@@ -165,11 +174,12 @@
(labels ((lookup-in-stack (context-stack)
(if (endp context-stack)
nil
- (or (getcontext (first context-stack) key)
- (lookup-in-stack (rest context-stack))))))
+ (let ((thing (getcontext (first context-stack) key)))
+ (if (eql thing +not-found+)
+ (lookup-in-stack (rest context-stack))
+ thing)))))
(lookup-in-stack contexts)))
-
(defun expand-things-to-stream (template contexts stream)
(dolist (thing template)
(ecase (first thing)