Corrected handling of non-space whitespace.

Pascal J. Bourguignon [2015-07-02 02:34]
Corrected handling of non-space whitespace.
Filename
languages/cpp/cpp.lisp
languages/cpp/token.lisp
diff --git a/languages/cpp/cpp.lisp b/languages/cpp/cpp.lisp
index 643056d..d0547ff 100644
--- a/languages/cpp/cpp.lisp
+++ b/languages/cpp/cpp.lisp
@@ -235,19 +235,18 @@

 ;;; --------------------

-(defparameter *whitespaces* #(#\space #\tab #\vt #\page #\nul #\newline #\return #\linefeed))

 (defun skip-spaces (text start)
   (loop
     :while (and (< start (length text))
-                (find (aref text start) *whitespaces*))
+                (whitespacep (aref text start)))
     :do (incf start))
   start)

 (defun skip-spaces-but-one (text start)
   (let ((start (skip-spaces text start)))
     (when (and (plusp start)
-               (find (aref text (1- start)) *whitespaces*))
+               (whitespacep (aref text (1- start))))
       (decf start))
     start))

@@ -429,7 +428,7 @@ RETURN: the token text; the end position."
                                          nil)))
                       (prog1 (make-identifier token start lino file)
                         (setf start end))))
-                   ((char= ch #\space)
+                   ((whitespacep ch)
                     (prog1 (make-punctuation " " start lino file)
                       (incf start)))
                    ((or (and (char= ch #\.)
diff --git a/languages/cpp/token.lisp b/languages/cpp/token.lisp
index b3efccf..f7009e6 100644
--- a/languages/cpp/token.lisp
+++ b/languages/cpp/token.lisp
@@ -111,9 +111,16 @@
      (and (typep token 'punctuation-token)
           (or (string= ,value  (token-text token))))))

+(defparameter *whitespaces* #(#\space #\tab #\vt #\page #\nul #\newline #\return #\linefeed))
+(defun  whitespacep (character)
+  (find character *whitespaces*))
+(defun spacep (token)
+  (and (typep token 'punctuation-token)
+       (= 1 (length (token-text token)))
+       (whitespacep (aref (token-text token) 0))))
+
 (define-punctuation-predicate sharpp           "#")
 (define-punctuation-predicate sharpsharpp      "##")
-(define-punctuation-predicate spacep           " ")
 (define-punctuation-predicate openp            "(")
 (define-punctuation-predicate closep           ")")
 (define-punctuation-predicate open-bracket-p   "<")
ViewGit