From: Frank Duncan Date: Sun, 12 Jul 2015 18:28:50 +0000 (-0500) Subject: Exceptions for comments X-Git-Tag: 0.1~4 X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9508457e34796fd7fcd8029ecd3209582f4c945;p=wolf Exceptions for comments --- diff --git a/resources/commentneedsspace.lisp b/resources/commentneedsspace.lisp new file mode 100644 index 0000000..8bd5ae1 --- /dev/null +++ b/resources/commentneedsspace.lisp @@ -0,0 +1,8 @@ +(in-package #:nothing) + +; header comments +(defun multiline-1 (a b c) + (+ a b)) +; still need a space between these forms! +(defun multiline-1 (a b c) + (+ a b)) diff --git a/resources/goodcomment.lisp b/resources/goodcomment.lisp new file mode 100644 index 0000000..9865926 --- /dev/null +++ b/resources/goodcomment.lisp @@ -0,0 +1,36 @@ +(in-package #:nothing) + +(defun small-guy (a b) (+ a b)) + ; great comment here +(defun small-guy-2 (a b) (+ a b)) + +; this is a function definition +; comment about things +; yo +(defun hello-world (a b c) ; This comment is a test + (progn ; of things + (let ; ( and how + ((x y) ; comments can break + (z 9)) ; the evaluator and everything is ok + (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) + (when ; because we don't care + (read-line str) + (format t "This file had some things in int, yay!~%")))))) +; what kinds of comments +; do to a file +; + +; header comments +(defun multiline-1 (a b c) + (+ a b)) + +; header comments +(defun multiline-1 (a b c) + (+ a b)) + +; then a comment for +; informational purpose + +(x y z) + +; Then a final comment in the file diff --git a/resources/twoemptylineswithcomment.lisp b/resources/twoemptylineswithcomment.lisp new file mode 100644 index 0000000..080740b --- /dev/null +++ b/resources/twoemptylineswithcomment.lisp @@ -0,0 +1,15 @@ +(in-package #:nothing) + +; comment resets line counter + +; this one does two + +; but we'll get an error soon! + + +(defun hello-world (a b c) + (progn + (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) + (when + (read-line str) + (format t "This file had some things in int, yay!~%"))))) diff --git a/src/main/checker.lisp b/src/main/checker.lisp index bb057fb..0e3dd7a 100644 --- a/src/main/checker.lisp +++ b/src/main/checker.lisp @@ -18,7 +18,7 @@ ; * No hanging close parens ; ; Exceptions -; - comments +; * comments ; - multiline strings ; Some thoughts @@ -45,6 +45,8 @@ :beginning-of-line-with-separator ; empty space in there :beginning-of-symbols :beginning-of-symbols-with-separator + :comment-with-separator ; weird edge case for pre-function comments + :beginning-of-line-with-comment-and-separator ; weird edge case part 2 :first-symbol ; first symbol of form/line :all ; matches everything ))) @@ -118,6 +120,12 @@ ; These are in reverse order (progn (setf *evaluators* nil) + (defevaluator :beginning-of-symbols " *;[^\\n]*" + (lambda () (set-state :normal))) + (defevaluator :beginning-of-symbols-with-separator " *;[^\\n]*" + (lambda () (set-state :comment-with-separator))) + (defevaluator :normal " *;[^\\n]*" + (lambda () (set-state :normal))) (defevaluator :normal "\\(" (lambda () (push (list *line-no* *col-no*) *form-stack*) @@ -142,9 +150,22 @@ (incf *line-no*) (setf *col-no* -1) (set-state :beginning-of-line))) + (defevaluator :comment-with-separator "\\n" + (lambda () + (incf *line-no*) + (setf *col-no* -1) + (set-state :beginning-of-line-with-comment-and-separator) + nil)) (defevaluator :normal " +\\n" (constantly "No whitespace at end of line")) (defevaluator :beginning-of-line " *" (lambda () (set-state :beginning-of-symbols))) (defevaluator :beginning-of-line-with-separator " *" (lambda () (set-state :beginning-of-symbols-with-separator))) + (defevaluator :beginning-of-line-with-comment-and-separator "\\n" + (lambda () + (progn + (incf *line-no*) + (setf *col-no* -1) + (set-state :beginning-of-line-with-separator)))) + (defevaluator :beginning-of-line-with-comment-and-separator " *" (lambda () (set-state :beginning-of-symbols-with-separator))) (defevaluator :beginning-of-symbols "\\n" (lambda () (if