pretty: add consume_comment to process optional comments
authorJean Privat <jean@pryen.org>
Fri, 24 Apr 2015 11:03:46 +0000 (18:03 +0700)
committerJean Privat <jean@pryen.org>
Mon, 4 May 2015 20:08:12 +0000 (16:08 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/pretty.nit

index 2028628..0dc4ffb 100644 (file)
@@ -165,8 +165,14 @@ class PrettyPrinterVisitor
                end
        end
 
+       # Consume comments and end of lines if any
+       fun consume_comments do
+               while current_token isa TEol or current_token isa TComment do visit current_token
+       end
+
        # Visit `current_token`.
        fun consume(token: String) do
+               consume_comments
                if current_token.text == token then else current_token.debug("Got `{current_token.text}`; expected `{token}`.")
                visit current_token
        end
@@ -1278,10 +1284,8 @@ redef class AIfExpr
                                end
                        end
 
+                       v.consume_comments
                        if has_else(v) then
-                               while not v.current_token isa TKwelse do
-                                       v.consume v.current_token.text
-                               end
 
                                v.indent -= 1
                                v.addt