luau_parser/types/cst.rs
1use luau_lexer::error::Error;
2use smol_str::SmolStr;
3
4use crate::types::Block;
5
6/// An enum representing different states of a CST.
7#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
8#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9pub enum AstStatus {
10 /// Indicates that the parsed CST is a perfect clone of the code
11 /// passed to it and that no errors has occurred.
12 #[default]
13 Complete,
14
15 /// Indicates that the parsed CST is incomplete because the code had
16 /// syntax errors.
17 HasErrors,
18}
19
20/// A struct representing a scope in a file. This CST is lossless, meaning it can be
21/// printed back to the code it was created from without losing any details.
22#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
23#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
24pub struct Cst {
25 /// The path pointing to the file that this [`CST`](Cst) represents.
26 pub uri: SmolStr,
27
28 /// The [`block`](Block) of code for this scope.
29 pub block: Block,
30
31 /// All [`syntactical errors`](Error) in this CST.
32 pub errors: Vec<Error>,
33
34 /// The status of the [`CST`](Cst). If it isn't [`complete`](AstStatus::Complete), it's
35 /// better to not use it for operations which affect the source code, like formatting;
36 /// the output will have missing parts of the code.
37 pub status: AstStatus,
38}