oxblade 0.1.0

Blade templates for Laravel for Rust: Blade's markup and directives, Laravel's helpers, Rust's expressions. Community package, not affiliated with Laravel.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
//! Source-spanned template and expression syntax.

use crate::span::Span;

/// A parsed source.
#[derive(Clone, Debug, PartialEq)]
pub struct Template {
    /// Range of the entire template.
    pub span: Span,
    /// Top-level nodes in source order.
    pub nodes: Vec<Node>,
}

/// A template node and its full source range.
#[derive(Clone, Debug, PartialEq)]
pub struct Node {
    /// Source extent, including closing marker for a block.
    pub span: Span,
    /// Template operation.
    pub kind: NodeKind,
}

/// An expression and its source range.
#[derive(Clone, Debug, PartialEq)]
pub struct Expr {
    /// Source extent.
    pub span: Span,
    /// Expression operation.
    pub kind: ExprKind,
}

/// A binding or match pattern.
#[derive(Clone, Debug, PartialEq)]
pub struct Pattern {
    /// Source extent.
    pub span: Span,
    /// Pattern operation.
    pub kind: PatternKind,
}

/// A statement and its source range.
#[derive(Clone, Debug, PartialEq)]
pub struct Stmt {
    /// Source extent.
    pub span: Span,
    /// Statement operation.
    pub kind: StmtKind,
}

/// A Rust-style block with an optional tail expression.
#[derive(Clone, Debug, PartialEq)]
pub struct Block {
    /// Statements in execution order.
    pub statements: Vec<Stmt>,
    /// Value of the block, if present.
    pub tail: Option<Box<Expr>>,
}

/// A match arm evaluated in source order.
#[derive(Clone, Debug, PartialEq)]
pub struct MatchArm {
    /// Pattern to test.
    pub pattern: Pattern,
    /// Optional boolean guard.
    pub guard: Option<Expr>,
    /// Result expression.
    pub value: Expr,
}

/// A prop, aware or injected binding declaration.
#[derive(Clone, Debug, PartialEq)]
pub struct FieldDecl {
    /// Binding name.
    pub name: String,
    /// Type spelling, when supplied.
    pub ty: Option<String>,
    /// Default value, when supplied.
    pub default: Option<Expr>,
    /// Source extent.
    pub span: Span,
}

/// A conditional branch.
#[derive(Clone, Debug, PartialEq)]
pub struct Branch {
    /// Test, or no test for the final else.
    pub test: Option<Condition>,
    /// Branch content.
    pub body: Vec<Node>,
    /// Branch opening marker.
    pub span: Span,
}

/// A typed condition and its operands.
#[derive(Clone, Debug, PartialEq)]
pub struct Condition {
    /// Conditional operation.
    pub kind: ConditionKind,
    /// Operands in source order.
    pub args: Vec<Expr>,
}

/// A switch label and its fall-through body.
#[derive(Clone, Debug, PartialEq)]
pub struct SwitchArm {
    /// Case expression, or no expression for default.
    pub test: Option<Expr>,
    /// Case content.
    pub body: Vec<Node>,
    /// Label source extent.
    pub span: Span,
}

/// One branch in a conditional push.
#[derive(Clone, Debug, PartialEq)]
pub struct PushBranch {
    /// Test, or no test for the final else.
    pub condition: Option<Expr>,
    /// Stack name expression.
    pub stack: Expr,
    /// Content to push.
    pub body: Vec<Node>,
    /// Branch opening marker.
    pub span: Span,
}

/// An invocation written as an x-tag.
#[derive(Clone, Debug, PartialEq)]
pub struct Component {
    /// Component name, including any namespace.
    pub name: String,
    /// Attributes in source order.
    pub attributes: Vec<ComponentAttr>,
    /// Default and named slot content.
    pub body: Vec<Node>,
    /// Whether the call used a self-closing tag.
    pub self_closing: bool,
}

/// A named slot written as an x-slot tag.
#[derive(Clone, Debug, PartialEq)]
pub struct Slot {
    /// Name encoded in the tag name, if present.
    pub name: Option<String>,
    /// Attributes including any explicit name binding.
    pub attributes: Vec<ComponentAttr>,
    /// Slot content.
    pub body: Vec<Node>,
    /// Whether the tag was self-closing.
    pub self_closing: bool,
}

/// An attribute on a component or slot tag.
#[derive(Clone, Debug, PartialEq)]
pub struct ComponentAttr {
    /// Source extent.
    pub span: Span,
    /// Attribute operation.
    pub kind: ComponentAttrKind,
}

