From 3ec934e1b1c2c2855a358c154601b67e453cf557 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 16 Oct 2015 22:30:59 -0400 Subject: [PATCH] highlight: add flag `include_loose_tokens` Signed-off-by: Jean Privat --- src/highlight.nit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/highlight.nit b/src/highlight.nit index 7bce52d..d2be8d8 100644 --- a/src/highlight.nit +++ b/src/highlight.nit @@ -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 -- 1.7.9.5