1mod expr;
2mod macros;
3mod unary;
4mod atomics;
5mod func;
6mod binary;
7mod bindings;
8mod call;
9mod field_access;
10mod path_access;
11mod parenthesized;
12mod statement;
13mod assignment;
14mod control_flow;
15mod range;
16mod map;
17mod module;
18mod index_access;
19
20use ecow::EcoString;
21use crate::node::SyntaxNode;
22use crate::span::{HasSpan, Span};
23
24pub use expr::*;
25use macros::*;
26pub use unary::*;
27pub use atomics::*;
28pub use binary::*;
29pub use bindings::*;
30pub use func::*;
31pub use call::*;
32pub use field_access::*;
33pub use path_access::*;
34pub use parenthesized::*;
35pub use statement::*;
36pub use assignment::*;
37pub use control_flow::*;
38pub use range::*;
39pub use map::*;
40pub use module::*;
41pub use index_access::*;
42
43pub trait AstNode<'a>: Sized {
44 fn from_untyped(node: &'a SyntaxNode) -> Option<Self>;
45 fn to_untyped(&self) -> &'a SyntaxNode;
46 fn span(&self) -> Span {
47 self.to_untyped().span()
48 }
49
50 fn to_text(&self) -> EcoString {
51 self.to_untyped().to_text()
52 }
53
54 fn cast<T: AstNode<'a>>(&self) -> Option<T> {
55 self.to_untyped().cast()
56 }
57}
58
59impl<'a, T> HasSpan for T where T: AstNode<'a> {
60 fn span(&self) -> Span {
61 AstNode::span(self)
62 }
63}
64
65