From 48420596ab8da727a1977416bd888bb23a7c94fe Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 14 May 2015 19:17:11 -0400 Subject: [PATCH] parser: add `is_loose`, `prev_looses` and `next_looses` Signed-off-by: Jean Privat fixup loos in nodes --- src/parser/parser_nodes.nit | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index fe79ef1..6d7233e 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -311,6 +311,35 @@ abstract class Token # May have disappeared in the AST var next_token: nullable Token = null + # Is `self` a token discarded from the AST? + # + # Loose tokens are not present in the AST. + # It means they were identified by the lexer but were discarded by the parser. + # It also means that they are not visited or manipulated by AST-related functions. + # + # Each loose token is attached to the non-loose token that precedes or follows it. + # The rules are the following: + # + # * tokens that follow a non-loose token on a same line are attached to it. + # See `next_looses`. + # * other tokens, thus that precede a non-loose token on the same line or the next one, + # are attached to this one. See `prev_looses`. + # + # Loose tokens are mostly end of lines (`TEol`) and comments (`TComment`). + # Whitespace are ignored by the lexer, so they are not even considered as loose tokens. + # See `blank_before` to get the whitespace that separate tokens. + var is_loose = false + + # Loose tokens that precede `self`. + # + # These tokens start the line or belong to a line with only loose tokens. + var prev_looses = new Array[Token] is lazy + + # Loose tokens that follow `self` + # + # These tokens are on the same line than `self`. + var next_looses = new Array[Token] is lazy + # The verbatim blank text between `prev_token` and `self` fun blank_before: String do -- 1.7.9.5