macroforge_ts_quote 0.1.78

Quote macro for generating TypeScript code at compile time
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
//! Syntax kinds for the template language.
//!
//! This module defines all token and node types in the template grammar.
//! These are used by both the lexer (for tokens) and parser (for nodes).

/// All syntax kinds in the template language.
///
/// Tokens are prefixed with their category:
/// - Literals: Text, StringLit, etc.
/// - Punctuation: At, LBrace, RBrace, etc.
/// - Keywords: IfKw, ForKw, etc.
/// - Special: Error, Whitespace, etc.
///
/// Nodes are suffixed with their category:
/// - Expr: Expression nodes
/// - Stmt: Statement nodes
/// - Block: Block nodes
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u16)]
pub enum SyntaxKind {
    // ============================================
    // Tokens - Atoms produced by the lexer
    // ============================================

    // Literals and text
    /// Plain text content (TypeScript code, etc.)
    Text = 0,
    /// Whitespace (spaces, tabs, newlines)
    Whitespace,
    /// Error token (invalid input)
    Error,

    // Punctuation
    /// `@` - interpolation prefix
    At,
    /// `@` followed by identifier - TypeScript decorator marker
    DecoratorAt,
    /// `@@` - escaped @ (produces literal @)
    AtAt,
    /// `${` - JavaScript template expression start (inside template literals)
    DollarBrace,
    /// `{` - left brace
    LBrace,
    /// `}` - right brace
    RBrace,
    // Template control flow - opening constructs `{#...`
    /// `{#if` - template if open
    BraceHashIf,
    /// `{#for` - template for open
    BraceHashFor,
    /// `{#while` - template while open
    BraceHashWhile,
    /// `{#match` - template match open
    BraceHashMatch,

    // Template control flow - continuation constructs `{:...`
    /// `{:else}` - template else (complete with closing brace)
    BraceColonElseBrace,
    /// `{:else if` - template else-if open
    BraceColonElseIf,
    /// `{:case` - template match case
    BraceColonCase,

    // Template control flow - closing constructs `{/...}`
    /// `{/if}` - template if close
    BraceSlashIfBrace,
    /// `{/for}` - template for close
    BraceSlashForBrace,
    /// `{/while}` - template while close
    BraceSlashWhileBrace,
    /// `{/match}` - template match close
    BraceSlashMatchBrace,
    /// `{$` - directive open (let, do, typescript)
    DollarOpen,
    /// `` - ident block open
    PipeOpen,
    /// `` - ident block close
    PipeClose,
    /// `{>` - line comment open
    CommentLineOpen,
    /// `<}` - line comment close
    CommentLineClose,
    /// `{>>` - block comment open
    CommentBlockOpen,
    /// `<<}` - block comment close
    CommentBlockClose,
    /// `"` - double quote
    DoubleQuote,
    /// `'` - single quote
    SingleQuote,
    /// `` ` `` - backtick
    Backtick,
    /// `///` - doc comment prefix
    DocCommentPrefix,
    /// `/**` - jsdoc block open
    JsDocOpen,
    /// `*/` - jsdoc block close
    JsDocClose,
    /// `// comment` - TypeScript line comment (not doc comment)
    TsLineComment,
    /// `/* comment */` - TypeScript block comment (not JSDoc)
    TsBlockComment,
    /// `#[doc = "..."]` - Rust doc attribute (converted from `/** ... */` by Rust tokenizer)
    RustDocAttr,
    /// `:` - colon (for type annotations, object properties)
    Colon,
    /// `;` - semicolon
    Semicolon,
    /// `(` - left paren
    LParen,
    /// `)` - right paren
    RParen,
    /// `[` - left bracket
    LBracket,
    /// `]` - right bracket
    RBracket,
    /// `<` - less than (for generics)
    Lt,
    /// `>` - greater than (for generics)
    Gt,
    /// `,` - comma
    Comma,
    /// `=` - equals (assignment)
    Eq,
    /// `==` - equality operator
    EqEq,
    /// `===` - strict equality operator
    EqEqEq,
    /// `=>` - fat arrow (for arrow functions)
    FatArrow,
    /// `?` - question mark (for optional)
    Question,
    /// `.` - dot
    Dot,
    /// `*` - star/asterisk (for namespace imports, multiplication)
    Star,
    /// `#` - hash (for private names like #field)
    Hash,
    /// `!` - exclamation mark (for non-null assertions)
    Exclaim,
    /// `!=` - not equal operator
    NotEq,
    /// `!==` - strict not equal operator
    NotEqEq,
    /// `++` - increment operator
    PlusPlus,
    /// `--` - decrement operator
    MinusMinus,
    /// `?.` - optional chaining
    QuestionDot,
    /// `&` - ampersand (for intersection types and bitwise AND)
    Ampersand,
    /// `&&` - logical AND operator
    AmpersandAmpersand,
    /// `&=` - bitwise AND assignment
    AmpersandEq,
    /// `...` - spread/rest operator
    DotDotDot,

