tokit 0.0.0

Blazing fast parser combinators: parse-while-lexing (zero-copy), deterministic LALR-style parsing, no backtracking. Flexible emitters for fail-fast runtime or greedy compiler diagnostics
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
use crate::{
  Lexer,
  error::{
    Unclosed, Undelimited, Unopened,
    syntax::{FullContainer, MissingSyntaxOf, TooFew, TooMany},
    token::{
      MissingLeadingOf, MissingSeparatorOf, MissingTrailingOf, UnexpectedLeadingOf,
      UnexpectedRepeatedOf, UnexpectedToken, UnexpectedTrailingOf,
    },
  },
  lexer::Cursor,
  utils::{Message, Spanned},
};

use super::Token;

pub use fatal::Fatal;
pub use silent::Silent;

mod fatal;
mod ignored;
mod silent;

/// A trait for handling and emitting errors during tokenization and parsing.
///
/// `Emitter` provides a unified interface for error handling in the tokenization pipeline.
/// Implementations can decide whether errors are fatal (stop processing) or non-fatal
/// (logged and processing continues). This is particularly useful when you want to collect
/// multiple errors before stopping, or when implementing error recovery.
///
/// # Error Handling Strategy
///
/// The emitter uses a `Result`-based approach where:
/// - `Ok(())` means the error was handled as non-fatal and processing should continue
/// - `Err(error)` means the error is fatal and processing should stop immediately
///
/// # Use Cases
///
/// - **Error Collection**: Accumulate multiple errors before reporting them all at once
/// - **Error Recovery**: Log errors but continue parsing to find more issues
/// - **Fail-Fast**: Stop on the first error by always returning `Err`
/// - **Filtering**: Only treat certain error types as fatal
///
/// # Example
///
/// ```ignore
/// struct MyEmitter {
///     errors: Vec<String>,
///     max_errors: usize,
/// }
///
/// impl<'a, T: Token<'a>> Emitter<'a, T> for MyEmitter {
///     type Error = String;
///
///     fn emit_token_error(&mut self, err: Spanned<...>) -> Result<(), Self::Error> {
///         self.errors.push(format!("Lexer error at {:?}", err.span));
///         if self.errors.len() >= self.max_errors {
///             Err("Too many errors".to_string())
///         } else {
///             Ok(())
///         }
///     }
///
///     fn emit_error(&mut self, err: Spanned<Self::Error>) -> Result<(), Self::Error> {
///         self.errors.push(err.data);
///         if self.errors.len() >= self.max_errors {
///             Err("Too many errors".to_string())
///         } else {
///             Ok(())
///         }
///     }
/// }
/// ```
pub trait Emitter<'a, L, Lang: ?Sized = ()> {
  /// The error type that this emitter produces.
  ///
  /// This is the type returned when a fatal error occurs (via `Err(Self::Error)`).
  /// It can be any type that represents your application's error model.
  type Error;

  /// Emits a lexer error from the underlying Logos tokenizer.
  ///
  /// This method is called when Logos encounters an error during lexing (e.g.,
  /// invalid input that doesn't match any token pattern). The implementation
  /// decides whether to treat it as fatal or non-fatal.
  ///
  /// # Parameters
  ///
  /// - `err`: The lexer error wrapped with its source span
  ///
  /// # Returns
  ///
  /// - `Ok(())` if the error should be treated as non-fatal (processing continues)
  /// - `Err(Self::Error)` if the error is fatal (processing stops immediately)
  fn emit_lexer_error(
    &mut self,
    err: Spanned<<L::Token as Token<'a>>::Error, L::Span>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an unexpected token error encountered during parsing.
  fn emit_unexpected_token(
    &mut self,
    err: UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits a custom error from the application or parser.
  ///
  /// This method is called for application-level errors (not lexer errors).
  /// Like `emit_token_error`, the implementation decides whether the error
  /// is fatal or should be logged and processing continued.
  ///
  /// # Parameters
  ///
  /// - `err`: The application error wrapped with its source span
  ///
  /// # Returns
  ///
  /// - `Ok(())` if the error should be treated as non-fatal (processing continues)
  /// - `Err(Self::Error)` if the error is fatal (processing stops immediately)
  fn emit_error(&mut self, err: Spanned<Self::Error, L::Span>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Rewinds the emitter state to the specified cursor.
  fn rewind(&mut self, cursor: &Cursor<'a, '_, L>)
  where
    L: Lexer<'a>;
}

impl<'a, L, U, Lang: ?Sized> Emitter<'a, L, Lang> for &mut U
where
  U: Emitter<'a, L, Lang>,
{
  type Error = U::Error;

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_lexer_error(
    &mut self,
    err: Spanned<<L::Token as Token<'a>>::Error, L::Span>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_lexer_error(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unexpected_token(
    &mut self,
    err: UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_unexpected_token(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_error(&mut self, err: Spanned<Self::Error, L::Span>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_error(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn rewind(&mut self, cursor: &Cursor<'a, '_, L>)
  where
    L: Lexer<'a>,
  {
    (**self).rewind(cursor)
  }
}

/// A trait bound for generic emitter error conversion.
pub trait FromEmitterError<'a, L, Lang: ?Sized = ()> {
  /// Creates an emitter error from a lexer error.
  fn from_lexer_error(err: Spanned<<L::Token as Token<'a>>::Error, L::Span>) -> Self
  where
    L: Lexer<'a>;

  /// Creates an emitter error from an unexpected token error.
  fn from_unexpected_token(
    err: UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>,
  ) -> Self
  where
    L: Lexer<'a>;
}

impl<'a, T, L, Lang: ?Sized> FromEmitterError<'a, L, Lang> for T
where
  L: Lexer<'a>,
  T: From<<L::Token as Token<'a>>::Error>
    + From<UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_lexer_error(err: Spanned<<L::Token as Token<'a>>::Error, L::Span>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into_data().into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unexpected_token(
    err: UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>,
  ) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }
}

/// An emitter that supports batching of errors for more efficient reporting.
pub trait BatchEmitter<'a, L, Error, Lang: ?Sized = ()>: Emitter<'a, L, Lang> {
  /// Creates a new empty batch for collecting errors, returning its ID.
  ///
  /// The given `span` represents the starting span of the batch, and `description`
  /// provides a message describing the batch.
  fn create_batch(&mut self, span: L::Span, description: Message)
  where
    L: Lexer<'a>;

  /// Creates a new batch for collecting errors with an initial error.
  ///
  /// If the initial error is kind of fatal error, it returns an `Err`.
  fn create_batch_with_error(
    &mut self,
    description: Message,
    err: Spanned<Error, L::Span>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an single error into the specified batch.
  ///
  /// If this error can trigger a fatal condition, the emitter can return an `Err`.
  fn emit_to_batch(
    &mut self,
    id: &L::Span,
    err: Spanned<Error, L::Span>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits all errors collected in the specified batch.
  ///
  /// If the batch does not exist or is empty, this method does nothing.
  ///
  /// If emitting the batch triggers a fatal condition, the emitter can return an `Err`.
  fn emit_batch(&mut self, id: &L::Span) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Drops the specified batch without emitting its errors.
  ///
  /// This can be used to discard non-fatal errors that are replaced by other errors.
  fn drop_batch(&mut self, id: &L::Span)
  where
    L: Lexer<'a>;
}

impl<'a, L, Error, U, Lang: ?Sized> BatchEmitter<'a, L, Error, Lang> for &mut U
where
  U: BatchEmitter<'a, L, Error, Lang>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn create_batch(&mut self, span: L::Span, description: Message)
  where
    L: Lexer<'a>,
  {
    (**self).create_batch(span, description)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn create_batch_with_error(
    &mut self,
    description: Message,
    err: Spanned<Error, L::Span>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).create_batch_with_error(description, err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_to_batch(&mut self, id: &L::Span, err: Spanned<Error, L::Span>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_to_batch(id, err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_batch(&mut self, id: &L::Span) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_batch(id)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn drop_batch(&mut self, id: &L::Span)
  where
    L: Lexer<'a>,
  {
    (**self).drop_batch(id)
  }
}

/// An emitter that emits delimiter errors
pub trait DelimiterEmitter<'a, Delim, L, Lang: ?Sized = ()>: Emitter<'a, L, Lang> {
  /// Emits an error indicating that there are unclosed.
  fn emit_unclosed(&mut self, err: Unclosed<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an error indicating that there are unopened.
  fn emit_unopened(&mut self, err: Unopened<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an error indicating that undelimited content was found.
  fn emit_undelimited(&mut self, err: Undelimited<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;
}

impl<'a, Delim, L, U, Lang: ?Sized> DelimiterEmitter<'a, Delim, L, Lang> for &mut U
where
  U: DelimiterEmitter<'a, Delim, L, Lang>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unclosed(&mut self, err: Unclosed<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_unclosed(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unopened(&mut self, err: Unopened<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_unopened(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_undelimited(&mut self, err: Undelimited<Delim, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_undelimited(err)
  }
}

/// A trait bound for converting delimiter errors into emitter errors.
pub trait FromDelimiterEmitterError<'a, Delim, L, Lang: ?Sized = ()> {
  /// Creates an emitter error from an unclosed delimiter error.
  fn from_unclosed(err: Unclosed<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;

  /// Creates an emitter error from an unopened delimiter error.
  fn from_unopened(err: Unopened<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;

  /// Creates an emitter error from an undelimited content error.
  fn from_undelimited(err: Undelimited<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;
}

impl<'a, T, Delim, L, Lang: ?Sized> FromDelimiterEmitterError<'a, Delim, L, Lang> for T
where
  L: Lexer<'a>,
  T: From<Unclosed<Delim, L::Span, Lang>>
    + From<Unopened<Delim, L::Span, Lang>>
    + From<Undelimited<Delim, L::Span, Lang>>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unclosed(err: Unclosed<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unopened(err: Unopened<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_undelimited(err: Undelimited<Delim, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }
}

/// An emitter that handles errors related to repeated elements during parsing.
pub trait RepeatedEmitter<'a, O: ?Sized, L, Lang: ?Sized = ()>: Emitter<'a, L, Lang> {
  /// Emits an error indicating that too few elements were found.
  fn emit_too_few(&mut self, err: TooFew<O, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an error indicating that too many elements were found.
  fn emit_too_many(&mut self, err: TooMany<O, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;

  /// Emits an error indicating that the given container is full, and cannot accept more elements.
  fn emit_full_container(
    &mut self,
    err: FullContainer<O, L::Span, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'a>;
}

impl<'a, O, L, U, Lang: ?Sized> RepeatedEmitter<'a, O, L, Lang> for &mut U
where
  U: RepeatedEmitter<'a, O, L, Lang>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_too_few(&mut self, err: TooFew<O, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_too_few(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_too_many(&mut self, err: TooMany<O, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_too_many(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_full_container(&mut self, err: FullContainer<O, L::Span, Lang>) -> Result<(), Self::Error>
  where
    L: Lexer<'a>,
  {
    (**self).emit_full_container(err)
  }
}

/// A trait bound for emitters that handle separated-by syntax errors.
pub trait FromRepeatedEmitterError<'a, O: ?Sized, L, Lang: ?Sized = ()> {
  /// Creates an emitter error from a too few elements error.
  fn from_too_few(err: TooFew<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;

  /// Creates an emitter error from a too many elements error.
  fn from_too_many(err: TooMany<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;

  /// Creates an emitter error from a full container error.
  fn from_full_container(err: FullContainer<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>;
}

impl<'a, T, O: ?Sized, L, Lang: ?Sized> FromRepeatedEmitterError<'a, O, L, Lang> for T
where
  L: Lexer<'a>,
  T: From<TooFew<O, L::Span, Lang>>
    + From<TooMany<O, L::Span, Lang>>
    + From<FullContainer<O, L::Span, Lang>>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_too_few(err: TooFew<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_too_many(err: TooMany<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_full_container(err: FullContainer<O, L::Span, Lang>) -> Self
  where
    L: Lexer<'a>,
  {
    err.into()
  }
}

/// An emitter that handles missing separator or repeated separators found during parsing.
pub trait SeparatedByEmitter<'inp, O, Sep, L, Lang: ?Sized = ()>:
  RepeatedEmitter<'inp, O, L, Lang>
  + BatchEmitter<'inp, L, UnexpectedLeadingOf<'inp, Sep, L, Lang>, Lang>
  + BatchEmitter<'inp, L, UnexpectedTrailingOf<'inp, Sep, L, Lang>, Lang>
  + BatchEmitter<'inp, L, UnexpectedRepeatedOf<'inp, Sep, L, Lang>, Lang>
where
  L: Lexer<'inp>,
{
  /// Emits an error or warning for a missing separator found during parsing.
  fn emit_missing_separator(
    &mut self,
    err: MissingSeparatorOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a missing an element after a leading separator.
  fn emit_missing_element(
    &mut self,
    err: MissingSyntaxOf<'inp, O, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a missing a leading separator found during parsing.
  fn emit_missing_leading_separator(
    &mut self,
    err: MissingLeadingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a missing a trailing separator found during parsing.
  fn emit_missing_trailing_separator(
    &mut self,
    err: MissingTrailingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a repeated separators found during parsing.
  ///
  /// The `span` covers all the repeated separators.
  fn emit_unexpected_repeated_separator(
    &mut self,
    err: UnexpectedRepeatedOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a leading separator(s) found during parsing.
  ///
  /// The `leadings` covers the leading separator(s).
  fn emit_unexpected_leading_separator(
    &mut self,
    err: UnexpectedLeadingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;

  /// Emits an error or warning for a trailing separator(s) found during parsing.
  ///
  /// The `trailings` covers the trailing separator(s).
  fn emit_unexpected_trailing_separator(
    &mut self,
    err: UnexpectedTrailingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>;
}

impl<'inp, O, L, Sep, U, Lang: ?Sized> SeparatedByEmitter<'inp, O, Sep, L, Lang> for &mut U
where
  L: Lexer<'inp>,
  U: SeparatedByEmitter<'inp, O, Sep, L, Lang>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_missing_separator(
    &mut self,
    err: MissingSeparatorOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_missing_separator(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_missing_element(
    &mut self,
    err: MissingSyntaxOf<'inp, O, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_missing_element(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_missing_leading_separator(
    &mut self,
    err: MissingLeadingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_missing_leading_separator(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_missing_trailing_separator(
    &mut self,
    err: MissingTrailingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_missing_trailing_separator(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unexpected_repeated_separator(
    &mut self,
    err: UnexpectedRepeatedOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_unexpected_repeated_separator(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unexpected_leading_separator(
    &mut self,
    err: UnexpectedLeadingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_unexpected_leading_separator(err)
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn emit_unexpected_trailing_separator(
    &mut self,
    err: UnexpectedTrailingOf<'inp, Sep, L, Lang>,
  ) -> Result<(), Self::Error>
  where
    L: Lexer<'inp>,
  {
    (**self).emit_unexpected_trailing_separator(err)
  }
}

/// A trait bound for converting separated-by emitter errors into emitter errors.
pub trait FromSeparatedByEmitterError<'inp, O, Sep, L, Lang: ?Sized = ()>:
  FromRepeatedEmitterError<'inp, O, L, Lang>
  + FromEmitterError<'inp, L, Lang>
  + From<UnexpectedLeadingOf<'inp, Sep, L, Lang>>
  + From<UnexpectedTrailingOf<'inp, Sep, L, Lang>>
  + From<UnexpectedRepeatedOf<'inp, Sep, L, Lang>>
where
  L: Lexer<'inp>,
{
  /// Creates an emitter error from a missing separator error.
  fn from_missing_separator(err: MissingSeparatorOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from a missing element error.
  fn from_missing_element(err: MissingSyntaxOf<'inp, O, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from a missing leading separator error.
  fn from_missing_leading_separator(err: MissingLeadingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from a missing trailing separator error.
  fn from_missing_trailing_separator(err: MissingTrailingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from an unexpected repeated separator error.
  fn from_unexpected_repeated_separator(err: UnexpectedRepeatedOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from an unexpected leading separator error.
  fn from_unexpected_leading_separator(err: UnexpectedLeadingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;

  /// Creates an emitter error from an unexpected trailing separator error.
  fn from_unexpected_trailing_separator(err: UnexpectedTrailingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>;
}

impl<'inp, T, O, Sep, L, Lang: ?Sized> FromSeparatedByEmitterError<'inp, O, Sep, L, Lang> for T
where
  L: Lexer<'inp>,
  T: From<MissingSeparatorOf<'inp, Sep, L, Lang>>
    + From<MissingSyntaxOf<'inp, O, L, Lang>>
    + From<MissingLeadingOf<'inp, Sep, L, Lang>>
    + From<MissingTrailingOf<'inp, Sep, L, Lang>>
    + From<UnexpectedRepeatedOf<'inp, Sep, L, Lang>>
    + From<UnexpectedLeadingOf<'inp, Sep, L, Lang>>
    + From<UnexpectedTrailingOf<'inp, Sep, L, Lang>>
    + FromEmitterError<'inp, L, Lang>
    + FromRepeatedEmitterError<'inp, O, L, Lang>,
{
  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_missing_separator(err: MissingSeparatorOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_missing_element(err: MissingSyntaxOf<'inp, O, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_missing_leading_separator(err: MissingLeadingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_missing_trailing_separator(err: MissingTrailingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unexpected_repeated_separator(err: UnexpectedRepeatedOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unexpected_leading_separator(err: UnexpectedLeadingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }

  #[cfg_attr(not(tarpaulin), inline(always))]
  fn from_unexpected_trailing_separator(err: UnexpectedTrailingOf<'inp, Sep, L, Lang>) -> Self
  where
    L: Lexer<'inp>,
  {
    err.into()
  }
}