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
use self::RuleResult::{Matched, Failed};
use self::super::super::{HrxEntryData, HrxEntry, HrxPath};
use std::num::NonZeroUsize;
fn escape_default(s: &str) -> String {
    s.chars().flat_map(|c| c.escape_default()).collect()
}
fn char_range_at(s: &str, pos: usize) -> (char, usize) {
    let c = &s[pos..].chars().next().unwrap();
    let next_pos = pos + c.len_utf8();
    (*c, next_pos)
}
#[derive(Clone)]
enum RuleResult<T> {
    Matched(usize, T),
    Failed,
}
#[derive(PartialEq, Eq, Debug, Clone)]
/// HRX parsing error 
pub struct ParseError {
/// 1-based line # of error 
    pub line: usize,
/// 1-based column # of error 
    pub column: usize,
/// Byte offset of error 
    pub offset: usize,
/// Expected but unmatched rules 
    pub expected: ::std::collections::HashSet<&'static str>,
}
/// Convenience result type 
pub type ParseResult<T> = Result<T, ParseError>;
impl ::std::fmt::Display for ParseError {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
        write!(fmt, "error at {}:{}: expected ", self.line, self.column)?;
        if self.expected.len() == 0 {
            write!(fmt, "EOF")?;
        } else if self.expected.len() == 1 {
            write!(fmt, "`{}`", escape_default(self.expected.iter().next().unwrap()))?;
        } else {
            let mut iter = self.expected.iter();
            write!(fmt, "one of `{}`", escape_default(iter.next().unwrap()))?;
            for elem in iter {
                write!(fmt, ", `{}`", escape_default(elem))?;
            }
        }
        Ok(())
    }
}
impl ::std::error::Error for ParseError {
    fn description(&self) -> &str {
        "parse error"
    }
}
fn slice_eq(input: &str, state: &mut ParseState, pos: usize, m: &'static str) -> RuleResult<()> {
# ! [inline] # ! [allow(dead_code)]    let l = m.len();
    if input.len() >= pos + l && &input.as_bytes()[pos..pos + l] == m.as_bytes() {
        Matched(pos + l, ())
    } else {
        state.mark_failure(pos, m)
    }
}
fn slice_eq_case_insensitive(input: &str, state: &mut ParseState, pos: usize, m: &'static str) -> RuleResult<()> {
# ! [inline] # ! [allow(dead_code)]    let mut used = 0usize;
    let mut input_iter = input[pos..].chars().flat_map(|x| x.to_uppercase());
    for m_char_upper in m.chars().flat_map(|x| x.to_uppercase()) {
        used += m_char_upper.len_utf8();
        let input_char_result = input_iter.next();
        if input_char_result.is_none() || input_char_result.unwrap() != m_char_upper {
            return state.mark_failure(pos, m);
        }
    }
    Matched(pos + used, ())
}
fn any_char(input: &str, state: &mut ParseState, pos: usize) -> RuleResult<()> {
# ! [inline] # ! [allow(dead_code)]    if input.len() > pos {
        let (_, next) = char_range_at(input, pos);
        Matched(next, ())
    } else {
        state.mark_failure(pos, "<character>")
    }
}
fn pos_to_line(input: &str, pos: usize) -> (usize, usize) {
    let before = &input[..pos];
    let line = before.as_bytes().iter().filter(|&&c| c == b'\n').count() + 1;
    let col = before.chars().rev().take_while(|&c| c != '\n').count() + 1;
    (line, col)
}
impl<'input> ParseState<'input> {
    fn mark_failure(&mut self, pos: usize, expected: &'static str) -> RuleResult<()> {
        if self.suppress_fail == 0 {
            if pos > self.max_err_pos {
                self.max_err_pos = pos;
                self.expected.clear();
            }
            if pos == self.max_err_pos {
                self.expected.insert(expected);
            }
        }
        Failed
    }
}
struct ParseState<'input> {
    max_err_pos: usize,
    suppress_fail: usize,
    expected: ::std::collections::HashSet<&'static str>,
    _phantom: ::std::marker::PhantomData<&'input ()>,
}
impl<'input> ParseState<'input> {
    fn new() -> ParseState<'input> {
        ParseState {
            max_err_pos: 0,
            suppress_fail: 0,
            expected: ::std::collections::HashSet::new(),
            _phantom: ::std::marker::PhantomData,
        }
    }
}

