summaryrefslogtreecommitdiff
path: root/crates/typst-syntax
diff options
context:
space:
mode:
authorPgBiel <9021226+PgBiel@users.noreply.github.com>2024-07-23 13:27:45 -0300
committerPgBiel <9021226+PgBiel@users.noreply.github.com>2024-07-23 19:06:16 -0300
commit46e4fbfac7535e2cc19c7246c12eb1e36ea7d7aa (patch)
treeea90f25b36b0cd2b33769c98dd0a5e11089010e7 /crates/typst-syntax
parente105cd1956b311bb90045d4e0c339c51a6567cc8 (diff)
initial improvements to allow multiline annotations
- Improve tree search - Improve annotation argument loop
Diffstat (limited to 'crates/typst-syntax')
-rw-r--r--crates/typst-syntax/src/lexer.rs4
-rw-r--r--crates/typst-syntax/src/node.rs18
2 files changed, 12 insertions, 10 deletions
diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs
index d13fc527..9c36b2e8 100644
--- a/crates/typst-syntax/src/lexer.rs
+++ b/crates/typst-syntax/src/lexer.rs
@@ -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)
diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs
index 9a55ca5c..7c66d1d6 100644
--- a/crates/typst-syntax/src/node.rs
+++ b/crates/typst-syntax/src/node.rs
@@ -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.