From 1437fe10eb4bcfca53c8c4746fdf68ab37aba0c1 Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Sun, 12 Jul 2015 08:06:53 -0500 Subject: [PATCH] Check for duplicated empty lines, empty at end of file --- resources/emptylineatend.lisp | 9 +++++++++ resources/twoemptylines.lisp | 9 +++++++++ src/main/checker.lisp | 18 ++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 resources/emptylineatend.lisp create mode 100644 resources/twoemptylines.lisp diff --git a/resources/emptylineatend.lisp b/resources/emptylineatend.lisp new file mode 100644 index 0000000..ead2dbb --- /dev/null +++ b/resources/emptylineatend.lisp @@ -0,0 +1,9 @@ +(in-package #:nothing) + +(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/resources/twoemptylines.lisp b/resources/twoemptylines.lisp new file mode 100644 index 0000000..8bba7ed --- /dev/null +++ b/resources/twoemptylines.lisp @@ -0,0 +1,9 @@ +(in-package #:nothing) + + +(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 2c42714..f20b6a8 100644 --- a/src/main/checker.lisp +++ b/src/main/checker.lisp @@ -11,7 +11,8 @@ ; * in-package must be first line in file unless file is package.lisp ; * No whitespace at end of line ; * No lines that are only whitespace -; - No empty lines at end of file +; * No empty lines at end of file +; * Never have two empty lines in a row ; * Only one in-package per file ; ; Some thoughts @@ -34,6 +35,7 @@ '(: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 ))) @@ -110,6 +112,10 @@ (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 ".*" (constantly "Must begin with in-package form")) (defevaluator :normal "\\( *in-package " @@ -127,8 +133,16 @@ (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 () (when (< 0 *col-no*) "No whitespace only lines"))) + (lambda () + (if + (< 0 *col-no*) + "No whitespace only lines" + (set-state :beginning-of-separators-with-space)))) (defevaluator :beginning-of-symbols "" (lambda () (set-state :normal) -- 2.25.1