orrery-parser 0.2.0

Parser for the Orrery diagram language
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
//! Lexical analyzer for Orrery source text.
//!
//! The lexer converts source text into a stream of [`Token`]s for parsing.
//! It handles whitespace, comments, string literals, and all language tokens
//! defined in the [`tokens`](super::tokens) module.
//!
//! The public entry point is [`tokenize`], which performs error-recovering
//! lexical analysis and collects all diagnostics in a single pass.

use std::char;

use winnow::{
    Parser as _,
    ascii::{float, multispace1},
    combinator::{alt, cut_err, delimited, not, peek, preceded, repeat, terminated},
    error::{AddContext, ContextError, ErrMode, ModalResult},
    stream::{LocatingSlice, Location, Stream},
    token::{literal, none_of, one_of, take_while},
};

use crate::{
    error::{Diagnostic, DiagnosticCollector, ErrorCode},
    span::Span,
    tokens::{PositionedToken, Token},
};

/// Rich diagnostic information for lexer errors.
///
/// Attached to winnow errors via `.context()` to provide detailed error
/// messages with codes, help text, and precise span information.
#[derive(Debug, Clone, PartialEq, Eq)]
struct LexerDiagnostic {
    pub code: ErrorCode,
    pub message: &'static str,
    pub help: Option<&'static str>,
    /// The error span covers from `start` to the error position.
    pub start: usize,
}

type Input<'a> = LocatingSlice<&'a str>;
type IResult<'a, O> = ModalResult<O, ContextError<LexerDiagnostic>>;

/// Parse a unicode escape sequence in a string: `\u{XXXX}` where XXXX is 1-6 hex digits.
///
/// This parser handles the portion after the backslash, starting with 'u'.
/// It validates:
/// - Format: must be `u{...}` with hex digits inside braces
/// - Length: 1-6 hex digits allowed
/// - Codepoint: must be valid Unicode (0x0000-0xD7FF or 0xE000-0x10FFFF)
///
/// Takes `escape_start` position (before `\`) for error span calculation.
/// Uses `cut_err` after 'u' to commit and preserve diagnostic context.
fn string_escape_unicode<'a>(input: &mut Input<'a>, escape_start: usize) -> IResult<'a, char> {
    preceded(
        'u',
        cut_err(
            delimited(
                '{',
                take_while(1..=6, |c: char| c.is_ascii_hexdigit()).context(LexerDiagnostic {
                    code: ErrorCode::E006,
                    message: "empty unicode escape",
                    help: Some("provide 1-6 hex digits: `\\u{1F602}`"),
                    start: escape_start,
                }),
                '}',
            )
            .context(LexerDiagnostic {
                code: ErrorCode::E004,
                message: "invalid unicode escape",
                help: Some("use format `\\u{XXXX}` with 1-6 hex digits"),
                start: escape_start,
            })
            .verify(|hex_str: &str| {
                u32::from_str_radix(hex_str, 16)
                    .ok()
                    .and_then(char::from_u32)
                    .is_some()
            })
            .context(LexerDiagnostic {
                code: ErrorCode::E005,
                message: "invalid unicode codepoint",
                help: Some("valid range: `0x0000`-`0xD7FF` or `0xE000`-`0x10FFFF`"),
                start: escape_start,
            })
            .map(|hex_str: &str| {
                u32::from_str_radix(hex_str, 16)
                    .ok()
                    .and_then(char::from_u32)
                    .expect("verified hex digits form valid unicode codepoint")
            }),
        ),
    )
    .parse_next(input)
}

/// Parse a standard escape character in a string after the backslash.
fn string_escape_char<'a>(input: &mut Input<'a>) -> IResult<'a, char> {
    one_of(['n', 'r', 't', 'b', 'f', '\\', '/', '\'', '"', '0'])
        .map(|c| match c {
            'n' => '\n',
            'r' => '\r',
            't' => '\t',
            'b' => '\u{08}',
            'f' => '\u{0C}',
            '\\' => '\\',
            '/' => '/',
            '\'' => '\'',
            '"' => '"',
            '0' => '\0',
            _ => unreachable!(),
        })
        .parse_next(input)
}

/// Parse escaped whitespace in a string (backslash followed by whitespace).
///
/// Returns a placeholder character (`\u{E000}`) that is filtered out later.
/// This allows multi-line string formatting where trailing backslash
/// consumes the following whitespace.
fn string_escape_whitespace<'a>(input: &mut Input<'a>) -> IResult<'a, char> {
    multispace1.value('\u{E000}').parse_next(input)
}

/// Parse an escape sequence in a string starting with backslash.
///
/// Handles:
/// - Unicode escapes: `\u{XXXX}`
/// - Standard escapes: `\n`, `\r`, `\t`, `\b`, `\f`, `\\`, `\/`, `\'`, `\"`, `\0`
/// - Escaped whitespace: `\` followed by whitespace (consumed and ignored)
fn string_escape<'a>(input: &mut Input<'a>) -> IResult<'a, char> {
    let escape_start = input.current_token_start();

    '\\'.parse_next(input)?;

    match string_escape_unicode(input, escape_start) {
        Ok(ch) => return Ok(ch),
        Err(ErrMode::Backtrack(_)) => {} // Try next alternative
        Err(e) => return Err(e),         // Propagate cut errors (E004, E005, E006)
    }

    if let Ok(ch) = string_escape_char(input) {
        return Ok(ch);
    }

    if let Ok(ch) = string_escape_whitespace(input) {
        return Ok(ch);
    }

    // None matched - return error with context for invalid escape
    Err(ErrMode::Cut(ContextError::new().add_context(
        input,
        &input.checkpoint(),
        LexerDiagnostic {
            code: ErrorCode::E003,
            message: "invalid escape sequence",
            help: Some(
                "valid escapes: `\\n`, `\\r`, `\\t`, `\\b`, `\\f`, `\\\\`, `\\/`, `\\'`, `\\\"`, `\\0`, `\\u{}`",
            ),
            start: escape_start,
        },
    )))
}

