Skip to main content

graphcal_compiler/syntax/
ast.rs

1use core::convert::Infallible;
2
3use crate::syntax::phase::{Desugared, Phase, Raw};
4
5mod common;
6mod decl;
7mod format_equivalent;
8mod plot_props;
9mod value;
10
11pub use common::*;
12pub use decl::*;
13pub use format_equivalent::FormatEquivalent;
14pub use plot_props::*;
15pub use value::*;
16
17impl Phase for Raw {
18    type DeclSugar = RawDeclSugar;
19    type ExprSugar = RawExprSugar;
20}
21
22impl Phase for Desugared {
23    type DeclSugar = Infallible;
24    type ExprSugar = Infallible;
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use crate::syntax::names::DeclName;
31    use crate::syntax::span::{Span, Spanned};
32
33    #[test]
34    fn construct_ast_by_hand() {
35        let file: File<crate::syntax::phase::Desugared> = File {
36            declarations: vec![Declaration {
37                attributes: vec![],
38                kind: DeclKind::Param(ParamDecl {
39                    name: Spanned::new(DeclName::new("x"), Span::new(6, 1)),
40                    type_ann: TypeExpr {
41                        kind: TypeExprKind::Dimensionless,
42                        constraints: vec![],
43                        span: Span::new(9, 15),
44                    },
45                    value: Some(Expr::new(ExprKind::Number(1.0), Span::new(27, 3))),
46                }),
47                span: Span::new(0, 31),
48            }],
49        };
50        assert_eq!(file.declarations.len(), 1);
51    }
52}