sway_core/language/parsed/
mod.rsmod code_block;
pub mod declaration;
mod expression;
mod include_statement;
mod module;
mod program;
mod use_statement;
pub use code_block::*;
pub use declaration::*;
pub use expression::*;
pub use include_statement::IncludeStatement;
pub use module::{ModuleEvaluationOrder, ParseModule, ParseSubmodule};
pub use program::{ParseProgram, TreeType};
use sway_error::handler::ErrorEmitted;
use sway_types::span::Span;
pub use use_statement::{ImportType, UseStatement};
use crate::{
engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext},
Engines,
};
#[derive(Debug, Clone)]
pub struct ParseTree {
pub root_nodes: Vec<AstNode>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct AstNode {
pub content: AstNodeContent,
pub span: Span,
}
impl EqWithEngines for AstNode {}
impl PartialEqWithEngines for AstNode {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
self.content.eq(&other.content, ctx)
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
pub enum AstNodeContent {
UseStatement(UseStatement),
Declaration(Declaration),
Expression(Expression),
IncludeStatement(IncludeStatement),
Error(Box<[Span]>, ErrorEmitted),
}
impl EqWithEngines for AstNodeContent {}
impl PartialEqWithEngines for AstNodeContent {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
match (self, other) {
(AstNodeContent::UseStatement(lhs), AstNodeContent::UseStatement(rhs)) => lhs.eq(rhs),
(AstNodeContent::Declaration(lhs), AstNodeContent::Declaration(rhs)) => {
lhs.eq(rhs, ctx)
}
(AstNodeContent::Expression(lhs), AstNodeContent::Expression(rhs)) => lhs.eq(rhs, ctx),
(AstNodeContent::IncludeStatement(lhs), AstNodeContent::IncludeStatement(rhs)) => {
lhs.eq(rhs)
}
(AstNodeContent::Error(lhs, ..), AstNodeContent::Error(rhs, ..)) => lhs.eq(rhs),
_ => false,
}
}
}
impl ParseTree {
pub(crate) fn exclude_tests(&mut self, engines: &Engines) {
self.root_nodes.retain(|node| !node.is_test(engines));
}
}
impl AstNode {
pub(crate) fn is_test(&self, engines: &Engines) -> bool {
if let AstNodeContent::Declaration(decl) = &self.content {
decl.is_test(engines)
} else {
false
}
}
}