Skip to main content

php_ast/ast/
misc.rs

1use serde::Serialize;
2
3use crate::Span;
4
5use super::{ArenaVec, Expr, Name, Stmt};
6
7/// A comment found in the source file.
8#[derive(Debug, Serialize)]
9pub struct Comment<'src> {
10    pub kind: CommentKind,
11    /// Raw text of the comment including its delimiters (e.g. `// foo`, `/* bar */`, `/** baz */`).
12    pub text: &'src str,
13    pub span: Span,
14}
15
16/// Distinguishes the four syntactic forms of PHP comment.
17#[derive(Debug, Serialize, Clone, Copy, PartialEq, Eq)]
18pub enum CommentKind {
19    /// `// …` — single-line slash comment
20    Line,
21    /// `# …` — single-line hash comment
22    Hash,
23    /// `/* … */` — block comment
24    Block,
25    /// `/** … */` — doc-block comment (first non-whitespace char after `/*` is `*`)
26    Doc,
27}
28
29/// The root AST node representing a complete PHP file.
30#[derive(Debug, Serialize)]
31pub struct Program<'arena, 'src> {
32    pub stmts: ArenaVec<'arena, Stmt<'arena, 'src>>,
33    pub span: Span,
34}
35
36#[derive(Debug, Serialize)]
37pub struct Arg<'arena, 'src> {
38    pub name: Option<Name<'arena, 'src>>,
39    pub value: Expr<'arena, 'src>,
40    pub unpack: bool,
41    pub by_ref: bool,
42    pub span: Span,
43}
44
45#[derive(Debug, Serialize)]
46pub struct Attribute<'arena, 'src> {
47    pub name: Name<'arena, 'src>,
48    pub args: ArenaVec<'arena, Arg<'arena, 'src>>,
49    pub span: Span,
50}