Permalink
Browse files

refactored and fixed some bugs.

  • Loading branch information...
1 parent ec21db0 commit 48705f95e3303b9fa0d3155f768f95c5619d4caf @fukamachi committed Apr 21, 2012
Showing with 17 additions and 13 deletions.
  1. +13 −12 src/core.lisp
  2. +4 −1 t/shelly.lisp
View
25 src/core.lisp
@@ -18,18 +18,15 @@
(cl-annot:enable-annot-syntax)
+@export
(defun shelly.core::read (expr)
(destructuring-bind (fn &rest args) expr
- (cons (handler-case (read-from-string fn)
+ (cons (handler-case (if (stringp fn)
+ (read-from-string fn)
+ fn)
(error (c) (format t "Read-time error: ~A~%~A"
expr c)))
- (mapcar #'(lambda (a)
- (let* ((a (canonicalize-arg a)))
- (if (and (not (keywordp a))
- (not (typep a 'boolean))
- (symbolp a))
- (string a)
- a)))
+ (mapcar #'canonicalize-arg
args))))
(defun shelly.core::print (result)
@@ -75,9 +72,12 @@
finally (quit-lisp)))
(defun canonicalize-arg (arg0)
+ (unless (stringp arg0)
+ (return-from canonicalize-arg arg0))
+
(let ((arg (handler-case (read-from-string arg0)
- ((or reader-error package-error end-of-file) ()
- arg0))))
+ ((or reader-error package-error end-of-file) ()
+ arg0))))
(cond
((or (numberp arg) (consp arg) (typep arg 'boolean))
arg)
@@ -86,8 +86,9 @@
(simple-error ())))
(intern (subseq (string arg) 2)
:keyword))
- ((fad:file-exists-p (string arg)))
- ((and (not (keywordp arg)) (symbolp arg))
+ ((ignore-errors (fad:file-exists-p arg0)))
+ ((and (not (keywordp arg))
+ (symbolp arg))
(string arg0))
(t arg))))
View
5 t/shelly.lisp
@@ -7,6 +7,8 @@
(defpackage shelly-test
(:use :cl
:cl-test-more)
+ (:shadowing-import-from :shelly.core
+ :read)
(:import-from :shelly.core
:canonicalize-arg))
(in-package :shelly-test)
@@ -34,8 +36,9 @@
(is (canonicalize-arg "--prompt")
:prompt
"keyword")
+
(is (canonicalize-arg "'clack")
- ''clack
+ ''cl-user::clack
"quoted symbol")
(is-type (canonicalize-arg

0 comments on commit 48705f9

Please sign in to comment.