php_parser_rs/parser/ast/
mod.rs

1use schemars::JsonSchema;
2use serde::Deserialize;
3use serde::Serialize;
4
5use crate::lexer::byte_string::ByteString;
6use crate::lexer::token::Span;
7use crate::lexer::token::TokenKind;
8use crate::node::Node;
9use crate::parser::ast::arguments::ArgumentPlaceholder;
10use crate::parser::ast::arguments::{ArgumentList, SingleArgument};
11use crate::parser::ast::classes::AnonymousClassExpression;
12use crate::parser::ast::classes::ClassStatement;
13use crate::parser::ast::comments::Comment;
14use crate::parser::ast::constant::ConstantStatement;
15use crate::parser::ast::control_flow::IfStatement;
16use crate::parser::ast::declares::DeclareStatement;
17use crate::parser::ast::enums::BackedEnumStatement;
18use crate::parser::ast::enums::UnitEnumStatement;
19use crate::parser::ast::functions::ArrowFunctionExpression;
20use crate::parser::ast::functions::ClosureExpression;
21use crate::parser::ast::functions::FunctionStatement;
22use crate::parser::ast::goto::GotoStatement;
23use crate::parser::ast::goto::LabelStatement;
24use crate::parser::ast::identifiers::Identifier;
25use crate::parser::ast::identifiers::SimpleIdentifier;
26use crate::parser::ast::interfaces::InterfaceStatement;
27use crate::parser::ast::literals::Literal;
28use crate::parser::ast::loops::BreakStatement;
29use crate::parser::ast::loops::ContinueStatement;
30use crate::parser::ast::loops::DoWhileStatement;
31use crate::parser::ast::loops::ForStatement;
32use crate::parser::ast::loops::ForeachStatement;
33use crate::parser::ast::loops::WhileStatement;
34use crate::parser::ast::namespaces::NamespaceStatement;
35use crate::parser::ast::operators::ArithmeticOperationExpression;
36use crate::parser::ast::operators::AssignmentOperationExpression;
37use crate::parser::ast::operators::BitwiseOperationExpression;
38use crate::parser::ast::operators::ComparisonOperationExpression;
39use crate::parser::ast::operators::LogicalOperationExpression;
40use crate::parser::ast::traits::TraitStatement;
41use crate::parser::ast::try_block::TryStatement;
42use crate::parser::ast::utils::CommaSeparated;
43use crate::parser::ast::variables::Variable;
44
45pub mod arguments;
46pub mod attributes;
47pub mod classes;
48pub mod comments;
49pub mod constant;
50pub mod control_flow;
51pub mod data_type;
52pub mod declares;
53pub mod enums;
54pub mod functions;
55pub mod goto;
56pub mod identifiers;
57pub mod interfaces;
58pub mod literals;
59pub mod loops;
60pub mod modifiers;
61pub mod namespaces;
62pub mod operators;
63pub mod properties;
64pub mod traits;
65pub mod try_block;
66pub mod utils;
67pub mod variables;
68
69pub type Block = Vec<Statement>;
70
71impl Node for Block {
72    fn children(&mut self) -> Vec<&mut dyn Node> {
73        self.iter_mut().map(|s| s as &mut dyn Node).collect()
74    }
75}
76
77pub type Program = Block;
78
79#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
80#[serde(tag = "type")]
81pub enum UseKind {
82    Normal,
83    Function,
84    Const,
85}
86
87#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
88
89pub struct StaticVar {
90    pub var: Variable,
91    pub default: Option<Expression>,
92}
93
94impl Node for StaticVar {
95    fn children(&mut self) -> Vec<&mut dyn Node> {
96        let mut children: Vec<&mut dyn Node> = vec![&mut self.var];
97        if let Some(default) = &mut self.default {
98            children.push(default);
99        }
100        children
101    }
102}
103
104#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
105#[serde(tag = "type", content = "value")]
106pub enum Ending {
107    Semicolon(Span),
108    CloseTag(Span),
109}
110
111#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
112#[serde(tag = "type")]
113pub struct HaltCompilerStatement {
114    pub content: Option<ByteString>,
115}
116
117impl Node for HaltCompilerStatement {}
118
119#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
120#[serde(tag = "type")]
121pub struct StaticStatement {
122    pub vars: Vec<StaticVar>,
123}
124
125impl Node for StaticStatement {
126    fn children(&mut self) -> Vec<&mut dyn Node> {
127        self.vars.iter_mut().map(|v| v as &mut dyn Node).collect()
128    }
129}
130
131#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
132#[serde(tag = "type")]
133pub struct SwitchStatement {
134    pub switch: Span,
135    pub left_parenthesis: Span,
136    pub condition: Expression,
137    pub right_parenthesis: Span,
138    pub cases: Vec<Case>,
139}
140
141impl Node for SwitchStatement {
142    fn children(&mut self) -> Vec<&mut dyn Node> {
143        let mut children: Vec<&mut dyn Node> = vec![&mut self.condition];
144        children.extend(self.cases.iter_mut().map(|c| c as &mut dyn Node));
145        children
146    }
147}
148
149#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
150#[serde(tag = "type")]
151pub struct EchoStatement {
152    pub echo: Span,
153    pub values: Vec<Expression>,
154    pub ending: Ending,
155}
156
157impl Node for EchoStatement {
158    fn children(&mut self) -> Vec<&mut dyn Node> {
159        self.values.iter_mut().map(|v| v as &mut dyn Node).collect()
160    }
161}
162
163#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
164#[serde(tag = "type")]
165pub struct ReturnStatement {
166    pub r#return: Span,
167    pub value: Option<Expression>,
168    pub ending: Ending,
169}
170
171impl Node for ReturnStatement {
172    fn children(&mut self) -> Vec<&mut dyn Node> {
173        if let Some(value) = &mut self.value {
174            vec![value]
175        } else {
176            vec![]
177        }
178    }
179}
180
181#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
182#[serde(tag = "type")]
183pub struct UseStatement {
184    pub kind: UseKind,
185    pub uses: Vec<Use>,
186}
187
188impl Node for UseStatement {
189    fn children(&mut self) -> Vec<&mut dyn Node> {
190        self.uses.iter_mut().map(|u| u as &mut dyn Node).collect()
191    }
192}
193
194#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
195#[serde(tag = "type")]
196pub struct GroupUseStatement {
197    pub prefix: SimpleIdentifier,
198    pub kind: UseKind,
199    pub uses: Vec<Use>,
200}
201
202impl Node for GroupUseStatement {
203    fn children(&mut self) -> Vec<&mut dyn Node> {
204        let mut children: Vec<&mut dyn Node> = vec![&mut self.prefix];
205        children.extend(self.uses.iter_mut().map(|u| u as &mut dyn Node));
206        children
207    }
208}
209
210#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
211#[serde(tag = "type", content = "value")]
212pub enum Statement {
213    FullOpeningTag(FullOpeningTagStatement),
214    ShortOpeningTag(ShortOpeningTagStatement),
215    EchoOpeningTag(EchoOpeningTagStatement),
216    ClosingTag(ClosingTagStatement),
217    InlineHtml(InlineHtmlStatement),
218    Label(LabelStatement),
219    Goto(GotoStatement),
220    HaltCompiler(HaltCompilerStatement),
221    Static(StaticStatement),
222    DoWhile(DoWhileStatement),
223    While(WhileStatement),
224    For(ForStatement),
225    Foreach(ForeachStatement),
226    Break(BreakStatement),
227    Continue(ContinueStatement),
228    Constant(ConstantStatement),
229    Function(FunctionStatement),
230    Class(ClassStatement),
231    Trait(TraitStatement),
232    Interface(InterfaceStatement),
233    If(IfStatement),
234    Switch(SwitchStatement),
235    Echo(EchoStatement),
236    Expression(ExpressionStatement),
237    Return(ReturnStatement),
238    Namespace(NamespaceStatement),
239    Use(UseStatement),
240    GroupUse(GroupUseStatement),
241    Comment(Comment),
242    Try(TryStatement),
243    UnitEnum(UnitEnumStatement),
244    BackedEnum(BackedEnumStatement),
245    Block(BlockStatement),
246    Global(GlobalStatement),
247    Declare(DeclareStatement),
248    Noop(Span),
249}
250
251#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
252
253pub struct InlineHtmlStatement {
254    pub html: ByteString,
255}
256
257#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
258
259pub struct FullOpeningTagStatement {
260    pub span: Span,
261}
262
263#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
264
265pub struct ShortOpeningTagStatement {
266    pub span: Span,
267}
268
269#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
270
271pub struct EchoOpeningTagStatement {
272    pub span: Span,
273}
274
275#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
276
277pub struct ClosingTagStatement {
278    pub span: Span,
279}
280
281impl Node for Statement {
282    fn children(&mut self) -> Vec<&mut dyn Node> {
283        match self {
284            Statement::Label(statement) => vec![statement],
285            Statement::Goto(statement) => vec![statement],
286            Statement::HaltCompiler(statement) => vec![statement],
287            Statement::Static(statement) => vec![statement],
288            Statement::DoWhile(statement) => vec![statement],
289            Statement::While(statement) => vec![statement],
290            Statement::For(statement) => vec![statement],
291            Statement::Foreach(statement) => vec![statement],
292            Statement::Break(statement) => vec![statement],
293            Statement::Continue(statement) => vec![statement],
294            Statement::Constant(statement) => vec![statement],
295            Statement::Function(statement) => vec![statement],
296            Statement::Class(statement) => vec![statement],
297            Statement::Trait(statement) => vec![statement],
298            Statement::Interface(statement) => vec![statement],
299            Statement::If(statement) => vec![statement],
300            Statement::Switch(statement) => vec![statement],
301            Statement::Echo(statement) => vec![statement],
302            Statement::Expression(statement) => vec![statement],
303            Statement::Return(statement) => vec![statement],
304            Statement::Namespace(statement) => vec![statement],
305            Statement::Use(statement) => vec![statement],
306            Statement::GroupUse(statement) => vec![statement],
307            Statement::Comment(statement) => vec![statement],
308            Statement::Try(statement) => vec![statement],
309            Statement::UnitEnum(statement) => vec![statement],
310            Statement::BackedEnum(statement) => vec![statement],
311            Statement::Block(statement) => vec![statement],
312            Statement::Global(statement) => vec![statement],
313            Statement::Declare(statement) => vec![statement],
314            _ => vec![],
315        }
316    }
317}
318
319#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
320#[serde(tag = "type")]
321pub struct ExpressionStatement {
322    pub expression: Expression,
323    pub ending: Ending,
324}
325
326impl Node for ExpressionStatement {
327    fn children(&mut self) -> Vec<&mut dyn Node> {
328        vec![&mut self.expression]
329    }
330}
331
332#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
333#[serde(tag = "type")]
334pub struct GlobalStatement {
335    pub global: Span,
336    pub variables: Vec<Variable>,
337}
338
339impl Node for GlobalStatement {
340    fn children(&mut self) -> Vec<&mut dyn Node> {
341        self.variables
342            .iter_mut()
343            .map(|v| v as &mut dyn Node)
344            .collect()
345    }
346}
347
348#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
349#[serde(tag = "type")]
350pub struct BlockStatement {
351    pub left_brace: Span,
352    pub statements: Vec<Statement>,
353    pub right_brace: Span,
354}
355
356impl Node for BlockStatement {
357    fn children(&mut self) -> Vec<&mut dyn Node> {
358        self.statements
359            .iter_mut()
360            .map(|s| s as &mut dyn Node)
361            .collect()
362    }
363}
364
365// See https://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting for more info.
366#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
367#[serde(tag = "type")]
368pub enum CastKind {
369    Int,
370    Bool,
371    Float,
372    String,
373    Array,
374    Object,
375    Unset,
376}
377
378impl From<TokenKind> for CastKind {
379    fn from(kind: TokenKind) -> Self {
380        match kind {
381            TokenKind::StringCast | TokenKind::BinaryCast => Self::String,
382            TokenKind::ObjectCast => Self::Object,
383            TokenKind::BoolCast | TokenKind::BooleanCast => Self::Bool,
384            TokenKind::IntCast | TokenKind::IntegerCast => Self::Int,
385            TokenKind::FloatCast | TokenKind::DoubleCast | TokenKind::RealCast => Self::Float,
386            TokenKind::UnsetCast => Self::Unset,
387            TokenKind::ArrayCast => Self::Array,
388            _ => unreachable!(),
389        }
390    }
391}
392
393impl From<&TokenKind> for CastKind {
394    fn from(kind: &TokenKind) -> Self {
395        kind.clone().into()
396    }
397}
398
399#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
400
401pub struct Case {
402    pub condition: Option<Expression>,
403    pub body: Block,
404}
405
406impl Node for Case {
407    fn children(&mut self) -> Vec<&mut dyn Node> {
408        let mut children: Vec<&mut dyn Node> = vec![];
409        if let Some(condition) = &mut self.condition {
410            children.push(condition);
411        }
412        children.extend(
413            self.body
414                .iter_mut()
415                .map(|statement| statement as &mut dyn Node)
416                .collect::<Vec<&mut dyn Node>>(),
417        );
418        children
419    }
420}
421
422#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
423
424pub struct Use {
425    pub name: SimpleIdentifier,
426    pub alias: Option<SimpleIdentifier>,
427    pub kind: Option<UseKind>,
428}
429
430impl Node for Use {
431    fn children(&mut self) -> Vec<&mut dyn Node> {
432        let mut children: Vec<&mut dyn Node> = vec![&mut self.name];
433        if let Some(alias) = &mut self.alias {
434            children.push(alias);
435        }
436        children
437    }
438}
439
440#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
441pub struct EvalExpression {
442    pub eval: Span,
443    // eval
444    pub argument: Box<SingleArgument>, // ("$a = 1")
445}
446
447#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
448pub struct EmptyExpression {
449    pub empty: Span,
450    // empty
451    pub argument: Box<SingleArgument>, // ($a)
452}
453
454#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
455pub struct DieExpression {
456    pub die: Span,
457    // die
458    pub argument: Option<Box<SingleArgument>>, // (1)
459}
460
461#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
462pub struct ExitExpression {
463    pub exit: Span,
464    // exit
465    pub argument: Option<Box<SingleArgument>>, // (1)
466}
467
468#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
469pub struct IssetExpression {
470    pub isset: Span,
471    // isset
472    pub arguments: ArgumentList, // `($a, ...)`
473}
474
475#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
476pub struct UnsetExpression {
477    pub unset: Span,
478    // unset
479    pub arguments: ArgumentList, // `($a, ...)`
480}
481
482#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
483pub struct PrintExpression {
484    pub print: Span,
485    // print
486    pub value: Option<Box<Expression>>,
487    // 1
488    pub argument: Option<Box<SingleArgument>>, // (1)
489}
490
491#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
492pub struct ConcatExpression {
493    pub left: Box<Expression>,
494    pub dot: Span,
495    pub right: Box<Expression>,
496}
497
498#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
499pub struct InstanceofExpression {
500    pub left: Box<Expression>,
501    pub instanceof: Span,
502    pub right: Box<Expression>,
503}
504
505#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
506pub struct ReferenceExpression {
507    pub ampersand: Span,
508    pub right: Box<Expression>,
509}
510
511#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
512pub struct ParenthesizedExpression {
513    pub start: Span,
514    pub expr: Box<Expression>,
515    pub end: Span,
516}
517
518#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
519pub struct ErrorSuppressExpression {
520    pub at: Span,
521    pub expr: Box<Expression>,
522}
523
524#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
525pub struct IncludeExpression {
526    pub include: Span,
527    pub path: Box<Expression>,
528}
529
530#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
531pub struct IncludeOnceExpression {
532    pub include_once: Span,
533    pub path: Box<Expression>,
534}
535
536#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
537pub struct RequireExpression {
538    pub require: Span,
539    pub path: Box<Expression>,
540}
541
542#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
543pub struct RequireOnceExpression {
544    pub require_once: Span,
545    pub path: Box<Expression>,
546}
547
548#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
549pub struct FunctionCallExpression {
550    pub target: Box<Expression>,
551    // `foo`
552    pub arguments: ArgumentList, // `(1, 2, 3)`
553}
554
555impl Node for FunctionCallExpression {
556    fn children(&mut self) -> Vec<&mut dyn Node> {
557        vec![self.target.as_mut(), &mut self.arguments]
558    }
559}
560
561#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
562pub struct FunctionClosureCreationExpression {
563    pub target: Box<Expression>,
564    // `foo`
565    pub placeholder: ArgumentPlaceholder, // `(...)`
566}
567
568impl Node for FunctionClosureCreationExpression {
569    fn children(&mut self) -> Vec<&mut dyn Node> {
570        vec![self.target.as_mut()]
571    }
572}
573
574#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
575pub struct MethodCallExpression {
576    pub target: Box<Expression>,
577    // `$foo`
578    pub arrow: Span,
579    // `->`
580    pub method: Box<Expression>,
581    // `bar`
582    pub arguments: ArgumentList, // `(1, 2, 3)`
583}
584
585impl Node for MethodCallExpression {
586    fn children(&mut self) -> Vec<&mut dyn Node> {
587        vec![
588            self.target.as_mut(),
589            self.method.as_mut(),
590            &mut self.arguments,
591        ]
592    }
593}
594
595#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
596pub struct MethodClosureCreationExpression {
597    pub target: Box<Expression>,
598    // `$foo`
599    pub arrow: Span,
600    // `->`
601    pub method: Box<Expression>,
602    // `bar`
603    pub placeholder: ArgumentPlaceholder, // `(...)`
604}
605
606impl Node for MethodClosureCreationExpression {
607    fn children(&mut self) -> Vec<&mut dyn Node> {
608        vec![self.target.as_mut(), self.method.as_mut()]
609    }
610}
611
612#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
613pub struct NullsafeMethodCallExpression {
614    pub target: Box<Expression>,
615    // `$foo`
616    pub question_arrow: Span,
617    // `?->`
618    pub method: Box<Expression>,
619    // `bar`
620    pub arguments: ArgumentList, // `(1, 2, 3)`
621}
622
623impl Node for NullsafeMethodCallExpression {
624    fn children(&mut self) -> Vec<&mut dyn Node> {
625        vec![
626            self.target.as_mut(),
627            self.method.as_mut(),
628            &mut self.arguments,
629        ]
630    }
631}
632
633#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
634pub struct StaticMethodCallExpression {
635    pub target: Box<Expression>,
636    // `Foo`
637    pub double_colon: Span,
638    // `::`
639    pub method: Identifier,
640    // `bar`
641    pub arguments: ArgumentList, // `(1, 2, 3)`
642}
643
644impl Node for StaticMethodCallExpression {
645    fn children(&mut self) -> Vec<&mut dyn Node> {
646        vec![self.target.as_mut(), &mut self.method, &mut self.arguments]
647    }
648}
649
650#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
651pub struct StaticVariableMethodCallExpression {
652    pub target: Box<Expression>,
653    // `Foo`
654    pub double_colon: Span,
655    // `::`
656    pub method: Variable,
657    // `$bar`
658    pub arguments: ArgumentList, // `(1, 2, 3)`
659}
660
661impl Node for StaticVariableMethodCallExpression {
662    fn children(&mut self) -> Vec<&mut dyn Node> {
663        vec![self.target.as_mut(), &mut self.method, &mut self.arguments]
664    }
665}
666
667#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
668pub struct StaticMethodClosureCreationExpression {
669    pub target: Box<Expression>,
670    // `Foo`
671    pub double_colon: Span,
672    // `::`
673    pub method: Identifier,
674    // `bar`
675    pub placeholder: ArgumentPlaceholder, // `(...)`
676}
677
678impl Node for StaticMethodClosureCreationExpression {
679    fn children(&mut self) -> Vec<&mut dyn Node> {
680        vec![self.target.as_mut(), &mut self.method]
681    }
682}
683
684#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
685pub struct StaticVariableMethodClosureCreationExpression {
686    pub target: Box<Expression>,
687    // `Foo`
688    pub double_colon: Span,
689    // `::`
690    pub method: Variable,
691    // `$bar`
692    pub placeholder: ArgumentPlaceholder, // `(...)`
693}
694
695impl Node for StaticVariableMethodClosureCreationExpression {
696    fn children(&mut self) -> Vec<&mut dyn Node> {
697        vec![self.target.as_mut(), &mut self.method]
698    }
699}
700
701#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
702pub struct PropertyFetchExpression {
703    pub target: Box<Expression>,
704    // `foo()`
705    pub arrow: Span,
706    // `->`
707    pub property: Box<Expression>, // `bar`
708}
709
710impl Node for PropertyFetchExpression {
711    fn children(&mut self) -> Vec<&mut dyn Node> {
712        vec![self.target.as_mut(), self.property.as_mut()]
713    }
714}
715
716#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
717pub struct NullsafePropertyFetchExpression {
718    pub target: Box<Expression>,
719    // `foo()`
720    pub question_arrow: Span,
721    // `?->`
722    pub property: Box<Expression>, // `bar`
723}
724
725impl Node for NullsafePropertyFetchExpression {
726    fn children(&mut self) -> Vec<&mut dyn Node> {
727        vec![self.target.as_mut(), self.property.as_mut()]
728    }
729}
730
731#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
732pub struct StaticPropertyFetchExpression {
733    pub target: Box<Expression>,
734    // `foo()`
735    pub double_colon: Span,
736    // `::`
737    pub property: Variable, // `$bar`
738}
739
740impl Node for StaticPropertyFetchExpression {
741    fn children(&mut self) -> Vec<&mut dyn Node> {
742        vec![self.target.as_mut(), &mut self.property]
743    }
744}
745
746#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
747pub struct ConstantFetchExpression {
748    pub target: Box<Expression>,
749    // `foo()`
750    pub double_colon: Span,
751    // `::`
752    pub constant: Identifier, // `bar`
753}
754
755impl Node for ConstantFetchExpression {
756    fn children(&mut self) -> Vec<&mut dyn Node> {
757        vec![self.target.as_mut(), &mut self.constant]
758    }
759}
760
761#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
762pub struct ShortArrayExpression {
763    pub start: Span,
764    // `[`
765    pub items: CommaSeparated<ArrayItem>,
766    // `1, 2, 3`
767    pub end: Span, // `]`
768}
769
770impl Node for ShortArrayExpression {
771    fn children(&mut self) -> Vec<&mut dyn Node> {
772        vec![&mut self.items]
773    }
774}
775
776#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
777pub struct ArrayExpression {
778    pub array: Span,
779    // `array`
780    pub start: Span,
781    // `(`
782    pub items: CommaSeparated<ArrayItem>,
783    // `1, 2, 3`
784    pub end: Span, // `)`
785}
786
787impl Node for ArrayExpression {
788    fn children(&mut self) -> Vec<&mut dyn Node> {
789        vec![&mut self.items]
790    }
791}
792
793#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
794pub struct ListExpression {
795    pub list: Span,
796    // `list`
797    pub start: Span,
798    // `(`
799    pub items: Vec<ListEntry>,
800    // `$a, $b`
801    pub end: Span, // `)`
802}
803
804impl Node for ListExpression {
805    fn children(&mut self) -> Vec<&mut dyn Node> {
806        self.items.iter_mut().map(|i| i as &mut dyn Node).collect()
807    }
808}
809
810#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
811pub struct NewExpression {
812    pub new: Span,
813    // `new`
814    pub target: Box<Expression>,
815    // `Foo`
816    pub arguments: Option<ArgumentList>, // `(1, 2, 3)`
817}
818
819impl Node for NewExpression {
820    fn children(&mut self) -> Vec<&mut dyn Node> {
821        let mut children: Vec<&mut dyn Node> = vec![self.target.as_mut()];
822        if let Some(arguments) = &mut self.arguments {
823            children.push(arguments);
824        }
825        children
826    }
827}
828
829#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
830pub struct InterpolatedStringExpression {
831    pub parts: Vec<StringPart>,
832}
833
834impl Node for InterpolatedStringExpression {
835    fn children(&mut self) -> Vec<&mut dyn Node> {
836        self.parts
837            .iter_mut()
838            .map(|part| part as &mut dyn Node)
839            .collect()
840    }
841}
842
843#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
844pub struct HeredocExpression {
845    pub label: ByteString,
846    pub parts: Vec<StringPart>,
847}
848
849impl Node for HeredocExpression {
850    fn children(&mut self) -> Vec<&mut dyn Node> {
851        self.parts
852            .iter_mut()
853            .map(|part| part as &mut dyn Node)
854            .collect()
855    }
856}
857
858#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
859pub struct NowdocExpression {
860    pub label: ByteString,
861    pub value: ByteString,
862}
863
864impl Node for NowdocExpression {}
865
866#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
867pub struct ShellExecExpression {
868    pub parts: Vec<StringPart>,
869}
870
871impl Node for ShellExecExpression {
872    fn children(&mut self) -> Vec<&mut dyn Node> {
873        self.parts
874            .iter_mut()
875            .map(|part| part as &mut dyn Node)
876            .collect()
877    }
878}
879
880#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
881pub struct BoolExpression {
882    pub value: bool,
883}
884
885impl Node for BoolExpression {}
886
887#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
888pub struct ArrayIndexExpression {
889    pub array: Box<Expression>,
890    pub left_bracket: Span,
891    pub index: Option<Box<Expression>>,
892    pub right_bracket: Span,
893}
894
895impl Node for ArrayIndexExpression {
896    fn children(&mut self) -> Vec<&mut dyn Node> {
897        let mut children: Vec<&mut dyn Node> = vec![];
898        if let Some(index) = &mut self.index {
899            children.push(index.as_mut());
900        }
901        children
902    }
903}
904
905#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
906pub struct ShortTernaryExpression {
907    pub condition: Box<Expression>,
908    // `foo()`
909    pub question_colon: Span,
910    // `?:`
911    pub r#else: Box<Expression>, // `bar()`
912}
913
914impl Node for ShortTernaryExpression {
915    fn children(&mut self) -> Vec<&mut dyn Node> {
916        vec![self.condition.as_mut(), self.r#else.as_mut()]
917    }
918}
919
920#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
921pub struct TernaryExpression {
922    pub condition: Box<Expression>,
923    // `foo()`
924    pub question: Span,
925    // `?`
926    pub then: Box<Expression>,
927    // `bar()`
928    pub colon: Span,
929    // `:`
930    pub r#else: Box<Expression>, // `baz()`
931}
932
933impl Node for TernaryExpression {
934    fn children(&mut self) -> Vec<&mut dyn Node> {
935        vec![
936            self.condition.as_mut(),
937            self.then.as_mut(),
938            self.r#else.as_mut(),
939        ]
940    }
941}
942
943#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
944pub struct CoalesceExpression {
945    pub lhs: Box<Expression>,
946    pub double_question: Span,
947    pub rhs: Box<Expression>,
948}
949
950impl Node for CoalesceExpression {
951    fn children(&mut self) -> Vec<&mut dyn Node> {
952        vec![self.lhs.as_mut(), self.rhs.as_mut()]
953    }
954}
955
956#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
957pub struct CloneExpression {
958    pub target: Box<Expression>,
959}
960
961impl Node for CloneExpression {
962    fn children(&mut self) -> Vec<&mut dyn Node> {
963        vec![self.target.as_mut()]
964    }
965}
966
967#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
968pub struct MatchExpression {
969    pub keyword: Span,
970    pub left_parenthesis: Span,
971    pub condition: Box<Expression>,
972    pub right_parenthesis: Span,
973    pub left_brace: Span,
974    pub default: Option<Box<DefaultMatchArm>>,
975    pub arms: Vec<MatchArm>,
976    pub right_brace: Span,
977}
978
979impl Node for MatchExpression {
980    fn children(&mut self) -> Vec<&mut dyn Node> {
981        let mut children: Vec<&mut dyn Node> = vec![self.condition.as_mut()];
982        if let Some(default) = &mut self.default {
983            children.push(default.as_mut());
984        }
985        children.extend(
986            self.arms
987                .iter_mut()
988                .map(|arm| arm as &mut dyn Node)
989                .collect::<Vec<&mut dyn Node>>(),
990        );
991        children
992    }
993}
994
995#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
996pub struct ThrowExpression {
997    pub value: Box<Expression>,
998}
999
1000impl Node for ThrowExpression {
1001    fn children(&mut self) -> Vec<&mut dyn Node> {
1002        vec![self.value.as_mut()]
1003    }
1004}
1005
1006#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1007pub struct YieldExpression {
1008    pub key: Option<Box<Expression>>,
1009    pub value: Option<Box<Expression>>,
1010}
1011
1012impl Node for YieldExpression {
1013    fn children(&mut self) -> Vec<&mut dyn Node> {
1014        let mut children: Vec<&mut dyn Node> = vec![];
1015        if let Some(key) = &mut self.key {
1016            children.push(key.as_mut());
1017        }
1018        if let Some(value) = &mut self.value {
1019            children.push(value.as_mut());
1020        }
1021        children
1022    }
1023}
1024
1025#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1026pub struct YieldFromExpression {
1027    pub value: Box<Expression>,
1028}
1029
1030impl Node for YieldFromExpression {
1031    fn children(&mut self) -> Vec<&mut dyn Node> {
1032        vec![self.value.as_mut()]
1033    }
1034}
1035
1036#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1037pub struct CastExpression {
1038    pub cast: Span,
1039    pub kind: CastKind,
1040    pub value: Box<Expression>,
1041}
1042
1043impl Node for CastExpression {
1044    fn children(&mut self) -> Vec<&mut dyn Node> {
1045        vec![self.value.as_mut()]
1046    }
1047}
1048
1049#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1050#[serde(tag = "type", content = "value")]
1051pub enum Expression {
1052    // eval("$a = 1")
1053    Eval(EvalExpression),
1054    // empty($a)
1055    Empty(EmptyExpression),
1056    // die, die(1)
1057    Die(DieExpression),
1058    // exit, exit(1)
1059    Exit(ExitExpression),
1060    // isset($a), isset($a, ...)
1061    Isset(IssetExpression),
1062    // unset($a), isset($a, ...)
1063    Unset(UnsetExpression),
1064    // print(1), print 1;
1065    Print(PrintExpression),
1066    Literal(Literal),
1067    ArithmeticOperation(ArithmeticOperationExpression),
1068    AssignmentOperation(AssignmentOperationExpression),
1069    BitwiseOperation(BitwiseOperationExpression),
1070    ComparisonOperation(ComparisonOperationExpression),
1071    LogicalOperation(LogicalOperationExpression),
1072    // $a . $b
1073    Concat(ConcatExpression),
1074    // $foo instanceof Bar
1075    Instanceof(InstanceofExpression),
1076    // &$foo
1077    Reference(ReferenceExpression),
1078    // ($a && $b)
1079    Parenthesized(ParenthesizedExpression),
1080    // @foo()
1081    ErrorSuppress(ErrorSuppressExpression),
1082    // `foo`, `foo_bar`, etc
1083    Identifier(Identifier),
1084    // `$foo`, `$foo_bar`, etc
1085    Variable(Variable),
1086    // include "foo.php"
1087    Include(IncludeExpression),
1088    // include_once "foo.php"
1089    IncludeOnce(IncludeOnceExpression),
1090    // require "foo.php"
1091    Require(RequireExpression),
1092    // require_once "foo.php"
1093    RequireOnce(RequireOnceExpression),
1094    // `foo(1, 2, 3)`
1095    FunctionCall(FunctionCallExpression),
1096    // `foo(...)`
1097    FunctionClosureCreation(FunctionClosureCreationExpression),
1098    // `$foo->bar(1, 2, 3)`
1099    MethodCall(MethodCallExpression),
1100    // `$foo->bar(...)`
1101    MethodClosureCreation(MethodClosureCreationExpression),
1102    // `$foo?->bar(1, 2, 3)`
1103    NullsafeMethodCall(NullsafeMethodCallExpression),
1104    // `Foo::bar(1, 2, 3)`
1105    StaticMethodCall(StaticMethodCallExpression),
1106    // `Foo::$bar(1, 2, 3)`
1107    StaticVariableMethodCall(StaticVariableMethodCallExpression),
1108    // `Foo::bar(...)`
1109    StaticMethodClosureCreation(StaticMethodClosureCreationExpression),
1110    // `Foo::$bar(...)`
1111    StaticVariableMethodClosureCreation(StaticVariableMethodClosureCreationExpression),
1112    // `foo()->bar`
1113    PropertyFetch(PropertyFetchExpression),
1114    // `foo()?->bar`
1115    NullsafePropertyFetch(NullsafePropertyFetchExpression),
1116    // `foo()::$bar`
1117    StaticPropertyFetch(StaticPropertyFetchExpression),
1118    // `foo()::bar` or `foo()::{$name}`
1119    ConstantFetch(ConstantFetchExpression),
1120    // `static`
1121    Static,
1122    // `self`
1123    Self_,
1124    // `parent`
1125    Parent,
1126    // `[1, 2, 3]`
1127    ShortArray(ShortArrayExpression),
1128    // `array(1, 2, 3)`
1129    Array(ArrayExpression),
1130    // list($a, $b)
1131    List(ListExpression),
1132    // `function() {}`
1133    Closure(ClosureExpression),
1134    // `fn() => $foo`
1135    ArrowFunction(ArrowFunctionExpression),
1136    // `new Foo(1, 2, 3)`
1137    New(NewExpression),
1138    // `"foo $bar foo"`
1139    InterpolatedString(InterpolatedStringExpression),
1140    // `<<<"EOT"` / `<<<EOT`
1141    Heredoc(HeredocExpression),
1142    // `<<<'EOT'`
1143    Nowdoc(NowdocExpression),
1144    // ``foo``
1145    ShellExec(ShellExecExpression),
1146    // `new class { ... }`
1147    AnonymousClass(AnonymousClassExpression),
1148    // `true`, `false`
1149    Bool(BoolExpression),
1150    // `$foo[0]`
1151    ArrayIndex(ArrayIndexExpression),
1152    // `null`
1153    Null,
1154    // `__DIR__`, etc
1155    MagicConstant(MagicConstantExpression),
1156    // `foo() ?: bar()`
1157    ShortTernary(ShortTernaryExpression),
1158    // `foo() ? bar() : baz()`
1159    Ternary(TernaryExpression),
1160    // `foo() ?? bar()`
1161    Coalesce(CoalesceExpression),
1162    // `clone $foo`
1163    Clone(CloneExpression),
1164    // `match ($foo) { ... }`
1165    Match(MatchExpression),
1166    // `throw new Exception`
1167    Throw(ThrowExpression),
1168    // `yield $foo`
1169    Yield(YieldExpression),
1170    // `yield from foo()`
1171    YieldFrom(YieldFromExpression),
1172    // `(int) "1"`, etc
1173    Cast(CastExpression),
1174    // ;
1175    Noop,
1176}
1177
1178impl Node for EvalExpression {
1179    fn children(&mut self) -> Vec<&mut dyn Node> {
1180        vec![self.argument.as_mut()]
1181    }
1182}
1183
1184impl Node for EmptyExpression {
1185    fn children(&mut self) -> Vec<&mut dyn Node> {
1186        vec![self.argument.as_mut()]
1187    }
1188}
1189
1190impl Node for DieExpression {
1191    fn children(&mut self) -> Vec<&mut dyn Node> {
1192        if let Some(argument) = &mut self.argument {
1193            vec![argument.as_mut()]
1194        } else {
1195            vec![]
1196        }
1197    }
1198}
1199
1200impl Node for ExitExpression {
1201    fn children(&mut self) -> Vec<&mut dyn Node> {
1202        if let Some(argument) = &mut self.argument {
1203            vec![argument.as_mut()]
1204        } else {
1205            vec![]
1206        }
1207    }
1208}
1209
1210impl Node for IssetExpression {
1211    fn children(&mut self) -> Vec<&mut dyn Node> {
1212        vec![&mut self.arguments]
1213    }
1214}
1215
1216impl Node for UnsetExpression {
1217    fn children(&mut self) -> Vec<&mut dyn Node> {
1218        vec![&mut self.arguments]
1219    }
1220}
1221
1222impl Node for PrintExpression {
1223    fn children(&mut self) -> Vec<&mut dyn Node> {
1224        if let Some(argument) = &mut self.argument {
1225            vec![argument.as_mut()]
1226        } else if let Some(value) = &mut self.value {
1227            vec![value.as_mut()]
1228        } else {
1229            vec![]
1230        }
1231    }
1232}
1233
1234impl Node for ConcatExpression {
1235    fn children(&mut self) -> Vec<&mut dyn Node> {
1236        vec![self.left.as_mut(), self.right.as_mut()]
1237    }
1238}
1239
1240impl Node for InstanceofExpression {
1241    fn children(&mut self) -> Vec<&mut dyn Node> {
1242        vec![self.left.as_mut(), self.right.as_mut()]
1243    }
1244}
1245
1246impl Node for ReferenceExpression {
1247    fn children(&mut self) -> Vec<&mut dyn Node> {
1248        vec![self.right.as_mut()]
1249    }
1250}
1251
1252impl Node for ParenthesizedExpression {
1253    fn children(&mut self) -> Vec<&mut dyn Node> {
1254        vec![self.expr.as_mut()]
1255    }
1256}
1257
1258impl Node for ErrorSuppressExpression {
1259    fn children(&mut self) -> Vec<&mut dyn Node> {
1260        vec![self.expr.as_mut()]
1261    }
1262}
1263
1264impl Node for IncludeExpression {
1265    fn children(&mut self) -> Vec<&mut dyn Node> {
1266        vec![self.path.as_mut()]
1267    }
1268}
1269
1270impl Node for IncludeOnceExpression {
1271    fn children(&mut self) -> Vec<&mut dyn Node> {
1272        vec![self.path.as_mut()]
1273    }
1274}
1275
1276impl Node for RequireExpression {
1277    fn children(&mut self) -> Vec<&mut dyn Node> {
1278        vec![self.path.as_mut()]
1279    }
1280}
1281
1282impl Node for RequireOnceExpression {
1283    fn children(&mut self) -> Vec<&mut dyn Node> {
1284        vec![self.path.as_mut()]
1285    }
1286}
1287
1288impl Node for Expression {
1289    fn children(&mut self) -> Vec<&mut dyn Node> {
1290        match self {
1291            Expression::Eval(expression) => vec![expression],
1292            Expression::Empty(expression) => vec![expression],
1293            Expression::Die(expression) => vec![expression],
1294            Expression::Exit(expression) => vec![expression],
1295            Expression::Isset(expression) => vec![expression],
1296            Expression::Unset(expression) => vec![expression],
1297            Expression::Print(expression) => vec![expression],
1298            Expression::Literal(literal) => vec![literal],
1299            Expression::ArithmeticOperation(operation) => vec![operation],
1300            Expression::AssignmentOperation(operation) => vec![operation],
1301            Expression::BitwiseOperation(operation) => vec![operation],
1302            Expression::ComparisonOperation(operation) => vec![operation],
1303            Expression::LogicalOperation(operation) => vec![operation],
1304            Expression::Concat(expression) => vec![expression],
1305            Expression::Instanceof(expression) => vec![expression],
1306            Expression::Reference(expression) => vec![expression],
1307            Expression::Parenthesized(expression) => vec![expression],
1308            Expression::ErrorSuppress(expression) => vec![expression],
1309            Expression::Identifier(identifier) => vec![identifier],
1310            Expression::Variable(variable) => vec![variable],
1311            Expression::Include(expression) => vec![expression],
1312            Expression::IncludeOnce(expression) => vec![expression],
1313            Expression::Require(expression) => vec![expression],
1314            Expression::RequireOnce(expression) => vec![expression],
1315            Expression::FunctionCall(expression) => vec![expression],
1316            Expression::FunctionClosureCreation(expression) => vec![expression],
1317            Expression::MethodCall(expression) => vec![expression],
1318            Expression::MethodClosureCreation(expression) => vec![expression],
1319            Expression::NullsafeMethodCall(expression) => vec![expression],
1320            Expression::StaticMethodCall(expression) => vec![expression],
1321            Expression::StaticVariableMethodCall(expression) => vec![expression],
1322            Expression::StaticMethodClosureCreation(expression) => vec![expression],
1323            Expression::StaticVariableMethodClosureCreation(expression) => vec![expression],
1324            Expression::PropertyFetch(expression) => vec![expression],
1325            Expression::NullsafePropertyFetch(expression) => vec![expression],
1326            Expression::StaticPropertyFetch(expression) => vec![expression],
1327            Expression::ConstantFetch(expression) => vec![expression],
1328            Expression::Static => vec![],
1329            Expression::Self_ => vec![],
1330            Expression::Parent => vec![],
1331            Expression::ShortArray(expression) => vec![expression],
1332            Expression::Array(expression) => vec![expression],
1333            Expression::List(expression) => vec![expression],
1334            Expression::Closure(expression) => vec![expression],
1335            Expression::ArrowFunction(expression) => vec![expression],
1336            Expression::New(expression) => vec![expression],
1337            Expression::InterpolatedString(expression) => vec![expression],
1338            Expression::Heredoc(expression) => vec![expression],
1339            Expression::Nowdoc(expression) => vec![expression],
1340            Expression::ShellExec(expression) => vec![expression],
1341            Expression::AnonymousClass(expression) => vec![expression],
1342            Expression::Bool(_) => vec![],
1343            Expression::ArrayIndex(expression) => vec![expression],
1344            Expression::Null => vec![],
1345            Expression::MagicConstant(constant) => vec![constant],
1346            Expression::ShortTernary(expression) => vec![expression],
1347            Expression::Ternary(expression) => vec![expression],
1348            Expression::Coalesce(expression) => vec![expression],
1349            Expression::Clone(expression) => vec![expression],
1350            Expression::Match(expression) => vec![expression],
1351            Expression::Throw(expression) => vec![expression],
1352            Expression::Yield(expression) => vec![expression],
1353            Expression::YieldFrom(expression) => vec![expression],
1354            Expression::Cast(expression) => vec![expression],
1355            Expression::Noop => vec![],
1356        }
1357    }
1358}
1359
1360#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1361
1362pub struct DefaultMatchArm {
1363    pub keyword: Span,      // `default`
1364    pub double_arrow: Span, // `=>`
1365    pub body: Expression,   // `foo()`
1366}
1367
1368impl Node for DefaultMatchArm {
1369    fn children(&mut self) -> Vec<&mut dyn Node> {
1370        vec![&mut self.body]
1371    }
1372}
1373
1374#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1375
1376pub struct MatchArm {
1377    pub conditions: Vec<Expression>,
1378    pub arrow: Span,
1379    pub body: Expression,
1380}
1381
1382impl Node for MatchArm {
1383    fn children(&mut self) -> Vec<&mut dyn Node> {
1384        let mut children: Vec<&mut dyn Node> = self
1385            .conditions
1386            .iter_mut()
1387            .map(|condition| condition as &mut dyn Node)
1388            .collect();
1389        children.push(&mut self.body);
1390        children
1391    }
1392}
1393
1394#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1395#[serde(tag = "type", content = "value")]
1396pub enum MagicConstantExpression {
1397    Directory(Span),
1398    File(Span),
1399    Line(Span),
1400    Class(Span),
1401    Function(Span),
1402    Method(Span),
1403    Namespace(Span),
1404    Trait(Span),
1405    CompilerHaltOffset(Span),
1406}
1407
1408impl Node for MagicConstantExpression {
1409    //
1410}
1411
1412#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1413#[serde(tag = "type", content = "value")]
1414pub enum StringPart {
1415    Literal(LiteralStringPart),
1416    Expression(ExpressionStringPart),
1417}
1418
1419#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1420
1421pub struct LiteralStringPart {
1422    pub value: ByteString,
1423}
1424
1425impl Node for LiteralStringPart {
1426    //
1427}
1428
1429#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1430
1431pub struct ExpressionStringPart {
1432    pub expression: Box<Expression>,
1433}
1434
1435impl Node for ExpressionStringPart {
1436    fn children(&mut self) -> Vec<&mut dyn Node> {
1437        vec![self.expression.as_mut()]
1438    }
1439}
1440
1441impl Node for StringPart {
1442    fn children(&mut self) -> Vec<&mut dyn Node> {
1443        match self {
1444            StringPart::Literal(part) => vec![part],
1445            StringPart::Expression(part) => vec![part],
1446        }
1447    }
1448}
1449
1450#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1451#[serde(tag = "type", content = "value")]
1452pub enum ArrayItem {
1453    Skipped,
1454    Value {
1455        value: Expression, // `$foo`
1456    },
1457    ReferencedValue {
1458        ampersand: Span,   // `&`
1459        value: Expression, // `$foo`
1460    },
1461    SpreadValue {
1462        ellipsis: Span,    // `...`
1463        value: Expression, // `$foo`
1464    },
1465    KeyValue {
1466        key: Expression,    // `$foo`
1467        double_arrow: Span, // `=>`
1468        value: Expression,  // `$bar`
1469    },
1470    ReferencedKeyValue {
1471        key: Expression,    // `$foo`
1472        double_arrow: Span, // `=>`
1473        ampersand: Span,    // `&`
1474        value: Expression,  // `$bar`
1475    },
1476}
1477
1478impl Node for ArrayItem {
1479    fn children(&mut self) -> Vec<&mut dyn Node> {
1480        match self {
1481            ArrayItem::Skipped => vec![],
1482            ArrayItem::Value { value } => vec![value],
1483            ArrayItem::ReferencedValue {
1484                ampersand: _,
1485                value,
1486            } => vec![value],
1487            ArrayItem::SpreadValue { ellipsis: _, value } => vec![value],
1488            ArrayItem::KeyValue {
1489                key,
1490                double_arrow: _,
1491                value,
1492            } => vec![key, value],
1493            ArrayItem::ReferencedKeyValue {
1494                key,
1495                double_arrow: _,
1496                ampersand: _,
1497                value,
1498            } => vec![key, value],
1499        }
1500    }
1501}
1502
1503#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
1504#[serde(tag = "type", content = "value")]
1505pub enum ListEntry {
1506    Skipped,
1507    Value {
1508        value: Expression, // `$foo`
1509    },
1510    KeyValue {
1511        key: Expression,    // `$foo`
1512        double_arrow: Span, // `=>`
1513        value: Expression,  // `$bar`
1514    },
1515}
1516
1517impl Node for ListEntry {
1518    fn children(&mut self) -> Vec<&mut dyn Node> {
1519        match self {
1520            ListEntry::Skipped => vec![],
1521            ListEntry::Value { value } => vec![value],
1522            ListEntry::KeyValue {
1523                key,
1524                double_arrow: _,
1525                value,
1526            } => vec![key, value],
1527        }
1528    }
1529}