oak_nginx/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum NginxElementType {
7 Root,
9 Directive,
11 Block,
13 Parameter,
15 Value,
17 Comment,
19 Error,
21}
22
23impl NginxElementType {
24 pub fn is_element(&self) -> bool {
26 matches!(self, Self::Root | Self::Directive | Self::Block | Self::Parameter | Self::Value | Self::Comment)
27 }
28
29 pub fn is_token(&self) -> bool {
31 !self.is_element()
32 }
33}
34
35impl ElementType for NginxElementType {
36 type Role = UniversalElementRole;
37
38 fn role(&self) -> Self::Role {
39 match self {
40 Self::Root => UniversalElementRole::Root,
41 Self::Directive => UniversalElementRole::Statement,
42 Self::Block => UniversalElementRole::Container,
43 Self::Parameter => UniversalElementRole::AttributeKey,
44 Self::Value => UniversalElementRole::Value,
45 Self::Comment => UniversalElementRole::Documentation,
46 Self::Error => UniversalElementRole::Error,
47 }
48 }
49}
50
51impl From<crate::lexer::token_type::NginxTokenType> for NginxElementType {
52 fn from(token: crate::lexer::token_type::NginxTokenType) -> Self {
53 use crate::lexer::token_type::NginxTokenType as T;
54 match token {
55 T::Root => Self::Root,
56 T::Directive => Self::Directive,
57 T::Block => Self::Block,
58 T::Parameter => Self::Parameter,
59 T::Value => Self::Value,
60 T::Comment => Self::Comment,
61 _ => Self::Error,
62 }
63 }
64}