/// Operands of a helper or method call.
#[derive(Clone, Debug, PartialEq)]
pub struct CallArgs {
    /// Explicit turbofish type spellings.
    pub types: Vec<String>,
    /// Positional and named operands.
    pub values: Vec<Expr>,
}

/// The spelling and trust mode of an echo.
#[derive(Clone, Debug, PartialEq, Copy, Eq)]
#[non_exhaustive]
pub enum EchoKind {
    /// Double-brace escaped echo.
    Escaped,
    /// Trusted raw echo.
    Raw,
    /// Triple-brace escaped echo.
    Legacy,
}

/// A constant in a template expression.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Literal {
    /// The None literal.
    Null,
    /// Boolean.
    Bool(bool),
    /// Signed integer.
    Int(i64),
    /// Floating-point number.
    Float(f64),
    /// Decoded string.
    String(String),
}

/// Prefix operation.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum UnaryOp {
    /// Boolean negation.
    Not,
    /// Numeric negation.
    Negate,
}

/// Infix operation in precedence-independent form.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum BinaryOp {
    /// Missing-value fallback.
    Coalesce,
    /// Logical or.
    Or,
    /// Logical and.
    And,
    /// Strict equality.
    Eq,
    /// Strict inequality.
    Ne,
    /// Less than.
    Lt,
    /// Less than or equal.
    Le,
    /// Greater than.
    Gt,
    /// Greater than or equal.
    Ge,
    /// Exclusive or.
    Xor,
    /// Addition or string concatenation.
    Add,
    /// Subtraction.
    Sub,
    /// Multiplication.
    Mul,
    /// Division.
    Div,
    /// Remainder.
    Rem,
}

/// Assignment operation.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum AssignOp {
    /// Simple assignment.
    Set,
    /// Add and assign.
    Add,
    /// Subtract and assign.
    Sub,
    /// Multiply and assign.
    Mul,
    /// Divide and assign.
    Div,
    /// Take remainder and assign.
    Rem,
    /// Exclusive or and assign.
    Xor,
}

/// A map key expression or an already-known key.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum MapKey {
    /// Literal key, including identifiers and keywords.
    Static(String),
    /// Key evaluated at runtime.
    Computed(Expr),
}

/// Forms of binding and match patterns.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum PatternKind {
    /// Named binding.
    Binding(String),
    /// Ignore the value.
    Wildcard,
    /// Match a literal.
    Literal(Literal),
    /// Match a qualified constant or enum case.
    Path(Vec<String>),
    /// Tuple destructuring.
    Tuple(Vec<Pattern>),
    /// List destructuring.
    List(Vec<Pattern>),
    /// Match any alternative.
    Or(Vec<Pattern>),
}

/// Expressions evaluated by the engine.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ExprKind {
    /// A constant.
    Literal(Literal),
    /// Variable, qualified constant, or callable path.
    Path(Vec<String>),
    /// List items.
    List(Vec<Expr>),
    /// Tuple items.
    Tuple(Vec<Expr>),
    /// Ordered map entries.
    Map(Vec<(MapKey, Expr)>),
    /// PHP-style conditional class or style entry.
    ConditionalEntry {
        /// Candidate class or style.
        value: Box<Expr>,
        /// Boolean predicate.
        condition: Box<Expr>,
    },
    /// A named call operand.
    NamedArgument {
        /// Parameter name.
        name: String,
        /// Supplied value.
        value: Box<Expr>,
    },
    /// Field access.
    Field {
        /// Value being accessed.
        receiver: Box<Expr>,
        /// Field name.
        name: String,
        /// Whether missing receivers short-circuit.
        optional: bool,
    },
    /// Indexed access.
    Index {
        /// Value being indexed.
        receiver: Box<Expr>,
        /// Key or numeric index.
        index: Box<Expr>,
        /// Whether missing receivers short-circuit.
        optional: bool,
    },
    /// Function or closure invocation.
    Call {
        /// Callable expression.
        callee: Box<Expr>,
        /// Arguments and type arguments.
        args: CallArgs,
    },
    /// Method call.
    Method {
        /// Method receiver.
        receiver: Box<Expr>,
        /// Method name.
        name: String,
        /// Whether missing receivers short-circuit.
        optional: bool,
        /// Arguments and type arguments.
        args: CallArgs,
    },
    /// Postfix failure propagation.
    Try(Box<Expr>),
    /// Explicit numeric cast.
    Cast {
        /// Value to convert.
        value: Box<Expr>,
        /// Target type spelling.
        ty: String,
    },
    /// Prefix operation.
    Unary {
        /// Operator.
        op: UnaryOp,
        /// Operand.
        value: Box<Expr>,
    },
    /// Infix operation.
    Binary {
        /// Operator.
        op: BinaryOp,
        /// Left operand.
        left: Box<Expr>,
        /// Right operand.
        right: Box<Expr>,
    },
    /// An exclusive or inclusive range.
    Range {
        /// Optional lower endpoint.
        start: Option<Box<Expr>>,
        /// Optional upper endpoint.
        end: Option<Box<Expr>>,
        /// Whether the upper endpoint is included.
        inclusive: bool,
    },
    /// Conditional expression with block bodies.
    If {
        /// Boolean condition.
        test: Box<Expr>,
        /// True branch.
        then: Block,
        /// Else block or nested if.
        otherwise: Option<Box<Expr>>,
    },
    /// A block expression.
    Block(Block),
    /// Pattern match expression.
    Match {
        /// Scrutinee.
        value: Box<Expr>,
        /// Arms in source order.
        arms: Vec<MatchArm>,
    },
    /// A closure with expression or block body.
    Closure {
        /// Parameters.
        params: Vec<Pattern>,
        /// Body expression.
        body: Box<Expr>,
    },
}