/// Parse a complete string literal with double quotes.
///
/// This function parses Rust-style string literals including:
/// - Basic strings: "hello world"
/// - Escape sequences: "hello\nworld", "quote: \"test\""
/// - Unicode escapes: "emoji: \u{1F602}", "symbol: \u{00AC}"
/// - Escaped whitespace: "before\   \n  after" (whitespace is consumed)
/// - Empty strings: ""
fn string_literal<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    // Regular string content (not quotes, backslashes, or newlines)
    let string_char = none_of(['"', '\\', '\n', '\r']);

    // String content: mix of regular chars and escapes
    let string_content =
        repeat(0.., alt((string_escape, string_char))).fold(String::new, |mut acc, ch| {
            if ch != '\u{E000}' {
                // Filter out escaped whitespace placeholders
                acc.push(ch);
            }
            acc
        });

    let start_pos = input.current_token_start();

    // Parse opening quote using combinator (properly advances LocatingSlice)
    '"'.parse_next(input)
        .map_err(|_: ErrMode<ContextError<LexerDiagnostic>>| {
            ErrMode::Backtrack(ContextError::new())
        })?;

    // Parse content with cut_err to commit after opening quote
    // Include start_pos so error span covers from opening quote to error position
    cut_err(terminated(string_content, '"'))
        .context(LexerDiagnostic {
            code: ErrorCode::E001,
            message: "unterminated string literal",
            help: Some("add closing `\"`"),
            start: start_pos,
        })
        .parse_next(input)
        .map(Token::StringLiteral)
}

/// Parse a float literal
fn float_literal<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    // Parse float but ensure it's not followed by identifier characters
    // This prevents "inf" in "info_note" from being parsed as a float literal
    (
        float,
        peek(not(one_of(|c: char| c.is_alphanumeric() || c == '_'))),
    )
        .map(|(f, _)| Token::FloatLiteral(f))
        .parse_next(input)
}

/// Parse line comment starting with '//'
fn line_comment<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    preceded("//", take_while(0.., |c| c != '\n'))
        .map(Token::LineComment)
        .parse_next(input)
}

/// Parse keywords with word boundary checking
fn keyword<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    terminated(
        alt((
            alt((
                literal("diagram"),
                literal("component"),
                literal("sequence"),
                literal("type"),
                literal("embed"),
                literal("import"),
                literal("library"),
                literal("as"),
                literal("deactivate"),
            )),
            alt((
                literal("activate"),
                literal("fragment"),
                literal("section"),
                literal("critical"),
                literal("break"),
                literal("else"),
                literal("loop"),
                literal("alt"),
                literal("opt"),
            )),
            alt((literal("par"), literal("note"))),
        )),
        // Ensure keyword is not followed by identifier character (word boundary)
        peek(not(one_of(|c: char| c.is_ascii_alphanumeric() || c == '_'))),
    )
    .map(|keyword: &str| match keyword {
        "diagram" => Token::Diagram,
        "component" => Token::Component,
        "sequence" => Token::Sequence,
        "type" => Token::Type,
        "embed" => Token::Embed,
        "import" => Token::Import,
        "library" => Token::Library,
        "as" => Token::As,
        "deactivate" => Token::Deactivate,
        "activate" => Token::Activate,
        "fragment" => Token::Fragment,
        "section" => Token::Section,
        "alt" => Token::Alt,
        "else" => Token::Else,
        "opt" => Token::Opt,
        "loop" => Token::Loop,
        "par" => Token::Par,
        "break" => Token::Break,
        "critical" => Token::Critical,
        "note" => Token::Note,
        _ => unreachable!(),
    })
    .parse_next(input)
}

/// Parse identifiers
fn identifier<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    // Start with letter or underscore, followed by alphanumeric or underscore
    take_while(1.., |c: char| {
        c.is_ascii_alphabetic() || c == '_' || c.is_ascii_digit()
    })
    .verify(|s: &str| {
        s.chars()
            .next()
            .is_some_and(|c| c.is_ascii_alphabetic() || c == '_')
    })
    .map(Token::Identifier)
    .parse_next(input)
}

/// Parses multi-character operators (order matters — longest first).
fn multi_char_operator<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    alt((
        literal("<->").value(Token::DoubleArrow),
        literal("->").value(Token::Arrow_),
        literal("<-").value(Token::LeftArrow),
        literal("::").value(Token::DoubleColon),
    ))
    .parse_next(input)
}

/// Parses a single-character operator or punctuation token.
fn single_char_token<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    alt((
        alt((
            '-'.value(Token::Plain),
            '='.value(Token::Equals),
            ':'.value(Token::Colon),
            '@'.value(Token::At),
            '{'.value(Token::LeftBrace),
            '}'.value(Token::RightBrace),
            '['.value(Token::LeftBracket),
            ']'.value(Token::RightBracket),
            ';'.value(Token::Semicolon),
        )),
        alt((','.value(Token::Comma), '*'.value(Token::Star))),
    ))
    .parse_next(input)
}

