From 5b292a2b6f2939e2b1fac120ce34427cb77cf1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Sun, 25 Feb 2024 14:28:27 +0100 Subject: [PATCH] Remove some unused TopDecl fields and methods --- crates/h10/src/ast.rs | 49 ++++++----------------------------- crates/h10/src/parser.rs | 2 +- crates/h10/src/parser/decl.rs | 2 -- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/crates/h10/src/ast.rs b/crates/h10/src/ast.rs index 01169dd..62d1dd6 100644 --- a/crates/h10/src/ast.rs +++ b/crates/h10/src/ast.rs @@ -43,27 +43,20 @@ pub struct TopDecl { // NB. We don't need the span (`AstNode`) here as we have access to the tokens. pub kind: TopDeclKind, - /// Line number of the `first_token` in the source file. + /// First token of the top-level declaration. /// - /// Line numbers of tokens attached to this declaration will be relative to this number. + /// This token will always be at column 0. /// - /// TODO: For this to hold, `first_token` should be the same token as the declaration's - /// indentation group's first token. Is this really the case? - pub line_number: u32, - - /// The first token where this top-level declaration starts. This token will always be at - /// column 0. - /// - /// TODO: Clarify whether this is the same as the declaration's indentation group's first + /// Note: initial trivia (whitespace, comments, documentation) are not a part of the + /// declaration, so this token can be different than the declaration's indentation group's first /// token. pub first_token: TokenRef, - /// The last token (inclusive) where this top-level declaration ends. + /// The last token (inclusive) of this top-level declaration. /// - /// This will almost always be a whitespace token as there needs to be at least one new line - /// between top-level declarations, and files usually end with a new line. - /// - /// TODO: Clarify whether this is the same as the declaration's indentation group's last token. + /// Note: trailing trivia (whitespace, comments, documentation) are not a part of the + /// declaration, so this token can be different than the declaration's indentation group's last + /// token. pub last_token: TokenRef, /// Defined and used ids in the decl. @@ -77,32 +70,6 @@ impl fmt::Debug for TopDecl { } } -impl TopDecl { - pub fn span_start(&self) -> Pos { - let token_pos = self.first_token.span().start; - Pos { - line: token_pos.line + self.line_number, - char: token_pos.char, - } - } - - pub fn span_end(&self) -> Pos { - let token_pos = self.last_token.span().end; - Pos { - line: token_pos.line + self.line_number, - char: token_pos.char, - } - } - - pub fn contains_location(&self, pos: Pos) -> bool { - pos >= self.span_start() && pos < self.span_end() - } - - pub fn iter_tokens(&self) -> impl Iterator { - self.first_token.iter_until(&self.last_token) - } -} - #[cfg(test)] impl TopDecl { pub fn class(&self) -> &ClassDecl { diff --git a/crates/h10/src/parser.rs b/crates/h10/src/parser.rs index a41db3c..e0c7791 100644 --- a/crates/h10/src/parser.rs +++ b/crates/h10/src/parser.rs @@ -32,7 +32,7 @@ pub fn parse_module(module_str: &str) -> ParserResult> { for group_idx in indentation_groups { let group = arena.get(group_idx); - // HACK: Because the layout token generator won't be generationg `;`s after a top-level + // HACK: Because the layout token generator won't be generating `;`s after a top-level // group, for now remove the link from the last token to the next. let next_token = group.last_token.next(); group.last_token.set_next(None); diff --git a/crates/h10/src/parser/decl.rs b/crates/h10/src/parser/decl.rs index 49a3018..cf23971 100644 --- a/crates/h10/src/parser/decl.rs +++ b/crates/h10/src/parser/decl.rs @@ -132,11 +132,9 @@ impl<'a> Parser<'a> { _ => self.value_decl().map(TopDeclKind::Value), }?; let (_, r) = self.last_tok_span(); - let line_number = t.span().start.line; let info = DeclInfo::new_from_top_decl(&top_decl_kind); Ok(TopDecl { kind: top_decl_kind, - line_number, first_token: t, last_token: self.last_tok.clone().unwrap(), info,