kind_tree/
lib.rs

1//! This crate describes two types of abstract syntax trees.
2//! one for sugared trees (that are useful to create documentation),
3//! to format and to locate "phisically" all of the nodes so we can
4//! generate a lot of error messages. The other one that is desugured
5//! is useful to interface with HVM and KDL.
6
7/// The concrete AST.
8#[macro_use]
9pub mod concrete;
10
11/// The desugared AST.
12pub mod desugared;
13
14/// The untyped AST.
15pub mod untyped;
16
17/// Telescope (Iterated sigma type representation)
18pub mod telescope;
19
20/// Describes symbols (identifiers) on the language. It will
21/// be really useful when we change the Symbol to take a number
22/// instead of a string due to optimizations.
23pub mod symbol;
24
25use std::fmt::{Formatter, Display, Error};
26
27use symbol::Ident;
28
29/// Attributes describes some compiler specific aspects
30/// like inlining and derivations.
31#[derive(Clone, Debug, Default)]
32pub struct Attributes {
33    pub inlined: bool,
34    pub kdl_run: bool,
35    pub kdl_erase: bool,
36    pub kdl_name: Option<Ident>,
37    pub kdl_state: Option<Ident>,
38    pub trace: Option<bool>, // Some is enabled and some(true) is enabled with arguments
39    pub keep: bool,
40    pub partial: bool,
41    pub axiom: bool,
42}
43
44/// Enum of binary operators.
45#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
46pub enum Operator {
47    Add,
48    Sub,
49    Mul,
50    Div,
51    Mod,
52    And,
53    Or,
54    Xor,
55    Shl,
56    Shr,
57    Ltn,
58    Lte,
59    Eql,
60    Gte,
61    Gtn,
62    Neq,
63}
64
65impl Display for Operator {
66    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
67        use Operator::*;
68
69        match self {
70            Add => write!(f, "+"),
71            Sub => write!(f, "-"),
72            Mul => write!(f, "*"),
73            Div => write!(f, "/"),
74            Mod => write!(f, "%"),
75            And => write!(f, "&"),
76            Or => write!(f, "|"),
77            Xor => write!(f, "^"),
78            Shl => write!(f, "<<"),
79            Shr => write!(f, ">>"),
80            Ltn => write!(f, "<"),
81            Lte => write!(f, "<="),
82            Eql => write!(f, "=="),
83            Gte => write!(f, ">="),
84            Gtn => write!(f, ">"),
85            Neq => write!(f, "!="),
86        }
87    }
88}