/// Parses whitespace (spaces, tabs, etc. but not newlines).
fn whitespace<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    take_while(1.., |c: char| c.is_whitespace() && c != '\n')
        .value(Token::Whitespace)
        .parse_next(input)
}

/// Parses a newline character.
fn newline<'a>(input: &mut Input<'a>) -> IResult<'a, Token<'a>> {
    '\n'.value(Token::Newline).parse_next(input)
}

/// Parses a single token with position tracking.
fn positioned_token<'a>(input: &mut Input<'a>) -> IResult<'a, PositionedToken<'a>> {
    let start_pos = input.current_token_start();

    let token = alt((
        line_comment,        // Must come before single char '-'
        string_literal,      // Must come before any single char
        multi_char_operator, // Must come before single char operators
        keyword,             // Must come before identifier
        float_literal,       // Must come before identifier
        identifier,          // Must come before single chars
        single_char_token,   // Single character tokens
        newline,             // Must come before whitespace
        whitespace,          // General whitespace
    ))
    .parse_next(input)?;

    let end_pos = input.current_token_start();
    let span = Span::new(start_pos..end_pos);

    Ok(PositionedToken::new(token, span))
}

/// Lexer that accumulates tokens and diagnostics during tokenization.
struct Lexer<'a> {
    tokens: Vec<PositionedToken<'a>>,
    diagnostics: DiagnosticCollector,
    /// Starting position of this file in the virtual address space.
    base_offset: usize,
}

impl<'a> Lexer<'a> {
    /// Creates a new lexer whose spans start at `base_offset`.
    fn new(base_offset: usize) -> Self {
        Self {
            tokens: Vec::new(),
            diagnostics: DiagnosticCollector::new(),
            base_offset,
        }
    }

    /// Tokenizes the input, collecting tokens and errors.
    ///
    /// Token and error spans are positioned relative to `base_offset`.
    fn tokenize(&mut self, mut input: Input<'a>) {
        while !input.is_empty() {
            match positioned_token(&mut input) {
                Ok(mut token) => {
                    token.span = token.span.shift(self.base_offset);
                    self.tokens.push(token);
                }
                Err(e) => {
                    // Get position before recovery
                    let error_pos = input.current_token_start();

                    let diagnostic = self.convert_err_mode(e, error_pos);
                    self.diagnostics.emit(diagnostic);

                    // FIXME: Simple single-character skip causes cascading errors for
                    // string escape failures. E.g., `"test\u{}"` produces E006 (empty
                    // unicode escape) then E001 (unterminated string) because after
                    // skipping one char, the closing `"` starts a new unterminated string.
                    if !input.is_empty() {
                        input.next_token();
                    }
                }
            }
        }
    }

    /// Finishes lexing and returns tokens or collected errors.
    fn finish(self) -> Result<Vec<PositionedToken<'a>>, Vec<Diagnostic>> {
        self.diagnostics.finish().map(|()| self.tokens)
    }

    /// Converts a winnow `ErrMode` and file-local error position to a [`Diagnostic`].
    ///
    /// Extracts [`LexerDiagnostic`] from the error context for rich error info
    /// with code, message, and help. Falls back to `E002` (unexpected character)
    /// if no diagnostic context is found. All spans are shifted by `base_offset`.
    fn convert_err_mode(
        &self,
        err: ErrMode<ContextError<LexerDiagnostic>>,
        error_pos: usize,
    ) -> Diagnostic {
        let context_error = match err {
            ErrMode::Backtrack(ctx) | ErrMode::Cut(ctx) => ctx,
            ErrMode::Incomplete(_) => ContextError::new(),
        };

        // Use the first diagnostic context if available
        if let Some(LexerDiagnostic {
            code,
            message,
            help,
            start,
        }) = context_error.context().next()
        {
            let span = Span::new(*start..error_pos).shift(self.base_offset);

            let mut diag = Diagnostic::error(*message)
                .with_code(*code)
                .with_label(span, code.description());
            if let Some(h) = help {
                diag = diag.with_help(*h);
            }
            return diag;
        }

        // Fallback when no context is present
        let span = Span::new(error_pos..error_pos.saturating_add(1)).shift(self.base_offset);
        Diagnostic::error("unexpected character")
            .with_code(ErrorCode::E002)
            .with_label(span, ErrorCode::E002.description())
    }
}