    // Keywords (inside control blocks)
    /// `if` keyword
    IfKw,
    /// `else` keyword
    ElseKw,
    /// `for` keyword
    ForKw,
    /// `while` keyword
    WhileKw,
    /// `match` keyword
    MatchKw,
    /// `case` keyword
    CaseKw,
    /// `let` keyword
    LetKw,
    /// `do` keyword
    DoKw,
    /// `in` keyword
    InKw,
    /// `typescript` keyword
    TypeScriptKw,
    /// `mut` keyword
    MutKw,

    // TypeScript-specific (for type position detection)
    /// `as` keyword (type assertion)
    AsKw,
    /// `function` keyword
    FunctionKw,
    /// `const` keyword
    ConstKw,
    /// `var` keyword
    VarKw,
    /// `class` keyword
    ClassKw,
    /// `interface` keyword
    InterfaceKw,
    /// `type` keyword
    TypeKw,
    /// `export` keyword
    ExportKw,
    /// `import` keyword
    ImportKw,
    /// `return` keyword
    ReturnKw,
    /// `new` keyword
    NewKw,
    /// `keyof` keyword (type operator)
    KeyofKw,
    /// `typeof` keyword (type operator)
    TypeofKw,
    /// `extends` keyword
    ExtendsKw,
    /// `implements` keyword
    ImplementsKw,
    /// `readonly` keyword
    ReadonlyKw,
    /// `private` keyword
    PrivateKw,
    /// `public` keyword
    PublicKw,
    /// `protected` keyword
    ProtectedKw,
    /// `static` keyword
    StaticKw,
    /// `abstract` keyword
    AbstractKw,
    /// `declare` keyword
    DeclareKw,
    /// `async` keyword
    AsyncKw,
    /// `await` keyword
    AwaitKw,
    /// `yield` keyword
    YieldKw,
    /// `throw` keyword
    ThrowKw,
    /// `try` keyword
    TryKw,
    /// `catch` keyword
    CatchKw,
    /// `finally` keyword
    FinallyKw,
    /// `default` keyword
    DefaultKw,
    /// `from` keyword
    FromKw,
    /// `of` keyword
    OfKw,
    /// `get` keyword
    GetKw,
    /// `set` keyword
    SetKw,
    /// `satisfies` keyword
    SatisfiesKw,
    /// `infer` keyword
    InferKw,
    /// `is` keyword (type guard)
    IsKw,
    /// `enum` keyword
    EnumKw,

    // Expression keywords
    /// `void` keyword (unary operator)
    VoidKw,
    /// `delete` keyword (unary operator)
    DeleteKw,
    /// `instanceof` keyword (binary operator)
    InstanceofKw,
    /// `this` keyword
    ThisKw,
    /// `super` keyword
    SuperKw,
    /// `null` literal keyword
    NullKw,
    /// `true` literal keyword
    TrueKw,
    /// `false` literal keyword
    FalseKw,
    /// `undefined` keyword
    UndefinedKw,
    /// `break` keyword
    BreakKw,
    /// `continue` keyword
    ContinueKw,
    /// `debugger` keyword
    DebuggerKw,
    /// `with` keyword
    WithKw,
    /// `switch` keyword
    SwitchKw,

