claw_ast/
lib.rs

1pub mod component;
2pub mod expressions;
3pub mod statements;
4pub mod types;
5
6use cranelift_entity::entity_impl;
7use miette::SourceSpan;
8
9pub use wit_parser::PackageName;
10
11pub type Span = SourceSpan;
12
13pub use component::*;
14pub use expressions::*;
15pub use statements::*;
16pub use types::*;
17
18pub fn merge(left: &Span, right: &Span) -> Span {
19    let left_most = left.offset();
20    let right_most = right.offset() + right.len();
21    let len = right_most - left_most;
22    Span::from((left_most, len))
23}
24
25#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
26pub struct NameId(u32);
27entity_impl!(NameId, "name");
28
29impl ContextEq<Component> for NameId {
30    fn context_eq(&self, other: &Self, context: &Component) -> bool {
31        let self_str = context.get_name(*self);
32        let other_str = context.get_name(*other);
33        let str_eq = self_str == other_str;
34
35        let self_span = context.name_span(*self);
36        let other_span = context.name_span(*other);
37        let span_eq = self_span == other_span;
38
39        str_eq && span_eq
40    }
41}