/// Tokenizes source text into positioned tokens, collecting multiple errors.
///
/// Attempts to recover from errors and continue tokenizing, collecting
/// all errors encountered. This provides better user experience by
/// reporting multiple issues in a single pass.
///
/// # Arguments
///
/// * `input` - The source text to tokenize.
/// * `base_offset` - Starting byte position of this file in the virtual
///   address space.
///
/// # Returns
///
/// The token sequence on success, or a [`Vec<Diagnostic>`] containing all
/// accumulated diagnostics on failure.
pub fn tokenize(
    input: &str,
    base_offset: usize,
) -> Result<Vec<PositionedToken<'_>>, Vec<Diagnostic>> {
    let located_input = LocatingSlice::new(input);
    let mut lexer = Lexer::new(base_offset);
    lexer.tokenize(located_input);
    lexer.finish()
}

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

    fn test_single_token(input: &str, expected: Token<'_>) {
        let mut located_input = LocatingSlice::new(input);
        let result = positioned_token(&mut located_input);
        assert!(result.is_ok(), "Failed to parse: {}", input);
        let positioned = result.unwrap();
        assert_eq!(positioned.token, expected);
    }

    #[test]
    fn test_keywords() {
        test_single_token("diagram", Token::Diagram);
        test_single_token("component", Token::Component);
        test_single_token("sequence", Token::Sequence);
        test_single_token("type", Token::Type);
        test_single_token("embed", Token::Embed);
        test_single_token("import", Token::Import);
        test_single_token("library", Token::Library);
        test_single_token("as", Token::As);
        test_single_token("deactivate", Token::Deactivate);
        test_single_token("activate", Token::Activate);
        test_single_token("fragment", Token::Fragment);
        test_single_token("section", Token::Section);
        test_single_token("alt", Token::Alt);
        test_single_token("else", Token::Else);
        test_single_token("opt", Token::Opt);
        test_single_token("loop", Token::Loop);
        test_single_token("par", Token::Par);
        test_single_token("break", Token::Break);
        test_single_token("critical", Token::Critical);
        test_single_token("note", Token::Note);
    }

    #[test]
    fn test_identifiers() {
        test_single_token("hello", Token::Identifier("hello"));
        test_single_token("_private", Token::Identifier("_private"));
        test_single_token("var123", Token::Identifier("var123"));
        test_single_token("CamelCase", Token::Identifier("CamelCase"));
    }

    #[test]
    fn test_activate_keyword_word_boundaries() {
        // Test that "activate" is recognized as a keyword
        test_single_token("activate", Token::Activate);

        // Test that identifiers containing "activate" are still treated as identifiers
        test_single_token("activateUser", Token::Identifier("activateUser"));
        test_single_token("useractivate", Token::Identifier("useractivate"));
        test_single_token("reactivate", Token::Identifier("reactivate"));

        // Test that "activate_user" is treated as a single identifier (no word boundary)
        test_single_token("activate_user", Token::Identifier("activate_user"));

        // Test that "activate" followed by space and identifier tokenizes correctly
        let input = "activate user";
        let tokens = tokenize(input, 0).expect("Should tokenize");
        assert_eq!(tokens.len(), 3); // activate, space, user
        assert_eq!(tokens[0].token, Token::Activate);
        assert_eq!(tokens[1].token, Token::Whitespace);
        assert_eq!(tokens[2].token, Token::Identifier("user"));
    }

    #[test]
    fn test_operators() {
        test_single_token("<->", Token::DoubleArrow);
        test_single_token("->", Token::Arrow_);
        test_single_token("<-", Token::LeftArrow);
        test_single_token("-", Token::Plain);
        test_single_token("=", Token::Equals);
        test_single_token(":", Token::Colon);
        test_single_token("@", Token::At);
    }

    #[test]
    fn test_punctuation() {
        test_single_token("{", Token::LeftBrace);
        test_single_token("}", Token::RightBrace);
        test_single_token("[", Token::LeftBracket);
        test_single_token("]", Token::RightBracket);
        test_single_token(";", Token::Semicolon);
        test_single_token(",", Token::Comma);
    }

    #[test]
    fn test_string_literals() {
        test_single_token(
            "\"hello world\"",
            Token::StringLiteral("hello world".to_string()),
        );
        test_single_token("\"\"", Token::StringLiteral("".to_string()));
        test_single_token("\"abc123\"", Token::StringLiteral("abc123".to_string()));
    }

    #[test]
    fn test_float_literals() {
        // Basic float literals
        test_single_token("1.0", Token::FloatLiteral(1.0));
        test_single_token("2.5", Token::FloatLiteral(2.5));
        test_single_token("10.0", Token::FloatLiteral(10.0));
        test_single_token("0.0", Token::FloatLiteral(0.0));

        // Float literals with leading decimal
        test_single_token(".5", Token::FloatLiteral(0.5));
        test_single_token(".25", Token::FloatLiteral(0.25));

        // Float literals with trailing decimal
        test_single_token("5.", Token::FloatLiteral(5.0));
        test_single_token("100.", Token::FloatLiteral(100.0));

        // Scientific notation
        test_single_token("1e5", Token::FloatLiteral(1e5));
        test_single_token("2.5e-3", Token::FloatLiteral(2.5e-3));
        test_single_token("1.23e+4", Token::FloatLiteral(1.23e+4));
        test_single_token("1E5", Token::FloatLiteral(1E5));
        test_single_token("2.5E-3", Token::FloatLiteral(2.5E-3));

        // Large and small numbers
        test_single_token("999999.999999", Token::FloatLiteral(999999.999999));
        test_single_token("0.000001", Token::FloatLiteral(0.000001));

        // Basic integer literals (converted to floats)
        test_single_token("1", Token::FloatLiteral(1.0));
        test_single_token("42", Token::FloatLiteral(42.0));
        test_single_token("0", Token::FloatLiteral(0.0));
        test_single_token("123", Token::FloatLiteral(123.0));
    }

    #[test]
    fn test_float_inf_vs_identifiers() {
        // Special float values when standalone (followed by non-identifier chars)
        test_single_token("inf ", Token::FloatLiteral(f32::INFINITY));
        test_single_token("infinity ", Token::FloatLiteral(f32::INFINITY));
        test_single_token("-inf ", Token::FloatLiteral(f32::NEG_INFINITY)); // Negative infinity

        // Identifiers that start with "inf" or "infinity" should NOT be parsed as floats
        // These should be parsed as identifiers
        test_single_token("InfoNote", Token::Identifier("InfoNote"));
        test_single_token("info", Token::Identifier("info"));
        test_single_token("information", Token::Identifier("information"));
        test_single_token("infinite", Token::Identifier("infinite"));
        test_single_token("infinity_pool", Token::Identifier("infinity_pool"));

        // Test in context with other tokens
        let tokens = tokenize("inf;", 0).expect("Should tokenize");
        assert_eq!(tokens.len(), 2);
        assert!(matches!(tokens[0].token, Token::FloatLiteral(_)));
        assert!(matches!(tokens[1].token, Token::Semicolon));

        // Test identifier starting with inf in context
        let tokens = tokenize("InfoNote;", 0).expect("Should tokenize");
        assert_eq!(tokens.len(), 2);
        assert!(matches!(tokens[0].token, Token::Identifier("InfoNote")));
        assert!(matches!(tokens[1].token, Token::Semicolon));
    }

    #[test]
    fn test_string_escape_sequences() {
        test_single_token(
            "\"hello\\nworld\"",
            Token::StringLiteral("hello\nworld".to_string()),
        );
        test_single_token(
            "\"quote: \\\"test\\\"\"",
            Token::StringLiteral("quote: \"test\"".to_string()),
        );
        test_single_token(
            "\"tab:\\tafter\"",
            Token::StringLiteral("tab:\tafter".to_string()),
        );
        test_single_token(
            "\"backslash: \\\\\"",
            Token::StringLiteral("backslash: \\".to_string()),
        );
    }

    #[test]
    fn test_unicode_escapes() {
        test_single_token(
            "\"emoji: \\u{1F602}\"",
            Token::StringLiteral("emoji: 😂".to_string()),
        );
        test_single_token(
            "\"unicode: \\u{00AC}\"",
            Token::StringLiteral("unicode: ¬".to_string()),
        );
        test_single_token(
            "\"letter: \\u{41}\"",
            Token::StringLiteral("letter: A".to_string()),
        );
    }

    #[test]
    fn test_escaped_whitespace_handling() {
        // Test that escaped whitespace is consumed and ignored
        // Note: The current implementation uses multispace1 to consume escaped whitespace
        test_single_token(
            "\"before\\  \n  after\"",
            Token::StringLiteral("beforeafter".to_string()),
        );
        test_single_token(
            "\"line1\\   \n   line2\"",
            Token::StringLiteral("line1line2".to_string()),
        );
    }

    #[test]
    fn test_control_character_escapes() {
        // Test control character escape sequences that are currently supported
        test_single_token(
            "\"bell: \\b form: \\f\"",
            Token::StringLiteral("bell: \u{08} form: \u{0C}".to_string()),
        );
        test_single_token(
            "\"slash: \\/\"",
            Token::StringLiteral("slash: /".to_string()),
        );
        test_single_token(
            "\"single: \\'\"",
            Token::StringLiteral("single: '".to_string()),
        );
        // Test null character separately
        test_single_token(
            "\"null: \\0\"",
            Token::StringLiteral("null: \0".to_string()),
        );
    }

    #[test]
    fn test_complex_escape_combinations() {
        // Test strings with multiple different escape types
        test_single_token(
            "\"Mixed: \\n\\t\\r\\\\\\\"\"",
            Token::StringLiteral("Mixed: \n\t\r\\\"".to_string()),
        );

        let complex_input =
            "\"tab:\\tafter tab, newline:\\nnew line, quote: \\\", emoji: \\u{1F602}\"";
        let expected_output = "tab:\tafter tab, newline:\nnew line, quote: \", emoji: 😂";
        test_single_token(
            complex_input,
            Token::StringLiteral(expected_output.to_string()),
        );
    }

    #[test]
    fn test_string_edge_cases() {
        // String with only escape sequences
        test_single_token("\"\\n\\t\\r\"", Token::StringLiteral("\n\t\r".to_string()));

        // String with only unicode escapes
        test_single_token(
            "\"\\u{41}\\u{42}\\u{43}\"",
            Token::StringLiteral("ABC".to_string()),
        );

        // Empty string
        test_single_token("\"\"", Token::StringLiteral("".to_string()));
    }

    #[test]
    fn test_mixed_content_advanced() {
        // Test combination of escaped whitespace, unicode, and regular escapes
        test_single_token(
            "\"Hello\\   \n  \\u{1F44B} World\\n!\"",
            Token::StringLiteral("Hello👋 World\n!".to_string()),
        );

        // Test escaped whitespace with unicode and control characters
        test_single_token(
            "\"start\\  \n\\u{41}\\b\\tend\"",
            Token::StringLiteral("startA\u{08}\tend".to_string()),
        );
    }

    #[test]
    fn test_string_boundary_conditions() {
        // Test very long strings with many escapes
        test_single_token(
            "\"a\\nb\\tc\\rd\\\\e\\\"f\\u{41}g\"",
            Token::StringLiteral("a\nb\tc\rd\\e\"fAg".to_string()),
        );

        // Test string with repeated escape patterns
        test_single_token("\"\\n\\n\\n\"", Token::StringLiteral("\n\n\n".to_string()));

        // Test unicode at boundaries
        test_single_token(
            "\"\\u{1F602}middle\\u{1F44B}\"",
            Token::StringLiteral("😂middle👋".to_string()),
        );

        // Test combinations that are known to work
        test_single_token(
            "\"backslash: \\\\, quote: \\\", tab: \\t\"",
            Token::StringLiteral("backslash: \\, quote: \", tab: \t".to_string()),
        );
    }

    #[test]
    fn test_comments() {
        test_single_token(
            "// this is a comment",
            Token::LineComment(" this is a comment"),
        );
        test_single_token("//", Token::LineComment(""));
        test_single_token("//no space", Token::LineComment("no space"));
    }

    #[test]
    fn test_whitespace() {
        test_single_token(" ", Token::Whitespace);
        test_single_token("\t", Token::Whitespace);
        test_single_token("   ", Token::Whitespace);
        test_single_token("\n", Token::Newline);
    }

    #[test]
    fn test_full_lexing() {
        let input = r#"diagram component "My System" -> target;"#;
        let result = tokenize(input, 0);

        assert!(result.is_ok(), "Lexing failed: {:?}", result);
        let tokens = result.unwrap();

        // Extract just the token types for easier testing
        let token_types: Vec<_> = tokens.iter().map(|p| &p.token).collect();

        // Expected sequence: diagram, whitespace, component, whitespace, "My System", whitespace, ->, whitespace, target, ;
        assert!(matches!(token_types[0], Token::Diagram));
        assert!(matches!(token_types[1], Token::Whitespace));
        assert!(matches!(token_types[2], Token::Component));
        assert!(matches!(token_types[3], Token::Whitespace));
        assert!(matches!(token_types[4], Token::StringLiteral(_)));
        assert!(matches!(token_types[5], Token::Whitespace));
        assert!(matches!(token_types[6], Token::Arrow_));
        assert!(matches!(token_types[7], Token::Whitespace));
        assert!(matches!(token_types[8], Token::Identifier("target")));
        assert!(matches!(token_types[9], Token::Semicolon));
    }

    #[test]
    fn test_span_tracking() {
        let input = "hello world";
        let result = tokenize(input, 0);

        assert!(result.is_ok());
        let tokens = result.unwrap();

        assert_eq!(tokens.len(), 3); // "hello", " ", "world"

        // Check spans
        assert_eq!(tokens[0].span.start(), 0);
        assert_eq!(tokens[0].span.end(), 5); // "hello"
        assert_eq!(tokens[1].span.start(), 5);
        assert_eq!(tokens[1].span.end(), 6); // " "
        assert_eq!(tokens[2].span.start(), 6);
        assert_eq!(tokens[2].span.end(), 11); // "world"
    }

    // Helper function to test lexer errors with span information
    fn test_lexer_error_at_position(input: &str, expected_error_pos: usize) {
        let result = tokenize(input, 0);
        assert!(
            result.is_err(),
            "Expected lexer to fail on input: '{}'",
            input
        );

        // Verify we got a DiagnosticError
        let _error = result.unwrap_err();

        // TODO: Extract precise error span when winnow error details are accessible
        // For now, validate that lexing fails at expected position by checking partial success
        let mut partial_input = &input[..expected_error_pos.min(input.len())];
        if partial_input.is_empty() {
            return; // Cannot test empty input
        }

        // Test that we can lex up to the error position
        loop {
            let partial_result = tokenize(partial_input, 0);
            if partial_result.is_ok() || partial_input.is_empty() {
                break;
            }
            if partial_input.len() <= 1 {
                break;
            }
            partial_input = &partial_input[..partial_input.len() - 1];
        }
    }

    /// Comprehensive lexer error tests focusing on span accuracy
    mod lexer_error_tests {
        use super::*;

        #[test]
        fn test_unclosed_string_literal_errors() {
            // Basic unclosed string - error at end of input
            test_lexer_error_at_position("\"hello", 6);

            // Unclosed string with content - error at end
            test_lexer_error_at_position("\"hello world", 12);

            // Empty unclosed string - error at position 1 (after opening quote)
            test_lexer_error_at_position("\"", 1);

            // Unclosed string with escape sequence
            test_lexer_error_at_position("\"hello\\nworld", 13);

            // Unclosed string with Unicode escape
            test_lexer_error_at_position("\"emoji\\u{1F602}", 15);
        }

        #[test]
        fn test_invalid_escape_sequence_errors() {
            // Invalid escape character
            test_lexer_error_at_position("\"hello\\x\"", 7); // \x is not valid

            // Incomplete escape at end
            test_lexer_error_at_position("\"hello\\", 7);

            // Invalid escape character combinations
            test_lexer_error_at_position("\"test\\q\"", 6); // \q is not valid
            test_lexer_error_at_position("\"test\\1\"", 6); // \1 is not valid
            test_lexer_error_at_position("\"test\\z\"", 6); // \z is not valid
        }

        #[test]
        fn test_malformed_unicode_escape_errors() {
            // Missing opening brace
            test_lexer_error_at_position("\"test\\u1F602\"", 7);

            // Missing closing brace
            test_lexer_error_at_position("\"test\\u{1F602\"", 13);

            // Invalid hex characters in Unicode escape
            test_lexer_error_at_position("\"test\\u{GHIJK}\"", 9);
            test_lexer_error_at_position("\"test\\u{123G}\"", 11);
            test_lexer_error_at_position("\"test\\u{XYZ}\"", 9);
        }

        #[test]
        fn test_invalid_unicode_codepoint_errors() {
            // Unicode code point too large (greater than 0x10FFFF)
            test_lexer_error_at_position("\"test\\u{110000}\"", 8);
            test_lexer_error_at_position("\"test\\u{FFFFFF}\"", 8);

            // Invalid Unicode surrogate range (0xD800-0xDFFF)
            test_lexer_error_at_position("\"test\\u{D800}\"", 8);
            test_lexer_error_at_position("\"test\\u{DFFF}\"", 8);
        }

        #[test]
        fn test_unterminated_unicode_escape_errors() {
            // Unterminated Unicode escape at end of string
            test_lexer_error_at_position("\"test\\u{123", 11);

            // Unterminated Unicode escape with quote
            test_lexer_error_at_position("\"test\\u{123\"", 12);

            // Unterminated empty Unicode escape
            test_lexer_error_at_position("\"test\\u{\"", 9);
        }

        #[test]
        fn test_empty_unicode_escape_errors() {
            // Empty Unicode escape braces
            test_lexer_error_at_position("\"test\\u{}\"", 8);

            // Unicode escape with only whitespace
            test_lexer_error_at_position("\"test\\u{ }\"", 8);
            test_lexer_error_at_position("\"test\\u{\t}\"", 8);
        }

        #[test]
        fn test_unicode_escape_too_long_errors() {
            // Unicode escape with too many hex digits (more than 6)
            test_lexer_error_at_position("\"test\\u{1234567}\"", 8);
            test_lexer_error_at_position("\"test\\u{12345678}\"", 8);
            test_lexer_error_at_position("\"test\\u{1F6020000}\"", 8);
        }

        #[test]
        fn test_missing_quote_handling_errors() {
            // String content without quotes
            let result = tokenize("hello world", 0);
            assert!(result.is_ok()); // This should parse as identifier + whitespace + identifier

            // Mixed quote types (though " is standard)
            test_lexer_error_at_position("'hello'", 0); // Single quotes not supported for strings
        }

        #[test]
        fn test_complex_error_combinations() {
            // Multiple error conditions in one string
            test_lexer_error_at_position("\"unclosed with \\x invalid", 15);

            // Unicode and quote errors combined
            test_lexer_error_at_position("\"test\\u{GHIJK", 9);

            // Escape sequence errors at different positions
            test_lexer_error_at_position("\"start\\x middle\\u{} end", 7); // First error wins
        }

        #[test]
        fn test_error_position_boundaries() {
            // Test that errors occur at precise character boundaries

            // Error exactly at escape sequence start
            test_lexer_error_at_position("\"good\\xbad\"", 6);

            // Error at string boundary
            test_lexer_error_at_position("\"unterminated", 13);
        }

        #[test]
        fn test_multiline_string_errors() {
            // Unterminated string across lines (though strings can't normally span lines)
            test_lexer_error_at_position("\"hello\nworld\"", 6); // Newline in string

            // Unicode escape spanning lines
            test_lexer_error_at_position("\"test\\u{\n1F602}\"", 8);
        }

        #[test]
        fn test_invalid_relation_token_error() {
            // Test that invalid characters cause lexer errors
            let source = r#"
            diagram component;
            a: Rectangle;
            b: Rectangle;
            a > b;
        "#;

            // The lexer should fail because '>' is not a valid token
            let result = tokenize(source, 0);
            assert!(
                result.is_err(),
                "Expected lexer to fail on invalid token '>'"
            );
        }

        /// Helper to verify error codes in diagnostics match exactly in order.
        fn assert_error_codes(input: &str, expected_codes: &[ErrorCode]) {
            let result = tokenize(input, 0);
            assert!(
                result.is_err(),
                "Expected lexer to fail on input: '{input}'"
            );
            let parse_error = result.unwrap_err();
            let diagnostics = &parse_error;
            assert_eq!(
                diagnostics.len(),
                expected_codes.len(),
                "Expected {} errors for input '{input}', got {}",
                expected_codes.len(),
                diagnostics.len()
            );
            for (i, (diag, expected)) in diagnostics.iter().zip(expected_codes).enumerate() {
                assert_eq!(
                    diag.code(),
                    Some(*expected),
                    "Error {i}: expected {expected:?} for input '{input}', got {:?}",
                    diag.code()
                );
            }
        }

        #[test]
        fn test_error_code_e003_invalid_escape_sequence() {
            // Invalid escape produces E003, then cascading E001 (see FIXME in recovery code)
            assert_error_codes("\"test\\x\"", &[ErrorCode::E003, ErrorCode::E001]);
            assert_error_codes("\"test\\q\"", &[ErrorCode::E003, ErrorCode::E001]);
            assert_error_codes("\"test\\z\"", &[ErrorCode::E003, ErrorCode::E001]);
            assert_error_codes("\"test\\1\"", &[ErrorCode::E003, ErrorCode::E001]);
        }

        #[test]
        fn test_error_code_e005_invalid_unicode_codepoint() {
            // Invalid codepoint produces E005, then cascading E001 (see FIXME in recovery code)
            assert_error_codes("\"test\\u{110000}\"", &[ErrorCode::E005, ErrorCode::E001]);
            assert_error_codes("\"test\\u{FFFFFF}\"", &[ErrorCode::E005, ErrorCode::E001]);
            // Surrogate range
            assert_error_codes("\"test\\u{D800}\"", &[ErrorCode::E005, ErrorCode::E001]);
            assert_error_codes("\"test\\u{DFFF}\"", &[ErrorCode::E005, ErrorCode::E001]);
        }

        #[test]
        fn test_error_code_e006_empty_unicode_escape() {
            // Empty unicode escape produces E006, then cascading E001 (see FIXME in recovery code)
            assert_error_codes("\"test\\u{}\"", &[ErrorCode::E006, ErrorCode::E001]);
        }

        #[test]
        fn test_error_code_e001_unterminated_string() {
            // Unterminated string should still produce E001
            assert_error_codes("\"unterminated", &[ErrorCode::E001]);
            assert_error_codes("\"", &[ErrorCode::E001]);
        }

        #[test]
        fn test_start_offset_span_for_unterminated_string() {
            // Verify StartOffset creates span from opening quote to error position
            // Use multi-line input with tokens before the string so it doesn't start at 0
            let input = "foo \"hello world\nbar";
            //           ^   ^           ^
            //           0   4           16 (newline position)
            //           |   |           |
            //           |   string start|
            //           identifier      error position (at newline)
            let result = tokenize(input, 0);
            assert!(result.is_err());

            let parse_error = result.unwrap_err();
            let diagnostics = &parse_error;
            assert!(!diagnostics.is_empty(), "Expected at least one diagnostic");
            let diagnostic = &diagnostics[0];
            let labels = diagnostic.labels();
            assert!(!labels.is_empty(), "Expected at least one label");

            let span = labels[0].span();
            // Span should start at 4 (opening quote after "foo ") and end at newline
            assert_eq!(
                span.start(),
                4,
                "Span should start at opening quote position (after 'foo ')"
            );
            assert_eq!(
                span.end(),
                16,
                "Span should end at newline (error position)"
            );
        }

        #[test]
        fn test_error_code_e002_unexpected_character() {
            // Invalid token should produce E002
            assert_error_codes(">", &[ErrorCode::E002]);
            assert_error_codes("$", &[ErrorCode::E002]);
        }

        #[test]
        fn test_multiple_unterminated_strings() {
            assert_error_codes(
                "\"first\n\"second\n\"third",
                &[ErrorCode::E001, ErrorCode::E001, ErrorCode::E001],
            );
        }

        #[test]
        fn test_mixed_error_types() {
            assert_error_codes(
                "> \"unterminated\n$",
                &[ErrorCode::E002, ErrorCode::E001, ErrorCode::E002],
            );
        }

        #[test]
        fn test_errors_with_valid_tokens_between() {
            assert_error_codes(
                "valid > identifier $ another",
                &[ErrorCode::E002, ErrorCode::E002],
            );
        }
    }

    #[test]
    fn tokenize_with_base_offset_shifts_all_spans() {
        let input = "a -> b";
        let tokens = tokenize(input, 100).unwrap();

        for token in &tokens {
            assert!(
                token.span.start() >= 100,
                "span start {} should be >= 100",
                token.span.start()
            );
        }

        // First non-whitespace token 'a' starts at offset 100.
        let first = tokens.first().unwrap();
        assert_eq!(first.token, Token::Identifier("a"));
        assert_eq!(first.span.start(), 100);
        assert_eq!(first.span.end(), 101);
    }

    #[test]
    fn tokenize_with_base_offset_shifts_error_spans() {
        // '$' is an unexpected character that produces E002.
        let err = tokenize("$", 200).unwrap_err();
        let diag = &err[0];
        let label = &diag.labels()[0];

        assert!(
            label.span().start() >= 200,
            "error span start {} should be >= 200",
            label.span().start()
        );
    }
}

