Skip to main content

oak_solidity/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Solidity element types.
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum SolidityElementType {
7    /// Root element.
8    Root,
9    /// Pragma directive.
10    PragmaDirective,
11    /// Contract definition.
12    ContractDefinition,
13    /// Error element.
14    Error,
15}
16
17impl ElementType for SolidityElementType {
18    type Role = UniversalElementRole;
19
20    fn is_root(&self) -> bool {
21        matches!(self, Self::Root)
22    }
23
24    fn is_error(&self) -> bool {
25        matches!(self, Self::Error)
26    }
27
28    fn role(&self) -> Self::Role {
29        match self {
30            Self::Root => UniversalElementRole::Root,
31            Self::PragmaDirective | Self::ContractDefinition => UniversalElementRole::Definition,
32            Self::Error => UniversalElementRole::Error,
33        }
34    }
35}