Skip to main content

oak_nginx/language/
mod.rs

1#![doc = include_str!("readme.md")]
2use oak_core::{Language, LanguageCategory};
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Configuration for the Nginx language support.
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct NginxLanguage {
10    /// Whether to allow extended directives.
11    pub allow_extensions: bool,
12    /// Whether to enable strict mode.
13    pub strict_mode: bool,
14}
15
16impl Default for NginxLanguage {
17    fn default() -> Self {
18        Self { allow_extensions: false, strict_mode: false }
19    }
20}
21
22impl Language for NginxLanguage {
23    const NAME: &'static str = "nginx";
24    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
25
26    type TokenType = crate::lexer::token_type::NginxTokenType;
27    type ElementType = crate::parser::element_type::NginxElementType;
28    type TypedRoot = crate::ast::NginxRoot;
29}
30
31impl NginxLanguage {
32    /// Creates a new `NginxLanguage` with default settings.
33    pub fn new() -> Self {
34        Self::default()
35    }
36
37    /// Creates a new `NginxLanguage` with standard settings (strict mode enabled).
38    pub fn standard() -> Self {
39        Self { allow_extensions: false, strict_mode: true }
40    }
41
42    /// Creates a new `NginxLanguage` with extended settings (extensions allowed).
43    pub fn extended() -> Self {
44        Self { allow_extensions: true, strict_mode: false }
45    }
46}