typst_analyzer/typst_lang/
semantic_analysis.rs

1//! # semantic analysis
2//!
3//! semantic analysis for typst lang, utilizing concepts like symbol tables,
4//! scopes, and type checking. It processes an abstract syntax tree (AST) to
5//! ensure semantic correctness (e.g., variables are defined before use, types
6//! are consistent).
7
8use thiserror::Error;
9
10use super::span::Span;
11
12#[derive(Error, Debug)]
13pub enum SemanticError {
14    #[error("Undefined variable {name}")]
15    UndefinedVariable { name: String, span: Span },
16    #[error("Expect element type: {expect_type}, but got {actual_type}")]
17    ImConsistentArrayType {
18        expect_type: String,
19        actual_type: String,
20        span: Span,
21    },
22}
23
24impl SemanticError {
25    pub fn span(&self) -> Span {
26        match self {
27            SemanticError::UndefinedVariable { span, .. } => span.clone(),
28            SemanticError::ImConsistentArrayType { span, .. } => span.clone(),
29        }
30    }
31}
32
33pub type Result<T> = std::result::Result<T, SemanticError>;
34
35pub enum IndentType {}