/// Operations allowed inside a code block.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum StmtKind {
    /// Declares a binding.
    Let {
        /// Binding pattern.
        pattern: Pattern,
        /// Whether the binding can be reassigned.
        mutable: bool,
        /// Optional Rust type spelling.
        ty: Option<String>,
        /// Initializer.
        value: Expr,
    },
    /// Updates a binding or indexed location.
    Assign {
        /// Assignment target.
        target: Expr,
        /// Assignment operator.
        op: AssignOp,
        /// New value or operand.
        value: Expr,
    },
    /// Expression evaluated for side effects.
    Expr(Expr),
    /// Iterates inside a code block.
    For {
        /// Item binding.
        pattern: Pattern,
        /// Items to iterate.
        iterable: Expr,
        /// Loop body.
        body: Block,
    },
    /// Loops inside a code block.
    While {
        /// Boolean condition.
        test: Expr,
        /// Loop body.
        body: Block,
    },
    /// Leaves the nearest code loop.
    Break,
    /// Continues the nearest code loop.
    Continue,
}

/// Component attribute forms.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ComponentAttrKind {
    /// Quoted or unquoted attribute, optionally containing echoes.
    Literal {
        /// Literal attribute name.
        name: String,
        /// Interpolated value.
        parts: Vec<AttributePart>,
    },
    /// An expression-valued attribute.
    Bound {
        /// Attribute name without its colon.
        name: String,
        /// Bound expression.
        value: Expr,
    },
    /// A binding written as :$name.
    Shorthand(String),
    /// An Alpine-style escaped colon attribute.
    Escaped {
        /// Name with the first colon removed.
        name: String,
        /// Optional interpolated value.
        parts: Option<Vec<AttributePart>>,
    },
    /// An attribute without a value.
    Bare(String),
    /// An echoed attribute bag.
    Spread(Expr),
    /// An on-tag class directive.
    Class(Expr),
    /// An on-tag style directive.
    Style(Expr),
}

/// One part of a literal component attribute.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum AttributePart {
    /// Literal substring.
    Text(String),
    /// Interpolated expression.
    Echo(EchoKind, Expr),
}

/// The spelling of a template iteration.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum LoopKind {
    /// Range-style iteration.
    For,
    /// Collection iteration.
    Foreach,
    /// Collection iteration with an empty branch.
    Forelse,
}

/// How a captured section is stored and emitted.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum SectionEnd {
    /// Normal section end.
    Stop,
    /// End and render the section.
    Show,
    /// Append to the section.
    Append,
    /// Replace the section.
    Overwrite,
}

/// Template conditional operations.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ConditionKind {
    /// The @if condition.
    If,
    /// The @unless condition.
    Unless,
    /// The @isset condition.
    Isset,
    /// The @empty condition.
    Empty,
    /// The @auth condition.
    Auth,
    /// The @guest condition.
    Guest,
    /// The @can condition.
    Can,
    /// The @cannot condition.
    Cannot,
    /// The @canany condition.
    CanAny,
    /// The @env condition.
    Env,
    /// The @production condition.
    Production,
    /// The @session condition.
    Session,
    /// The @context condition.
    Context,
    /// The @hassection condition.
    HasSection,
    /// The @sectionmissing condition.
    SectionMissing,
    /// The @hasstack condition.
    HasStack,
    /// The @error condition.
    Error,
    /// A registered condition.
    Custom {
        /// Canonical registered name.
        name: String,
        /// Whether this invocation used unless.
        negated: bool,
    },
}

