wright/ast/
expr.rs

1use crate::ast::identifier::Identifier;
2use crate::ast::literal::{BooleanLiteral, IntegerLiteral};
3use crate::source_tracking::fragment::Fragment;
4
5/// Atoms of an expression -- these are individual tokens from the lexer that are valid as an
6/// expression all on their own.
7#[derive(Debug)]
8#[allow(missing_docs)]
9pub enum Atom {
10    Identifier(Identifier),
11    IntegerLiteral(IntegerLiteral),
12    BooleanLiteral(BooleanLiteral),
13}
14
15impl Atom {
16    /// Get the matching fragment of source code.
17    pub fn fragment(&self) -> &Fragment {
18        match self {
19            Atom::Identifier(i) => &i.fragment,
20            Atom::IntegerLiteral(lit) => &lit.fragment,
21            Atom::BooleanLiteral(lit) => &lit.fragment,
22        }
23    }
24}
25
26#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
27#[allow(missing_docs)]
28pub enum UnaryOperation {
29    Reference,
30    Dereference,
31    Negate,
32    BooleanNot,
33    BitwiseNot,
34}