Skip to main content

oak_php/language/
mod.rs

1#![doc = include_str!("readme.md")]
2use oak_core::{Language, LanguageCategory};
3
4/// The type of the root node for PHP AST.
5pub type TypedRoot = crate::ast::PhpRoot;
6
7/// PHP language implementation.
8///
9/// This struct implements the [`Language`] trait for the PHP language.
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct PhpLanguage {
13    /// Start tag, e.g., "<?php"
14    pub tag_start: String,
15    /// End tag, e.g., "?>"
16    pub tag_end: String,
17    /// Short start tag, e.g., "<?"
18    pub short_tag_start: String,
19    /// Echo tag start, e.g., "<?="
20    pub echo_tag_start: String,
21}
22
23impl Default for PhpLanguage {
24    fn default() -> Self {
25        Self { tag_start: "<?php".to_string(), tag_end: "?>".to_string(), short_tag_start: "<?".to_string(), echo_tag_start: "<?=".to_string() }
26    }
27}
28
29impl PhpLanguage {
30    /// Creates a new `PhpLanguage` instance.
31    pub fn new() -> Self {
32        Self::default()
33    }
34}
35
36impl Language for PhpLanguage {
37    const NAME: &'static str = "php";
38    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
39
40    type TokenType = crate::lexer::token_type::PhpTokenType;
41    type ElementType = crate::parser::element_type::PhpElementType;
42    type TypedRoot = crate::ast::PhpRoot;
43}