#[cfg(test)]
mod proptest_tests {
    use proptest::prelude::*;

    use super::*;

    // ===================
    // Strategies
    // ===================

    /// Strategy for generating valid identifier strings.
    /// Identifiers start with a letter and contain letters, digits, and underscores.
    fn valid_identifier_strategy() -> impl Strategy<Value = String> {
        "[a-z][a-z0-9_]{0,20}".prop_filter("avoid keywords", |s| {
            !matches!(
                s.as_str(),
                "diagram"
                    | "component"
                    | "sequence"
                    | "note"
                    | "on"
                    | "left"
                    | "right"
                    | "over"
                    | "activate"
                    | "deactivate"
                    | "alt"
                    | "else"
                    | "opt"
                    | "loop"
                    | "par"
                    | "critical"
                    | "group"
                    | "break"
                    | "ref"
                    | "type"
                    | "of"
                    | "true"
                    | "false"
                    | "inf"
            )
        })
    }

    /// Strategy for generating valid float literal strings.
    fn float_literal_strategy() -> impl Strategy<Value = String> {
        (0u32..10000, 0u32..10000).prop_map(|(integer, fraction)| format!("{integer}.{fraction}"))
    }

    // ===================
    // Property Test Functions
    // ===================

    /// Valid identifiers should always tokenize successfully.
    fn check_valid_identifiers_tokenize(id: &str) -> Result<(), TestCaseError> {
        let source = format!("diagram component; {id}: Rectangle;");
        let result = tokenize(&source, 0);

        let err = result.err();
        prop_assert!(
            err.is_none(),
            "Failed to tokenize valid identifier `{id}`: {err:?}"
        );
        Ok(())
    }

    /// Float literals with various integer and fractional parts should parse.
    fn check_float_literals_parse(float_literal: &str) -> Result<(), TestCaseError> {
        let source = format!("diagram component; x: Rectangle [width={float_literal}];");
        let result = tokenize(&source, 0);

        let err = result.err();
        prop_assert!(
            err.is_none(),
            "Failed to tokenize float literal `{float_literal}`: {err:?}"
        );
        Ok(())
    }

    // ===================
    // Proptest Wrappers
    // ===================

    proptest! {
        #[test]
        fn valid_identifiers_tokenize(id in valid_identifier_strategy()) {
            check_valid_identifiers_tokenize(&id)?;
        }

        #[test]
        fn float_literals_parse(float_literal in float_literal_strategy()) {
            check_float_literals_parse(&float_literal)?;
        }
    }
}