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