/// Capture and grouping modes for Blade block directives.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum BlockKind {
    /// The @once block.
    Once,
    /// The @push block.
    Push,
    /// The @pushonce block.
    PushOnce,
    /// The @prepend block.
    Prepend,
    /// The @prependonce block.
    PrependOnce,
    /// The @fragment block.
    Fragment,
    /// The @component block.
    Component,
    /// The @componentfirst block.
    ComponentFirst,
    /// The @slot block.
    Slot,
    /// The @lang block.
    Lang,
}

/// Single Blade directive operations.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum InlineKind {
    /// The @extends directive.
    Extends,
    /// The @extendsfirst directive.
    ExtendsFirst,
    /// The @yield directive.
    Yield,
    /// The @parent directive.
    Parent,
    /// The @include directive.
    Include,
    /// The @includeif directive.
    IncludeIf,
    /// The @includewhen directive.
    IncludeWhen,
    /// The @includeunless directive.
    IncludeUnless,
    /// The @includefirst directive.
    IncludeFirst,
    /// The @includeisolated directive.
    IncludeIsolated,
    /// The @each directive.
    Each,
    /// The @stack directive.
    Stack,
    /// The @class directive.
    Class,
    /// The @style directive.
    Style,
    /// The @checked directive.
    Checked,
    /// The @selected directive.
    Selected,
    /// The @disabled directive.
    Disabled,
    /// The @readonly directive.
    Readonly,
    /// The @required directive.
    Required,
    /// The @bool directive.
    Bool,
    /// The @csrf directive.
    Csrf,
    /// The @method directive.
    Method,
    /// The @json directive.
    Json,
    /// The @js directive.
    Js,
    /// The @lang directive.
    Lang,
    /// The @choice directive.
    Choice,
    /// The @vite directive.
    Vite,
    /// The @vitereactrefresh directive.
    ViteReactRefresh,
    /// Vite font asset tags.
    Fonts,
    /// The @dump directive.
    Dump,
    /// The @dd directive.
    Dd,
    /// The @unset directive.
    Unset,
    /// The @break directive.
    Break,
    /// The @continue directive.
    Continue,
    /// The @slot directive.
    Slot,
    /// A registered inline directive.
    Custom(String),
}

/// Template operations.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum NodeKind {
    /// Literal output, including the body of verbatim.
    Text(String),
    /// Render an expression.
    Echo(EchoKind, Expr),
    /// A removed Blade comment.
    Comment,
    /// A typed single directive.
    Inline {
        /// Directive operation.
        kind: InlineKind,
        /// Operands.
        args: Vec<Expr>,
        /// Opaque source range for directive expansion.
        raw_args: Option<Span>,
    },
    /// An ordered conditional chain.
    Conditional(Vec<Branch>),
    /// A Blade for, foreach or forelse block.
    Loop {
        /// Loop spelling.
        kind: LoopKind,
        /// Item binding.
        pattern: Pattern,
        /// Items to iterate.
        iterable: Expr,
        /// Loop content.
        body: Vec<Node>,
        /// Optional empty fallback.
        empty: Option<Vec<Node>>,
    },
    /// A Blade while block.
    While {
        /// Boolean test.
        test: Expr,
        /// Loop content.
        body: Vec<Node>,
    },
    /// A fall-through switch.
    Switch {
        /// Value to compare.
        value: Expr,
        /// Cases in order.
        arms: Vec<SwitchArm>,
    },
    /// A code or let directive.
    Code(Vec<Stmt>),
    /// A capture or grouping directive.
    Block {
        /// Directive operation.
        kind: BlockKind,
        /// Opening operands.
        args: Vec<Expr>,
        /// Nested content.
        body: Vec<Node>,
    },
    /// A layout section.
    Section {
        /// Section name.
        name: Expr,
        /// Inline content, if supplied.
        content: Option<Expr>,
        /// Captured content for block form.
        body: Vec<Node>,
        /// How the section terminates.
        end: SectionEnd,
    },
    /// Conditional stack captures in branch order.
    PushIf(Vec<PushBranch>),
    /// Component prop declarations.
    Props(Vec<FieldDecl>),
    /// Inherited prop declarations.
    Aware(Vec<FieldDecl>),
    /// Injected service binding.
    Inject(FieldDecl),
    /// A validated Rust-style import tree, kept in source spelling.
    Use(String),
    /// A component tag call.
    Component(Component),
    /// A named slot tag.
    Slot(Slot),
}