    // Identifiers and expressions
    /// An identifier (variable name, type name, etc.)
    Ident,
    /// A Rust token stream (inside @{...})
    RustTokens,

    // ============================================
    // Composite nodes - Built by the parser
    // ============================================
    /// Root node of the template
    Root,

    // Interpolation nodes
    /// `@{expr}` - basic interpolation
    Interpolation,
    /// ` parts ` - ident block (concatenated identifier)
    IdentBlock,

    // String/template nodes
    /// `"string with @{expr}"` - string interpolation
    StringInterp,
    /// `` `template ${expr}` `` - template literal
    TemplateLiteral,
    /// Part of a string (text or interpolation)
    StringPart,

    // Comment nodes
    /// `{> "comment" <}` - line comment
    LineComment,
    /// `{>> "comment" <<}` - block comment
    BlockComment,
    /// `/// doc` or `/** doc */` - doc comment
    DocComment,

    // Control flow nodes
    /// `{#if cond}...{/if}` - if block
    IfBlock,
    /// `{#if let pat = expr}...{/if}` - if-let block
    IfLetBlock,
    /// `{:else}...` - else clause
    ElseClause,
    /// `{:else if cond}...` - else-if clause
    ElseIfClause,
    /// `{#for pat in iter}...{/for}` - for loop
    ForBlock,
    /// `{#while cond}...{/while}` - while loop
    WhileBlock,
    /// `{#while let pat = expr}...{/while}` - while-let loop
    WhileLetBlock,
    /// `{#match expr}...{/match}` - match block
    MatchBlock,
    /// `{:case pat}...` - match case
    MatchCase,

    // Directive nodes
    /// `{$let name = expr}` - let binding
    LetDirective,
    /// `{$do expr}` - do expression
    DoDirective,
    /// `{$typescript stream}` - typescript injection
    TypeScriptDirective,

    // TypeScript structural nodes (for type position detection)
    /// A TypeScript statement
    TsStmt,
    /// A TypeScript expression
    TsExpr,
    /// A TypeScript type annotation (`: Type`)
    TypeAnnotation,
    /// A TypeScript type assertion (`as Type` or `<Type>`)
    TypeAssertion,
    /// A TypeScript function declaration/expression
    TsFunction,
    /// A TypeScript parameter (with optional type)
    TsParam,
    /// A TypeScript generic type parameters (`<T, U>`)
    TsTypeParams,
    /// A TypeScript object literal
    TsObject,
    /// A TypeScript object property
    TsObjectProp,
    /// A TypeScript class declaration
    TsClass,
    /// A TypeScript class member
    TsClassMember,

    // Brace block (preserves structure)
    /// `{ ... }` - brace-delimited block
    BraceBlock,

    // Object property loop
    /// `{ {#for (k,v) in items} @{k}: @{v}, {/for} }` - object from loop
    ObjectPropLoop,

    // Placeholder markers (after semantic analysis)
    /// Placeholder in expression position
    ExprPlaceholder,
    /// Placeholder in type position
    TypePlaceholder,
    /// Placeholder in identifier position
    IdentPlaceholder,
    /// Placeholder in identifier name position (string → ident)
    IdentNamePlaceholder,
    /// Placeholder in statement position
    StmtPlaceholder,

    // Sentinel - must be last
    #[doc(hidden)]
    __LAST,
}

impl SyntaxKind {
    /// Returns true if this is a token (vs a composite node).
    pub fn is_token(self) -> bool {
        (self as u16) < (Self::Root as u16)
    }

    /// Returns true if this is a trivia token (whitespace, comments).
    pub fn is_trivia(self) -> bool {
        matches!(
            self,
            Self::Whitespace | Self::TsLineComment | Self::TsBlockComment
        )
    }

