Skip to main content

oak_solidity/parser/
element_type.rs

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