fn __parse_archive<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize)
    -> RuleResult<(Option<String>, Vec<(HrxPath, HrxEntry)>, NonZeroUsize)> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = {
            let mut __repeat_pos = __pos;
            let mut __repeat_value = vec![];
            loop {
                let __pos = __repeat_pos;
                let __step_res = __parse_entry(__input, __state, __pos, boundary_length);
                match __step_res {
                    Matched(__newpos, __value) => {
                        __repeat_pos = __newpos;
                        __repeat_value.push(__value);
                    }
                    Failed => {
                        break;
                    }
                }
            }
            Matched(__repeat_pos, __repeat_value)
        };
        match __seq_res {
            Matched(__pos, ee) => {
                let __seq_res = match __parse_comment(__input, __state, __pos, boundary_length) {
                    Matched(__newpos, __value) => Matched(__newpos, Some(__value)),
                    Failed => Matched(__pos, None),
                };
                match __seq_res {
                    Matched(__pos, c) => {
                        Matched(__pos, {
                            (c.map(str::to_string), ee, boundary_length)
                        })
                    }
                    Failed => Failed,
                }
            }
            Failed => Failed,
        }
    }
}

fn __parse_entry<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize)
    -> RuleResult<(HrxPath, HrxEntry)> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __choice_res = {
            let __seq_res = match __parse_comment(__input, __state, __pos, boundary_length) {
                Matched(__newpos, __value) => Matched(__newpos, Some(__value)),
                Failed => Matched(__pos, None),
            };
            match __seq_res {
                Matched(__pos, c) => {
                    let __seq_res = __parse_file(__input, __state, __pos, boundary_length);
                    match __seq_res {
                        Matched(__pos, d) => {
                            Matched(__pos, {
                                (
                                    d.0,
                                    HrxEntry {
                                        comment: c.map(str::to_string),
                                        data: HrxEntryData::File { body: d.1.map(str::to_string) },
                                    },
                                )
                            })
                        }
                        Failed => Failed,
                    }
                }
                Failed => Failed,
            }
        };
        match __choice_res {
            Matched(__pos, __value) => Matched(__pos, __value),
            Failed => {
                let __seq_res = match __parse_comment(__input, __state, __pos, boundary_length) {
                    Matched(__newpos, __value) => Matched(__newpos, Some(__value)),
                    Failed => Matched(__pos, None),
                };
                match __seq_res {
                    Matched(__pos, c) => {
                        let __seq_res = __parse_directory(__input, __state, __pos, boundary_length);
                        match __seq_res {
                            Matched(__pos, d) => {
                                Matched(__pos, {
                                    (
                                        d,
                                        HrxEntry {
                                            comment: c.map(str::to_string),
                                            data: HrxEntryData::Directory,
                                        },
                                    )
                                })
                            }
                            Failed => Failed,
                        }
                    }
                    Failed => Failed,
                }
            }
        }
    }
}

fn __parse_comment<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = __parse_boundary(__input, __state, __pos, boundary_length);
        match __seq_res {
            Matched(__pos, _) => {
                let __seq_res = __parse_newline(__input, __state, __pos, boundary_length);
                match __seq_res {
                    Matched(__pos, _) => {
                        let __seq_res = __parse_body(__input, __state, __pos, boundary_length);
                        match __seq_res {
                            Matched(__pos, b) => {
                                Matched(__pos, {
                                    b
                                })
                            }
                            Failed => Failed,
                        }
                    }
                    Failed => Failed,
                }
            }
            Failed => Failed,
        }
    }
}

