From: Jean Privat Date: Sat, 17 Oct 2015 02:30:59 +0000 (-0400) Subject: highlight: add flag `include_loose_tokens` X-Git-Tag: v0.7.9~27^2~4 X-Git-Url: http://nitlanguage.org highlight: add flag `include_loose_tokens` Signed-off-by: Jean Privat --- 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