/// Canonical names understood by the Blade lexer and template parser.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DirectiveName {
    /// The `@if` directive.
    If,
    /// The `@elseif` directive.
    Elseif,
    /// The `@else` directive.
    Else,
    /// The `@endif` directive.
    Endif,
    /// The `@unless` directive.
    Unless,
    /// The `@endunless` directive.
    Endunless,
    /// The `@isset` directive.
    Isset,
    /// The `@endisset` directive.
    Endisset,
    /// The `@empty` directive.
    Empty,
    /// The `@endempty` directive.
    Endempty,
    /// The `@switch` directive.
    Switch,
    /// The `@case` directive.
    Case,
    /// The `@default` directive.
    Default,
    /// The `@endswitch` directive.
    Endswitch,
    /// The `@auth` directive.
    Auth,
    /// The `@elseauth` directive.
    Elseauth,
    /// The `@endauth` directive.
    Endauth,
    /// The `@guest` directive.
    Guest,
    /// The `@elseguest` directive.
    Elseguest,
    /// The `@endguest` directive.
    Endguest,
    /// The `@can` directive.
    Can,
    /// The `@elsecan` directive.
    Elsecan,
    /// The `@endcan` directive.
    Endcan,
    /// The `@cannot` directive.
    Cannot,
    /// The `@elsecannot` directive.
    Elsecannot,
    /// The `@endcannot` directive.
    Endcannot,
    /// The `@canany` directive.
    CanAny,
    /// The `@elsecanany` directive.
    Elsecanany,
    /// The `@endcanany` directive.
    Endcanany,
    /// The `@env` directive.
    Env,
    /// The `@endenv` directive.
    Endenv,
    /// The `@production` directive.
    Production,
    /// The `@endproduction` directive.
    Endproduction,
    /// The `@session` directive.
    Session,
    /// The `@endsession` directive.
    Endsession,
    /// The `@context` directive.
    Context,
    /// The `@endcontext` directive.
    Endcontext,
    /// The `@hassection` directive.
    HasSection,
    /// The `@sectionmissing` directive.
    SectionMissing,
    /// The `@hasstack` directive.
    HasStack,
    /// The `@foreach` directive.
    Foreach,
    /// The `@endforeach` directive.
    Endforeach,
    /// The `@forelse` directive.
    Forelse,
    /// The `@endforelse` directive.
    Endforelse,
    /// The `@for` directive.
    For,
    /// The `@endfor` directive.
    Endfor,
    /// The `@while` directive.
    While,
    /// The `@endwhile` directive.
    Endwhile,
    /// The `@break` directive.
    Break,
    /// The `@continue` directive.
    Continue,
    /// The `@let` directive.
    Let,
    /// The `@code` directive.
    Code,
    /// The `@endcode` directive.
    Endcode,
    /// The `@php` directive.
    Php,
    /// The `@endphp` directive.
    Endphp,
    /// The `@verbatim` directive.
    Verbatim,
    /// The `@endverbatim` directive.
    Endverbatim,
    /// The `@unset` directive.
    Unset,
    /// The `@use` directive.
    Use,
    /// The `@inject` directive.
    Inject,
    /// The `@class` directive.
    Class,
    /// The `@style` directive.
    Style,
    /// The `@checked` directive.
    Checked,
    /// The `@selected` directive.
    Selected,
    /// The `@disabled` directive.
    Disabled,
    /// The `@readonly` directive.
    Readonly,
    /// The `@required` directive.
    Required,
    /// The `@bool` directive.
    Bool,
    /// The `@csrf` directive.
    Csrf,
    /// The `@method` directive.
    Method,
    /// The `@error` directive.
    Error,
    /// The `@enderror` directive.
    Enderror,
    /// The `@json` directive.
    Json,
    /// The `@js` directive.
    Js,
    /// The `@include` directive.
    Include,
    /// The `@includeif` directive.
    IncludeIf,
    /// The `@includewhen` directive.
    IncludeWhen,
    /// The `@includeunless` directive.
    IncludeUnless,
    /// The `@includefirst` directive.
    IncludeFirst,
    /// The `@includeisolated` directive.
    IncludeIsolated,
    /// The `@each` directive.
    Each,
    /// The `@extends` directive.
    Extends,
    /// The `@extendsfirst` directive.
    ExtendsFirst,
    /// The `@section` directive.
    Section,
    /// The `@endsection` directive.
    Endsection,
    /// The `@stop` directive.
    Stop,
    /// The `@show` directive.
    Show,
    /// The `@append` directive.
    Append,
    /// The `@overwrite` directive.
    Overwrite,
    /// The `@yield` directive.
    Yield,
    /// The `@parent` directive.
    Parent,
    /// The `@push` directive.
    Push,
    /// The `@endpush` directive.
    Endpush,
    /// The `@prepend` directive.
    Prepend,
    /// The `@endprepend` directive.
    Endprepend,
    /// The `@pushonce` directive.
    PushOnce,
    /// The `@endpushonce` directive.
    Endpushonce,
    /// The `@prependonce` directive.
    PrependOnce,
    /// The `@endprependonce` directive.
    Endprependonce,
    /// The `@pushif` directive.
    PushIf,
    /// The `@elsepushif` directive.
    ElsePushIf,
    /// The `@elsepush` directive.
    ElsePush,
    /// The `@endpushif` directive.
    Endpushif,
    /// The `@stack` directive.
    Stack,
    /// The `@once` directive.
    Once,
    /// The `@endonce` directive.
    Endonce,
    /// The `@fragment` directive.
    Fragment,
    /// The `@endfragment` directive.
    Endfragment,
    /// The `@props` directive.
    Props,
    /// The `@aware` directive.
    Aware,
    /// The `@component` directive.
    Component,
    /// The `@endcomponent` directive.
    Endcomponent,
    /// The `@componentfirst` directive.
    ComponentFirst,
    /// The `@endcomponentfirst` directive.
    Endcomponentfirst,
    /// The `@slot` directive.
    Slot,
    /// The `@endslot` directive.
    Endslot,
    /// The `@lang` directive.
    Lang,
    /// The `@endlang` directive.
    Endlang,
    /// The `@choice` directive.
    Choice,
    /// The `@vite` directive.
    Vite,
    /// The `@vitereactrefresh` directive.
    ViteReactRefresh,
    /// Vite font asset tags.
    Fonts,
    /// The `@dump` directive.
    Dump,
    /// The `@dd` directive.
    Dd,
    /// An application-registered single directive.
    Custom(String),
    /// An application-registered conditional opener.
    Condition(String),
    /// An application-registered conditional's negated opener.
    UnlessCondition(String),
    /// An application-registered conditional's alternate branch.
    ElseCondition(String),
    /// An application-registered conditional's closing directive.
    EndCondition(String),
}