fn __parse_file<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize)
    -> RuleResult<(HrxPath, Option<&'input str>)> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = __parse_boundary(__input, __state, __pos, boundary_length);
        match __seq_res {
            Matched(__pos, _) => {
                let __seq_res = {
                    let mut __repeat_pos = __pos;
                    let mut __repeat_value = vec![];
                    loop {
                        let __pos = __repeat_pos;
                        let __step_res = slice_eq(__input, __state, __pos, " ");
                        match __step_res {
                            Matched(__newpos, __value) => {
                                __repeat_pos = __newpos;
                                __repeat_value.push(__value);
                            }
                            Failed => {
                                break;
                            }
                        }
                    }
                    if __repeat_value.len() >= 1 {
                        Matched(__repeat_pos, ())
                    } else {
                        Failed
                    }
                };
                match __seq_res {
                    Matched(__pos, _) => {
                        let __seq_res = __parse_path(__input, __state, __pos, boundary_length);
                        match __seq_res {
                            Matched(__pos, p) => {
                                let __seq_res = __parse_newline(__input, __state, __pos, boundary_length);
                                match __seq_res {
                                    Matched(__pos, _) => {
                                        let __seq_res = match __parse_body(__input, __state, __pos, boundary_length) {
                                            Matched(__newpos, __value) => Matched(__newpos, Some(__value)),
                                            Failed => Matched(__pos, None),
                                        };
                                        match __seq_res {
                                            Matched(__pos, b) => {
                                                Matched(__pos, {
                                                    (p, b)
                                                })
                                            }
                                            Failed => Failed,
                                        }
                                    }
                                    Failed => Failed,
                                }
                            }
                            Failed => Failed,
                        }
                    }
                    Failed => Failed,
                }
            }
            Failed => Failed,
        }
    }
}

fn __parse_directory<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<HrxPath> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = __parse_boundary(__input, __state, __pos, boundary_length);
        match __seq_res {
            Matched(__pos, _) => {
                let __seq_res = {
                    let mut __repeat_pos = __pos;
                    let mut __repeat_value = vec![];
                    loop {
                        let __pos = __repeat_pos;
                        let __step_res = slice_eq(__input, __state, __pos, " ");
                        match __step_res {
                            Matched(__newpos, __value) => {
                                __repeat_pos = __newpos;
                                __repeat_value.push(__value);
                            }
                            Failed => {
                                break;
                            }
                        }
                    }
                    if __repeat_value.len() >= 1 {
                        Matched(__repeat_pos, ())
                    } else {
                        Failed
                    }
                };
                match __seq_res {
                    Matched(__pos, _) => {
                        let __seq_res = __parse_path(__input, __state, __pos, boundary_length);
                        match __seq_res {
                            Matched(__pos, p) => {
                                let __seq_res = slice_eq(__input, __state, __pos, "/");
                                match __seq_res {
                                    Matched(__pos, _) => {
                                        let __seq_res = {
                                            let mut __repeat_pos = __pos;
                                            let mut __repeat_value = vec![];
                                            loop {
                                                let __pos = __repeat_pos;
                                                let __step_res = __parse_newline(__input, __state, __pos, boundary_length);
                                                match __step_res {
                                                    Matched(__newpos, __value) => {
                                                        __repeat_pos = __newpos;
                                                        __repeat_value.push(__value);
                                                    }
                                                    Failed => {
                                                        break;
                                                    }
                                                }
                                            }
                                            if __repeat_value.len() >= 1 {
                                                Matched(__repeat_pos, ())
                                            } else {
                                                Failed
                                            }
                                        };
                                        match __seq_res {
                                            Matched(__pos, _) => {
                                                Matched(__pos, {
                                                    p
                                                })
                                            }
                                            Failed => Failed,
                                        }
                                    }
                                    Failed => Failed,
                                }
                            }
                            Failed => Failed,
                        }
                    }
                    Failed => Failed,
                }
            }
            Failed => Failed,
        }
    }
}

