X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=wolf;a=blobdiff_plain;f=src%2Fmain%2Fchecker.lisp;h=dcbe9ec6fd1ad77b0dd8ea1001f48c8e4122c5f4;hp=2ccf7f427cf40e50160b6a75020b8ede83bd3a75;hb=1f818db;hpb=3225bfce49dc471d98e50bd7e1ba268f5adce257 diff --git a/src/main/checker.lisp b/src/main/checker.lisp index 2ccf7f4..dcbe9ec 100644 --- a/src/main/checker.lisp +++ b/src/main/checker.lisp @@ -2,15 +2,18 @@ ; Rules ; - Elements in each form must be indented the same amount -; - No form longer than 50 lines +; * No form longer than 50 lines ; - 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 ; ; Some thoughts ; - form starting reader macros will have to be hand added to this code @@ -25,11 +28,17 @@ (defvar *line-no* nil) (defvar *col-no* nil) (defvar *evaluators* nil) +(defvar *form-stack* nil) -(defparameter *possible-states* - '(:begin ; start of file - :normal ; normal processing - )) +(eval-when (:compile-toplevel :load-toplevel :execute) + (defparameter *possible-states* + '(:begin ; start of file + :normal ; normal processing + :beginning-of-line + :beginning-of-separators-with-space ; empty space in there + :beginning-of-symbols + :all ; matches everything + ))) (defun set-state (state) @@ -48,13 +57,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*)))) @@ -98,16 +107,61 @@ ; 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)) + (defevaluator :beginning-of-separators-with-space :eof + (constantly "Must not end with empty line")) + (defevaluator :beginning-of-separators-with-space "\\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" + (lambda () + "No whitespace at end of line")) + (defevaluator :beginning-of-line " *" + (lambda () + (set-state :beginning-of-symbols) nil)) + (defevaluator :beginning-of-separators-with-space " *" + (lambda () + (set-state :beginning-of-symbols) + nil)) + (defevaluator :beginning-of-symbols "\\n" + (lambda () + (if + (< 0 *col-no*) + "No whitespace only lines" + (set-state :beginning-of-separators-with-space)))) + (defevaluator :beginning-of-symbols "" + (lambda () + (set-state :normal) + nil)) + (defevaluator :normal "\\(" + (lambda () + (push + (list *line-no* *col-no*) + *form-stack*) + nil)) + (defevaluator :normal "\\)" + (lambda () + (let + ((form (pop *form-stack*))) + (cond + ((not form) "Unmatched ending paren") + ((< 50 (- *line-no* (car form))) "Forms can't be over 50 lines long"))))) + (defevaluator :normal "::" + (constantly "No internal symbols from other packages")) + (defevaluator :normal "." (constantly nil)) )