misc_analysis: warn on superfluous `;`
authorJean Privat <jean@pryen.org>
Wed, 6 May 2015 01:21:33 +0000 (21:21 -0400)
committerJean Privat <jean@pryen.org>
Wed, 6 May 2015 12:58:00 +0000 (08:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/frontend/simple_misc_analysis.nit

index cc12d01..885d794 100644 (file)
@@ -40,6 +40,12 @@ redef class AModule
        do
                var v = new SimpleMiscVisitor(toolcontext)
                v.enter_visit(self)
+
+               var t = location.file.first_token
+               while t != null do
+                       t.accept_simple_misc_token(v)
+                       t = t.next_token
+               end
        end
 end
 
@@ -73,6 +79,12 @@ redef class ANode
        private fun after_simple_misc(v: SimpleMiscVisitor) do end
 end
 
+redef class Token
+       private fun accept_simple_misc_token(v: SimpleMiscVisitor)
+       do
+       end
+end
+
 redef class ASignature
        redef fun after_simple_misc(v)
        do
@@ -168,3 +180,25 @@ redef class AOnceExpr
                v.once_count = v.once_count - 1
        end
 end
+
+redef class TSemi
+       redef fun accept_simple_misc_token(v)
+       do
+               var n = next_token
+               var p = prev_token
+               if
+                       n == null or
+                       n isa TEol or
+                       n isa EOF or
+                       n isa TComment or
+                       p == null or
+                       p isa TEol or
+                       p isa EOF or
+                       p isa TComment or
+                       p isa TSemi
+               then
+                       v.warning(self, "semi", "Warning: superfluous `;`.")
+                       return
+               end
+       end
+end