/// `"<" "="+ ">"`
///
/// Must exactly match the first boundary in the archive
fn __parse_boundary<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<()> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = slice_eq(__input, __state, __pos, "<");
        match __seq_res {
            Matched(__pos, _) => {
                let __seq_res = {
                    let mut __repeat_pos = __pos;
                    let mut __repeat_value = vec![];
                    loop {
                        let __pos = __repeat_pos;
                        if __repeat_value.len() >=
                            {
                                boundary_length.get()
                            }
                        {
                            break;
                        }
                        let __step_res = slice_eq(__input, __state, __pos, "=");
                        match __step_res {
                            Matched(__newpos, __value) => {
                                __repeat_pos = __newpos;
                                __repeat_value.push(__value);
                            }
                            Failed => {
                                break;
                            }
                        }
                    }
                    if __repeat_value.len() >=
                        {
                            boundary_length.get()
                        }
                    {
                        Matched(__repeat_pos, ())
                    } else {
                        Failed
                    }
                };
                match __seq_res {
                    Matched(__pos, _) => slice_eq(__input, __state, __pos, ">"),
                    Failed => Failed,
                }
            }
            Failed => Failed,
        }
    }
}

/// U+000A LINE FEED
fn __parse_newline<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<()> {# ! [ allow ( non_snake_case , unused ) ]    slice_eq(__input, __state, __pos, "\n")
}

fn __parse_body<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    __parse_contents(__input, __state, __pos, boundary_length)
}

/// Any sequence of characters that neither begins with `boundary` nor includes U+000A LINE FEED followed immediately by `boundary`
///
/// The fist pattern stolen from the `@E` "Search loop" expansion from here https://nim-lang.org/docs/pegs.html
fn __parse_contents<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __choice_res = {
            let __seq_res = {
                __state.suppress_fail += 1;
                let __assert_res = __parse_boundary(__input, __state, __pos, boundary_length);
                __state.suppress_fail -= 1;
                match __assert_res {
                    Failed => Matched(__pos, ()),
                    Matched(..) => Failed,
                }
            };
            match __seq_res {
                Matched(__pos, _) => {
                    let __seq_res = {
                        let str_start = __pos;
                        match {
                            let mut __repeat_pos = __pos;
                            let mut __repeat_value = vec![];
                            loop {
                                let __pos = __repeat_pos;
                                let __step_res = {
                                    let __seq_res = {
                                        __state.suppress_fail += 1;
                                        let __assert_res = {
                                            let __seq_res = __parse_newline(__input, __state, __pos, boundary_length);
                                            match __seq_res {
                                                Matched(__pos, _) => __parse_boundary(__input, __state, __pos, boundary_length),
                                                Failed => Failed,
                                            }
                                        };
                                        __state.suppress_fail -= 1;
                                        match __assert_res {
                                            Failed => Matched(__pos, ()),
                                            Matched(..) => Failed,
                                        }
                                    };
                                    match __seq_res {
                                        Matched(__pos, _) => any_char(__input, __state, __pos),
                                        Failed => Failed,
                                    }
                                };
                                match __step_res {
                                    Matched(__newpos, __value) => {
                                        __repeat_pos = __newpos;
                                        __repeat_value.push(__value);
                                    }
                                    Failed => {
                                        break;
                                    }
                                }
                            }
                            if __repeat_value.len() >= 1 {
                                Matched(__repeat_pos, ())
                            } else {
                                Failed
                            }
                        } {
                            Matched(__newpos, _) => Matched(__newpos, &__input[str_start..__newpos]),
                            Failed => Failed,
                        }
                    };
                    match __seq_res {
                        Matched(__pos, ctnt) => {
                            let __seq_res = __parse_newline(__input, __state, __pos, boundary_length);
                            match __seq_res {
                                Matched(__pos, _) => {
                                    let __seq_res = {
                                        __state.suppress_fail += 1;
                                        let __assert_res = __parse_boundary(__input, __state, __pos, boundary_length);
                                        __state.suppress_fail -= 1;
                                        match __assert_res {
                                            Matched(_, __value) => Matched(__pos, __value),
                                            Failed => Failed,
                                        }
                                    };
                                    match __seq_res {
                                        Matched(__pos, _) => {
                                            Matched(__pos, {
                                                ctnt
                                            })
                                        }
                                        Failed => Failed,
                                    }
                                }
                                Failed => Failed,
                            }
                        }
                        Failed => Failed,
                    }
                }
                Failed => Failed,
            }
        };
        match __choice_res {
            Matched(__pos, __value) => Matched(__pos, __value),
            Failed => {
                let __seq_res = {
                    __state.suppress_fail += 1;
                    let __assert_res = __parse_boundary(__input, __state, __pos, boundary_length);
                    __state.suppress_fail -= 1;
                    match __assert_res {
                        Failed => Matched(__pos, ()),
                        Matched(..) => Failed,
                    }
                };
                match __seq_res {
                    Matched(__pos, _) => {
                        let __seq_res = {
                            let str_start = __pos;
                            match {
                                let mut __repeat_pos = __pos;
                                let mut __repeat_value = vec![];
                                loop {
                                    let __pos = __repeat_pos;
                                    let __step_res = any_char(__input, __state, __pos);
                                    match __step_res {
                                        Matched(__newpos, __value) => {
                                            __repeat_pos = __newpos;
                                            __repeat_value.push(__value);
                                        }
                                        Failed => {
                                            break;
                                        }
                                    }
                                }
                                if __repeat_value.len() >= 1 {
                                    Matched(__repeat_pos, ())
                                } else {
                                    Failed
                                }
                            } {
                                Matched(__newpos, _) => Matched(__newpos, &__input[str_start..__newpos]),
                                Failed => Failed,
                            }
                        };
                        match __seq_res {
                            Matched(__pos, ctnt) => {
                                Matched(__pos, {
                                    ctnt
                                })
                            }
                            Failed => Failed,
                        }
                    }
                    Failed => Failed,
                }
            }
        }
    }
}

