sway_core/language/parsed/
program.rs

1use strum::EnumString;
2
3use crate::Engines;
4
5use super::ParseModule;
6
7/// A parsed, but not yet type-checked, Sway program.
8///
9/// Includes all modules in the form of a `ParseModule` tree accessed via the `root`.
10#[derive(Debug, Clone)]
11pub struct ParseProgram {
12    pub kind: TreeType,
13    pub root: ParseModule,
14}
15
16/// A Sway program can be either a contract, script, predicate, or a library.
17///
18/// All submodules declared with `dep` should be `Library`s.
19#[derive(Copy, Clone, Debug, PartialEq, Eq, EnumString)]
20pub enum TreeType {
21    #[strum(serialize = "predicate")]
22    Predicate,
23    #[strum(serialize = "script")]
24    Script,
25    #[strum(serialize = "contract")]
26    Contract,
27    #[strum(serialize = "library")]
28    Library,
29}
30
31impl std::fmt::Display for TreeType {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(
34            f,
35            "{}",
36            match self {
37                Self::Predicate => "predicate",
38                Self::Script => "script",
39                Self::Contract => "contract",
40                Self::Library => "library",
41            }
42        )
43    }
44}
45
46impl ParseProgram {
47    /// Excludes all test functions from the parse tree.
48    pub(crate) fn exclude_tests(&mut self, engines: &Engines) {
49        self.root.tree.exclude_tests(engines)
50    }
51}