Skip to main content

oak_php/language/
mod.rs

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