fn __parse_path<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<HrxPath> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = {
            let str_start = __pos;
            match {
                let __seq_res = match __parse_path_component(__input, __state, __pos, boundary_length) {
                    Matched(pos, _) => Matched(pos, ()),
                    Failed => Failed,
                };
                match __seq_res {
                    Matched(__pos, _) => {
                        let mut __repeat_pos = __pos;
                        loop {
                            let __pos = __repeat_pos;
                            let __step_res = {
                                let __seq_res = slice_eq(__input, __state, __pos, "/");
                                match __seq_res {
                                    Matched(__pos, _) => {
                                        match __parse_path_component(__input, __state, __pos, boundary_length) {
                                            Matched(pos, _) => Matched(pos, ()),
                                            Failed => Failed,
                                        }
                                    }
                                    Failed => Failed,
                                }
                            };
                            match __step_res {
                                Matched(__newpos, __value) => {
                                    __repeat_pos = __newpos;
                                }
                                Failed => {
                                    break;
                                }
                            }
                        }
                        Matched(__repeat_pos, ())
                    }
                    Failed => Failed,
                }
            } {
                Matched(__newpos, _) => Matched(__newpos, &__input[str_start..__newpos]),
                Failed => Failed,
            }
        };
        match __seq_res {
            Matched(__pos, p) => {
                Matched(__pos, {
                    HrxPath(p.to_string())
                })
            }
            Failed => Failed,
        }
    }
}

/// `path-character+`
///
/// Not equal to `"."` or `".."`
fn __parse_path_component<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize)
    -> RuleResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __seq_res = {
            let str_start = __pos;
            match {
                let mut __repeat_pos = __pos;
                let mut __repeat_value = vec![];
                loop {
                    let __pos = __repeat_pos;
                    let __step_res = match __parse_path_character(__input, __state, __pos, boundary_length) {
                        Matched(pos, _) => Matched(pos, ()),
                        Failed => Failed,
                    };
                    match __step_res {
                        Matched(__newpos, __value) => {
                            __repeat_pos = __newpos;
                            __repeat_value.push(__value);
                        }
                        Failed => {
                            break;
                        }
                    }
                }
                if __repeat_value.len() >= 1 {
                    Matched(__repeat_pos, ())
                } else {
                    Failed
                }
            } {
                Matched(__newpos, _) => Matched(__newpos, &__input[str_start..__newpos]),
                Failed => Failed,
            }
        };
        match __seq_res {
            Matched(__pos, pc) => {
                match {
                    if pc == "." || pc == ".." {
                        Err("Invalid '.' or '..' path component")
                    } else {
                        Ok(pc)
                    }
                } {
                    Ok(res) => Matched(__pos, res),
                    Err(expected) => {
                        __state.mark_failure(__pos, expected);
                        Failed
                    }
                }
            }
            Failed => Failed,
        }
    }
}