    /// Returns true if this is a control flow keyword.
    pub fn is_control_keyword(self) -> bool {
        matches!(
            self,
            Self::IfKw | Self::ElseKw | Self::ForKw | Self::WhileKw | Self::MatchKw | Self::CaseKw
        )
    }

    /// Returns true if this is a directive keyword.
    pub fn is_directive_keyword(self) -> bool {
        matches!(
            self,
            Self::LetKw | Self::DoKw | Self::TypeScriptKw | Self::MutKw
        )
    }

    /// Returns true if this is a TypeScript keyword.
    pub fn is_ts_keyword(self) -> bool {
        matches!(
            self,
            Self::AsKw
                | Self::FunctionKw
                | Self::ConstKw
                | Self::VarKw
                | Self::ClassKw
                | Self::InterfaceKw
                | Self::TypeKw
                | Self::ExportKw
                | Self::ImportKw
                | Self::ReturnKw
                | Self::NewKw
                | Self::KeyofKw
                | Self::TypeofKw
                | Self::ExtendsKw
                | Self::ImplementsKw
                | Self::ReadonlyKw
                | Self::PrivateKw
                | Self::PublicKw
                | Self::ProtectedKw
                | Self::StaticKw
                | Self::AbstractKw
                | Self::DeclareKw
                | Self::AsyncKw
                | Self::AwaitKw
                | Self::YieldKw
                | Self::ThrowKw
                | Self::TryKw
                | Self::CatchKw
                | Self::FinallyKw
                | Self::DefaultKw
                | Self::FromKw
                | Self::OfKw
                | Self::GetKw
                | Self::SetKw
                | Self::SatisfiesKw
                | Self::InferKw
                | Self::IsKw
                | Self::EnumKw
                | Self::VoidKw
                | Self::DeleteKw
                | Self::InstanceofKw
                | Self::ThisKw
                | Self::SuperKw
                | Self::NullKw
                | Self::TrueKw
                | Self::FalseKw
                | Self::UndefinedKw
                | Self::BreakKw
                | Self::ContinueKw
                | Self::DebuggerKw
                | Self::WithKw
                | Self::SwitchKw
        )
    }

    /// Returns true if this keyword introduces an identifier context.
    /// After these keywords, the next token is typically an identifier being declared.
    pub fn starts_identifier_context(self) -> bool {
        matches!(
            self,
            Self::FunctionKw
                | Self::ClassKw
                | Self::InterfaceKw
                | Self::TypeKw
                | Self::ConstKw
                | Self::LetKw
                | Self::VarKw
        )
    }

    /// Returns true if this keyword introduces a type context.
    /// After these keywords, the following tokens are types.
    pub fn starts_type_context(self) -> bool {
        matches!(
            self,
            Self::AsKw
                | Self::KeyofKw
                | Self::TypeofKw
                | Self::ExtendsKw
                | Self::ImplementsKw
                | Self::SatisfiesKw
                | Self::InferKw
                | Self::IsKw
        )
    }

    /// Returns true if this keyword introduces an expression context.
    pub fn starts_expression_context(self) -> bool {
        matches!(
            self,
            Self::ReturnKw | Self::ThrowKw | Self::YieldKw | Self::AwaitKw | Self::NewKw
        )
    }

    /// Returns true if this is an opening control block token (`{#if`, `{#for`, `{#while`, `{#match`).
    pub fn is_brace_hash_open(self) -> bool {
        matches!(
            self,
            Self::BraceHashIf | Self::BraceHashFor | Self::BraceHashWhile | Self::BraceHashMatch
        )
    }

    /// Returns true if this is a closing control block token (`{/if}`, `{/for}`, `{/while}`, `{/match}`).
    pub fn is_brace_slash_close(self) -> bool {
        matches!(
            self,
            Self::BraceSlashIfBrace
                | Self::BraceSlashForBrace
                | Self::BraceSlashWhileBrace
                | Self::BraceSlashMatchBrace
        )
    }

