diff options
| author | astrale-sharp <ash4567@outlook.fr> | 2024-06-12 14:00:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-12 12:00:22 +0000 |
| commit | ad4ef68a112dedabf80f885a02bcb574eb9af9e4 (patch) | |
| tree | a5de8e9f9de8e4ac64efa4a30b343fe70fda9656 /crates/typst-syntax/src/node.rs | |
| parent | 20b8d2c121c713cb32f6048df6435735a0c0262f (diff) | |
Lexer hint (#4346)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-syntax/src/node.rs')
| -rw-r--r-- | crates/typst-syntax/src/node.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs index 8e623d51..bc378e66 100644 --- a/crates/typst-syntax/src/node.rs +++ b/crates/typst-syntax/src/node.rs @@ -35,8 +35,8 @@ impl SyntaxNode { } /// Create a new error node. - pub fn error(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self { - Self(Repr::Error(Arc::new(ErrorNode::new(message, text)))) + pub fn error(error: SyntaxError, text: impl Into<EcoString>) -> Self { + Self(Repr::Error(Arc::new(ErrorNode::new(error, text)))) } /// Create a dummy node of the given kind. @@ -209,7 +209,7 @@ impl SyntaxNode { pub(super) fn convert_to_error(&mut self, message: impl Into<EcoString>) { if !self.kind().is_error() { let text = std::mem::take(self).into_text(); - *self = SyntaxNode::error(message, text); + *self = SyntaxNode::error(SyntaxError::new(message), text); } } @@ -628,15 +628,8 @@ struct ErrorNode { impl ErrorNode { /// Create new error node. - fn new(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self { - Self { - text: text.into(), - error: SyntaxError { - span: Span::detached(), - message: message.into(), - hints: eco_vec![], - }, - } + fn new(error: SyntaxError, text: impl Into<EcoString>) -> Self { + Self { text: text.into(), error } } /// The byte length of the node in the source text. @@ -674,6 +667,15 @@ pub struct SyntaxError { } impl SyntaxError { + /// Create a new detached syntax error. + pub fn new(message: impl Into<EcoString>) -> Self { + Self { + span: Span::detached(), + message: message.into(), + hints: eco_vec![], + } + } + /// Whether the two errors are the same apart from spans. fn spanless_eq(&self, other: &Self) -> bool { self.message == other.message && self.hints == other.hints |