/// Any character other than U+0000 through U+001F, U+007F DELETE, U+002F SOLIDUS, U+003A COLON, or U+005C REVERSE SOLIDUS
fn __parse_path_character<'input>(__input: &'input str, __state: &mut ParseState<'input>, __pos: usize, boundary_length: NonZeroUsize) -> RuleResult<char> {# ! [ allow ( non_snake_case , unused ) ]    {
        let __choice_res = {
            __state.suppress_fail += 1;
            let res = {
                let __seq_res = {
                    let str_start = __pos;
                    match if __input.len() > __pos {
                        let (__ch, __next) = char_range_at(__input, __pos);
                        match __ch {
                            '\0'...'\u{1f}' | '\u{7f}' | '/' | ':' | '\\' => __state.mark_failure(__pos, "[^\0-\u{1f}\u{7f}/:\\]"),
                            _ => Matched(__next, ()),
                        }
                    } else {
                        __state.mark_failure(__pos, "[^\0-\u{1f}\u{7f}/:\\]")
                    } {
                        Matched(__newpos, _) => Matched(__newpos, &__input[str_start..__newpos]),
                        Failed => Failed,
                    }
                };
                match __seq_res {
                    Matched(__pos, c) => {
                        Matched(__pos, {
                            c.chars().next().unwrap()
                        })
                    }
                    Failed => Failed,
                }
            };
            __state.suppress_fail -= 1;
            res
        };
        match __choice_res {
            Matched(__pos, __value) => Matched(__pos, __value),
            Failed => {
                __state.mark_failure(
                    __pos,
                    "Any character other than U+0000 through U+001F, U+007F DELETE, U+002F SOLIDUS, U+003A COLON, or U+005C REVERSE SOLIDUS",
                );
                Failed
            }
        }
    }
}

/// `entry* comment?`
///
/// Note, that this does not perform any content validation beyond grammar.
pub fn archive<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<(Option<String>, Vec<(HrxPath, HrxEntry)>, NonZeroUsize)> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_archive(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `comment? (file | directory)`
pub fn entry<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<(HrxPath, HrxEntry)> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_entry(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `boundary newline body`
pub fn comment<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_comment(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `boundary " "+ path newline body?`
pub fn file<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<(HrxPath, Option<&'input str>)> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_file(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `boundary " "+ path "/" newline+`
pub fn directory<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<HrxPath> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_directory(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `contents newline`
///
/// No newline at the end of the archive (if the archive ends in a body, all trailing newlines are part of that body's contents)
///
/// NB: this doesn't explicitly consume a newline as that has been moved down to `contents`.
pub fn body<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<&'input str> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_body(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}

/// `path-component ("/" path-component)*`
pub fn path<'input>(__input: &'input str, boundary_length: NonZeroUsize) -> ParseResult<HrxPath> {# ! [ allow ( non_snake_case , unused ) ]    let mut __state = ParseState::new();
    match __parse_path(__input, &mut __state, 0, boundary_length) {
        Matched(__pos, __value) => {
            if __pos == __input.len() {
                return Ok(__value);
            }
        }
        _ => {}
    }
    let (__line, __col) = pos_to_line(__input, __state.max_err_pos);
    Err(ParseError {
        line: __line,
        column: __col,
        offset: __state.max_err_pos,
        expected: __state.expected,
    })
}