highlight: add flag `include_loose_tokens`
authorJean Privat <jean@pryen.org>
Sat, 17 Oct 2015 02:30:59 +0000 (22:30 -0400)
committerJean Privat <jean@pryen.org>
Sat, 17 Oct 2015 14:03:59 +0000 (10:03 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/highlight.nit

index 7bce52d..d2be8d8 100644 (file)
@@ -48,6 +48,17 @@ class HighlightVisitor
                html.add_class("nitcode")
        end
 
+       # When highlighting a node, also consider the loose tokens around it.
+       #
+       # Loose tokens are tokens discarded from the AST but attached before
+       # or after some non-loose tokens. See `Token::is_loose`.
+       #
+       # When this flag is set to `true`, the loose tokens that are before the
+       # first token and after the last token are also highlighted.
+       #
+       # Default: false.
+       var include_loose_tokens = false is writable
+
        # The entry-point of the highlighting.
        # Will fill `html` with the generated HTML content.
        fun enter_visit(n: ANode)
@@ -68,6 +79,11 @@ class HighlightVisitor
                        if l == null then return
                end
 
+               if include_loose_tokens then
+                       if f.prev_looses.not_empty then f = f.prev_looses.first
+                       if l.next_looses.not_empty then l = l.next_looses.last
+               end
+
                htmlize(f, l)
        end