branch: externals/phpinspect
commit 964b9d3c21fe91081d9507d6586817e6917cf682
Author: Hugo Thunnissen <de...@hugot.nl>
Commit: Hugo Thunnissen <de...@hugot.nl>

    Fix bug in parser that caused end-of-buffer error while parsing comments 
delimited by max-point
---
 phpinspect-parser.el | 21 ++++++++++++---------
 test/test-parser.el  |  5 +++++
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/phpinspect-parser.el b/phpinspect-parser.el
index f34262f4df..a3b9480237 100644
--- a/phpinspect-parser.el
+++ b/phpinspect-parser.el
@@ -546,26 +546,30 @@ nature like argument lists"
 
   (cond ((string-match "/\\*" start-token)
          (let* ((region-start (point))
+                (found-delimiter nil)
                 ;; Move to the end of the comment region
                 (region-end
                  (progn
-                   (while (not (or (= max-point (point)) (looking-at "\\*/")))
+                   (while (not (or (= max-point (point))
+                                   (and (looking-at "\\*/") (setq 
found-delimiter t))))
                      (forward-char))
                    (point)))
                 (doc-block (save-restriction
                              (goto-char region-start)
                              (narrow-to-region region-start region-end)
                              (phpinspect--parse-doc-block (current-buffer) 
(point-max)))))
-           (forward-char 2)
+           ;; If a delimiter (*/) was found, skip over it.
+           (when found-delimiter
+             (forward-char 2))
            doc-block))
         (t
          (let* ((end-position (line-end-position))
-               (token
-                (phpinspect--parse-comment (current-buffer) end-position 1)))
-          ;; Move to start of next line (absorb end of line)
-          (while (not (bolp))
-            (forward-char))
-          token))))
+                       (token
+                        (phpinspect--parse-comment (current-buffer) 
end-position)))
+              ;; Move to start of next line (absorb end of line)
+              (while (not (or (bolp) (= max-point (point))))
+                (forward-char))
+              token))))
 
 (phpinspect-defhandler class-variable (start-token &rest _ignored)
   "Handler for tokens indicating reference to a variable"
@@ -575,7 +579,6 @@ nature like argument lists"
       (phpinspect-munch-token-without-attribs (match-string 0) :class-variable)
     (list :class-variable nil)))
 
-
 (phpinspect-defhandler whitespace (whitespace &rest _ignored)
   "Handler that discards whitespace"
   ((regexp . "[[:blank:]\n]+"))
diff --git a/test/test-parser.el b/test/test-parser.el
index 741a65b4ee..573854333d 100644
--- a/test/test-parser.el
+++ b/test/test-parser.el
@@ -195,3 +195,8 @@ interface Test
                           (:terminator ";"))))))))))
 
     (should (equal expected result))))
+
+(ert-deftest phpinspect-parse-incomplete-comments ()
+  (dolist (code (list "//" "/*" "// " "/* "))
+
+    (should (phpinspect-parse-string code))))

Reply via email to