impl DirectiveName {
    pub(crate) fn builtin(name: &str) -> Option<Self> {
        Some(match name {
            "if" => Self::If,
            "elseif" => Self::Elseif,
            "else" => Self::Else,
            "endif" => Self::Endif,
            "unless" => Self::Unless,
            "endunless" => Self::Endunless,
            "isset" => Self::Isset,
            "endisset" => Self::Endisset,
            "empty" => Self::Empty,
            "endempty" => Self::Endempty,
            "switch" => Self::Switch,
            "case" => Self::Case,
            "default" => Self::Default,
            "endswitch" => Self::Endswitch,
            "auth" => Self::Auth,
            "elseauth" => Self::Elseauth,
            "endauth" => Self::Endauth,
            "guest" => Self::Guest,
            "elseguest" => Self::Elseguest,
            "endguest" => Self::Endguest,
            "can" => Self::Can,
            "elsecan" => Self::Elsecan,
            "endcan" => Self::Endcan,
            "cannot" => Self::Cannot,
            "elsecannot" => Self::Elsecannot,
            "endcannot" => Self::Endcannot,
            "canany" => Self::CanAny,
            "elsecanany" => Self::Elsecanany,
            "endcanany" => Self::Endcanany,
            "env" => Self::Env,
            "endenv" => Self::Endenv,
            "production" => Self::Production,
            "endproduction" => Self::Endproduction,
            "session" => Self::Session,
            "endsession" => Self::Endsession,
            "context" => Self::Context,
            "endcontext" => Self::Endcontext,
            "hassection" => Self::HasSection,
            "sectionmissing" => Self::SectionMissing,
            "hasstack" => Self::HasStack,
            "foreach" => Self::Foreach,
            "endforeach" => Self::Endforeach,
            "forelse" => Self::Forelse,
            "endforelse" => Self::Endforelse,
            "for" => Self::For,
            "endfor" => Self::Endfor,
            "while" => Self::While,
            "endwhile" => Self::Endwhile,
            "break" => Self::Break,
            "continue" => Self::Continue,
            "let" => Self::Let,
            "code" => Self::Code,
            "endcode" => Self::Endcode,
            "php" => Self::Php,
            "endphp" => Self::Endphp,
            "verbatim" => Self::Verbatim,
            "endverbatim" => Self::Endverbatim,
            "unset" => Self::Unset,
            "use" => Self::Use,
            "inject" => Self::Inject,
            "class" => Self::Class,
            "style" => Self::Style,
            "checked" => Self::Checked,
            "selected" => Self::Selected,
            "disabled" => Self::Disabled,
            "readonly" => Self::Readonly,
            "required" => Self::Required,
            "bool" => Self::Bool,
            "csrf" => Self::Csrf,
            "method" => Self::Method,
            "error" => Self::Error,
            "enderror" => Self::Enderror,
            "json" => Self::Json,
            "js" => Self::Js,
            "include" => Self::Include,
            "includeif" => Self::IncludeIf,
            "includewhen" => Self::IncludeWhen,
            "includeunless" => Self::IncludeUnless,
            "includefirst" => Self::IncludeFirst,
            "includeisolated" => Self::IncludeIsolated,
            "each" => Self::Each,
            "extends" => Self::Extends,
            "extendsfirst" => Self::ExtendsFirst,
            "section" => Self::Section,
            "endsection" => Self::Endsection,
            "stop" => Self::Stop,
            "show" => Self::Show,
            "append" => Self::Append,
            "overwrite" => Self::Overwrite,
            "yield" => Self::Yield,
            "parent" => Self::Parent,
            "push" => Self::Push,
            "endpush" => Self::Endpush,
            "prepend" => Self::Prepend,
            "endprepend" => Self::Endprepend,
            "pushonce" => Self::PushOnce,
            "endpushonce" => Self::Endpushonce,
            "prependonce" => Self::PrependOnce,
            "endprependonce" => Self::Endprependonce,
            "pushif" => Self::PushIf,
            "elsepushif" => Self::ElsePushIf,
            "elsepush" => Self::ElsePush,
            "endpushif" => Self::Endpushif,
            "stack" => Self::Stack,
            "once" => Self::Once,
            "endonce" => Self::Endonce,
            "fragment" => Self::Fragment,
            "endfragment" => Self::Endfragment,
            "props" => Self::Props,
            "aware" => Self::Aware,
            "component" => Self::Component,
            "endcomponent" => Self::Endcomponent,
            "componentfirst" => Self::ComponentFirst,
            "endcomponentfirst" => Self::Endcomponentfirst,
            "slot" => Self::Slot,
            "endslot" => Self::Endslot,
            "lang" => Self::Lang,
            "endlang" => Self::Endlang,
            "choice" => Self::Choice,
            "vite" => Self::Vite,
            "vitereactrefresh" => Self::ViteReactRefresh,
            "fonts" => Self::Fonts,
            "dump" => Self::Dump,
            "dd" => Self::Dd,
            _ => return None,
        })
    }