    /// Returns true if this is a continuation control block token (`{:else}`, `{:else if`, `{:case`).
    pub fn is_brace_colon(self) -> bool {
        matches!(
            self,
            Self::BraceColonElseBrace | Self::BraceColonElseIf | Self::BraceColonCase
        )
    }
}

impl From<SyntaxKind> for rowan::SyntaxKind {
    fn from(kind: SyntaxKind) -> Self {
        Self(kind as u16)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    // ==================== is_token Tests ====================

    #[test]
    fn test_syntax_kind_is_token() {
        assert!(SyntaxKind::Text.is_token());
        assert!(SyntaxKind::At.is_token());
        assert!(SyntaxKind::IfKw.is_token());
        assert!(!SyntaxKind::Root.is_token());
        assert!(!SyntaxKind::Interpolation.is_token());
    }

    #[test]
    fn test_all_tokens_are_tokens() {
        let tokens = [
            SyntaxKind::Text,
            SyntaxKind::Whitespace,
            SyntaxKind::Error,
            SyntaxKind::At,
            SyntaxKind::AtAt,
            SyntaxKind::LBrace,
            SyntaxKind::RBrace,
            SyntaxKind::BraceHashIf,
            SyntaxKind::BraceHashFor,
            SyntaxKind::BraceHashWhile,
            SyntaxKind::BraceHashMatch,
            SyntaxKind::BraceColonElseBrace,
            SyntaxKind::BraceColonElseIf,
            SyntaxKind::BraceColonCase,
            SyntaxKind::BraceSlashIfBrace,
            SyntaxKind::BraceSlashForBrace,
            SyntaxKind::BraceSlashWhileBrace,
            SyntaxKind::BraceSlashMatchBrace,
            SyntaxKind::DollarOpen,
            SyntaxKind::Colon,
            SyntaxKind::Semicolon,
            SyntaxKind::LParen,
            SyntaxKind::RParen,
            SyntaxKind::LBracket,
            SyntaxKind::RBracket,
            SyntaxKind::Lt,
            SyntaxKind::Gt,
            SyntaxKind::Comma,
            SyntaxKind::Eq,
            SyntaxKind::Question,
            SyntaxKind::Dot,
            SyntaxKind::IfKw,
            SyntaxKind::ElseKw,
            SyntaxKind::ForKw,
            SyntaxKind::WhileKw,
            SyntaxKind::MatchKw,
            SyntaxKind::CaseKw,
            SyntaxKind::LetKw,
            SyntaxKind::DoKw,
            SyntaxKind::Ident,
            SyntaxKind::RustTokens,
        ];
        for token in tokens {
            assert!(token.is_token(), "{:?} should be a token", token);
        }
    }

    #[test]
    fn test_composite_nodes_are_not_tokens() {
        let nodes = [
            SyntaxKind::Root,
            SyntaxKind::Interpolation,
            SyntaxKind::IdentBlock,
            SyntaxKind::StringInterp,
            SyntaxKind::TemplateLiteral,
            SyntaxKind::LineComment,
            SyntaxKind::BlockComment,
            SyntaxKind::DocComment,
            SyntaxKind::IfBlock,
            SyntaxKind::ForBlock,
            SyntaxKind::WhileBlock,
            SyntaxKind::MatchBlock,
            SyntaxKind::LetDirective,
            SyntaxKind::DoDirective,
        ];
        for node in nodes {
            assert!(!node.is_token(), "{:?} should not be a token", node);
        }
    }

    // ==================== is_control_keyword Tests ====================

    #[test]
    fn test_is_control_keyword() {
        assert!(SyntaxKind::IfKw.is_control_keyword());
        assert!(SyntaxKind::ForKw.is_control_keyword());
        assert!(!SyntaxKind::LetKw.is_control_keyword());
        assert!(!SyntaxKind::Text.is_control_keyword());
    }

    #[test]
    fn test_all_control_keywords() {
        let control_keywords = [
            SyntaxKind::IfKw,
            SyntaxKind::ElseKw,
            SyntaxKind::ForKw,
            SyntaxKind::WhileKw,
            SyntaxKind::MatchKw,
            SyntaxKind::CaseKw,
        ];
        for kw in control_keywords {
            assert!(
                kw.is_control_keyword(),
                "{:?} should be a control keyword",
                kw
            );
        }
    }

    // ==================== is_directive_keyword Tests ====================

    #[test]
    fn test_is_directive_keyword() {
        assert!(SyntaxKind::LetKw.is_directive_keyword());
        assert!(SyntaxKind::DoKw.is_directive_keyword());
        assert!(SyntaxKind::TypeScriptKw.is_directive_keyword());
        assert!(SyntaxKind::MutKw.is_directive_keyword());
        assert!(!SyntaxKind::IfKw.is_directive_keyword());
        assert!(!SyntaxKind::Text.is_directive_keyword());
    }

    #[test]
    fn test_all_directive_keywords() {
        let directive_keywords = [
            SyntaxKind::LetKw,
            SyntaxKind::DoKw,
            SyntaxKind::TypeScriptKw,
            SyntaxKind::MutKw,
        ];
        for kw in directive_keywords {
            assert!(
                kw.is_directive_keyword(),
                "{:?} should be a directive keyword",
                kw
            );
        }
    }

    // ==================== is_ts_keyword Tests ====================

    #[test]
    fn test_is_ts_keyword() {
        assert!(SyntaxKind::AsKw.is_ts_keyword());
        assert!(SyntaxKind::FunctionKw.is_ts_keyword());
        assert!(SyntaxKind::ClassKw.is_ts_keyword());
        assert!(SyntaxKind::InterfaceKw.is_ts_keyword());
        assert!(!SyntaxKind::IfKw.is_ts_keyword());
        assert!(!SyntaxKind::ForKw.is_ts_keyword());
        assert!(!SyntaxKind::Text.is_ts_keyword());
    }

    #[test]
    fn test_ts_keyword_sample() {
        let ts_keywords = [
            SyntaxKind::AsKw,
            SyntaxKind::FunctionKw,
            SyntaxKind::ConstKw,
            SyntaxKind::VarKw,
            SyntaxKind::ClassKw,
            SyntaxKind::InterfaceKw,
            SyntaxKind::TypeKw,
            SyntaxKind::ExportKw,
            SyntaxKind::ImportKw,
            SyntaxKind::ReturnKw,
            SyntaxKind::NewKw,
            SyntaxKind::AsyncKw,
            SyntaxKind::AwaitKw,
        ];
        for kw in ts_keywords {
            assert!(kw.is_ts_keyword(), "{:?} should be a TS keyword", kw);
        }
    }

    // ==================== is_trivia Tests ====================

    #[test]
    fn test_is_trivia() {
        assert!(SyntaxKind::Whitespace.is_trivia());
        assert!(!SyntaxKind::Text.is_trivia());
        assert!(!SyntaxKind::Ident.is_trivia());
    }

    // ==================== starts_identifier_context Tests ====================

    #[test]
    fn test_starts_identifier_context() {
        assert!(SyntaxKind::FunctionKw.starts_identifier_context());
        assert!(SyntaxKind::ClassKw.starts_identifier_context());
        assert!(SyntaxKind::InterfaceKw.starts_identifier_context());
        assert!(SyntaxKind::TypeKw.starts_identifier_context());
        assert!(SyntaxKind::ConstKw.starts_identifier_context());
        assert!(SyntaxKind::LetKw.starts_identifier_context());
        assert!(SyntaxKind::VarKw.starts_identifier_context());
        assert!(!SyntaxKind::ReturnKw.starts_identifier_context());
        assert!(!SyntaxKind::Text.starts_identifier_context());
    }

    // ==================== starts_type_context Tests ====================

    #[test]
    fn test_starts_type_context() {
        assert!(SyntaxKind::AsKw.starts_type_context());
        assert!(SyntaxKind::KeyofKw.starts_type_context());
        assert!(SyntaxKind::TypeofKw.starts_type_context());
        assert!(SyntaxKind::ExtendsKw.starts_type_context());
        assert!(SyntaxKind::ImplementsKw.starts_type_context());
        assert!(SyntaxKind::SatisfiesKw.starts_type_context());
        assert!(SyntaxKind::InferKw.starts_type_context());
        assert!(SyntaxKind::IsKw.starts_type_context());
        assert!(!SyntaxKind::ReturnKw.starts_type_context());
        assert!(!SyntaxKind::FunctionKw.starts_type_context());
    }

    // ==================== starts_expression_context Tests ====================

    #[test]
    fn test_starts_expression_context() {
        assert!(SyntaxKind::ReturnKw.starts_expression_context());
        assert!(SyntaxKind::ThrowKw.starts_expression_context());
        assert!(SyntaxKind::YieldKw.starts_expression_context());
        assert!(SyntaxKind::AwaitKw.starts_expression_context());
        assert!(SyntaxKind::NewKw.starts_expression_context());
        assert!(!SyntaxKind::FunctionKw.starts_expression_context());
        assert!(!SyntaxKind::ClassKw.starts_expression_context());
        assert!(!SyntaxKind::AsKw.starts_expression_context());
    }

    // ==================== Debug and Clone Tests ====================

    #[test]
    fn test_syntax_kind_debug() {
        let kind = SyntaxKind::Text;
        let debug_str = format!("{:?}", kind);
        assert_eq!(debug_str, "Text");
    }

    #[test]
    fn test_syntax_kind_clone() {
        let kind = SyntaxKind::IfKw;
        let cloned = kind;
        assert_eq!(kind, cloned);
    }

    #[test]
    fn test_syntax_kind_copy() {
        let kind = SyntaxKind::ForKw;
        let copied: SyntaxKind = kind;
        assert_eq!(kind, copied);
    }

    // ==================== PartialOrd and Ord Tests ====================

    #[test]
    fn test_syntax_kind_ordering() {
        // Text is 0, Whitespace is 1, etc.
        assert!(SyntaxKind::Text < SyntaxKind::Whitespace);
        assert!(SyntaxKind::Text < SyntaxKind::Root);
    }

    // ==================== Hash Tests ====================

    #[test]
    fn test_syntax_kind_hash() {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        set.insert(SyntaxKind::Text);
        set.insert(SyntaxKind::At);
        set.insert(SyntaxKind::IfKw);
        assert_eq!(set.len(), 3);
        assert!(set.contains(&SyntaxKind::Text));
        assert!(!set.contains(&SyntaxKind::ForKw));
    }

    // ==================== Edge Cases ====================

    #[test]
    fn test_first_token_is_token() {
        assert!(SyntaxKind::Text.is_token());
    }

    #[test]
    fn test_last_token_before_root() {
        // RustTokens is the last token before composite nodes
        assert!(SyntaxKind::RustTokens.is_token());
    }

    #[test]
    fn test_keyword_categories_are_mutually_exclusive() {
        // Control keywords should not be directive keywords
        let control_kws = [
            SyntaxKind::IfKw,
            SyntaxKind::ElseKw,
            SyntaxKind::ForKw,
            SyntaxKind::WhileKw,
            SyntaxKind::MatchKw,
            SyntaxKind::CaseKw,
        ];
        for kw in control_kws {
            assert!(kw.is_control_keyword());
            assert!(!kw.is_directive_keyword());
        }

        // Directive keywords should not be control keywords
        let directive_kws = [
            SyntaxKind::LetKw,
            SyntaxKind::DoKw,
            SyntaxKind::TypeScriptKw,
            SyntaxKind::MutKw,
        ];
        for kw in directive_kws {
            assert!(kw.is_directive_keyword());
            assert!(!kw.is_control_keyword());
        }
    }
}