Skip to content

Commit

Permalink
Remove some unused TopDecl fields and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Feb 25, 2024
1 parent d0f9f23 commit 5b292a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 44 deletions.
49 changes: 8 additions & 41 deletions crates/h10/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Item = TokenRef> {
self.first_token.iter_until(&self.last_token)
}
}

#[cfg(test)]
impl TopDecl {
pub fn class(&self) -> &ClassDecl {
Expand Down
2 changes: 1 addition & 1 deletion crates/h10/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn parse_module(module_str: &str) -> ParserResult<Vec<TopDecl>> {
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);
Expand Down
2 changes: 0 additions & 2 deletions crates/h10/src/parser/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b292a2

Please sign in to comment.