initial improvements to allow multiline annotations

- Improve tree search
- Improve annotation argument loop
This commit is contained in:
PgBiel 2024-07-23 13:27:45 -03:00
parent e105cd1956
commit 46e4fbfac7
2 changed files with 12 additions and 10 deletions

View File

@ -271,9 +271,9 @@ impl Lexer<'_> {
// parenthesis) or newline. We have to check the newline before eating
// (through '.peek()') to ensure it is not considered part of the
// annotation.
let mut current_start = self.s.cursor();
let mut found_closing_paren = false;
while !self.s.at(is_newline) {
let current_start = self.s.cursor();
let token = match self.s.eat() {
Some(c) if c.is_whitespace() => {
self.s.eat_while(is_inline_whitespace);
@ -325,8 +325,6 @@ impl Lexer<'_> {
let node = self.emit_token(token, current_start);
subtree.push(node);
current_start = self.s.cursor();
}
// Right parenthesis (covered above)

View File

@ -825,19 +825,23 @@ impl<'a> LinkedNode<'a> {
pub fn prev_attached_annotation(&self) -> Option<Self> {
let mut cursor = self.prev_sibling_inner()?;
let mut newlines = cursor.capped_newlines();
while newlines < 2 {
if cursor.kind() == SyntaxKind::Annotation {
return Some(cursor);
while cursor.kind() != SyntaxKind::Annotation {
if newlines >= 2 {
// Annotations are attached if they're in the previous line.
// If we counted at least two newlines without finding an
// annotation, no annotations are attached to this node.
//
// Note that this check is only run if the latest node was not
// an annotation, otherwise annotations with multiple lines
// would always be rejected.
return None;
}
cursor = cursor.prev_sibling_inner()?;
newlines += cursor.capped_newlines();
}
// Annotations are attached if they're in the previous line.
// If we counted at least two newlines, no annotations are attached to
// this node.
None
Some(cursor)
}
/// Get the next non-trivia sibling node.