Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion crates/echo_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mod pretty;

pub use pretty::format_file;
pub use pretty::{FormatError, format_file, format_file_with_comments};

use echo_source::{SourceId, Span};
use echo_syntax::LeaderKind;
Expand Down Expand Up @@ -94,6 +94,33 @@ pub enum Stmt {
Expr(Expr),
}

impl Stmt {
/// Source span of the whole statement, including any braced body.
#[must_use]
pub fn span(&self) -> Span {
match self {
Self::Bind(s) => s.span,
Self::MultiBind(s) => s.span,
Self::Assign(s) => s.span,
Self::Struct(s) | Self::StructExt(s) => s.span,
Self::If(s) => s.span,
Self::ElseIf(s) => s.span,
Self::Else(s) => s.span,
Self::ErrorReturn(s) => s.span,
Self::Return(s) => s.span,
Self::Loop(s) => s.span,
Self::Break { span } | Self::Continue { span } => *span,
Self::Match(s) => s.span,
Self::TaskSpawn(s) => s.span,
Self::TaskJoin(s) => s.span,
Self::EffectBlock(s) => s.span,
Self::Import(s) => s.span,
Self::Export(s) => s.span,
Self::Expr(e) => e.span(),
}
}
}

/// `& { … }` or `& name = { … }` — auto-unwrap result/option; short-circuit on fail.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct EffectBlockStmt {
Expand Down
Loading
Loading