forked from rrevenantt/antlr4rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
labelsparser.rs
1462 lines (1311 loc) · 53.9 KB
/
labelsparser.rs
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
// Generated from Labels.g4 by ANTLR 4.8
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(nonstandard_style)]
#![allow(unused_imports)]
#![allow(unused_mut)]
#![allow(unused_braces)]
use super::labelslistener::*;
use antlr_rust::atn::{ATN, INVALID_ALT};
use antlr_rust::atn_deserializer::ATNDeserializer;
use antlr_rust::dfa::DFA;
use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy};
use antlr_rust::errors::*;
use antlr_rust::int_stream::EOF;
use antlr_rust::lazy_static;
use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog};
use antlr_rust::parser_atn_simulator::ParserATNSimulator;
use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext};
use antlr_rust::recognizer::{Actions, Recognizer};
use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext};
use antlr_rust::token::{OwningToken, Token, TOKEN_EOF};
use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory};
use antlr_rust::token_stream::TokenStream;
use antlr_rust::tree::*;
use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl};
use antlr_rust::PredictionContextCache;
use antlr_rust::TokenSource;
use antlr_rust::{TidAble, TidExt};
use std::any::{Any, TypeId};
use std::borrow::{Borrow, BorrowMut};
use std::cell::RefCell;
use std::convert::TryFrom;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use std::sync::Arc;
pub const T__0: isize = 1;
pub const T__1: isize = 2;
pub const T__2: isize = 3;
pub const T__3: isize = 4;
pub const T__4: isize = 5;
pub const T__5: isize = 6;
pub const ID: isize = 7;
pub const INT: isize = 8;
pub const WS: isize = 9;
pub const RULE_s: usize = 0;
pub const RULE_e: usize = 1;
pub const ruleNames: [&'static str; 2] = ["s", "e"];
pub const _LITERAL_NAMES: [Option<&'static str>; 7] = [
None,
Some("'*'"),
Some("'+'"),
Some("'('"),
Some("')'"),
Some("'++'"),
Some("'--'"),
];
pub const _SYMBOLIC_NAMES: [Option<&'static str>; 10] = [
None,
None,
None,
None,
None,
None,
None,
Some("ID"),
Some("INT"),
Some("WS"),
];
lazy_static! {
static ref _shared_context_cache: Arc<PredictionContextCache> =
Arc::new(PredictionContextCache::new());
static ref VOCABULARY: Box<dyn Vocabulary> = Box::new(VocabularyImpl::new(
_LITERAL_NAMES.iter(),
_SYMBOLIC_NAMES.iter(),
None
));
}
type BaseParserType<'input, I> = BaseParser<
'input,
LabelsParserExt<'input>,
I,
LabelsParserContextType,
dyn LabelsListener<'input> + 'input,
>;
type TokenType<'input> = <LocalTokenFactory<'input> as TokenFactory<'input>>::Tok;
pub type LocalTokenFactory<'input> = CommonTokenFactory;
pub type LabelsTreeWalker<'input, 'a> =
ParseTreeWalker<'input, 'a, LabelsParserContextType, dyn LabelsListener<'input> + 'a>;
/// Parser for Labels grammar
pub struct LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
base: BaseParserType<'input, I>,
interpreter: Arc<ParserATNSimulator>,
_shared_context_cache: Box<PredictionContextCache>,
pub err_handler: H,
}
impl<'input, I, H> LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
pub fn get_serialized_atn() -> &'static str {
_serializedATN
}
pub fn set_error_strategy(&mut self, strategy: H) {
self.err_handler = strategy
}
pub fn with_strategy(input: I, strategy: H) -> Self {
antlr_rust::recognizer::check_version("0", "3");
let interpreter = Arc::new(ParserATNSimulator::new(
_ATN.clone(),
_decision_to_DFA.clone(),
_shared_context_cache.clone(),
));
Self {
base: BaseParser::new_base_parser(
input,
Arc::clone(&interpreter),
LabelsParserExt {
_pd: Default::default(),
},
),
interpreter,
_shared_context_cache: Box::new(PredictionContextCache::new()),
err_handler: strategy,
}
}
}
type DynStrategy<'input, I> = Box<dyn ErrorStrategy<'input, BaseParserType<'input, I>> + 'input>;
impl<'input, I> LabelsParser<'input, I, DynStrategy<'input, I>>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
{
pub fn with_dyn_strategy(input: I) -> Self {
Self::with_strategy(input, Box::new(DefaultErrorStrategy::new()))
}
}
impl<'input, I> LabelsParser<'input, I, DefaultErrorStrategy<'input, LabelsParserContextType>>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
{
pub fn new(input: I) -> Self {
Self::with_strategy(input, DefaultErrorStrategy::new())
}
}
/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for LabelsParser
pub trait LabelsParserContext<'input>:
for<'x> Listenable<dyn LabelsListener<'input> + 'x>
+ ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = LabelsParserContextType>
{
}
antlr_rust::coerce_from! { 'input : LabelsParserContext<'input> }
impl<'input> LabelsParserContext<'input> for TerminalNode<'input, LabelsParserContextType> {}
impl<'input> LabelsParserContext<'input> for ErrorNode<'input, LabelsParserContextType> {}
antlr_rust::tid! { impl<'input> TidAble<'input> for dyn LabelsParserContext<'input> + 'input }
antlr_rust::tid! { impl<'input> TidAble<'input> for dyn LabelsListener<'input> + 'input }
pub struct LabelsParserContextType;
antlr_rust::tid! {LabelsParserContextType}
impl<'input> ParserNodeType<'input> for LabelsParserContextType {
type TF = LocalTokenFactory<'input>;
type Type = dyn LabelsParserContext<'input> + 'input;
}
impl<'input, I, H> Deref for LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
type Target = BaseParserType<'input, I>;
fn deref(&self) -> &Self::Target {
&self.base
}
}
impl<'input, I, H> DerefMut for LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.base
}
}
pub struct LabelsParserExt<'input> {
_pd: PhantomData<&'input str>,
}
impl<'input> LabelsParserExt<'input> {}
antlr_rust::tid! { LabelsParserExt<'a> }
impl<'input> TokenAware<'input> for LabelsParserExt<'input> {
type TF = LocalTokenFactory<'input>;
}
impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>>
ParserRecog<'input, BaseParserType<'input, I>> for LabelsParserExt<'input>
{
}
impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>>
Actions<'input, BaseParserType<'input, I>> for LabelsParserExt<'input>
{
fn get_grammar_file_name(&self) -> &str {
"Labels.g4"
}
fn get_rule_names(&self) -> &[&str] {
&ruleNames
}
fn get_vocabulary(&self) -> &dyn Vocabulary {
&**VOCABULARY
}
fn sempred(
_localctx: Option<&(dyn LabelsParserContext<'input> + 'input)>,
rule_index: isize,
pred_index: isize,
recog: &mut BaseParserType<'input, I>,
) -> bool {
match rule_index {
1 => LabelsParser::<'input, I, _>::e_sempred(
_localctx.and_then(|x| x.downcast_ref()),
pred_index,
recog,
),
_ => true,
}
}
}
impl<'input, I> LabelsParser<'input, I, DefaultErrorStrategy<'input, LabelsParserContextType>>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
{
fn e_sempred(
_localctx: Option<&EContext<'input>>,
pred_index: isize,
recog: &mut <Self as Deref>::Target,
) -> bool {
match pred_index {
0 => recog.precpred(None, 7),
1 => recog.precpred(None, 6),
2 => recog.precpred(None, 3),
3 => recog.precpred(None, 2),
_ => true,
}
}
}
//------------------- s ----------------
pub type SContextAll<'input> = SContext<'input>;
pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>;
#[derive(Clone)]
pub struct SContextExt<'input> {
pub q: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
impl<'input> LabelsParserContext<'input> for SContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for SContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_s(self);
}
fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.exit_s(self);
listener.exit_every_rule(self);
}
}
impl<'input> CustomRuleContext<'input> for SContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_s
}
//fn type_rule_index() -> usize where Self: Sized { RULE_s }
}
antlr_rust::tid! {SContextExt<'a>}
impl<'input> SContextExt<'input> {
fn new(
parent: Option<Rc<dyn LabelsParserContext<'input> + 'input>>,
invoking_state: isize,
) -> Rc<SContextAll<'input>> {
Rc::new(BaseParserRuleContext::new_parser_ctx(
parent,
invoking_state,
SContextExt {
q: None,
ph: PhantomData,
},
))
}
}
pub trait SContextAttrs<'input>:
LabelsParserContext<'input> + BorrowMut<SContextExt<'input>>
{
fn e(&self) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(0)
}
}
impl<'input> SContextAttrs<'input> for SContext<'input> {}
impl<'input, I, H> LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
pub fn s(&mut self) -> Result<Rc<SContextAll<'input>>, ANTLRError> {
let mut recog = self;
let _parentctx = recog.ctx.take();
let mut _localctx = SContextExt::new(_parentctx.clone(), recog.base.get_state());
recog.base.enter_rule(_localctx.clone(), 0, RULE_s);
let mut _localctx: Rc<SContextAll> = _localctx;
let result: Result<(), ANTLRError> = (|| {
//recog.base.enter_outer_alt(_localctx.clone(), 1);
recog.base.enter_outer_alt(None, 1);
{
/*InvokeRule e*/
recog.base.set_state(4);
let tmp = recog.e_rec(0)?;
cast_mut::<_, SContext>(&mut _localctx).q = Some(tmp.clone());
}
Ok(())
})();
match result {
Ok(_) => {}
Err(e @ ANTLRError::FallThrough(_)) => return Err(e),
Err(ref re) => {
//_localctx.exception = re;
recog.err_handler.report_error(&mut recog.base, re);
recog.err_handler.recover(&mut recog.base, re)?;
}
}
recog.base.exit_rule();
Ok(_localctx)
}
}
//------------------- e ----------------
#[derive(Debug)]
pub enum EContextAll<'input> {
AddContext(AddContext<'input>),
ParensContext(ParensContext<'input>),
MultContext(MultContext<'input>),
DecContext(DecContext<'input>),
AnIDContext(AnIDContext<'input>),
AnIntContext(AnIntContext<'input>),
IncContext(IncContext<'input>),
Error(EContext<'input>),
}
antlr_rust::tid! {EContextAll<'a>}
impl<'input> antlr_rust::parser_rule_context::DerefSeal for EContextAll<'input> {}
impl<'input> LabelsParserContext<'input> for EContextAll<'input> {}
impl<'input> Deref for EContextAll<'input> {
type Target = dyn EContextAttrs<'input> + 'input;
fn deref(&self) -> &Self::Target {
use EContextAll::*;
match self {
AddContext(inner) => inner,
ParensContext(inner) => inner,
MultContext(inner) => inner,
DecContext(inner) => inner,
AnIDContext(inner) => inner,
AnIntContext(inner) => inner,
IncContext(inner) => inner,
Error(inner) => inner,
}
}
}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for EContextAll<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
self.deref().enter(listener)
}
fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
self.deref().exit(listener)
}
}
pub type EContext<'input> = BaseParserRuleContext<'input, EContextExt<'input>>;
#[derive(Clone)]
pub struct EContextExt<'input> {
pub v: String,
ph: PhantomData<&'input str>,
}
impl<'input> LabelsParserContext<'input> for EContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for EContext<'input> {}
impl<'input> CustomRuleContext<'input> for EContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
antlr_rust::tid! {EContextExt<'a>}
impl<'input> EContextExt<'input> {
fn new(
parent: Option<Rc<dyn LabelsParserContext<'input> + 'input>>,
invoking_state: isize,
) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::Error(BaseParserRuleContext::new_parser_ctx(
parent,
invoking_state,
EContextExt {
v: Default::default(),
ph: PhantomData,
},
)))
}
}
pub trait EContextAttrs<'input>:
LabelsParserContext<'input> + BorrowMut<EContextExt<'input>>
{
fn get_v<'a>(&'a self) -> &'a String
where
'input: 'a,
{
&self.borrow().v
}
fn set_v(&mut self, attr: String) {
self.borrow_mut().v = attr;
}
}
impl<'input> EContextAttrs<'input> for EContext<'input> {}
pub type AddContext<'input> = BaseParserRuleContext<'input, AddContextExt<'input>>;
pub trait AddContextAttrs<'input>: LabelsParserContext<'input> {
fn e_all(&self) -> Vec<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.children_of_type()
}
fn e(&self, i: usize) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(i)
}
}
impl<'input> AddContextAttrs<'input> for AddContext<'input> {}
pub struct AddContextExt<'input> {
base: EContextExt<'input>,
pub a: Option<Rc<EContextAll<'input>>>,
pub b: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {AddContextExt<'a>}
impl<'input> LabelsParserContext<'input> for AddContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for AddContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_add(self);
}
}
impl<'input> CustomRuleContext<'input> for AddContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for AddContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for AddContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for AddContext<'input> {}
impl<'input> AddContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::AddContext(BaseParserRuleContext::copy_from(
ctx,
AddContextExt {
a: None,
b: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
pub type ParensContext<'input> = BaseParserRuleContext<'input, ParensContextExt<'input>>;
pub trait ParensContextAttrs<'input>: LabelsParserContext<'input> {
fn e(&self) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(0)
}
}
impl<'input> ParensContextAttrs<'input> for ParensContext<'input> {}
pub struct ParensContextExt<'input> {
base: EContextExt<'input>,
pub x: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {ParensContextExt<'a>}
impl<'input> LabelsParserContext<'input> for ParensContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for ParensContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_parens(self);
}
}
impl<'input> CustomRuleContext<'input> for ParensContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for ParensContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for ParensContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for ParensContext<'input> {}
impl<'input> ParensContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::ParensContext(
BaseParserRuleContext::copy_from(
ctx,
ParensContextExt {
x: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
),
))
}
}
pub type MultContext<'input> = BaseParserRuleContext<'input, MultContextExt<'input>>;
pub trait MultContextAttrs<'input>: LabelsParserContext<'input> {
fn e_all(&self) -> Vec<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.children_of_type()
}
fn e(&self, i: usize) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(i)
}
}
impl<'input> MultContextAttrs<'input> for MultContext<'input> {}
pub struct MultContextExt<'input> {
base: EContextExt<'input>,
pub a: Option<Rc<EContextAll<'input>>>,
pub op: Option<TokenType<'input>>,
pub b: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {MultContextExt<'a>}
impl<'input> LabelsParserContext<'input> for MultContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for MultContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_mult(self);
}
}
impl<'input> CustomRuleContext<'input> for MultContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for MultContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for MultContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for MultContext<'input> {}
impl<'input> MultContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::MultContext(BaseParserRuleContext::copy_from(
ctx,
MultContextExt {
op: None,
a: None,
b: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
pub type DecContext<'input> = BaseParserRuleContext<'input, DecContextExt<'input>>;
pub trait DecContextAttrs<'input>: LabelsParserContext<'input> {
fn e(&self) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(0)
}
}
impl<'input> DecContextAttrs<'input> for DecContext<'input> {}
pub struct DecContextExt<'input> {
base: EContextExt<'input>,
pub x: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {DecContextExt<'a>}
impl<'input> LabelsParserContext<'input> for DecContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for DecContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_dec(self);
}
}
impl<'input> CustomRuleContext<'input> for DecContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for DecContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for DecContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for DecContext<'input> {}
impl<'input> DecContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::DecContext(BaseParserRuleContext::copy_from(
ctx,
DecContextExt {
x: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
pub type AnIDContext<'input> = BaseParserRuleContext<'input, AnIDContextExt<'input>>;
pub trait AnIDContextAttrs<'input>: LabelsParserContext<'input> {
/// Retrieves first TerminalNode corresponding to token ID
/// Returns `None` if there is no child corresponding to token ID
fn ID(&self) -> Option<Rc<TerminalNode<'input, LabelsParserContextType>>>
where
Self: Sized,
{
self.get_token(ID, 0)
}
}
impl<'input> AnIDContextAttrs<'input> for AnIDContext<'input> {}
pub struct AnIDContextExt<'input> {
base: EContextExt<'input>,
pub ID: Option<TokenType<'input>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {AnIDContextExt<'a>}
impl<'input> LabelsParserContext<'input> for AnIDContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for AnIDContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_anID(self);
}
}
impl<'input> CustomRuleContext<'input> for AnIDContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for AnIDContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for AnIDContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for AnIDContext<'input> {}
impl<'input> AnIDContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::AnIDContext(BaseParserRuleContext::copy_from(
ctx,
AnIDContextExt {
ID: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
pub type AnIntContext<'input> = BaseParserRuleContext<'input, AnIntContextExt<'input>>;
pub trait AnIntContextAttrs<'input>: LabelsParserContext<'input> {
/// Retrieves first TerminalNode corresponding to token INT
/// Returns `None` if there is no child corresponding to token INT
fn INT(&self) -> Option<Rc<TerminalNode<'input, LabelsParserContextType>>>
where
Self: Sized,
{
self.get_token(INT, 0)
}
}
impl<'input> AnIntContextAttrs<'input> for AnIntContext<'input> {}
pub struct AnIntContextExt<'input> {
base: EContextExt<'input>,
pub INT: Option<TokenType<'input>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {AnIntContextExt<'a>}
impl<'input> LabelsParserContext<'input> for AnIntContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for AnIntContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_anInt(self);
}
}
impl<'input> CustomRuleContext<'input> for AnIntContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for AnIntContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for AnIntContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for AnIntContext<'input> {}
impl<'input> AnIntContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::AnIntContext(BaseParserRuleContext::copy_from(
ctx,
AnIntContextExt {
INT: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
pub type IncContext<'input> = BaseParserRuleContext<'input, IncContextExt<'input>>;
pub trait IncContextAttrs<'input>: LabelsParserContext<'input> {
fn e(&self) -> Option<Rc<EContextAll<'input>>>
where
Self: Sized,
{
self.child_of_type(0)
}
}
impl<'input> IncContextAttrs<'input> for IncContext<'input> {}
pub struct IncContextExt<'input> {
base: EContextExt<'input>,
pub x: Option<Rc<EContextAll<'input>>>,
ph: PhantomData<&'input str>,
}
antlr_rust::tid! {IncContextExt<'a>}
impl<'input> LabelsParserContext<'input> for IncContext<'input> {}
impl<'input, 'a> Listenable<dyn LabelsListener<'input> + 'a> for IncContext<'input> {
fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) {
listener.enter_every_rule(self);
listener.enter_inc(self);
}
}
impl<'input> CustomRuleContext<'input> for IncContextExt<'input> {
type TF = LocalTokenFactory<'input>;
type Ctx = LabelsParserContextType;
fn get_rule_index(&self) -> usize {
RULE_e
}
//fn type_rule_index() -> usize where Self: Sized { RULE_e }
}
impl<'input> Borrow<EContextExt<'input>> for IncContext<'input> {
fn borrow(&self) -> &EContextExt<'input> {
&self.base
}
}
impl<'input> BorrowMut<EContextExt<'input>> for IncContext<'input> {
fn borrow_mut(&mut self) -> &mut EContextExt<'input> {
&mut self.base
}
}
impl<'input> EContextAttrs<'input> for IncContext<'input> {}
impl<'input> IncContextExt<'input> {
fn new(ctx: &dyn EContextAttrs<'input>) -> Rc<EContextAll<'input>> {
Rc::new(EContextAll::IncContext(BaseParserRuleContext::copy_from(
ctx,
IncContextExt {
x: None,
base: ctx.borrow().clone(),
ph: PhantomData,
},
)))
}
}
impl<'input, I, H> LabelsParser<'input, I, H>
where
I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>,
H: ErrorStrategy<'input, BaseParserType<'input, I>>,
{
pub fn e(&mut self) -> Result<Rc<EContextAll<'input>>, ANTLRError> {
self.e_rec(0)
}
fn e_rec(&mut self, _p: isize) -> Result<Rc<EContextAll<'input>>, ANTLRError> {
let recog = self;
let _parentctx = recog.ctx.take();
let _parentState = recog.base.get_state();
let mut _localctx = EContextExt::new(_parentctx.clone(), recog.base.get_state());
recog
.base
.enter_recursion_rule(_localctx.clone(), 2, RULE_e, _p);
let mut _localctx: Rc<EContextAll> = _localctx;
let mut _prevctx = _localctx.clone();
let _startState = 2;
let result: Result<(), ANTLRError> = (|| {
let mut _alt: isize;
//recog.base.enter_outer_alt(_localctx.clone(), 1);
recog.base.enter_outer_alt(None, 1);
{
recog.base.set_state(16);
recog.err_handler.sync(&mut recog.base)?;
match recog.base.input.la(1) {
INT => {
let mut tmp = AnIntContextExt::new(&**_localctx);
recog.ctx = Some(tmp.clone());
_localctx = tmp;
_prevctx = _localctx.clone();
recog.base.set_state(7);
let tmp = recog.base.match_token(INT, &mut recog.err_handler)?;
if let EContextAll::AnIntContext(ctx) =
cast_mut::<_, EContextAll>(&mut _localctx)
{
ctx.INT = Some(tmp.clone());
} else {
unreachable!("cant cast");
}
let tmp = {
if let Some(it) = &if let EContextAll::AnIntContext(ctx) =
cast::<_, EContextAll>(&*_localctx)
{
ctx
} else {