    /// Returns the canonical spelling without the leading @.
    pub fn spelling(&self) -> String {
        match self {
            Self::If => "if".into(),
            Self::Elseif => "elseif".into(),
            Self::Else => "else".into(),
            Self::Endif => "endif".into(),
            Self::Unless => "unless".into(),
            Self::Endunless => "endunless".into(),
            Self::Isset => "isset".into(),
            Self::Endisset => "endisset".into(),
            Self::Empty => "empty".into(),
            Self::Endempty => "endempty".into(),
            Self::Switch => "switch".into(),
            Self::Case => "case".into(),
            Self::Default => "default".into(),
            Self::Endswitch => "endswitch".into(),
            Self::Auth => "auth".into(),
            Self::Elseauth => "elseauth".into(),
            Self::Endauth => "endauth".into(),
            Self::Guest => "guest".into(),
            Self::Elseguest => "elseguest".into(),
            Self::Endguest => "endguest".into(),
            Self::Can => "can".into(),
            Self::Elsecan => "elsecan".into(),
            Self::Endcan => "endcan".into(),
            Self::Cannot => "cannot".into(),
            Self::Elsecannot => "elsecannot".into(),
            Self::Endcannot => "endcannot".into(),
            Self::CanAny => "canany".into(),
            Self::Elsecanany => "elsecanany".into(),
            Self::Endcanany => "endcanany".into(),
            Self::Env => "env".into(),
            Self::Endenv => "endenv".into(),
            Self::Production => "production".into(),
            Self::Endproduction => "endproduction".into(),
            Self::Session => "session".into(),
            Self::Endsession => "endsession".into(),
            Self::Context => "context".into(),
            Self::Endcontext => "endcontext".into(),
            Self::HasSection => "hassection".into(),
            Self::SectionMissing => "sectionmissing".into(),
            Self::HasStack => "hasstack".into(),
            Self::Foreach => "foreach".into(),
            Self::Endforeach => "endforeach".into(),
            Self::Forelse => "forelse".into(),
            Self::Endforelse => "endforelse".into(),
            Self::For => "for".into(),
            Self::Endfor => "endfor".into(),
            Self::While => "while".into(),
            Self::Endwhile => "endwhile".into(),
            Self::Break => "break".into(),
            Self::Continue => "continue".into(),
            Self::Let => "let".into(),
            Self::Code => "code".into(),
            Self::Endcode => "endcode".into(),
            Self::Php => "php".into(),
            Self::Endphp => "endphp".into(),
            Self::Verbatim => "verbatim".into(),
            Self::Endverbatim => "endverbatim".into(),
            Self::Unset => "unset".into(),
            Self::Use => "use".into(),
            Self::Inject => "inject".into(),
            Self::Class => "class".into(),
            Self::Style => "style".into(),
            Self::Checked => "checked".into(),
            Self::Selected => "selected".into(),
            Self::Disabled => "disabled".into(),
            Self::Readonly => "readonly".into(),
            Self::Required => "required".into(),
            Self::Bool => "bool".into(),
            Self::Csrf => "csrf".into(),
            Self::Method => "method".into(),
            Self::Error => "error".into(),
            Self::Enderror => "enderror".into(),
            Self::Json => "json".into(),
            Self::Js => "js".into(),
            Self::Include => "include".into(),
            Self::IncludeIf => "includeif".into(),
            Self::IncludeWhen => "includewhen".into(),
            Self::IncludeUnless => "includeunless".into(),
            Self::IncludeFirst => "includefirst".into(),
            Self::IncludeIsolated => "includeisolated".into(),
            Self::Each => "each".into(),
            Self::Extends => "extends".into(),
            Self::ExtendsFirst => "extendsfirst".into(),
            Self::Section => "section".into(),
            Self::Endsection => "endsection".into(),
            Self::Stop => "stop".into(),
            Self::Show => "show".into(),
            Self::Append => "append".into(),
            Self::Overwrite => "overwrite".into(),
            Self::Yield => "yield".into(),
            Self::Parent => "parent".into(),
            Self::Push => "push".into(),
            Self::Endpush => "endpush".into(),
            Self::Prepend => "prepend".into(),
            Self::Endprepend => "endprepend".into(),
            Self::PushOnce => "pushonce".into(),
            Self::Endpushonce => "endpushonce".into(),
            Self::PrependOnce => "prependonce".into(),
            Self::Endprependonce => "endprependonce".into(),
            Self::PushIf => "pushif".into(),
            Self::ElsePushIf => "elsepushif".into(),
            Self::ElsePush => "elsepush".into(),
            Self::Endpushif => "endpushif".into(),
            Self::Stack => "stack".into(),
            Self::Once => "once".into(),
            Self::Endonce => "endonce".into(),
            Self::Fragment => "fragment".into(),
            Self::Endfragment => "endfragment".into(),
            Self::Props => "props".into(),
            Self::Aware => "aware".into(),
            Self::Component => "component".into(),
            Self::Endcomponent => "endcomponent".into(),
            Self::ComponentFirst => "componentfirst".into(),
            Self::Endcomponentfirst => "endcomponentfirst".into(),
            Self::Slot => "slot".into(),
            Self::Endslot => "endslot".into(),
            Self::Lang => "lang".into(),
            Self::Endlang => "endlang".into(),
            Self::Choice => "choice".into(),
            Self::Vite => "vite".into(),
            Self::ViteReactRefresh => "vitereactrefresh".into(),
            Self::Fonts => "fonts".into(),
            Self::Dump => "dump".into(),
            Self::Dd => "dd".into(),
            Self::Custom(name) | Self::Condition(name) => name.clone(),
            Self::UnlessCondition(name) => format!("unless{name}"),
            Self::ElseCondition(name) => format!("else{name}"),
            Self::EndCondition(name) => format!("end{name}"),
        }
    }
}