X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=wolf;a=blobdiff_plain;f=src%2Fmain%2Fchecker.lisp;h=3db05e29e1b74c823cacf381b164c8676874a02e;hp=b369a1bb5a07f84e066d501aedf28a37107404e7;hb=7b1e850;hpb=49f4258f01eb8ab69f63730f381ba7116a90aeee diff --git a/src/main/checker.lisp b/src/main/checker.lisp index b369a1b..3db05e2 100644 --- a/src/main/checker.lisp +++ b/src/main/checker.lisp @@ -3,14 +3,18 @@ ; Rules ; - Elements in each form must be indented the same amount ; * No form longer than 50 lines -; - Top level multiline forms must be separated by exactly one space +; * Top level multiline forms must be separated by exactly one space ; * No line longer than 120 characters -; - No use of unexported symbols in other packages -; - No tabs +; * No use of unexported symbols in other packages +; * No tabs ; - Only one space between elements in a form on a single line ; * in-package must be first line in file unless file is package.lisp -; - No whitespace only lines -; - No empty lines at end of file +; * No whitespace at end of line +; * No lines that are only whitespace +; * No empty lines at end of file +; * Never have two empty lines in a row +; * Only one in-package per file +; * No hanging close parens ; ; Some thoughts ; - form starting reader macros will have to be hand added to this code @@ -26,11 +30,17 @@ (defvar *col-no* nil) (defvar *evaluators* nil) (defvar *form-stack* nil) +(defvar *form-ended-on-same-line* nil) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *possible-states* '(:begin ; start of file :normal ; normal processing + :beginning-of-line + :beginning-of-line-with-separator ; empty space in there + :beginning-of-symbols + :beginning-of-symbols-with-separator + :all ; matches everything ))) @@ -50,13 +60,13 @@ (list (lambda (state text) (and - (eql ,state state) + (or (eql :all ,state) (eql ,state state)) (or (and (symbolp text) (eql text ,match)) (and ,scanner (stringp text) (multiple-value-bind (start end) (cl-ppcre:scan ,scanner text) - (and start end (= 0 start) (/= 0 end))))))) + (and start end (= 0 start))))))) (lambda (text) (second (multiple-value-list (cl-ppcre:scan ,scanner text)))) ,func) *evaluators*)))) @@ -87,6 +97,8 @@ (set-state :begin) (setf *line-no* 0) (setf *col-no* 0) + (setf *form-stack* nil) + (setf *form-ended-on-same-line* nil) (format t "~%File: ~A~%" file) (handler-case (progn (evaluate (slurp-file file)) t) @@ -100,17 +112,49 @@ ; These are in reverse order (progn (setf *evaluators* nil) + (defevaluator :all "\\t" + (constantly "Must not use tabs")) (defevaluator :begin "\\(in-package[^\\)]*\\)" - (lambda () - (set-state :normal) nil)) + (lambda () (set-state :normal))) + (defevaluator :beginning-of-line-with-separator :eof + (constantly "Must not end with empty line")) + (defevaluator :beginning-of-line-with-separator "\\n" + (constantly "Must not have two empty lines in a row")) (defevaluator :begin ".*" - (lambda () - "Must begin with in-package form")) + (constantly "Must begin with in-package form")) + (defevaluator :normal "\\( *in-package " + (constantly "Only one in-package per file")) (defevaluator :normal "\\n" (lambda () + (set-state :beginning-of-line) (incf *line-no*) - (setf *col-no* 0) + (setf *col-no* -1) 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-symbols "\\n" + (lambda () + (if + (< 0 *col-no*) + "No whitespace only lines" + (set-state :beginning-of-line-with-separator)))) + (defevaluator :beginning-of-symbols "\\)" + (constantly "No hanging close parens")) + (defevaluator :beginning-of-symbols-with-separator "\\)" + (constantly "No hanging close parens")) + (defevaluator :beginning-of-symbols "" + (lambda () + (if + (and (not *form-stack*) (not *form-ended-on-same-line*)) + "Multiline top level forms must be separated by a space" + (set-state :normal)))) + (defevaluator :beginning-of-symbols-with-separator "" + (lambda () + (set-state :normal))) (defevaluator :normal "\\(" (lambda () (push @@ -121,9 +165,10 @@ (lambda () (let ((form (pop *form-stack*))) - (when - (< 50 (- *line-no* (car form))) - "Forms can't be over 50 lines long")))) - - (defevaluator :normal "." (constantly nil)) - ) + (cond + ((not form) "Unmatched ending paren") + ((< 50 (- *line-no* (car form))) "Forms can't be over 50 lines long") + (t (setf *form-ended-on-same-line* (= *line-no* (car form))) nil))))) + (defevaluator :normal "::" + (constantly "No internal symbols from other packages")) + (defevaluator :normal "." (constantly nil)))