From 9511928a30436c1ffeefccb79aea296a5b80f768 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 00:41:34 +0000 Subject: [PATCH 01/16] Remove unnecessary semicolons --- lispstrack.lisp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 1b2b79d..3809e9f 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -185,9 +185,10 @@ (defvar *compilations* nil) (defun ls-compile-block (sexps env fenv) - (join-trailing (mapcar (lambda (x) - (ls-compile x env fenv)) - sexps) + (join-trailing + (remove nil (mapcar (lambda (x) + (ls-compile x env fenv)) + sexps)) "; ")) @@ -222,7 +223,7 @@ (define-compilation if (condition true false) (concat "(" - (ls-compile condition env fenv) " == undefined" + (ls-compile condition env fenv) " ? " (ls-compile true env fenv) " : " @@ -416,7 +417,7 @@ (concat "(" (ls-compile x env fenv) " === " (ls-compile y env fenv) ")")) (define-compilation string (x) - (concat "String.fromCharCode( " (ls-compile x env fenv) ")")) + (concat "String.fromCharCode(" (ls-compile x env fenv) ")")) (define-compilation char (string index) (concat "(" @@ -516,12 +517,14 @@ #+common-lisp (progn (defun ls-compile-file (filename output) + (setq *env* nil *fenv* nil) (with-open-file (in filename) (with-open-file (out output :direction :output :if-exists :supersede) (loop for x = (ls-read in) until (eq x *eof*) for compilation = (ls-compile-toplevel x) - when compilation do (write-line (concat compilation "; ") out))))) + when (plusp (length compilation)) + do (write-line (concat compilation "; ") out))))) (defun bootstrap () (ls-compile-file "lispstrack.lisp" "lispstrack.js"))) -- 1.7.10.4 From 93bc4ffd8275ecbb337e62fb3139942e08c86c7f Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 00:45:41 +0000 Subject: [PATCH 02/16] Remove more unnecessary semicolons --- lispstrack.lisp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 3809e9f..89d6c4c 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -37,9 +37,13 @@ (join (cdr list) separator))))) (defun join-trailing (list separator) - (if (null list) - "" - (concat (car list) separator (join-trailing (cdr list) separator)))) + (cond + ((null list) + "") + ((null (car list)) + (join-trailing (cdr list) separator)) + (t + (concat (car list) separator (join-trailing (cdr list) separator))))) (defun integer-to-string (x) (if (zerop x) -- 1.7.10.4 From 6b2ca9e1d6ecd0607501c6cd1d2623f6fc144378 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 00:48:23 +0000 Subject: [PATCH 03/16] Fix nil translation --- lispstrack.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 89d6c4c..f508f71 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -284,7 +284,7 @@ (defun literal->js (sexp) (cond - ((null sexp) "unspecified") + ((null sexp) "undefined") ((integerp sexp) (integer-to-string sexp)) ((stringp sexp) (concat "\"" sexp "\"")) ((symbolp sexp) (concat "{name: \"" (symbol-name sexp) "\"}")) -- 1.7.10.4 From 2334fa90c5628d72c66527ecb287b77745d2707f Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 00:48:32 +0000 Subject: [PATCH 04/16] integer-to-string working --- test.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.lisp b/test.lisp index e5fdc77..878a18f 100644 --- a/test.lisp +++ b/test.lisp @@ -123,7 +123,7 @@ (if (zerop x) "0" (let ((digits nil)) - (while (not (= x 0)) + (while (not (zerop x 0)) (push (mod x 10) digits) (setq x (truncate x 10))) (join (mapcar (lambda (d) (string (char "0123456789" d))) -- 1.7.10.4 From a63ff17f5f5056c846ccb2dff25310916192bb35 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 00:51:51 +0000 Subject: [PATCH 05/16] Remove streams --- lispstrack.lisp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index f508f71..1661f22 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -66,17 +66,13 @@ (cons string 0)) (defun %peek-char (stream) - (if (streamp stream) - (peek-char nil stream nil) - (and (< (cdr stream) (length (car stream))) - (char (car stream) (cdr stream))))) + (and (< (cdr stream) (length (car stream))) + (char (car stream) (cdr stream)))) (defun %read-char (stream) - (if (streamp stream) - (read-char stream nil) - (and (< (cdr stream) (length (car stream))) - (prog1 (char (car stream) (cdr stream)) - (incf (cdr stream)))))) + (and (< (cdr stream) (length (car stream))) + (prog1 (char (car stream) (cdr stream)) + (incf (cdr stream))))) (defun whitespacep (ch) (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab))) @@ -520,15 +516,24 @@ #+common-lisp (progn + + (defun read-whole-file (filename) + (with-open-file (in filename) + (let ((seq (make-array (file-length in) :element-type 'character))) + (read-sequence seq in) + seq))) + (defun ls-compile-file (filename output) (setq *env* nil *fenv* nil) - (with-open-file (in filename) - (with-open-file (out output :direction :output :if-exists :supersede) + (with-open-file (out output :direction :output :if-exists :supersede) + (let* ((source (read-whole-file filename)) + (in (make-string-stream source))) (loop for x = (ls-read in) until (eq x *eof*) for compilation = (ls-compile-toplevel x) when (plusp (length compilation)) do (write-line (concat compilation "; ") out))))) + (defun bootstrap () (ls-compile-file "lispstrack.lisp" "lispstrack.js"))) -- 1.7.10.4 From 8e2f01785d31e908194c1846d8437285aad31478 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 01:14:26 +0000 Subject: [PATCH 06/16] < --- lispstrack.lisp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 1661f22..b53db0a 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -152,6 +152,8 @@ (ecase (%read-char stream) (#\' (list 'function (ls-read stream))) + (#\\ + (%read-char stream)) (#\+ (let ((feature (read-until stream #'terminalp))) (cond @@ -161,7 +163,8 @@ ((string= feature "lispstrack") (ls-read stream)) (t - (error "Unknown reader form."))))))) + (error "Unknown reader form."))))) + )) (t (let ((string (read-until stream #'terminalp))) (if (every #'digit-char-p string) @@ -386,6 +389,9 @@ (define-compilation / (x y) (concat "((" (ls-compile x env fenv) ") / (" (ls-compile y env fenv) "))")) +(define-compilation < (x y) + (concat "((" (ls-compile x env fenv) ") < (" (ls-compile y env fenv) "))")) + (define-compilation = (x y) (concat "((" (ls-compile x env fenv) ") == (" (ls-compile y env fenv) "))")) -- 1.7.10.4 From 57551edd60c2225f64745dfd25085dba741425b3 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 01:14:30 +0000 Subject: [PATCH 07/16] incf, decf, length --- test.lisp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test.lisp b/test.lisp index 878a18f..ee7a699 100644 --- a/test.lisp +++ b/test.lisp @@ -55,6 +55,19 @@ (defun reverse (list) (reverse-aux list '())) +(defmacro incf (x) + `(setq ,x (1+ ,x))) + +(defmacro decf (x) + `(setq ,x (1- ,x))) + +(defun length (list) + (let ((l 0)) + (while (not (null list)) + (incf l) + (setq list (cdr list))) + l)) + (defun mapcar (func list) (if (null list) '() @@ -129,3 +142,27 @@ (join (mapcar (lambda (d) (string (char "0123456789" d))) digits) "")))) + +(defmacro and (&rest forms) + (cond + ((null forms) + t) + ((null (cdr forms)) + (car forms)) + (t + `(if ,(car forms) + (and ,@(cdr forms)) + nil)))) + +;;;; Reader + +;;; It is a basic Lisp reader. It does not use advanced stuff +;;; intentionally, because we want to use it to bootstrap a simple +;;; Lisp. The main entry point is the function `ls-read', which +;;; accepts a strings as argument and return the Lisp expression. +(defun make-string-stream (string) + (cons string 0)) + +(defun %peek-char (stream) + (and (< (cdr stream) (length (car stream))) + (char (car stream) (cdr stream)))) -- 1.7.10.4 From 2467edf67e177707013ffa8e71b3d966735495ab Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 01:47:37 +0000 Subject: [PATCH 08/16] Character reader --- lispstrack.lisp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index b53db0a..9e864b5 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -153,23 +153,26 @@ (#\' (list 'function (ls-read stream))) (#\\ - (%read-char stream)) + (let ((cname (read-until stream #'terminalp))) + (cond + ((string= cname "space") (char-code #\space)) + ((string= cname "newline") (char-code #\newline)) + (t (char-code (char cname 0)))))) (#\+ (let ((feature (read-until stream #'terminalp))) (cond ((string= feature "common-lisp") - (ls-read stream);ignore + (ls-read stream) ;ignore (ls-read stream)) ((string= feature "lispstrack") (ls-read stream)) (t - (error "Unknown reader form."))))) - )) + (error "Unknown reader form."))))))) (t (let ((string (read-until stream #'terminalp))) (if (every #'digit-char-p string) (parse-integer string) - (intern (string-upcase string)))))))) + (intern (string-upcase string))))))))) (defun ls-read-from-string (string) (ls-read (make-string-stream string))) -- 1.7.10.4 From 9e5532f7bf5438d49d0e1ab9dac312a2379a2412 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 01:47:52 +0000 Subject: [PATCH 09/16] OR --- test.lisp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test.lisp b/test.lisp index ee7a699..1f12dc5 100644 --- a/test.lisp +++ b/test.lisp @@ -154,6 +154,22 @@ (and ,@(cdr forms)) nil)))) + +(defmacro or (&rest forms) + (cond + ((null forms) + nil) + ((null (cdr forms)) + (car forms)) + (t + `(if ,(car forms) + t + (or ,@(cdr forms)))))) + + +(defun char= (x y) (= x y)) + + ;;;; Reader ;;; It is a basic Lisp reader. It does not use advanced stuff @@ -166,3 +182,6 @@ (defun %peek-char (stream) (and (< (cdr stream) (length (car stream))) (char (car stream) (cdr stream)))) + +(defun whitespacep (ch) + (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab))) -- 1.7.10.4 From d6cff3e7f183719f080abfd5b18577def7dcf640 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 02:14:13 +0000 Subject: [PATCH 10/16] Progresses to bootstrap --- lispstrack.lisp | 29 ++++++++++++++++++++++++----- test.lisp | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 9e864b5..f034041 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -1,3 +1,9 @@ +(defun ensure-list (x) + (if (listp x) + x + (list x))) + + (defun !reduce (func list initial) (if (null list) initial @@ -15,7 +21,12 @@ ,@body)) (defun concat-two (s1 s2) - (concatenate 'string s1 s2))) + (concatenate 'string s1 s2)) + + (defun setcar (cons new) + (setf (car cons) new)) + (defun setcdr (cons new) + (setf (cdr cons) new))) (defvar *newline* (string (code-char 10))) @@ -72,7 +83,7 @@ (defun %read-char (stream) (and (< (cdr stream) (length (car stream))) (prog1 (char (car stream) (cdr stream)) - (incf (cdr stream))))) + (setcdr stream (1+ (cdr stream)))))) (defun whitespacep (ch) (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab))) @@ -172,7 +183,7 @@ (let ((string (read-until stream #'terminalp))) (if (every #'digit-char-p string) (parse-integer string) - (intern (string-upcase string))))))))) + (intern (string-upcase string)))))))) (defun ls-read-from-string (string) (ls-read (make-string-stream string))) @@ -340,8 +351,9 @@ `((lambda () ,@body))) (define-transformation let (bindings &rest body) - `((lambda ,(mapcar 'car bindings) ,@body) - ,@(mapcar 'cadr bindings))) + (let ((bindings (mapcar #'ensure-list bindings))) + `((lambda ,(mapcar 'car bindings) ,@body) + ,@(mapcar 'cadr bindings)))) ;;; A little backquote implementation without optimizations of any ;;; kind for lispstrack. @@ -416,6 +428,13 @@ (define-compilation cdr (x) (concat "(" (ls-compile x env fenv) ").cdr")) +(define-compilation setcar (x new) + (concat "((" (ls-compile x env fenv) ").car = " (ls-compile new env fenv) ")")) + +(define-compilation setcdr (x new) + (concat "((" (ls-compile x env fenv) ").cdr = " (ls-compile new env fenv) ")")) + + (define-compilation make-symbol (name) (concat "{name: " (ls-compile name env fenv) "}")) diff --git a/test.lisp b/test.lisp index 1f12dc5..7d06431 100644 --- a/test.lisp +++ b/test.lisp @@ -167,6 +167,13 @@ (or ,@(cdr forms)))))) +(defmacro prog1 (form &rest body) + (let ((value (make-symbol "VALUE"))) + `(let ((,value ,form)) + ,@body + ,value))) + + (defun char= (x y) (= x y)) @@ -183,5 +190,17 @@ (and (< (cdr stream) (length (car stream))) (char (car stream) (cdr stream)))) +;; (defun %read-char (stream) +;; (and (< (cdr stream) (length (car stream))) +;; (prog1 (char (car stream) (cdr stream)) +;; (setcdr stream (1+ (cdr stream)))))) + (defun whitespacep (ch) (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab))) + +;; (defun skip-whitespaces (stream) +;; (let (ch) +;; (setq ch (%peek-char stream)) +;; (while (and ch (whitespacep ch)) +;; (%read-char stream) +;; (setq ch (%peek-char stream))))) -- 1.7.10.4 From 3c8fb84375b8228964541fddeb31c309b596c10e Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 02:24:21 +0000 Subject: [PATCH 11/16] Fix problem with recursive macros --- lispstrack.lisp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index f034041..59fb5e4 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -527,10 +527,12 @@ ((stringp sexp) (concat "\"" sexp "\"")) ((listp sexp) (let ((sexp (ls-macroexpand-1 sexp env fenv))) - (let ((compiler-func (second (assoc (car sexp) *compilations*)))) - (if compiler-func - (apply compiler-func env fenv (cdr sexp)) - (compile-funcall (car sexp) (cdr sexp) env fenv))))))) + (if (listp sexp) + (let ((compiler-func (second (assoc (car sexp) *compilations*)))) + (if compiler-func + (apply compiler-func env fenv (cdr sexp)) + (compile-funcall (car sexp) (cdr sexp) env fenv))) + (ls-compile sexp env fenv)))))) (defun ls-compile-toplevel (sexp) (setq *toplevel-compilations* nil) -- 1.7.10.4 From 399f7409d326005321b88b2d973c35fb733dfe5d Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Tue, 18 Dec 2012 02:39:43 +0000 Subject: [PATCH 12/16] More nested macros --- lispstrack.lisp | 16 ++++++++++++++++ test.lisp | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 59fb5e4..b8cc906 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -534,6 +534,22 @@ (compile-funcall (car sexp) (cdr sexp) env fenv))) (ls-compile sexp env fenv)))))) + +(defun ls-compile (sexp &optional env fenv) + (cond + ((symbolp sexp) (lookup-variable sexp env)) + ((integerp sexp) (integer-to-string sexp)) + ((stringp sexp) (concat "\"" sexp "\"")) + ((listp sexp) + (if (assoc (car sexp) *compilations*) + (let ((comp (second (assoc (car sexp) *compilations*)))) + (apply comp env fenv (cdr sexp))) + (let ((fn (cdr (assoc (car sexp) *fenv*)))) + (if (and (listp fn) (eq (car fn) 'macro)) + (ls-compile (ls-macroexpand-1 sexp env fenv) env fenv) + (compile-funcall (car sexp) (cdr sexp) env fenv))))))) + + (defun ls-compile-toplevel (sexp) (setq *toplevel-compilations* nil) (let ((code (ls-compile sexp))) diff --git a/test.lisp b/test.lisp index 7d06431..9f58cf2 100644 --- a/test.lisp +++ b/test.lisp @@ -190,17 +190,17 @@ (and (< (cdr stream) (length (car stream))) (char (car stream) (cdr stream)))) -;; (defun %read-char (stream) -;; (and (< (cdr stream) (length (car stream))) -;; (prog1 (char (car stream) (cdr stream)) -;; (setcdr stream (1+ (cdr stream)))))) +(defun %read-char (stream) + (and (< (cdr stream) (length (car stream))) + (prog1 (char (car stream) (cdr stream)) + (setcdr stream (1+ (cdr stream)))))) (defun whitespacep (ch) (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab))) -;; (defun skip-whitespaces (stream) -;; (let (ch) -;; (setq ch (%peek-char stream)) -;; (while (and ch (whitespacep ch)) -;; (%read-char stream) -;; (setq ch (%peek-char stream))))) +(defun skip-whitespaces (stream) + (let (ch) + (setq ch (%peek-char stream)) + (while (and ch (whitespacep ch)) + (%read-char stream) + (setq ch (%peek-char stream))))) -- 1.7.10.4 From b88e51178beb03271b59cfa329568a8db16e25c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Tue, 18 Dec 2012 23:25:14 +0100 Subject: [PATCH 13/16] Remove duplicated ls-compile definition --- lispstrack.lisp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index b8cc906..7a0b9b8 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -526,21 +526,6 @@ ((integerp sexp) (integer-to-string sexp)) ((stringp sexp) (concat "\"" sexp "\"")) ((listp sexp) - (let ((sexp (ls-macroexpand-1 sexp env fenv))) - (if (listp sexp) - (let ((compiler-func (second (assoc (car sexp) *compilations*)))) - (if compiler-func - (apply compiler-func env fenv (cdr sexp)) - (compile-funcall (car sexp) (cdr sexp) env fenv))) - (ls-compile sexp env fenv)))))) - - -(defun ls-compile (sexp &optional env fenv) - (cond - ((symbolp sexp) (lookup-variable sexp env)) - ((integerp sexp) (integer-to-string sexp)) - ((stringp sexp) (concat "\"" sexp "\"")) - ((listp sexp) (if (assoc (car sexp) *compilations*) (let ((comp (second (assoc (car sexp) *compilations*)))) (apply comp env fenv (cdr sexp))) -- 1.7.10.4 From 08868487a3708573e6f26f23b60fa14bab5dbf30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Tue, 18 Dec 2012 23:28:51 +0100 Subject: [PATCH 14/16] Fix character reader for input like #\) --- lispstrack.lisp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 7a0b9b8..ba60596 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -164,7 +164,9 @@ (#\' (list 'function (ls-read stream))) (#\\ - (let ((cname (read-until stream #'terminalp))) + (let ((cname + (concat (string (%read-char stream)) + (read-until stream #'terminalp)))) (cond ((string= cname "space") (char-code #\space)) ((string= cname "newline") (char-code #\newline)) -- 1.7.10.4 From 42f5cdc28edf163d5b838b925395d0adce6b3979 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Tue, 18 Dec 2012 23:34:24 +0100 Subject: [PATCH 15/16] Use `false' like nil --- lispstrack.lisp | 4 ++-- test.lisp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index ba60596..b20ca47 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -299,7 +299,7 @@ (defun literal->js (sexp) (cond - ((null sexp) "undefined") + ((null sexp) "false") ((integerp sexp) (integer-to-string sexp)) ((stringp sexp) (concat "\"" sexp "\"")) ((symbolp sexp) (concat "{name: \"" (symbol-name sexp) "\"}")) @@ -419,7 +419,7 @@ (concat "(Math.floor(" (ls-compile x env fenv) "))")) (define-compilation null (x) - (concat "(" (ls-compile x env fenv) "== undefined)")) + (concat "(" (ls-compile x env fenv) "== false)")) (define-compilation cons (x y) (concat "{car: " (ls-compile x env fenv) ", cdr: " (ls-compile y env fenv) "}")) diff --git a/test.lisp b/test.lisp index 9f58cf2..560a255 100644 --- a/test.lisp +++ b/test.lisp @@ -204,3 +204,8 @@ (while (and ch (whitespacep ch)) (%read-char stream) (setq ch (%peek-char stream))))) + +(defun terminalp (ch) + (or (null ch) (whitespacep ch) (char= #\) ch) (char= #\( ch))) + + -- 1.7.10.4 From 137ff928aab4f5b9dcc6f3b927c4ea92cf1d0a82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Tue, 18 Dec 2012 23:35:36 +0100 Subject: [PATCH 16/16] eql to char= --- lispstrack.lisp | 4 ++-- test.lisp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index b20ca47..ee1aab7 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -112,8 +112,8 @@ (let (ch) (skip-whitespaces stream) (setq ch (%peek-char stream)) - (while (and ch (eql ch #\;)) - (read-until stream (lambda (x) (eql x #\newline))) + (while (and ch (char= ch #\;)) + (read-until stream (lambda (x) (char= x #\newline))) (skip-whitespaces stream) (setq ch (%peek-char stream))))) diff --git a/test.lisp b/test.lisp index 560a255..7a68a35 100644 --- a/test.lisp +++ b/test.lisp @@ -209,3 +209,21 @@ (or (null ch) (whitespacep ch) (char= #\) ch) (char= #\( ch))) +(defun read-until (stream func) + (let ((string "") + (ch)) + (setq ch (%peek-char stream)) + (while (not (funcall func ch)) + (setq string (concat string (string ch))) + (%read-char stream) + (setq ch (%peek-char stream))) + string)) + +(defun skip-whitespaces-and-comments (stream) + (let (ch) + (skip-whitespaces stream) + (setq ch (%peek-char stream)) + (while (and ch (char= ch #\;)) + (read-until stream (lambda (x) (char= x #\newline))) + (skip-whitespaces stream) + (setq ch (%peek-char stream))))) -- 1.7.10.4