From 6337ce96195863b984f9d5955571890705b7e1a6 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 07:42:45 -0500 Subject: [PATCH 01/10] minor clean ups Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_config.rs | 2 +- runtime/Rust/src/context_factory.rs | 203 ------------------ runtime/Rust/src/file_stream.rs | 14 -- runtime/Rust/src/interval_set.rs | 14 +- runtime/Rust/src/lexer.rs | 4 +- runtime/Rust/src/lexer_action_executor.rs | 4 +- runtime/Rust/src/lib.rs | 15 +- runtime/Rust/src/parser.rs | 2 +- runtime/Rust/src/parser_atn_simulator.rs | 18 +- runtime/Rust/src/prediction_context.rs | 4 +- runtime/Rust/src/rule_context.rs | 2 +- runtime/Rust/src/tokenstream_rewriter.rs | 164 -------------- runtime/Rust/src/tokenstream_rewriter_test.rs | 76 ------- runtime/Rust/src/trace_listener.rs | 19 -- 14 files changed, 31 insertions(+), 510 deletions(-) delete mode 100644 runtime/Rust/src/context_factory.rs delete mode 100644 runtime/Rust/src/file_stream.rs delete mode 100644 runtime/Rust/src/tokenstream_rewriter.rs delete mode 100644 runtime/Rust/src/tokenstream_rewriter_test.rs delete mode 100644 runtime/Rust/src/trace_listener.rs diff --git a/runtime/Rust/src/atn_config.rs b/runtime/Rust/src/atn_config.rs index 3a6ef241c8..6771356e64 100644 --- a/runtime/Rust/src/atn_config.rs +++ b/runtime/Rust/src/atn_config.rs @@ -32,7 +32,7 @@ impl PartialEq for ATNConfig { fn eq(&self, other: &Self) -> bool { self.get_state() == other.get_state() && self.get_alt() == other.get_alt() - // Arc is optimized to not do a deep equalitiy if arc pointers are equal so that's enough + // Arc is optimized to not do a deep equality if arc pointers are equal so that's enough && self.context == other.context && self.get_type() == other.get_type() && self.semantic_context == other.semantic_context diff --git a/runtime/Rust/src/context_factory.rs b/runtime/Rust/src/context_factory.rs deleted file mode 100644 index e18f4174b8..0000000000 --- a/runtime/Rust/src/context_factory.rs +++ /dev/null @@ -1,203 +0,0 @@ -use std::cell::{Ref, RefCell, RefMut}; -use std::marker::PhantomData; -use std::ops::{CoerceUnsized, Deref, DerefMut}; -use std::rc::Rc; - -use better_any::TidExt; -use qcell::{TLCell, TLCellOwner}; -use typed_arena::Arena; - -use crate::parser_rule_context::ParserRuleContext; - -trait ContextFactory<'a, T: ?Sized> { - type CtxRef; - type Ref: Deref + 'a; - type RefMut: DerefMut + 'a; - - fn new(&mut self, inner: T) -> Self::CtxRef - where - T: Sized; - - fn borrow(&'a self, this: &'a Self::CtxRef) -> Self::Ref; - fn borrow_mut(&'a mut self, this: &'a mut Self::CtxRef) -> Self::RefMut; -} - -struct RcFactory; - -impl<'a, T: 'a + ?Sized> ContextFactory<'a, T> for RcFactory { - type CtxRef = Rc; - type Ref = &'a T; - type RefMut = &'a mut T; - - fn new(&mut self, inner: T) -> Self::CtxRef - where - T: Sized, - { - Rc::new(inner) - } - - fn borrow(&'a self, this: &'a Self::CtxRef) -> Self::Ref { &*this } - - fn borrow_mut(&'a mut self, this: &'a mut Self::CtxRef) -> Self::RefMut { - unsafe { Rc::get_mut_unchecked(this) } - } -} - -struct RefCellFactory { - arena: Arena>>, -} - -impl<'a, 'this, T, Dyn> ContextFactory<'a, T> for &'this RefCellFactory -where - T: 'this + 'a + CoerceUnsized + ?Sized, - Dyn: 'this + 'a + ?Sized, - Box>: CoerceUnsized>>, -{ - type CtxRef = &'this RefCell; - type Ref = Ref<'a, T>; - type RefMut = RefMut<'a, T>; - - fn new(&mut self, inner: T) -> Self::CtxRef - where - T: Sized, - { - let val = Box::new(RefCell::new(inner)) as Box>; - let res = self.arena.alloc(val).as_mut(); - unsafe { &*(res as *mut RefCell as *mut RefCell) } - } - - fn borrow(&'a self, this: &'a Self::CtxRef) -> Self::Ref { RefCell::borrow(this) } - - fn borrow_mut(&'a mut self, this: &'a mut Self::CtxRef) -> Self::RefMut { - RefCell::borrow_mut(this) - } -} - -/// index that saves type info to downcast back without checks -struct Id { - idx: usize, - phantom: PhantomData>, -} - -struct IdFactory { - arena: Vec>, -} - -impl<'a, T, Dyn> ContextFactory<'a, T> for IdFactory -where - T: 'a + CoerceUnsized + ?Sized, - Dyn: 'a + ?Sized, - Box: CoerceUnsized>, -{ - type CtxRef = Id; - type Ref = &'a T; - type RefMut = &'a mut T; - - fn new(&mut self, inner: T) -> Self::CtxRef - where - T: Sized, - { - let b = Box::new(inner); - self.arena.push(b as _); - Id { - idx: self.arena.len() - 1, - phantom: Default::default(), - } - } - - fn borrow(&'a self, this: &'a Self::CtxRef) -> Self::Ref { - let this = &*self.arena[this.idx]; - // safe because we know that T:CoerceUnsized - unsafe { std::mem::transmute_copy::<&Dyn, &T>(&this) } - } - - fn borrow_mut(&'a mut self, this: &'a mut Self::CtxRef) -> Self::RefMut { - let this = &mut *self.arena[this.idx]; - unsafe { std::mem::transmute_copy::<&mut Dyn, &mut T>(&this) } - } -} - -struct Owner; - -struct QCellArena { - arena: Arena>>, - guard: TLCellOwner, -} - -impl<'a, 'this, T, Dyn> ContextFactory<'a, T> for &'this mut QCellArena -where - T: 'a + 'this + CoerceUnsized + ?Sized, - Dyn: 'a + 'this + ?Sized, - Box>: CoerceUnsized>>, -{ - type CtxRef = &'this TLCell; - type Ref = &'a T; - type RefMut = &'a mut T; - - fn new(&mut self, inner: T) -> Self::CtxRef - where - T: Sized, - { - let t = Box::new(self.guard.cell(inner)); - let r = &**self.arena.alloc(t); - unsafe { &*(r as *const _ as *const _) } - } - - fn borrow(&'a self, this: &'a Self::CtxRef) -> Self::Ref { self.guard.ro(this) } - - fn borrow_mut(&'a mut self, this: &'a mut Self::CtxRef) -> Self::RefMut { self.guard.rw(this) } -} - -trait Cast { - type WrappedT: CoerceUnsized; - type WrappedSelf; - fn downcast(this: Self::WrappedSelf) -> Self::WrappedT; -} - -impl<'i, T, Y: ?Sized> Cast for Y -where - Y: ParserRuleContext<'i>, - T: ParserRuleContext<'i>, - Rc: CoerceUnsized>, -{ - type WrappedT = Rc; - type WrappedSelf = Rc; - - fn downcast(this: Self::WrappedSelf) -> Self::WrappedT { this.downcast_rc().unwrap() } -} - -// -// trait Downcast<'i, Owner>: CoerceUnsized { -// type Inner: ParserRuleContext<'i, Ctx = Self::Dyn> + ?Sized; -// type DynRef; -// type Dyn; -// fn downcast<'x>(from: Self::DynRef, owner: Owner) -> Option; -// } -// -// impl<'i, T: ParserRuleContext<'i> + ?Sized, Owner, U> Downcast for Rc -// where -// Rc: CoerceUnsized>, -// { -// type Inner = T; -// type DynRef = Rc; -// type Dyn = T::Ctx; -// -// fn downcast<'x>(from: Rc, owner: Owner) -> Option { -// if from.self_id() == T::id() { -// Some(unsafe { Rc::from_raw(Rc::into_raw(from) as *const _) }) -// } else { -// None -// } -// } -// } -// -// impl<'i, T: ParserRuleContext<'i> + ?Sized, Owner, U> Downcast for &RefCell -// where -// Rc: CoerceUnsized>, -// { -// type Inner = T; -// type DynRef = Rc; -// type Dyn = T::Ctx; -// -// fn downcast<'x>(from: Self::DynRef, owner: Owner) -> Option { unimplemented!() } -// } diff --git a/runtime/Rust/src/file_stream.rs b/runtime/Rust/src/file_stream.rs deleted file mode 100644 index bb3bf8611b..0000000000 --- a/runtime/Rust/src/file_stream.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std; - -pub struct FileStream { - base: InputStream, - - filename: String, -} - -impl FileStream { - fn new(fileName: String) -> Result { unimplemented!() } - - fn get_source_name(&self) -> String { unimplemented!() } -} - \ No newline at end of file diff --git a/runtime/Rust/src/interval_set.rs b/runtime/Rust/src/interval_set.rs index fca2d59509..a5de616068 100644 --- a/runtime/Rust/src/interval_set.rs +++ b/runtime/Rust/src/interval_set.rs @@ -173,7 +173,7 @@ impl IntervalSet { } } - pub fn substract(&mut self, right: &IntervalSet) { + pub fn subtract(&mut self, right: &IntervalSet) { let result = self; let mut result_i = 0usize; let mut right_i = 0usize; @@ -228,10 +228,10 @@ impl IntervalSet { } pub fn complement(&self, start: i32, stop: i32) -> IntervalSet { - let mut vocablulary_is = IntervalSet::new(); - vocablulary_is.add_range(start, stop); - vocablulary_is.substract(self); - vocablulary_is + let mut vocabulary_is = IntervalSet::new(); + vocabulary_is.add_range(start, stop); + vocabulary_is.subtract(self); + vocabulary_is } pub fn contains(&self, _item: i32) -> bool { @@ -394,13 +394,13 @@ mod test { } #[test] - fn test_substract() { + fn test_subtract() { let mut set1 = IntervalSet::new(); set1.add_range(1, 2); set1.add_range(4, 5); let mut set2 = IntervalSet::new(); set2.add_range(2, 4); - set1.substract(&set2); + set1.subtract(&set2); assert_eq!( &set1.intervals, &[Interval { a: 1, b: 1 }, Interval { a: 5, b: 5 }] diff --git a/runtime/Rust/src/lexer.rs b/runtime/Rust/src/lexer.rs index 9c0a8c4d2a..96a17be6e0 100644 --- a/runtime/Rust/src/lexer.rs +++ b/runtime/Rust/src/lexer.rs @@ -289,14 +289,14 @@ where line: Cell::new(1), char_position_in_line: Cell::new(0), }), - token_type: super::token::TOKEN_INVALID_TYPE, + token_type: TOKEN_INVALID_TYPE, text: None, token: None, hit_eof: false, channel: super::token::TOKEN_DEFAULT_CHANNEL, // token_factory_source_pair: None, mode_stack: Vec::new(), - mode: self::LEXER_DEFAULT_MODE, + mode: LEXER_DEFAULT_MODE, }; let pos = lexer.current_pos.clone(); lexer.interpreter.as_mut().unwrap().current_pos = pos; diff --git a/runtime/Rust/src/lexer_action_executor.rs b/runtime/Rust/src/lexer_action_executor.rs index 4bfaaa73e6..94e6bb6806 100644 --- a/runtime/Rust/src/lexer_action_executor.rs +++ b/runtime/Rust/src/lexer_action_executor.rs @@ -49,7 +49,7 @@ impl LexerActionExecutor { pub fn fix_offset_before_match(mut self, offset: isize) -> LexerActionExecutor { for action in self.lexer_actions.iter_mut() { match action { - LexerAction::LexerIndexedCustomAction { .. } => {} + LexerIndexedCustomAction { .. } => {} _ => { if action.is_position_dependent() { *action = LexerIndexedCustomAction { @@ -68,7 +68,7 @@ impl LexerActionExecutor { let stop_index = lexer.input().index(); for action in self.lexer_actions.iter() { //println!("executing action {:?}",action); - if let LexerAction::LexerIndexedCustomAction { offset, .. } = action { + if let LexerIndexedCustomAction { offset, .. } = action { lexer.input().seek(start_index + offset); requires_seek = start_index + offset != stop_index; } else if action.is_position_dependent() { diff --git a/runtime/Rust/src/lib.rs b/runtime/Rust/src/lib.rs index d871324943..7cfccfda02 100644 --- a/runtime/Rust/src/lib.rs +++ b/runtime/Rust/src/lib.rs @@ -64,12 +64,12 @@ //! access in generated parser from embedded actions also can be downcasted to concrete types. //! To do it `TidExt::downcast_*` extension methods should be used. //! -//! [`CharStream`]: crate::char_stream::CharStream -//! [`TokenFactory`]: crate::token_factory::TokenFactory -//! [`ArenaFactory`]: crate::token_factory::ArenaFactory -//! [`Token`]: crate::token::Token -//! [`TokenStream`]: crate::token_stream::TokenStream -//! [`ParserRuleContext`]: crate::parser_rule_context::ParserRuleContext +//! [`CharStream`]: char_stream::CharStream +//! [`TokenFactory`]: token_factory::TokenFactory +//! [`ArenaFactory`]: token_factory::ArenaFactory +//! [`Token`]: token::Token +//! [`TokenStream`]: token_stream::TokenStream +//! [`ParserRuleContext`]: parser_rule_context::ParserRuleContext #[macro_use] extern crate lazy_static; @@ -133,7 +133,6 @@ pub mod dfa; #[doc(hidden)] pub mod transition; pub mod tree; -//pub mod file_stream; #[doc(hidden)] pub mod atn; #[doc(hidden)] @@ -156,9 +155,7 @@ mod prediction_mode; pub mod token; pub mod trees; mod utils; -//pub mod tokenstream_rewriter_test; mod atn_type; -// mod context_factory; pub mod rule_context; pub mod vocabulary; //#[cfg(test)] diff --git a/runtime/Rust/src/parser.rs b/runtime/Rust/src/parser.rs index 65eef7b44b..1b21c70243 100644 --- a/runtime/Rust/src/parser.rs +++ b/runtime/Rust/src/parser.rs @@ -81,7 +81,7 @@ pub trait Parser<'input>: Recognizer<'input> { // type Type = dyn CsvContext<'a>; // } -// workaround trait for rustc not being able to handle cycles in trait defenition yet, e.g. `trait A: Super{}` +// workaround trait for rustc not being able to handle cycles in trait definition yet, e.g. `trait A: Super{}` // whyyy rustc... whyyy... (╯°□°)╯︵ ┻━┻ It would have been so much cleaner. /// Workaround trait for rustc current limitations. /// diff --git a/runtime/Rust/src/parser_atn_simulator.rs b/runtime/Rust/src/parser_atn_simulator.rs index b2765b4502..f52125b56a 100644 --- a/runtime/Rust/src/parser_atn_simulator.rs +++ b/runtime/Rust/src/parser_atn_simulator.rs @@ -7,7 +7,7 @@ use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::rc::Rc; use std::sync::Arc; -use std::{ptr, usize}; +use std::{ptr}; use bit_set::BitSet; @@ -324,15 +324,15 @@ impl ParserATNSimulator { local.input().seek(self.start_index.get()); let alts = self.eval_semantic_context(local, &Dstate.predicates, true); - match alts.len() { + return match alts.len() { 0 => { - return Err(self.no_viable_alt( + Err(self.no_viable_alt( local, Dstate.configs.as_ref(), self.start_index.get(), )) } - 1 => return Ok(alts.iter().next().unwrap() as i32), + 1 => Ok(alts.iter().next().unwrap() as i32), _ => { self.report_ambiguity( &dfa, @@ -343,7 +343,7 @@ impl ParserATNSimulator { Dstate.configs.as_ref(), local.parser, ); - return Ok(alts.iter().next().unwrap() as i32); + Ok(alts.iter().next().unwrap() as i32) } } } @@ -900,7 +900,7 @@ impl ParserATNSimulator { } } - alts.get_min().unwrap_or(INVALID_ALT) as i32 + alts.get_min().unwrap_or(INVALID_ALT) } fn eval_semantic_context<'a, T: Parser<'a>>( @@ -1027,7 +1027,7 @@ impl ParserATNSimulator { config.semantic_context.clone(), ); c.set_reaches_into_outer_context(config.get_reaches_into_outer_context()); - assert!(depth > i32::min_value()); + assert!(depth > i32::MIN); self.closure_checking_stop_state( c, configs, @@ -1104,7 +1104,7 @@ impl ParserATNSimulator { .outermost_precedence_return; let atn_start_state = self.atn().states[local.dfa().atn_start_state as usize].as_ref(); - if outermost_precedence_return == atn_start_state.get_rule_index() as i32 + if outermost_precedence_return == atn_start_state.get_rule_index() { c.set_precedence_filter_suppressed(true); } @@ -1115,7 +1115,7 @@ impl ParserATNSimulator { continue; } configs.set_dips_into_outer_context(true); - assert!(new_depth > i32::min_value()); + assert!(new_depth > i32::MIN); new_depth -= 1; } else { if !tr.is_epsilon() && !closure_busy.insert(c.clone()) { diff --git a/runtime/Rust/src/prediction_context.rs b/runtime/Rust/src/prediction_context.rs index 454ed77654..fadc09ec07 100644 --- a/runtime/Rust/src/prediction_context.rs +++ b/runtime/Rust/src/prediction_context.rs @@ -191,7 +191,7 @@ impl PredictionContext { None => 0, Some(x) => x.hash_code(), }); - hasher.write_i32(*return_state as i32); + hasher.write_i32(*return_state); } PredictionContext::Array(ArrayPredictionContext { parents, @@ -206,7 +206,7 @@ impl PredictionContext { }); return_states .iter() - .for_each(|x| hasher.write_i32(*x as i32)); + .for_each(|x| hasher.write_i32(*x)); } // PredictionContext::Empty { .. } => {} }; diff --git a/runtime/Rust/src/rule_context.rs b/runtime/Rust/src/rule_context.rs index 13c7f39f46..79a509b9a7 100644 --- a/runtime/Rust/src/rule_context.rs +++ b/runtime/Rust/src/rule_context.rs @@ -78,7 +78,7 @@ impl<'a, TF: TokenFactory<'a> + 'a> CustomRuleContext<'a> for EmptyCustomRuleCon type Ctx = EmptyContextType<'a, TF>; fn get_rule_index(&self) -> usize { - usize::max_value() + usize::MAX } } diff --git a/runtime/Rust/src/tokenstream_rewriter.rs b/runtime/Rust/src/tokenstream_rewriter.rs deleted file mode 100644 index 93af3d46a5..0000000000 --- a/runtime/Rust/src/tokenstream_rewriter.rs +++ /dev/null @@ -1,164 +0,0 @@ -// const default_program_name = "default"; -// const program_init_size = 100; -// const min_token_index = 0; -// -// -// pub trait RewriteOperation { -// fn execute(&self, buffer: * bytes.Buffer) -> i32; -// fn String(&self) -> String; -// get_instruction_index() int -// get_index() int -// get_text() String -// get_op_name() String -// get_tokens() TokenStream -// set_instruction_index(val i32) -// set_index(i32) -// set_text(String) -// set_op_name(String) -// set_tokens(TokenStream) -// } -// -// pub struct BaseRewriteOperation { -// instruction_index: i32, -// index: i32, -// text: String, -// op_name: String, -// tokens: TokenStream, -// } -// -// impl BaseRewriteOperation { -// fn (op * BaseRewriteOperation)GetInstructionIndex() int { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)GetIndex() int { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)GetText() String { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)GetOpName() String { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)GetTokens() TokenStream { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)SetInstructionIndex(val i32) { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)SetIndex(val i32) { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)SetText(val String) { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)SetOpName(val String) { unimplemented ! () } -// -// fn (op * BaseRewriteOperation)SetTokens(val TokenStream) { unimplemented ! () } -// -// -// fn execute(&self, buffer: * bytes.Buffer) -> int { unimplemented!() } -// -// fn String(&self) -> String { unimplemented!() } -// -// -// pub struct InsertBeforeOp { -// base: base_rewrite_operation, -// } -// -// fn new_insert_before_op(index i32, text: String, stream: TokenStream) -> * InsertBeforeOp { unimplemented!() } -// -// fn execute(&self, buffer: * bytes.Buffer) -> int { unimplemented!() } -// -// fn String(&self) -> String { unimplemented!() } -// -// -// pub struct InsertAfterOp { -// base: base_rewrite_operation, -// } -// -// fn new_insert_after_op(index i32, text: String, stream: TokenStream) -> * InsertAfterOp { unimplemented!() } -// -// fn execute(&self, buffer: * bytes.Buffer) -> int { unimplemented!() } -// -// fn String(&self) -> String { unimplemented!() } -// -// pub struct ReplaceOp{ -// base: base_rewrite_operation, -// last_index: i32, -// } -// -// fn new_replace_op(from, to: i32, text: String, stream: TokenStream) -> * ReplaceOp { unimplemented!() } -// -// fn (op * ReplaceOp)Execute(buffer * bytes.Buffer) int { unimplemented ! () } -// -// fn String(&self) -> String { unimplemented!() } -// -// -// pub struct TokenStreamRewriter { -// tokens: TokenStream, -// programs: map[String]Vec < RewriteOperation >, -// last_rewrite_token_indexes: map[String]i32, -// } -// -// fn new_token_stream_rewriter(tokens TokenStream) -> * TokenStreamRewriter { unimplemented!() } -// -// fn get_token_stream(&self) -> TokenStream { unimplemented!() } -// -// fn rollback(&self, program_name: String, instruction_index: i32) { unimplemented!() } -// -// fn rollback_default(&self, instruction_index: i32) { unimplemented!() } -// fn delete_program(&self, program_name: String) { unimplemented!() } -// -// fn delete_program_default(&self) { unimplemented!() } -// -// fn insert_after(&self, program_name: String, index: i32, text: String) { unimplemented!() } -// -// fn insert_after_default(&self, index: i32, text: String) { unimplemented!() } -// -// fn insert_after_token(&self, program_name: String, token: Token, text: String) { unimplemented!() } -// -// fn insert_before(&self, program_name: String, index: i32, text: String) { unimplemented!() } -// -// fn insert_before_default(&self, index: i32, text: String) { unimplemented!() } -// -// fn insert_before_token(&self, program_name: String, token Token, text: String) { unimplemented!() } -// -// fn replace(&self, program_name: String, from: i32, to: i32, text: String) { unimplemented!() } -// -// fn (tsr * TokenStreamRewriter)ReplaceDefault(from, to: i32, text: String) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)ReplaceDefaultPos(index i32, text: String) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)ReplaceToken(program_name String, from: Token, to: Token, text: String) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)ReplaceTokenDefault(from, to: Token, text: String) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)ReplaceTokenDefaultPos(index Token, text: String) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)Delete(program_name String, from: i32, to: i32) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)DeleteDefault(from, to: i32) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)DeleteDefaultPos(index i32) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)DeleteToken(program_name String, from: Token, to: Token) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)DeleteTokenDefault(from, to Token) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)GetLastRewriteTokenIndex(program_name String)int { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)GetLastRewriteTokenIndexDefault()int { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)SetLastRewriteTokenIndex(program_name String, i: i32) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)InitializeProgram(name String)Vec< RewriteOperation > { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)AddToProgram(name String, op: RewriteOperation) { unimplemented ! () } -// -// fn (tsr * TokenStreamRewriter)GetProgram(name String) Vec< RewriteOperation > { unimplemented ! () } -// fn (tsr * TokenStreamRewriter)GetTextDefault() String { unimplemented ! () } -// fn (tsr * TokenStreamRewriter)GetText(program_name String, interval: * Interval) String { unimplemented ! () } -// -// fn reduce_to_single_operation_per_index(rewrites Vec) -> map[int]RewriteOperation { unimplemented ! () } -// -// -// /* -// quick fixing Go lack of: overloads, -// */ -// -// fn max(a, b i32) -> int { unimplemented!() } -// fn min(a, b i32) -> int { unimplemented!() } -// } -// \ No newline at end of file diff --git a/runtime/Rust/src/tokenstream_rewriter_test.rs b/runtime/Rust/src/tokenstream_rewriter_test.rs deleted file mode 100644 index 47d6dbfd44..0000000000 --- a/runtime/Rust/src/tokenstream_rewriter_test.rs +++ /dev/null @@ -1,76 +0,0 @@ -// fn test_insert_before_index0(t *testing.T) { unimplemented!() } -// -// fn prepare_rewriter(str String) -> * TokenStreamRewriter { unimplemented!() } -// -// pub struct LexerTest { -// input: String, -// expected: String, -// description: String, -// expected_exception: Vec, -// ops func( * TokenStreamRewriter), -// } -// -// impl LexerTest { -// fn new_lexer_test(input, expected: String, desc: String, ops: func(* TokenStreamRewriter)) LexerTest { unimplemented ! () } -// -// fn new_lexer_exception_test(input String, expected_err Vec, desc: String, ops: func(* TokenStreamRewriter)) LexerTest { unimplemented ! () } -// -// fn panic_tester(t *testing.T, expected_msg Vec, r: * TokenStreamRewriter) { unimplemented!() } -// -// fn test_lexer_a(t *testing.T) { unimplemented!() } -// -// -// var _ = fmt.Printf -// var _ = unicode.IsLetter -// -// var serializedLexerAtn = Vec < uint16 > { -// 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 5, 15, 8, -// 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, -// 4, 2, 2, 5, 3, 3, 5, 4, 7, 5, 3, 2, 2, 2, 14, 2, 3, 3, 2, 2, 2, 2, 5, 3, -// 2, 2, 2, 2, 7, 3, 2, 2, 2, 3, 9, 3, 2, 2, 2, 5, 11, 3, 2, 2, 2, 7, 13, -// 3, 2, 2, 2, 9, 10, 7, 99, 2, 2, 10, 4, 3, 2, 2, 2, 11, 12, 7, 100, 2, 2, -// 12, 6, 3, 2, 2, 2, 13, 14, 7, 101, 2, 2, 14, 8, 3, 2, 2, 2, 3, 2, 2, -// } -// -// var lexerDeserializer = NewATNDeserializer(nil) -// var lexerAtn = lexerDeserializer.DeserializeFromUInt16(serializedLexerAtn) -// -// var lexerChannelNames = Vec< String > { -// "DEFAULT_TOKEN_CHANNEL", "HIDDEN", -// } -// -// var lexerModeNames = Vec < String > { -// "DEFAULT_MODE", -// } -// -// var lexerLiteralNames = Vec < String > { -// "", "'a'", "'b'", "'c'", -// } -// -// var lexerSymbolicNames = Vec < String > { -// "", "A", "B", "C", -// } -// -// var lexerRuleNames = Vec < String > { -// "A", "B", "C", -// } -// -// pub struct LexerA { -// base: BaseLexer, -// channel_names: Vec < String > , -// mode_names: Vec < String >, -// } -// -// var lexerDecisionToDFA = make( & Vec < DFA >, len(lexerAtn.DecisionToState)) -// -// fn init() { unimplemented!() } -// -// fn new_lexer_a(input CharStream) -> * LexerA { unimplemented!() } -// -// const ( -// lexer_aa = 1 -// lexer_ab = 2 -// lexer_ac = 3 -// ) -// } -// \ No newline at end of file diff --git a/runtime/Rust/src/trace_listener.rs b/runtime/Rust/src/trace_listener.rs deleted file mode 100644 index 7921156c04..0000000000 --- a/runtime/Rust/src/trace_listener.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::rc::Weak; -use parser::BaseParser; - -pub struct TraceListener { - parser: Box, -} - -impl TraceListener { - fn new_trace_listener(parser: Box) -> * TraceListener { unimplemented!() } - - fn visit_error_node(&self, _: ErrorNode) { unimplemented!() } - - fn enter_every_rule(&self, ctx: ParserRuleContext) { unimplemented!() } - - fn visit_terminal(&self, node: TerminalNode) { unimplemented!() } - - fn exit_every_rule(&self, ctx: ParserRuleContext) { unimplemented!() } -} - \ No newline at end of file From 10d23295f67a3e01a52d514a28ff3927c4267711 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 07:46:56 -0500 Subject: [PATCH 02/10] cargo clippy --fix Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_config.rs | 4 ++-- runtime/Rust/src/atn_deserializer.rs | 2 +- runtime/Rust/src/error_strategy.rs | 4 ++-- runtime/Rust/src/lexer_atn_simulator.rs | 2 +- runtime/Rust/src/ll1_analyzer.rs | 2 +- runtime/Rust/src/parser_atn_simulator.rs | 4 ++-- runtime/Rust/src/prediction_context.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/runtime/Rust/src/atn_config.rs b/runtime/Rust/src/atn_config.rs index 6771356e64..b809a662cd 100644 --- a/runtime/Rust/src/atn_config.rs +++ b/runtime/Rust/src/atn_config.rs @@ -42,8 +42,8 @@ impl PartialEq for ATNConfig { impl Hash for ATNConfig { fn hash(&self, state: &mut H) { - state.write_i32(self.get_state() as i32); - state.write_i32(self.get_alt() as i32); + state.write_i32(self.get_state()); + state.write_i32(self.get_alt()); match self.get_context() { None => state.write_i32(0), Some(c) => c.hash(state), diff --git a/runtime/Rust/src/atn_deserializer.rs b/runtime/Rust/src/atn_deserializer.rs index aacfe3c559..7ae3f4de95 100644 --- a/runtime/Rust/src/atn_deserializer.rs +++ b/runtime/Rust/src/atn_deserializer.rs @@ -272,7 +272,7 @@ impl ATNDeserializer { .get_state_type() { if tr.precedence == 0 { - target.get_rule_index() as i32 + target.get_rule_index() } else { -1 } diff --git a/runtime/Rust/src/error_strategy.rs b/runtime/Rust/src/error_strategy.rs index fefad2962c..8728cc6074 100644 --- a/runtime/Rust/src/error_strategy.rs +++ b/runtime/Rust/src/error_strategy.rs @@ -314,7 +314,7 @@ impl<'input, Ctx: ParserNodeType<'input>> DefaultErrorStrategy<'input, Ctx> { recognizer: &mut T, ) -> >::Tok { let expected = self.get_expected_tokens(recognizer); - let expected_token_type = expected.get_min().unwrap_or(TOKEN_INVALID_TYPE) as i32; + let expected_token_type = expected.get_min().unwrap_or(TOKEN_INVALID_TYPE); let token_text = if expected_token_type == TOKEN_EOF { "".to_owned() } else { @@ -322,7 +322,7 @@ impl<'input, Ctx: ParserNodeType<'input>> DefaultErrorStrategy<'input, Ctx> { "", recognizer .get_vocabulary() - .get_display_name(expected_token_type as i32) + .get_display_name(expected_token_type) ) }; let token_text = >::Data::from_text(&token_text); diff --git a/runtime/Rust/src/lexer_atn_simulator.rs b/runtime/Rust/src/lexer_atn_simulator.rs index 99baf1dc02..1307f94e91 100644 --- a/runtime/Rust/src/lexer_atn_simulator.rs +++ b/runtime/Rust/src/lexer_atn_simulator.rs @@ -546,7 +546,7 @@ impl LexerATNSimulator { //println!("rule transition follow state{}", rt.follow_state); let pred_ctx = PredictionContext::new_singleton( Some(_config.get_context().unwrap().clone()), - rt.follow_state as i32, + rt.follow_state, ); result = Some(_config.cloned_with_new_ctx(target, Some(pred_ctx.into()))); } diff --git a/runtime/Rust/src/ll1_analyzer.rs b/runtime/Rust/src/ll1_analyzer.rs index 2ede95f854..434133a4ce 100644 --- a/runtime/Rust/src/ll1_analyzer.rs +++ b/runtime/Rust/src/ll1_analyzer.rs @@ -126,7 +126,7 @@ impl LL1Analyzer<'_> { let new_ctx = Arc::new(PredictionContext::new_singleton( ctx.clone(), - rule_tr.follow_state as i32, + rule_tr.follow_state, )); called_rule_stack.insert(target.get_rule_index() as usize); diff --git a/runtime/Rust/src/parser_atn_simulator.rs b/runtime/Rust/src/parser_atn_simulator.rs index f52125b56a..781e90d3ec 100644 --- a/runtime/Rust/src/parser_atn_simulator.rs +++ b/runtime/Rust/src/parser_atn_simulator.rs @@ -203,7 +203,7 @@ impl ParserATNSimulator { if local.dfa_mut().is_precedence_dfa() { s0 = local.dfa_mut().s0.unwrap(); let s0_closure_updated = self.apply_precedence_filter(&s0_closure, &mut local); - local.dfa_mut().states[s0].configs = Box::new(s0_closure); + *local.dfa_mut().states[s0].configs = s0_closure; s0 = self.add_dfastate( local.dfa_mut(), @@ -1355,7 +1355,7 @@ impl ParserATNSimulator { assert!(config.get_context().is_some()); let new_ctx = PredictionContext::new_singleton( config.get_context().cloned(), - t.follow_state as i32, + t.follow_state, ); config.cloned_with_new_ctx(self.atn().states[t.target as usize].as_ref(), Some(new_ctx.into())) } diff --git a/runtime/Rust/src/prediction_context.rs b/runtime/Rust/src/prediction_context.rs index fadc09ec07..86038b3571 100644 --- a/runtime/Rust/src/prediction_context.rs +++ b/runtime/Rust/src/prediction_context.rs @@ -533,7 +533,7 @@ impl PredictionContext { .deref() .cast::(); - PredictionContext::new_singleton(Some(parent), transition.follow_state as i32).alloc() + PredictionContext::new_singleton(Some(parent), transition.follow_state).alloc() } fn combine_common_parents(array: &mut ArrayPredictionContext) { From 5376597488ef56b8dba81c52de950667c822bb73 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 08:18:22 -0500 Subject: [PATCH 03/10] low hanging lints Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_deserializer.rs | 10 +++++----- runtime/Rust/src/atn_state.rs | 9 ++++----- runtime/Rust/src/atn_type.rs | 4 ++-- runtime/Rust/src/dfa.rs | 2 +- runtime/Rust/src/error_listener.rs | 14 +++++++------- runtime/Rust/src/error_strategy.rs | 18 +++++++++--------- runtime/Rust/src/input_stream.rs | 4 ++-- runtime/Rust/src/int_stream.rs | 10 +++++----- runtime/Rust/src/lexer_action.rs | 7 ++----- runtime/Rust/src/lexer_atn_simulator.rs | 3 +-- runtime/Rust/src/parser.rs | 9 ++++----- runtime/Rust/src/prediction_mode.rs | 14 +++++++------- runtime/Rust/src/tree.rs | 14 +++++++------- 13 files changed, 56 insertions(+), 62 deletions(-) diff --git a/runtime/Rust/src/atn_deserializer.rs b/runtime/Rust/src/atn_deserializer.rs index 7ae3f4de95..af2666978b 100644 --- a/runtime/Rust/src/atn_deserializer.rs +++ b/runtime/Rust/src/atn_deserializer.rs @@ -65,7 +65,7 @@ impl ATNDeserializer { self.read_edges(&mut atn, data, &sets); self.read_decisions(&mut atn, data); - if atn.grammar_type == ATNType::LEXER { + if atn.grammar_type == ATNType::Lexer { self.read_lexer_actions(&mut atn, data); } self.mark_precedence_decisions(&mut atn, data); @@ -95,8 +95,8 @@ impl ATNDeserializer { fn read_atn(&self, data: &mut Iter) -> ATN { ATN::new_atn( match data.next() { - Some(0) => ATNType::LEXER, - Some(1) => ATNType::PARSER, + Some(0) => ATNType::Lexer, + Some(1) => ATNType::Parser, _ => panic!("invalid ATN type"), }, *data.next().unwrap(), @@ -170,7 +170,7 @@ impl ATNDeserializer { for i in 0..nrules { let s = *data.next().unwrap(); atn.rule_to_start_state[i] = s; - if atn.grammar_type == ATNType::LEXER { + if atn.grammar_type == ATNType::Lexer { let token_type = *data.next().unwrap(); atn.rule_to_token_type.push(token_type); @@ -417,7 +417,7 @@ impl ATNDeserializer { arg1: i32, arg2: i32, arg3: i32, - sets: &Vec, + sets: &[IntervalSet], ) -> Box { // // let target = atn.states.get // let mut base = BaseTransition { diff --git a/runtime/Rust/src/atn_state.rs b/runtime/Rust/src/atn_state.rs index a558b20ae5..b84371eb8a 100644 --- a/runtime/Rust/src/atn_state.rs +++ b/runtime/Rust/src/atn_state.rs @@ -175,15 +175,14 @@ impl ATNState for BaseATNState { let mut already_present = false; for existing in self.transitions.iter() { if existing.get_target() == trans.get_target() { - if existing.get_label().is_some() + if (existing.get_label().is_some() && trans.get_label().is_some() - && existing.get_label() == trans.get_label() + && existing.get_label() == trans.get_label()) + || + (existing.is_epsilon() && trans.is_epsilon()) { already_present = true; break; - } else if existing.is_epsilon() && trans.is_epsilon() { - already_present = true; - break; } } } diff --git a/runtime/Rust/src/atn_type.rs b/runtime/Rust/src/atn_type.rs index e379b81f8f..d5f053e5a7 100644 --- a/runtime/Rust/src/atn_type.rs +++ b/runtime/Rust/src/atn_type.rs @@ -1,6 +1,6 @@ #[doc(hidden)] #[derive(Eq, PartialEq, Debug)] pub enum ATNType { - LEXER = 0, - PARSER, + Lexer = 0, + Parser, } diff --git a/runtime/Rust/src/dfa.rs b/runtime/Rust/src/dfa.rs index daf3f0da01..45e847a1ba 100644 --- a/runtime/Rust/src/dfa.rs +++ b/runtime/Rust/src/dfa.rs @@ -67,7 +67,7 @@ impl DFA { // to indicate null dfa.states.push(DFAState::new_dfastate( - usize::max_value(), + usize::MAX, Box::new(ATNConfigSet::new_base_atnconfig_set(true)), )); if let ATNStateType::DecisionState { diff --git a/runtime/Rust/src/error_listener.rs b/runtime/Rust/src/error_listener.rs index a2a7760470..db98bfd979 100644 --- a/runtime/Rust/src/error_listener.rs +++ b/runtime/Rust/src/error_listener.rs @@ -186,15 +186,15 @@ impl<'a, T: Recognizer<'a>> ErrorListener<'a, T> for ProxyErrorListener<'_, 'a, /// message. /// /// - Ambiguities: These are cases where more than one path through the -/// grammar can match the input. +/// grammar can match the input. /// - Weak context sensitivity: These are cases where full-context -/// prediction resolved an SLL conflict to a unique alternative which equaled the -/// minimum alternative of the SLL conflict. +/// prediction resolved an SLL conflict to a unique alternative which equaled the +/// minimum alternative of the SLL conflict. /// - Strong (forced) context sensitivity: These are cases where the -/// full-context prediction resolved an SLL conflict to a unique alternative, -/// *and* the minimum alternative of the SLL conflict was found to not be -/// a truly viable alternative. Two-stage parsing cannot be used for inputs where -/// this situation occurs. +/// full-context prediction resolved an SLL conflict to a unique alternative, +/// *and* the minimum alternative of the SLL conflict was found to not be +/// a truly viable alternative. Two-stage parsing cannot be used for inputs where +/// this situation occurs. #[derive(Debug)] pub struct DiagnosticErrorListener { exact_only: bool, diff --git a/runtime/Rust/src/error_strategy.rs b/runtime/Rust/src/error_strategy.rs index 8728cc6074..beb11ca794 100644 --- a/runtime/Rust/src/error_strategy.rs +++ b/runtime/Rust/src/error_strategy.rs @@ -27,7 +27,7 @@ use better_any::{Tid, TidAble}; /// during a parse by ANTLR-generated parsers. We distinguish between three /// different kinds of errors: /// - The parser could not figure out which path to take in the ATN (none of -/// the available alternatives could possibly match) +/// the available alternatives could possibly match) /// - The current input does not match what we were looking for /// - A predicate evaluated to false /// @@ -540,15 +540,15 @@ impl<'a, T: Parser<'a>> ErrorStrategy<'a, T> for DefaultErrorStrategy<'a, T::Nod ///

This error strategy is useful in the following scenarios.

/// /// - Two-stage parsing: This error strategy allows the first -/// stage of two-stage parsing to immediately terminate if an error is -/// encountered, and immediately fall back to the second stage. In addition to -/// avoiding wasted work by attempting to recover from errors here, the empty -/// implementation of `sync` improves the performance of -/// the first stage. +/// stage of two-stage parsing to immediately terminate if an error is +/// encountered, and immediately fall back to the second stage. In addition to +/// avoiding wasted work by attempting to recover from errors here, the empty +/// implementation of `sync` improves the performance of +/// the first stage. /// - Silent validation: When syntax errors are not being -/// reported or logged, and the parse result is simply ignored if errors occur, -/// the `BailErrorStrategy` avoids wasting work on recovering from errors -/// when the result will be ignored either way. +/// reported or logged, and the parse result is simply ignored if errors occur, +/// the `BailErrorStrategy` avoids wasting work on recovering from errors +/// when the result will be ignored either way. /// /// # Usage /// ```ignore diff --git a/runtime/Rust/src/input_stream.rs b/runtime/Rust/src/input_stream.rs index cc081edd24..f865bfa35f 100644 --- a/runtime/Rust/src/input_stream.rs +++ b/runtime/Rust/src/input_stream.rs @@ -141,7 +141,7 @@ where } } } -impl<'a, Data: Deref> InputStream +impl InputStream where Data::Target: InputData, { @@ -152,7 +152,7 @@ where } } -impl<'a, Data: Deref> IntStream for InputStream +impl IntStream for InputStream where Data::Target: InputData, { diff --git a/runtime/Rust/src/int_stream.rs b/runtime/Rust/src/int_stream.rs index bf0488d05b..3684d3e457 100644 --- a/runtime/Rust/src/int_stream.rs +++ b/runtime/Rust/src/int_stream.rs @@ -12,15 +12,15 @@ pub trait IntStream { /// Consumes the current symbol in the stream. /// Advances this stream to the next element. /// - /// This method has the following + /// This method has the following /// effects: /// /// - Forward movement: The value of `index` - /// before calling this method is less than the value of `index` - /// after calling this method. + /// before calling this method is less than the value of `index` + /// after calling this method. /// - Ordered lookahead: The value of {@code LA(1)} before - /// calling this method becomes the value of {@code LA(-1)} after calling - /// this method. + /// calling this method becomes the value of {@code LA(-1)} after calling + /// this method. /// /// Note that calling this method does not guarantee that `index()` is /// incremented by exactly 1. diff --git a/runtime/Rust/src/lexer_action.rs b/runtime/Rust/src/lexer_action.rs index d18f8c7879..4e1b42cd05 100644 --- a/runtime/Rust/src/lexer_action.rs +++ b/runtime/Rust/src/lexer_action.rs @@ -36,11 +36,8 @@ impl LexerAction { //// unsafe {discriminant_value(self)} as i32 // } pub fn is_position_dependent(&self) -> bool { - match self { - LexerAction::LexerCustomAction { .. } - | LexerAction::LexerIndexedCustomAction { .. } => true, - _ => false, - } + matches!(self, LexerAction::LexerCustomAction { .. } + | LexerAction::LexerIndexedCustomAction { .. }) } pub(crate) fn execute<'input, T: Lexer<'input>>(&self, lexer: &mut T) { match self { diff --git a/runtime/Rust/src/lexer_atn_simulator.rs b/runtime/Rust/src/lexer_atn_simulator.rs index 1307f94e91..05361fb14c 100644 --- a/runtime/Rust/src/lexer_atn_simulator.rs +++ b/runtime/Rust/src/lexer_atn_simulator.rs @@ -4,7 +4,6 @@ use std::cell::Cell; use std::ops::Deref; use std::rc::Rc; use std::sync::Arc; -use std::usize; use crate::atn::ATN; use crate::atn_config::{ATNConfig, ATNConfigType}; @@ -404,7 +403,7 @@ impl LexerATNSimulator { } } - fn accept<'input>(&mut self, input: &mut impl IntStream) { + fn accept(&mut self, input: &mut impl IntStream) { input.seek(self.prev_accept.index); self.current_pos.line.set(self.prev_accept.line); self.current_pos diff --git a/runtime/Rust/src/parser.rs b/runtime/Rust/src/parser.rs index 1b21c70243..359b126b04 100644 --- a/runtime/Rust/src/parser.rs +++ b/runtime/Rust/src/parser.rs @@ -186,7 +186,6 @@ where } } -/// pub trait ParserRecog<'a, P: Recognizer<'a>>: Actions<'a, P> {} impl<'input, Ext, I, Ctx, T> Recognizer<'input> for BaseParser<'input, Ext, I, Ctx, T> @@ -478,7 +477,7 @@ where where L: CoerceTo, { - let id = ListenerId::new(&listener); + let id = ListenerId::new(listener.as_ref()); self.parse_listeners.push(listener.coerce_box_to()); id } @@ -492,7 +491,7 @@ where let index = self .parse_listeners .iter() - .position(|it| ListenerId::new(it).actual_id == listener_id.actual_id) + .position(|it| ListenerId::new(it.as_ref()).actual_id == listener_id.actual_id) .expect("listener not found"); unsafe { listener_id.into_listener(self.parse_listeners.remove(index)) } } @@ -711,9 +710,9 @@ pub struct ListenerId { } impl ListenerId { - fn new(listener: &Box) -> ListenerId { + fn new(listener: &T) -> ListenerId { ListenerId { - actual_id: listener.as_ref() as *const T as *const () as usize, + actual_id: listener as *const T as *const () as usize, phantom: Default::default(), } } diff --git a/runtime/Rust/src/prediction_mode.rs b/runtime/Rust/src/prediction_mode.rs index e2c26f6fb9..24642aa340 100644 --- a/runtime/Rust/src/prediction_mode.rs +++ b/runtime/Rust/src/prediction_mode.rs @@ -114,25 +114,25 @@ pub(crate) fn has_sll_conflict_terminating_prediction( // for co //} -pub(crate) fn resolves_to_just_one_viable_alt(altsets: &Vec) -> i32 { +pub(crate) fn resolves_to_just_one_viable_alt(altsets: &[BitSet]) -> i32 { get_single_viable_alt(altsets) } -pub(crate) fn all_subsets_conflict(altsets: &Vec) -> bool { +pub(crate) fn all_subsets_conflict(altsets: &[BitSet]) -> bool { !has_non_conflicting_alt_set(altsets) } -pub(crate) fn all_subsets_equal(altsets: &Vec) -> bool { +pub(crate) fn all_subsets_equal(altsets: &[BitSet]) -> bool { let mut iter = altsets.iter(); let first = iter.next(); iter.all(|it| it == first.unwrap()) } -fn has_non_conflicting_alt_set(altsets: &Vec) -> bool { +fn has_non_conflicting_alt_set(altsets: &[BitSet]) -> bool { altsets.iter().any(|it| it.len() == 1) } -fn has_conflicting_alt_set(altsets: &Vec) -> bool { +fn has_conflicting_alt_set(altsets: &[BitSet]) -> bool { for alts in altsets { if alts.len() > 1 { return true; @@ -143,7 +143,7 @@ fn has_conflicting_alt_set(altsets: &Vec) -> bool { //fn get_unique_alt(altsets: &Vec) -> int { unimplemented!() } // -pub(crate) fn get_alts(altsets: &Vec) -> BitSet { +pub(crate) fn get_alts(altsets: &[BitSet]) -> BitSet { altsets.iter().fold(BitSet::new(), |mut acc, it| { acc.extend(it); acc @@ -182,7 +182,7 @@ fn has_state_associated_with_one_alt(configs: &ATNConfigSet) -> bool { false } -pub(crate) fn get_single_viable_alt(altsets: &Vec) -> i32 { +pub(crate) fn get_single_viable_alt(altsets: &[BitSet]) -> i32 { let mut viable_alts = BitSet::new(); let mut min_alt = INVALID_ALT as usize; for alt in altsets { diff --git a/runtime/Rust/src/tree.rs b/runtime/Rust/src/tree.rs index bfae7e3f6b..879aca89d6 100644 --- a/runtime/Rust/src/tree.rs +++ b/runtime/Rust/src/tree.rs @@ -75,8 +75,8 @@ pub trait ParseTree<'input>: Tree<'input> { /// also it includes only tokens added to the parse tree /// /// Since tokens on hidden channels (e.g. whitespace or comments) are not - /// added to the parse trees, they will not appear in the output of this - /// method. + /// added to the parse trees, they will not appear in the output of this + /// method. fn get_text(&self) -> String { String::new() } @@ -92,8 +92,8 @@ pub trait ParseTree<'input>: Tree<'input> { } } -/// text of the node. -/// Already implemented for all rule contexts +// text of the node. +// Already implemented for all rule contexts // pub trait NodeText { // fn get_node_text(&self, rule_names: &[&str]) -> String; // } @@ -137,7 +137,7 @@ impl<'input, Node: ParserNodeType<'input>, T: 'static> CustomRuleContext<'input> type Ctx = Node; fn get_rule_index(&self) -> usize { - usize::max_value() + usize::MAX } fn get_node_text(&self, _rule_names: &[&str]) -> String { @@ -324,8 +324,8 @@ where pub trait ParseTreeVisitor<'input, Node: ParserNodeType<'input>>: VisitChildren<'input, Node> { - /// Basically alias for `node.accept(self)` in visitor implementation - /// just to make api closer to java + // Basically alias for `node.accept(self)` in visitor implementation + // just to make api closer to java /// Called on terminal(leaf) node fn visit_terminal(&mut self, _node: &TerminalNode<'input, Node>) {} From 5e0cb853db8b369830479666bb77a7238a8539a2 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 08:19:09 -0500 Subject: [PATCH 04/10] rustfmt Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_config.rs | 6 +-- .../Rust/src/atn_deserialization_options.rs | 4 +- runtime/Rust/src/atn_deserializer.rs | 31 +++++-------- runtime/Rust/src/atn_state.rs | 3 +- runtime/Rust/src/common_token_stream.rs | 3 +- runtime/Rust/src/error_strategy.rs | 8 ++-- runtime/Rust/src/errors.rs | 2 +- runtime/Rust/src/int_stream.rs | 4 +- runtime/Rust/src/lexer.rs | 6 ++- runtime/Rust/src/lexer_action.rs | 6 ++- runtime/Rust/src/lexer_atn_simulator.rs | 19 +++++--- runtime/Rust/src/lib.rs | 14 +++--- runtime/Rust/src/parser_atn_simulator.rs | 46 +++++++++---------- runtime/Rust/src/parser_rule_context.rs | 3 -- runtime/Rust/src/prediction_context.rs | 4 +- runtime/Rust/src/tree.rs | 8 +++- runtime/Rust/tests/general_tests.rs | 25 ++++++++-- 17 files changed, 99 insertions(+), 93 deletions(-) diff --git a/runtime/Rust/src/atn_config.rs b/runtime/Rust/src/atn_config.rs index b809a662cd..0b3d26e660 100644 --- a/runtime/Rust/src/atn_config.rs +++ b/runtime/Rust/src/atn_config.rs @@ -110,11 +110,7 @@ impl ATNConfig { }) } - pub fn new( - state: ATNStateRef, - alt: i32, - context: Option>, - ) -> ATNConfig { + pub fn new(state: ATNStateRef, alt: i32, context: Option>) -> ATNConfig { ATNConfig { precedence_filter_suppressed: false, state, diff --git a/runtime/Rust/src/atn_deserialization_options.rs b/runtime/Rust/src/atn_deserialization_options.rs index 28c1a6ae86..b8b8effe50 100644 --- a/runtime/Rust/src/atn_deserialization_options.rs +++ b/runtime/Rust/src/atn_deserialization_options.rs @@ -11,8 +11,6 @@ impl ATNDeserializationOptions { impl Default for ATNDeserializationOptions { fn default() -> Self { - ATNDeserializationOptions { - verify_atn: true, - } + ATNDeserializationOptions { verify_atn: true } } } diff --git a/runtime/Rust/src/atn_deserializer.rs b/runtime/Rust/src/atn_deserializer.rs index af2666978b..29546f7773 100644 --- a/runtime/Rust/src/atn_deserializer.rs +++ b/runtime/Rust/src/atn_deserializer.rs @@ -51,8 +51,6 @@ impl ATNDeserializer { } pub fn deserialize(&self, data: &mut Iter) -> ATN { - - self.check_version(*data.next().unwrap()); let mut atn = self.read_atn(data); @@ -125,9 +123,7 @@ impl ATNDeserializer { state: ATNDecisionState::BlockStartState { end_state, .. }, .. } => *end_state = *data.next().unwrap(), - ATNStateType::LoopEndState(loop_back) => { - *loop_back = *data.next().unwrap() - } + ATNStateType::LoopEndState(loop_back) => *loop_back = *data.next().unwrap(), _ => (), } atn.add_state(state); @@ -206,11 +202,7 @@ impl ATNDeserializer { } } - fn read_sets( - &self, - _atn: &mut ATN, - data: &mut Iter, - ) -> Vec { + fn read_sets(&self, _atn: &mut ATN, data: &mut Iter) -> Vec { let nsets = *data.next().unwrap(); let mut sets = Vec::new(); for _i in 0..nsets { @@ -232,12 +224,7 @@ impl ATNDeserializer { sets } - fn read_edges( - &self, - atn: &mut ATN, - data: &mut Iter, - sets: &Vec, - ) { + fn read_edges(&self, atn: &mut ATN, data: &mut Iter, sets: &Vec) { let nedges = *data.next().unwrap(); for _i in 0..nedges { @@ -250,7 +237,10 @@ impl ATNDeserializer { let transition = self.edge_factory(atn, ttype, src, trg, arg1, arg2, arg3, sets); - atn.states.get_mut(src as usize).unwrap().add_transition(transition); + atn.states + .get_mut(src as usize) + .unwrap() + .add_transition(transition); } let mut new_tr = Vec::new(); @@ -368,8 +358,9 @@ impl ATNDeserializer { if let ATNStateType::RuleStartState { is_left_recursive: true, .. - } = - _atn.states[_atn.rule_to_start_state[state.get_rule_index() as usize] as usize].get_state_type() + } = _atn.states + [_atn.rule_to_start_state[state.get_rule_index() as usize] as usize] + .get_state_type() { let maybe_loop_end = state.get_transitions().iter().last().unwrap().get_target(); @@ -378,7 +369,7 @@ impl ATNDeserializer { if maybe_loop_end.has_epsilon_only_transitions() { if let ATNStateType::RuleStopState = _atn.states [maybe_loop_end.get_transitions()[0].get_target() as usize] - .get_state_type() + .get_state_type() { precedence_states.push(state.get_state_number()) } diff --git a/runtime/Rust/src/atn_state.rs b/runtime/Rust/src/atn_state.rs index b84371eb8a..869763367c 100644 --- a/runtime/Rust/src/atn_state.rs +++ b/runtime/Rust/src/atn_state.rs @@ -178,8 +178,7 @@ impl ATNState for BaseATNState { if (existing.get_label().is_some() && trans.get_label().is_some() && existing.get_label() == trans.get_label()) - || - (existing.is_epsilon() && trans.is_epsilon()) + || (existing.is_epsilon() && trans.is_epsilon()) { already_present = true; break; diff --git a/runtime/Rust/src/common_token_stream.rs b/runtime/Rust/src/common_token_stream.rs index 4449e2f8cd..eb89acebc9 100644 --- a/runtime/Rust/src/common_token_stream.rs +++ b/runtime/Rust/src/common_token_stream.rs @@ -117,7 +117,7 @@ impl<'input, T: TokenSource<'input>> CommonTokenStream<'input, T> { } r } - + pub fn get_dfa_string(&self) -> String { self.base.get_dfa_string() } @@ -313,5 +313,4 @@ impl<'input, T: TokenSource<'input>> CommonTokenStream<'input, T> { } // fn get_number_of_on_channel_tokens(&self) -> int { unimplemented!() } - } diff --git a/runtime/Rust/src/error_strategy.rs b/runtime/Rust/src/error_strategy.rs index beb11ca794..e0522043ab 100644 --- a/runtime/Rust/src/error_strategy.rs +++ b/runtime/Rust/src/error_strategy.rs @@ -577,11 +577,9 @@ impl<'input, Ctx: ParserNodeType<'input>> BailErrorStrategy<'input, Ctx> { e: &ANTLRError, ) -> ANTLRError { let mut ctx = recognizer.get_parser_rule_context().clone(); - let _: Option<()> = (|| { - loop { - ctx.set_exception(e.clone()); - ctx = ctx.get_parent()? - } + let _: Option<()> = (|| loop { + ctx.set_exception(e.clone()); + ctx = ctx.get_parent()? })(); ANTLRError::FallThrough(Arc::new(ParseCancelledError(e.clone()))) } diff --git a/runtime/Rust/src/errors.rs b/runtime/Rust/src/errors.rs index 0b5f56123b..70906b0f49 100644 --- a/runtime/Rust/src/errors.rs +++ b/runtime/Rust/src/errors.rs @@ -120,7 +120,7 @@ pub struct BaseRecognitionError { pub offending_token: OwningToken, pub offending_state: i32, states_stack: Vec, // ctx: Rc - // input: Box + // input: Box } impl BaseRecognitionError { diff --git a/runtime/Rust/src/int_stream.rs b/runtime/Rust/src/int_stream.rs index 3684d3e457..5da6841acc 100644 --- a/runtime/Rust/src/int_stream.rs +++ b/runtime/Rust/src/int_stream.rs @@ -1,6 +1,6 @@ //! Iterator for IterWrapper<'_, T> { fn next(&mut self) -> Option { if self.1 { - return None + return None; } let token = self.0.la(1); diff --git a/runtime/Rust/src/lexer.rs b/runtime/Rust/src/lexer.rs index 96a17be6e0..4b85d7a9c6 100644 --- a/runtime/Rust/src/lexer.rs +++ b/runtime/Rust/src/lexer.rs @@ -416,7 +416,11 @@ where } fn get_dfa_string(&self) -> String { - self.get_interpreter().unwrap().get_dfa_for_mode(LEXER_DEFAULT_MODE).upgradable_read().to_lexer_string() + self.get_interpreter() + .unwrap() + .get_dfa_for_mode(LEXER_DEFAULT_MODE) + .upgradable_read() + .to_lexer_string() } } diff --git a/runtime/Rust/src/lexer_action.rs b/runtime/Rust/src/lexer_action.rs index 4e1b42cd05..b951da66a4 100644 --- a/runtime/Rust/src/lexer_action.rs +++ b/runtime/Rust/src/lexer_action.rs @@ -36,8 +36,10 @@ impl LexerAction { //// unsafe {discriminant_value(self)} as i32 // } pub fn is_position_dependent(&self) -> bool { - matches!(self, LexerAction::LexerCustomAction { .. } - | LexerAction::LexerIndexedCustomAction { .. }) + matches!( + self, + LexerAction::LexerCustomAction { .. } | LexerAction::LexerIndexedCustomAction { .. } + ) } pub(crate) fn execute<'input, T: Lexer<'input>>(&self, lexer: &mut T) { match self { diff --git a/runtime/Rust/src/lexer_atn_simulator.rs b/runtime/Rust/src/lexer_atn_simulator.rs index 05361fb14c..0c2ae899fa 100644 --- a/runtime/Rust/src/lexer_atn_simulator.rs +++ b/runtime/Rust/src/lexer_atn_simulator.rs @@ -198,7 +198,8 @@ impl LexerATNSimulator { .ok_or_else(|| ANTLRError::IllegalStateError("invalid mode".into()))?; let _old_mode = self.mode; - let mut s0_closure = self.compute_start_state(atn.states[start_state as usize].as_ref(), lexer); + let mut s0_closure = + self.compute_start_state(atn.states[start_state as usize].as_ref(), lexer); let _supress_edge = s0_closure.has_semantic_context(); s0_closure.set_has_semantic_context(false); @@ -344,7 +345,8 @@ impl LexerATNSimulator { .fix_offset_before_match(lexer.input().index() - self.start_index) }); - let new = config.cloned_with_new_exec(self.atn().states[target as usize].as_ref(), exec); + let new = config + .cloned_with_new_exec(self.atn().states[target as usize].as_ref(), exec); if self.closure( new, _reach, @@ -534,7 +536,12 @@ impl LexerATNSimulator { lexer: &mut impl Lexer<'input>, ) -> Option { let mut result = None; - let target = self.atn().states.get(_trans.get_target() as usize).unwrap().as_ref(); + let target = self + .atn() + .states + .get(_trans.get_target() as usize) + .unwrap() + .as_ref(); // println!("epsilon target for {:?} is {:?}", _trans, target.get_state_type()); match _trans.get_serialization_type() { TransitionType::TRANSITION_EPSILON => { @@ -688,9 +695,9 @@ impl LexerATNSimulator { let states = &mut dfa.states; let key = dfastate.default_hash(); let dfastate_index: DFAStateRef = if let Some(entry) = dfa.states_map.get(&key) { - let find_result = entry.iter().find(|it| { - states[**it].configs == dfastate.configs - }); + let find_result = entry + .iter() + .find(|it| states[**it].configs == dfastate.configs); if let Some(find_result) = find_result { *find_result } else { diff --git a/runtime/Rust/src/lib.rs b/runtime/Rust/src/lib.rs index 7cfccfda02..ec716d446e 100644 --- a/runtime/Rust/src/lib.rs +++ b/runtime/Rust/src/lib.rs @@ -129,17 +129,15 @@ mod token_source; pub mod token_stream; //pub mod trace_listener; #[doc(hidden)] -pub mod dfa; -#[doc(hidden)] -pub mod transition; -pub mod tree; -#[doc(hidden)] pub mod atn; #[doc(hidden)] pub mod atn_config_set; #[doc(hidden)] pub mod atn_deserializer; +mod atn_type; pub mod common_token_stream; +#[doc(hidden)] +pub mod dfa; mod dfa_serializer; pub mod error_listener; pub mod error_strategy; @@ -152,11 +150,13 @@ pub mod lexer_atn_simulator; pub mod parser; pub mod parser_atn_simulator; mod prediction_mode; +pub mod rule_context; pub mod token; +#[doc(hidden)] +pub mod transition; +pub mod tree; pub mod trees; mod utils; -mod atn_type; -pub mod rule_context; pub mod vocabulary; //#[cfg(test)] // tests are either integration tests in "tests" foulder or unit tests in some modules diff --git a/runtime/Rust/src/parser_atn_simulator.rs b/runtime/Rust/src/parser_atn_simulator.rs index 781e90d3ec..fb4b2647f8 100644 --- a/runtime/Rust/src/parser_atn_simulator.rs +++ b/runtime/Rust/src/parser_atn_simulator.rs @@ -5,9 +5,9 @@ use std::collections::{HashMap, HashSet}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::ptr; use std::rc::Rc; use std::sync::Arc; -use std::{ptr}; use bit_set::BitSet; @@ -325,13 +325,11 @@ impl ParserATNSimulator { let alts = self.eval_semantic_context(local, &Dstate.predicates, true); return match alts.len() { - 0 => { - Err(self.no_viable_alt( - local, - Dstate.configs.as_ref(), - self.start_index.get(), - )) - } + 0 => Err(self.no_viable_alt( + local, + Dstate.configs.as_ref(), + self.start_index.get(), + )), 1 => Ok(alts.iter().next().unwrap() as i32), _ => { self.report_ambiguity( @@ -345,7 +343,7 @@ impl ParserATNSimulator { ); Ok(alts.iter().next().unwrap() as i32) } - } + }; } previousD = D; @@ -358,11 +356,7 @@ impl ParserATNSimulator { } #[allow(non_snake_case)] - fn get_existing_target_state( - dfa: &DFA, - previousD: DFAStateRef, - t: i32, - ) -> Option { + fn get_existing_target_state(dfa: &DFA, previousD: DFAStateRef, t: i32) -> Option { dfa.states[previousD] .edges .get((t + 1) as usize) @@ -663,7 +657,8 @@ impl ParserATNSimulator { if look_to_end_of_rule && state.has_epsilon_only_transitions() { let next_tokens = self.atn().next_tokens(state); if next_tokens.contains(TOKEN_EPSILON) { - let end_of_rule_state = self.atn().rule_to_stop_state[state.get_rule_index() as usize]; + let end_of_rule_state = + self.atn().rule_to_stop_state[state.get_rule_index() as usize]; result.add_cached( c.cloned(self.atn().states[end_of_rule_state as usize].as_ref()) .into(), @@ -894,7 +889,8 @@ impl ParserATNSimulator { let mut alts = IntervalSet::new(); for c in configs.get_items() { let has_empty_path = c.get_context().map(|x| x.has_empty_path()) == Some(true); - let is_stop = self.atn().states[c.get_state() as usize].get_state_type() == &RuleStopState; + let is_stop = + self.atn().states[c.get_state() as usize].get_state_type() == &RuleStopState; if c.get_reaches_into_outer_context() > 0 || (is_stop && has_empty_path) { alts.add_one(c.get_alt()) } @@ -1094,7 +1090,9 @@ impl ParserATNSimulator { ); if let Some(mut c) = c { let mut new_depth = depth; - if let RuleStopState = self.atn().states[config.get_state() as usize].get_state_type() { + if let RuleStopState = + self.atn().states[config.get_state() as usize].get_state_type() + { assert!(!full_ctx); if local.dfa().is_precedence_dfa() { @@ -1104,8 +1102,7 @@ impl ParserATNSimulator { .outermost_precedence_return; let atn_start_state = self.atn().states[local.dfa().atn_start_state as usize].as_ref(); - if outermost_precedence_return == atn_start_state.get_rule_index() - { + if outermost_precedence_return == atn_start_state.get_rule_index() { c.set_precedence_filter_suppressed(true); } } @@ -1353,11 +1350,12 @@ impl ParserATNSimulator { fn rule_transition(&self, config: &ATNConfig, t: &RuleTransition) -> ATNConfig { assert!(config.get_context().is_some()); - let new_ctx = PredictionContext::new_singleton( - config.get_context().cloned(), - t.follow_state, - ); - config.cloned_with_new_ctx(self.atn().states[t.target as usize].as_ref(), Some(new_ctx.into())) + let new_ctx = + PredictionContext::new_singleton(config.get_context().cloned(), t.follow_state); + config.cloned_with_new_ctx( + self.atn().states[t.target as usize].as_ref(), + Some(new_ctx.into()), + ) } fn get_conflicting_alts(&self, configs: &ATNConfigSet) -> BitSet { diff --git a/runtime/Rust/src/parser_rule_context.rs b/runtime/Rust/src/parser_rule_context.rs index 6e1e424c73..a4e0b8e5b5 100644 --- a/runtime/Rust/src/parser_rule_context.rs +++ b/runtime/Rust/src/parser_rule_context.rs @@ -430,8 +430,6 @@ impl<'input, Ctx: CustomRuleContext<'input>> Tree<'input> for BaseParserRuleCont impl<'input, Ctx: CustomRuleContext<'input> + TidAble<'input>> ParseTree<'input> for BaseParserRuleContext<'input, Ctx> { - - fn get_text(&self) -> String { let children = self.get_children(); let mut result = String::new(); @@ -580,7 +578,6 @@ where T: DerefSeal + 'input + Debug + Tid<'input>, I: ParserRuleContext<'input> + 'input + ?Sized, { - fn get_text(&self) -> String { self.deref().get_text() } diff --git a/runtime/Rust/src/prediction_context.rs b/runtime/Rust/src/prediction_context.rs index 86038b3571..1b6dca26c0 100644 --- a/runtime/Rust/src/prediction_context.rs +++ b/runtime/Rust/src/prediction_context.rs @@ -204,9 +204,7 @@ impl PredictionContext { Some(x) => x.hash_code(), }) }); - return_states - .iter() - .for_each(|x| hasher.write_i32(*x)); + return_states.iter().for_each(|x| hasher.write_i32(*x)); } // PredictionContext::Empty { .. } => {} }; diff --git a/runtime/Rust/src/tree.rs b/runtime/Rust/src/tree.rs index 879aca89d6..687ca7166c 100644 --- a/runtime/Rust/src/tree.rs +++ b/runtime/Rust/src/tree.rs @@ -371,7 +371,9 @@ pub trait Visitable { /// Calls corresponding visit callback on visitor`Vis` fn accept(&self, _visitor: &mut Vis) { if cfg!(feature = "debug") { - unreachable!("should have been properly implemented by generated context when reachable") + unreachable!( + "should have been properly implemented by generated context when reachable" + ) } } } @@ -381,7 +383,9 @@ pub trait Visitable { pub trait VisitableDyn { fn accept_dyn(&self, _visitor: &mut Vis) { if cfg!(feature = "debug") { - unreachable!("should have been properly implemented by generated context when reachable") + unreachable!( + "should have been properly implemented by generated context when reachable" + ) } } } diff --git a/runtime/Rust/tests/general_tests.rs b/runtime/Rust/tests/general_tests.rs index b0c76ec2c6..e2f0a0f148 100644 --- a/runtime/Rust/tests/general_tests.rs +++ b/runtime/Rust/tests/general_tests.rs @@ -163,7 +163,10 @@ if (x < x && a > 0) then duh struct Listener {} impl<'input> ParseTreeListener<'input, CSVParserContextType> for Listener { - fn enter_every_rule(&mut self, ctx: &dyn CSVParserContext<'input>) -> Result<(), ANTLRError> { + fn enter_every_rule( + &mut self, + ctx: &dyn CSVParserContext<'input>, + ) -> Result<(), ANTLRError> { println!( "rule entered {}", csvparser::ruleNames @@ -197,7 +200,10 @@ if (x < x && a > 0) then duh struct Listener2 {} impl<'input> ParseTreeListener<'input, ReferenceToATNParserContextType> for Listener2 { - fn enter_every_rule(&mut self, ctx: &dyn ReferenceToATNParserContext<'input>) -> Result<(), ANTLRError> { + fn enter_every_rule( + &mut self, + ctx: &dyn ReferenceToATNParserContext<'input>, + ) -> Result<(), ANTLRError> { println!( "rule entered {}", referencetoatnparser::ruleNames @@ -235,7 +241,10 @@ if (x < x && a > 0) then duh println!("terminal node {}", node.symbol.get_text()); } - fn enter_every_rule(&mut self, ctx: &dyn SimpleLRParserContext<'input>) -> Result<(), ANTLRError> { + fn enter_every_rule( + &mut self, + ctx: &dyn SimpleLRParserContext<'input>, + ) -> Result<(), ANTLRError> { println!( "rule entered {}", simplelrparser::ruleNames @@ -245,7 +254,10 @@ if (x < x && a > 0) then duh Ok(()) } - fn exit_every_rule(&mut self, ctx: &dyn SimpleLRParserContext<'input>) -> Result<(), ANTLRError> { + fn exit_every_rule( + &mut self, + ctx: &dyn SimpleLRParserContext<'input>, + ) -> Result<(), ANTLRError> { println!( "rule exited {}", simplelrparser::ruleNames @@ -289,7 +301,10 @@ if (x < x && a > 0) then duh println!("enter terminal"); let _ = writeln!(&mut self.data, "terminal node {}", node.symbol.get_text()); } - fn enter_every_rule(&mut self, ctx: &dyn SimpleLRParserContext<'input>) -> Result<(), ANTLRError> { + fn enter_every_rule( + &mut self, + ctx: &dyn SimpleLRParserContext<'input>, + ) -> Result<(), ANTLRError> { println!( "rule entered {}", simplelrparser::ruleNames From 9b92779255af1525bbae902621846c4064fb8c02 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 19:52:37 -0500 Subject: [PATCH 05/10] refactor: removed unused Tree::get_payload() Signed-off-by: Alex Snaps --- runtime/Rust/src/parser_rule_context.rs | 10 +--------- runtime/Rust/src/tree.rs | 4 ---- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/runtime/Rust/src/parser_rule_context.rs b/runtime/Rust/src/parser_rule_context.rs index a4e0b8e5b5..7c99a11474 100644 --- a/runtime/Rust/src/parser_rule_context.rs +++ b/runtime/Rust/src/parser_rule_context.rs @@ -1,5 +1,5 @@ //! Full parser node -use std::any::{type_name, Any}; +use std::any::type_name; use std::borrow::{Borrow, BorrowMut}; use std::cell::{Ref, RefCell, RefMut}; use std::fmt::{Debug, Error, Formatter}; @@ -404,10 +404,6 @@ impl<'input, Ctx: CustomRuleContext<'input>> Tree<'input> for BaseParserRuleCont self.base.parent_ctx.borrow().is_some() } - fn get_payload(&self) -> Box { - unimplemented!() - } - fn get_child(&self, i: usize) -> Option>::Type>> { self.children.borrow().get(i).cloned() } @@ -596,10 +592,6 @@ where self.deref().has_parent() } - fn get_payload(&self) -> Box { - self.deref().get_payload() - } - fn get_child(&self, i: usize) -> Option>::Type>> { self.deref().get_child(i) } diff --git a/runtime/Rust/src/tree.rs b/runtime/Rust/src/tree.rs index 687ca7166c..52025b7ac3 100644 --- a/runtime/Rust/src/tree.rs +++ b/runtime/Rust/src/tree.rs @@ -1,5 +1,4 @@ //! General AST -use std::any::Any; use std::borrow::Borrow; use std::fmt::{Debug, Formatter}; @@ -30,9 +29,6 @@ pub trait Tree<'input>: RuleContext<'input> { fn has_parent(&self) -> bool { false } - fn get_payload(&self) -> Box { - unimplemented!() - } fn get_child(&self, _i: usize) -> Option>::Type>> { None } From 169cefc49efabe9f187a7cd10f774f749bb77f32 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 20:00:54 -0500 Subject: [PATCH 06/10] refactor: collapse nested if statements Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_state.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/Rust/src/atn_state.rs b/runtime/Rust/src/atn_state.rs index 869763367c..7db2d8ac9b 100644 --- a/runtime/Rust/src/atn_state.rs +++ b/runtime/Rust/src/atn_state.rs @@ -174,15 +174,14 @@ impl ATNState for BaseATNState { let mut already_present = false; for existing in self.transitions.iter() { - if existing.get_target() == trans.get_target() { - if (existing.get_label().is_some() + if existing.get_target() == trans.get_target() + && ((existing.get_label().is_some() && trans.get_label().is_some() && existing.get_label() == trans.get_label()) - || (existing.is_epsilon() && trans.is_epsilon()) - { - already_present = true; - break; - } + || (existing.is_epsilon() && trans.is_epsilon())) + { + already_present = true; + break; } } if !already_present { From f472dfbfc00a805b2e6d7ea03f49108e3485c16d Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 20 Dec 2025 20:08:20 -0500 Subject: [PATCH 07/10] refactor: cleaned up ATNState Signed-off-by: Alex Snaps --- runtime/Rust/src/atn_state.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/runtime/Rust/src/atn_state.rs b/runtime/Rust/src/atn_state.rs index 7db2d8ac9b..09aa705cc7 100644 --- a/runtime/Rust/src/atn_state.rs +++ b/runtime/Rust/src/atn_state.rs @@ -71,7 +71,6 @@ pub trait ATNState: Sync + Send + Debug { fn has_epsilon_only_transitions(&self) -> bool; fn get_rule_index(&self) -> i32; - fn set_rule_index(&self, v: i32); fn get_next_tokens_within_rule(&self) -> &OnceCell; // fn set_next_token_within_rule(&mut self, v: IntervalSet); @@ -82,10 +81,8 @@ pub trait ATNState: Sync + Send + Debug { fn get_state_type_id(&self) -> i32; fn get_state_number(&self) -> i32; - fn set_state_number(&self, state_number: i32); fn get_transitions(&self) -> &Vec>; - fn set_transitions(&self, t: Vec>); fn add_transition(&mut self, trans: Box); } @@ -129,10 +126,6 @@ impl ATNState for BaseATNState { self.rule_index } - fn set_rule_index(&self, _v: i32) { - unimplemented!() - } - fn get_next_tokens_within_rule(&self) -> &OnceCell { &self.next_tokens_within_rule } @@ -153,18 +146,10 @@ impl ATNState for BaseATNState { self.state_number } - fn set_state_number(&self, _state_number: i32) { - unimplemented!() - } - fn get_transitions(&self) -> &Vec> { &self.transitions } - fn set_transitions(&self, _t: Vec>) { - unimplemented!() - } - fn add_transition(&mut self, trans: Box) { if self.transitions.is_empty() { self.epsilon_only_transitions = trans.is_epsilon() From c183b7f52d3476dfe26f911827b729de5b7fb2e8 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Mon, 2 Mar 2026 18:50:45 -0500 Subject: [PATCH 08/10] ci: Enable fmt checks and reformat gen'ed code Signed-off-by: Alex Snaps --- .github/workflows/hosted.yml | 4 +- runtime/Rust/tests/gen/csvlexer.rs | 264 ++- runtime/Rust/tests/gen/csvlistener.rs | 89 +- runtime/Rust/tests/gen/csvparser.rs | 1099 ++++----- runtime/Rust/tests/gen/csvvisitor.rs | 145 +- runtime/Rust/tests/gen/labelslexer.rs | 287 +-- runtime/Rust/tests/gen/labelslistener.rs | 197 +- runtime/Rust/tests/gen/labelsparser.rs | 2030 ++++++++++------- runtime/Rust/tests/gen/referencetoatnlexer.rs | 238 +- .../Rust/tests/gen/referencetoatnlistener.rs | 31 +- .../Rust/tests/gen/referencetoatnparser.rs | 525 +++-- runtime/Rust/tests/gen/simplelrlexer.rs | 198 -- runtime/Rust/tests/gen/simplelrlistener.rs | 49 +- runtime/Rust/tests/gen/simplelrparser.rs | 687 +++--- runtime/Rust/tests/gen/visitorbasiclexer.rs | 216 +- .../Rust/tests/gen/visitorbasiclistener.rs | 31 +- runtime/Rust/tests/gen/visitorbasicparser.rs | 430 ++-- runtime/Rust/tests/gen/visitorbasicvisitor.rs | 51 +- runtime/Rust/tests/gen/visitorcalclexer.rs | 268 +-- runtime/Rust/tests/gen/visitorcalclistener.rs | 103 +- runtime/Rust/tests/gen/visitorcalcparser.rs | 1314 ++++++----- runtime/Rust/tests/gen/visitorcalcvisitor.rs | 159 +- runtime/Rust/tests/gen/xmllexer.rs | 589 ++--- 23 files changed, 4776 insertions(+), 4228 deletions(-) diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml index f75de30183..229fad5797 100644 --- a/.github/workflows/hosted.yml +++ b/.github/workflows/hosted.yml @@ -390,8 +390,8 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose -# - name: Formatting -# run: cargo fmt -- --check + - name: Formatting + run: cargo fmt -- --check - uses: actions/checkout@v3 if: ${{ github.event_name == 'push' }} with: diff --git a/runtime/Rust/tests/gen/csvlexer.rs b/runtime/Rust/tests/gen/csvlexer.rs index 768f5286af..4484bc3790 100644 --- a/runtime/Rust/tests/gen/csvlexer.rs +++ b/runtime/Rust/tests/gen/csvlexer.rs @@ -4,91 +4,92 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const T__0: i32 = 1; +pub const T__1: i32 = 2; +pub const T__2: i32 = 3; +pub const WS: i32 = 4; +pub const TEXT: i32 = 5; +pub const STRING: i32 = 6; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; + +pub const modeNames: [&'static str; 1] = ["DEFAULT_MODE"]; + +pub const ruleNames: [&'static str; 6] = ["T__0", "T__1", "T__2", "WS", "TEXT", "STRING"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 4] = + [None, Some("','"), Some("'\\r'"), Some("'\\n'")]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 7] = [ + None, + None, + None, + None, + Some("WS"), + Some("TEXT"), + Some("STRING"), +]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} - pub const T__0:i32=1; - pub const T__1:i32=2; - pub const T__2:i32=3; - pub const WS:i32=4; - pub const TEXT:i32=5; - pub const STRING:i32=6; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;6] = [ - "T__0", "T__1", "T__2", "WS", "TEXT", "STRING" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;4] = [ - None, Some("','"), Some("'\\r'"), Some("'\\n'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;7] = [ - None, None, None, None, Some("WS"), Some("TEXT"), Some("STRING") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = antlr4rust::token_factory::ArenaCommonFactory<'input>; -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct CSVLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,CSVLexerActions,Input,LocalTokenFactory<'input>>, +pub struct CSVLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, CSVLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for CSVLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for CSVLexer<'input,Input>{ - type Target = BaseLexer<'input,CSVLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for CSVLexer<'input, Input> { + type Target = BaseLexer<'input, CSVLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for CSVLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for CSVLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> CSVLexer<'input,Input>{ +impl<'input, Input: CharStream>> CSVLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -104,49 +105,54 @@ impl<'input, Input:CharStream >> CSVLexer<'input,Input>{ "CSVLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - CSVLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> CSVLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - CSVLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct CSVLexerActions { + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + CSVLexerActions {}, + tf, + ), + } + } } -impl CSVLexerActions{ +impl<'input, Input: CharStream>> CSVLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + CSVLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,CSVLexerActions,Input,LocalTokenFactory<'input>>> for CSVLexerActions{ - } +pub struct CSVLexerActions {} - impl<'input, Input:CharStream >> CSVLexer<'input,Input>{ +impl CSVLexerActions {} +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, CSVLexerActions, Input, LocalTokenFactory<'input>>> + for CSVLexerActions +{ } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,CSVLexerActions,Input,LocalTokenFactory<'input>>> for CSVLexerActions{ +impl<'input, Input: CharStream>> CSVLexer<'input, Input> {} + +impl<'input, Input: CharStream>> + LexerRecog<'input, BaseLexer<'input, CSVLexerActions, Input, LocalTokenFactory<'input>>> + for CSVLexerActions +{ } -impl<'input> TokenAware<'input> for CSVLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for CSVLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for CSVLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> for CSVLexer<'input, Input> { + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -164,9 +170,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for CSVLexer<' self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -177,42 +183,32 @@ impl<'input, Input:CharStream >> TokenSource<'input> for CSVLexer<' } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 6, 42, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, - 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 4, 3, - 21, 8, 3, 11, 3, 12, 3, 22, 1, 3, 1, 3, 1, 4, 4, 4, 28, 8, 4, 11, 4, - 12, 4, 29, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 36, 8, 5, 10, 5, 12, 5, 39, - 9, 5, 1, 5, 1, 5, 0, 0, 6, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 1, 0, - 3, 1, 0, 32, 32, 5, 0, 10, 10, 13, 13, 32, 32, 34, 34, 44, 44, 1, 0, - 34, 34, 45, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, - 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 1, 13, 1, 0, 0, 0, - 3, 15, 1, 0, 0, 0, 5, 17, 1, 0, 0, 0, 7, 20, 1, 0, 0, 0, 9, 27, 1, 0, - 0, 0, 11, 31, 1, 0, 0, 0, 13, 14, 5, 44, 0, 0, 14, 2, 1, 0, 0, 0, 15, - 16, 5, 13, 0, 0, 16, 4, 1, 0, 0, 0, 17, 18, 5, 10, 0, 0, 18, 6, 1, 0, - 0, 0, 19, 21, 7, 0, 0, 0, 20, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, - 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 6, 3, - 0, 0, 25, 8, 1, 0, 0, 0, 26, 28, 8, 1, 0, 0, 27, 26, 1, 0, 0, 0, 28, - 29, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 10, 1, 0, - 0, 0, 31, 37, 5, 34, 0, 0, 32, 33, 5, 34, 0, 0, 33, 36, 5, 34, 0, 0, - 34, 36, 8, 2, 0, 0, 35, 32, 1, 0, 0, 0, 35, 34, 1, 0, 0, 0, 36, 39, 1, - 0, 0, 0, 37, 35, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, - 39, 37, 1, 0, 0, 0, 40, 41, 5, 34, 0, 0, 41, 12, 1, 0, 0, 0, 5, 0, 22, - 29, 35, 37, 1, 0, 1, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 6, 42, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, + 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 4, 3, 21, 8, 3, 11, 3, 12, 3, 22, 1, 3, 1, 3, 1, + 4, 4, 4, 28, 8, 4, 11, 4, 12, 4, 29, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 36, 8, 5, 10, 5, 12, 5, + 39, 9, 5, 1, 5, 1, 5, 0, 0, 6, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 1, 0, 3, 1, 0, 32, 32, + 5, 0, 10, 10, 13, 13, 32, 32, 34, 34, 44, 44, 1, 0, 34, 34, 45, 0, 1, 1, 0, 0, 0, 0, 3, 1, + 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 1, 13, 1, + 0, 0, 0, 3, 15, 1, 0, 0, 0, 5, 17, 1, 0, 0, 0, 7, 20, 1, 0, 0, 0, 9, 27, 1, 0, 0, 0, 11, + 31, 1, 0, 0, 0, 13, 14, 5, 44, 0, 0, 14, 2, 1, 0, 0, 0, 15, 16, 5, 13, 0, 0, 16, 4, 1, 0, + 0, 0, 17, 18, 5, 10, 0, 0, 18, 6, 1, 0, 0, 0, 19, 21, 7, 0, 0, 0, 20, 19, 1, 0, 0, 0, 21, + 22, 1, 0, 0, 0, 22, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 6, 3, + 0, 0, 25, 8, 1, 0, 0, 0, 26, 28, 8, 1, 0, 0, 27, 26, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, + 27, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 10, 1, 0, 0, 0, 31, 37, 5, 34, 0, 0, 32, 33, 5, 34, + 0, 0, 33, 36, 5, 34, 0, 0, 34, 36, 8, 2, 0, 0, 35, 32, 1, 0, 0, 0, 35, 34, 1, 0, 0, 0, 36, + 39, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 37, 1, 0, + 0, 0, 40, 41, 5, 34, 0, 0, 41, 12, 1, 0, 0, 0, 5, 0, 22, 29, 35, 37, 1, 0, 1, 0 + ]; +} diff --git a/runtime/Rust/tests/gen/csvlistener.rs b/runtime/Rust/tests/gen/csvlistener.rs index da2a91a038..dc8b0a11d1 100644 --- a/runtime/Rust/tests/gen/csvlistener.rs +++ b/runtime/Rust/tests/gen/csvlistener.rs @@ -1,52 +1,49 @@ #![allow(nonstandard_style)] // Generated from CSV.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::csvparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait CSVListener<'input> : ParseTreeListener<'input,CSVParserContextType>{ -/** - * Enter a parse tree produced by {@link CSVParser#csvFile}. - * @param ctx the parse tree - */ -fn enter_csvFile(&mut self, _ctx: &CsvFileContext<'input>) { } -/** - * Exit a parse tree produced by {@link CSVParser#csvFile}. - * @param ctx the parse tree - */ -fn exit_csvFile(&mut self, _ctx: &CsvFileContext<'input>) { } -/** - * Enter a parse tree produced by {@link CSVParser#hdr}. - * @param ctx the parse tree - */ -fn enter_hdr(&mut self, _ctx: &HdrContext<'input>) { } -/** - * Exit a parse tree produced by {@link CSVParser#hdr}. - * @param ctx the parse tree - */ -fn exit_hdr(&mut self, _ctx: &HdrContext<'input>) { } -/** - * Enter a parse tree produced by {@link CSVParser#row}. - * @param ctx the parse tree - */ -fn enter_row(&mut self, _ctx: &RowContext<'input>) { } -/** - * Exit a parse tree produced by {@link CSVParser#row}. - * @param ctx the parse tree - */ -fn exit_row(&mut self, _ctx: &RowContext<'input>) { } -/** - * Enter a parse tree produced by {@link CSVParser#field}. - * @param ctx the parse tree - */ -fn enter_field(&mut self, _ctx: &FieldContext<'input>) { } -/** - * Exit a parse tree produced by {@link CSVParser#field}. - * @param ctx the parse tree - */ -fn exit_field(&mut self, _ctx: &FieldContext<'input>) { } - +pub trait CSVListener<'input>: ParseTreeListener<'input, CSVParserContextType> { + /** + * Enter a parse tree produced by {@link CSVParser#csvFile}. + * @param ctx the parse tree + */ + fn enter_csvFile(&mut self, _ctx: &CsvFileContext<'input>) {} + /** + * Exit a parse tree produced by {@link CSVParser#csvFile}. + * @param ctx the parse tree + */ + fn exit_csvFile(&mut self, _ctx: &CsvFileContext<'input>) {} + /** + * Enter a parse tree produced by {@link CSVParser#hdr}. + * @param ctx the parse tree + */ + fn enter_hdr(&mut self, _ctx: &HdrContext<'input>) {} + /** + * Exit a parse tree produced by {@link CSVParser#hdr}. + * @param ctx the parse tree + */ + fn exit_hdr(&mut self, _ctx: &HdrContext<'input>) {} + /** + * Enter a parse tree produced by {@link CSVParser#row}. + * @param ctx the parse tree + */ + fn enter_row(&mut self, _ctx: &RowContext<'input>) {} + /** + * Exit a parse tree produced by {@link CSVParser#row}. + * @param ctx the parse tree + */ + fn exit_row(&mut self, _ctx: &RowContext<'input>) {} + /** + * Enter a parse tree produced by {@link CSVParser#field}. + * @param ctx the parse tree + */ + fn enter_field(&mut self, _ctx: &FieldContext<'input>) {} + /** + * Exit a parse tree produced by {@link CSVParser#field}. + * @param ctx the parse tree + */ + fn exit_field(&mut self, _ctx: &FieldContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : CSVListener<'input> } - - +antlr4rust::coerce_from! { 'input : CSVListener<'input> } diff --git a/runtime/Rust/tests/gen/csvparser.rs b/runtime/Rust/tests/gen/csvparser.rs index e3851cef99..2d7add88aa 100644 --- a/runtime/Rust/tests/gen/csvparser.rs +++ b/runtime/Rust/tests/gen/csvparser.rs @@ -7,38 +7,38 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::csvlistener::*; +use super::csvvisitor::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::csvlistener::*; -use super::csvvisitor::*; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -47,113 +47,130 @@ const _: () = { ); }; - pub const CSV_T__0:i32=1; - pub const CSV_T__1:i32=2; - pub const CSV_T__2:i32=3; - pub const CSV_WS:i32=4; - pub const CSV_TEXT:i32=5; - pub const CSV_STRING:i32=6; - pub const CSV_EOF:i32=EOF; - pub const RULE_csvFile:usize = 0; - pub const RULE_hdr:usize = 1; - pub const RULE_row:usize = 2; - pub const RULE_field:usize = 3; - pub const ruleNames: [&'static str; 4] = [ - "csvFile", "hdr", "row", "field" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;4] = [ - None, Some("','"), Some("'\\r'"), Some("'\\n'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;7] = [ - None, None, None, None, Some("WS"), Some("TEXT"), Some("STRING") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -type BaseParserType<'input, I> = - BaseParser<'input,CSVParserExt<'input>, I, CSVParserContextType , dyn CSVListener<'input> + 'input >; +pub const CSV_T__0: i32 = 1; +pub const CSV_T__1: i32 = 2; +pub const CSV_T__2: i32 = 3; +pub const CSV_WS: i32 = 4; +pub const CSV_TEXT: i32 = 5; +pub const CSV_STRING: i32 = 6; +pub const CSV_EOF: i32 = EOF; +pub const RULE_csvFile: usize = 0; +pub const RULE_hdr: usize = 1; +pub const RULE_row: usize = 2; +pub const RULE_field: usize = 3; +pub const ruleNames: [&'static str; 4] = ["csvFile", "hdr", "row", "field"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 4] = + [None, Some("','"), Some("'\\r'"), Some("'\\n'")]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 7] = [ + None, + None, + None, + None, + Some("WS"), + Some("TEXT"), + Some("STRING"), +]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} + +type BaseParserType<'input, I> = BaseParser< + 'input, + CSVParserExt<'input>, + I, + CSVParserContextType, + dyn CSVListener<'input> + 'input, +>; type TokenType<'input> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = antlr4rust::token_factory::ArenaCommonFactory<'input>; -pub type CSVTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, CSVParserContextType , dyn CSVListener<'input> + 'a>; +pub type CSVTreeWalker<'input, 'a> = + ParseTreeWalker<'input, 'a, CSVParserContextType, dyn CSVListener<'input> + 'a>; /// Parser for CSV grammar pub struct CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - CSVParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + CSVParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } /// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for CSVParser pub trait CSVParserContext<'input>: - for<'x> Listenable + 'x > + - for<'x> Visitable + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=CSVParserContextType> -{} + for<'x> Listenable + 'x> + + for<'x> Visitable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = CSVParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : CSVParserContext<'input> } +antlr4rust::coerce_from! { 'input : CSVParserContext<'input> } impl<'input, 'x, T> VisitableDyn for dyn CSVParserContext<'input> + 'input where @@ -164,26 +181,26 @@ where } } -impl<'input> CSVParserContext<'input> for TerminalNode<'input,CSVParserContextType> {} -impl<'input> CSVParserContext<'input> for ErrorNode<'input,CSVParserContextType> {} +impl<'input> CSVParserContext<'input> for TerminalNode<'input, CSVParserContextType> {} +impl<'input> CSVParserContext<'input> for ErrorNode<'input, CSVParserContextType> {} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn CSVParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn CSVListener<'input> + 'input } pub struct CSVParserContextType; -antlr4rust::tid!{CSVParserContextType} +antlr4rust::tid! {CSVParserContextType} -impl<'input> ParserNodeType<'input> for CSVParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn CSVParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for CSVParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn CSVParserContext<'input> + 'input; } impl<'input, I> Deref for CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -192,550 +209,574 @@ where impl<'input, I> DerefMut for CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct CSVParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct CSVParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> CSVParserExt<'input>{ -} +impl<'input> CSVParserExt<'input> {} antlr4rust::tid! { CSVParserExt<'a> } -impl<'input> TokenAware<'input> for CSVParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for CSVParserExt<'input> { + type TF = LocalTokenFactory<'input>; } -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> ParserRecog<'input, BaseParserType<'input,I>> for CSVParserExt<'input>{} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + ParserRecog<'input, BaseParserType<'input, I>> for CSVParserExt<'input> +{ +} -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> Actions<'input, BaseParserType<'input,I>> for CSVParserExt<'input>{ - fn get_grammar_file_name(&self) -> & str{ "CSV.g4"} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + Actions<'input, BaseParserType<'input, I>> for CSVParserExt<'input> +{ + fn get_grammar_file_name(&self) -> &str { + "CSV.g4" + } - fn get_rule_names(&self) -> &[& str] {&ruleNames} + fn get_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } } //------------------- csvFile ---------------- pub type CsvFileContextAll<'input> = CsvFileContext<'input>; - -pub type CsvFileContext<'input> = BaseParserRuleContext<'input,CsvFileContextExt<'input>>; +pub type CsvFileContext<'input> = BaseParserRuleContext<'input, CsvFileContextExt<'input>>; #[derive(Clone)] -pub struct CsvFileContextExt<'input>{ -ph:PhantomData<&'input str> +pub struct CsvFileContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input> CSVParserContext<'input> for CsvFileContext<'input>{} - -impl<'input,'a> Listenable + 'a> for CsvFileContext<'input>{ - fn enter(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_csvFile(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_csvFile(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} +impl<'input> CSVParserContext<'input> for CsvFileContext<'input> {} -impl<'input,'a> Visitable + 'a> for CsvFileContext<'input>{ - fn accept(&self,visitor: &mut (dyn CSVVisitor<'input> + 'a)) { - visitor.visit_csvFile(self); - } -} - -impl<'input> CustomRuleContext<'input> for CsvFileContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = CSVParserContextType; - fn get_rule_index(&self) -> usize { RULE_csvFile } - //fn type_rule_index() -> usize where Self: Sized { RULE_csvFile } +impl<'input, 'a> Listenable + 'a> for CsvFileContext<'input> { + fn enter(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_csvFile(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_csvFile(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{CsvFileContextExt<'a>} -impl<'input> CsvFileContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,CsvFileContextExt{ - - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for CsvFileContext<'input> { + fn accept(&self, visitor: &mut (dyn CSVVisitor<'input> + 'a)) { + visitor.visit_csvFile(self); + } } -pub trait CsvFileContextAttrs<'input>: CSVParserContext<'input> + BorrowMut>{ - -fn hdr(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) -} -fn row_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() -} -fn row(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) +impl<'input> CustomRuleContext<'input> for CsvFileContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = CSVParserContextType; + fn get_rule_index(&self) -> usize { + RULE_csvFile + } + //fn type_rule_index() -> usize where Self: Sized { RULE_csvFile } +} +antlr4rust::tid! {CsvFileContextExt<'a>} + +impl<'input> CsvFileContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + CsvFileContextExt { ph: PhantomData }, + )) + } } +pub trait CsvFileContextAttrs<'input>: + CSVParserContext<'input> + BorrowMut> +{ + fn hdr(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } + fn row_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn row(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } } -impl<'input> CsvFileContextAttrs<'input> for CsvFileContext<'input>{} +impl<'input> CsvFileContextAttrs<'input> for CsvFileContext<'input> {} impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn csvFile(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = CsvFileContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn csvFile(&mut self) -> Result>, ANTLRError> { + let mut recog = self; + let _parentctx = recog.ctx.take(); + let mut _localctx = CsvFileContextExt::new(_parentctx.clone(), recog.base.get_state()); recog.base.enter_rule(_localctx.clone(), 0, RULE_csvFile); let mut _localctx: Rc = _localctx; - let mut _la: i32 = -1; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - /*InvokeRule hdr*/ - recog.base.set_state(8); - recog.hdr()?; - - recog.base.set_state(10); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - loop { - { - { - /*InvokeRule row*/ - recog.base.set_state(9); - recog.row()?; - - } - } - recog.base.set_state(12); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - if !((((_la) & !0x3f) == 0 && ((1usize << _la) & 110) != 0)) {break} - } - } - 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) - } + let mut _la: i32 = -1; + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + /*InvokeRule hdr*/ + recog.base.set_state(8); + recog.hdr()?; + + recog.base.set_state(10); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + loop { + { + { + /*InvokeRule row*/ + recog.base.set_state(9); + recog.row()?; + } + } + recog.base.set_state(12); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + if !(((_la) & !0x3f) == 0 && ((1usize << _la) & 110) != 0) { + break; + } + } + } + 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) + } } //------------------- hdr ---------------- pub type HdrContextAll<'input> = HdrContext<'input>; - -pub type HdrContext<'input> = BaseParserRuleContext<'input,HdrContextExt<'input>>; +pub type HdrContext<'input> = BaseParserRuleContext<'input, HdrContextExt<'input>>; #[derive(Clone)] -pub struct HdrContextExt<'input>{ -ph:PhantomData<&'input str> +pub struct HdrContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input> CSVParserContext<'input> for HdrContext<'input>{} - -impl<'input,'a> Listenable + 'a> for HdrContext<'input>{ - fn enter(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_hdr(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_hdr(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} +impl<'input> CSVParserContext<'input> for HdrContext<'input> {} -impl<'input,'a> Visitable + 'a> for HdrContext<'input>{ - fn accept(&self,visitor: &mut (dyn CSVVisitor<'input> + 'a)) { - visitor.visit_hdr(self); - } -} - -impl<'input> CustomRuleContext<'input> for HdrContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = CSVParserContextType; - fn get_rule_index(&self) -> usize { RULE_hdr } - //fn type_rule_index() -> usize where Self: Sized { RULE_hdr } +impl<'input, 'a> Listenable + 'a> for HdrContext<'input> { + fn enter(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_hdr(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_hdr(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{HdrContextExt<'a>} -impl<'input> HdrContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,HdrContextExt{ - - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for HdrContext<'input> { + fn accept(&self, visitor: &mut (dyn CSVVisitor<'input> + 'a)) { + visitor.visit_hdr(self); + } } -pub trait HdrContextAttrs<'input>: CSVParserContext<'input> + BorrowMut>{ - -fn row(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) +impl<'input> CustomRuleContext<'input> for HdrContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = CSVParserContextType; + fn get_rule_index(&self) -> usize { + RULE_hdr + } + //fn type_rule_index() -> usize where Self: Sized { RULE_hdr } +} +antlr4rust::tid! {HdrContextExt<'a>} + +impl<'input> HdrContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + HdrContextExt { ph: PhantomData }, + )) + } } +pub trait HdrContextAttrs<'input>: + CSVParserContext<'input> + BorrowMut> +{ + fn row(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> HdrContextAttrs<'input> for HdrContext<'input>{} +impl<'input> HdrContextAttrs<'input> for HdrContext<'input> {} impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn hdr(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = HdrContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn hdr(&mut self) -> Result>, ANTLRError> { + let mut recog = self; + let _parentctx = recog.ctx.take(); + let mut _localctx = HdrContextExt::new(_parentctx.clone(), recog.base.get_state()); recog.base.enter_rule(_localctx.clone(), 2, RULE_hdr); let mut _localctx: Rc = _localctx; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - /*InvokeRule row*/ - recog.base.set_state(14); - recog.row()?; - - } - 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) - } + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + /*InvokeRule row*/ + recog.base.set_state(14); + recog.row()?; + } + 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) + } } //------------------- row ---------------- pub type RowContextAll<'input> = RowContext<'input>; - -pub type RowContext<'input> = BaseParserRuleContext<'input,RowContextExt<'input>>; +pub type RowContext<'input> = BaseParserRuleContext<'input, RowContextExt<'input>>; #[derive(Clone)] -pub struct RowContextExt<'input>{ -ph:PhantomData<&'input str> -} - -impl<'input> CSVParserContext<'input> for RowContext<'input>{} - -impl<'input,'a> Listenable + 'a> for RowContext<'input>{ - fn enter(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_row(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_row(self); - listener.exit_every_rule(self)?; - Ok(()) - } +pub struct RowContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input,'a> Visitable + 'a> for RowContext<'input>{ - fn accept(&self,visitor: &mut (dyn CSVVisitor<'input> + 'a)) { - visitor.visit_row(self); - } -} +impl<'input> CSVParserContext<'input> for RowContext<'input> {} -impl<'input> CustomRuleContext<'input> for RowContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = CSVParserContextType; - fn get_rule_index(&self) -> usize { RULE_row } - //fn type_rule_index() -> usize where Self: Sized { RULE_row } +impl<'input, 'a> Listenable + 'a> for RowContext<'input> { + fn enter(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_row(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_row(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{RowContextExt<'a>} - -impl<'input> RowContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,RowContextExt{ - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for RowContext<'input> { + fn accept(&self, visitor: &mut (dyn CSVVisitor<'input> + 'a)) { + visitor.visit_row(self); + } } -pub trait RowContextAttrs<'input>: CSVParserContext<'input> + BorrowMut>{ - -fn field_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() -} -fn field(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) +impl<'input> CustomRuleContext<'input> for RowContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = CSVParserContextType; + fn get_rule_index(&self) -> usize { + RULE_row + } + //fn type_rule_index() -> usize where Self: Sized { RULE_row } +} +antlr4rust::tid! {RowContextExt<'a>} + +impl<'input> RowContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + RowContextExt { ph: PhantomData }, + )) + } } +pub trait RowContextAttrs<'input>: + CSVParserContext<'input> + BorrowMut> +{ + fn field_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn field(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } } -impl<'input> RowContextAttrs<'input> for RowContext<'input>{} +impl<'input> RowContextAttrs<'input> for RowContext<'input> {} impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn row(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = RowContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn row(&mut self) -> Result>, ANTLRError> { + let mut recog = self; + let _parentctx = recog.ctx.take(); + let mut _localctx = RowContextExt::new(_parentctx.clone(), recog.base.get_state()); recog.base.enter_rule(_localctx.clone(), 4, RULE_row); let mut _localctx: Rc = _localctx; - let mut _la: i32 = -1; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - /*InvokeRule field*/ - recog.base.set_state(16); - recog.field()?; - - recog.base.set_state(21); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - while _la==CSV_T__0 { - { - { - recog.base.set_state(17); - recog.base.match_token(CSV_T__0,&mut recog.err_handler)?; - - /*InvokeRule field*/ - recog.base.set_state(18); - recog.field()?; - - } - } - recog.base.set_state(23); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - } - recog.base.set_state(25); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - if _la==CSV_T__1 { - { - recog.base.set_state(24); - recog.base.match_token(CSV_T__1,&mut recog.err_handler)?; - - } - } - - recog.base.set_state(27); - recog.base.match_token(CSV_T__2,&mut recog.err_handler)?; - - } - 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) - } + let mut _la: i32 = -1; + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + /*InvokeRule field*/ + recog.base.set_state(16); + recog.field()?; + + recog.base.set_state(21); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + while _la == CSV_T__0 { + { + { + recog.base.set_state(17); + recog.base.match_token(CSV_T__0, &mut recog.err_handler)?; + + /*InvokeRule field*/ + recog.base.set_state(18); + recog.field()?; + } + } + recog.base.set_state(23); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + } + recog.base.set_state(25); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + if _la == CSV_T__1 { + { + recog.base.set_state(24); + recog.base.match_token(CSV_T__1, &mut recog.err_handler)?; + } + } + + recog.base.set_state(27); + recog.base.match_token(CSV_T__2, &mut recog.err_handler)?; + } + 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) + } } //------------------- field ---------------- pub type FieldContextAll<'input> = FieldContext<'input>; - -pub type FieldContext<'input> = BaseParserRuleContext<'input,FieldContextExt<'input>>; +pub type FieldContext<'input> = BaseParserRuleContext<'input, FieldContextExt<'input>>; #[derive(Clone)] -pub struct FieldContextExt<'input>{ -ph:PhantomData<&'input str> +pub struct FieldContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input> CSVParserContext<'input> for FieldContext<'input>{} - -impl<'input,'a> Listenable + 'a> for FieldContext<'input>{ - fn enter(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_field(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_field(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} +impl<'input> CSVParserContext<'input> for FieldContext<'input> {} -impl<'input,'a> Visitable + 'a> for FieldContext<'input>{ - fn accept(&self,visitor: &mut (dyn CSVVisitor<'input> + 'a)) { - visitor.visit_field(self); - } -} - -impl<'input> CustomRuleContext<'input> for FieldContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = CSVParserContextType; - fn get_rule_index(&self) -> usize { RULE_field } - //fn type_rule_index() -> usize where Self: Sized { RULE_field } +impl<'input, 'a> Listenable + 'a> for FieldContext<'input> { + fn enter(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_field(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_field(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{FieldContextExt<'a>} - -impl<'input> FieldContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,FieldContextExt{ - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for FieldContext<'input> { + fn accept(&self, visitor: &mut (dyn CSVVisitor<'input> + 'a)) { + visitor.visit_field(self); + } } -pub trait FieldContextAttrs<'input>: CSVParserContext<'input> + BorrowMut>{ - -/// Retrieves first TerminalNode corresponding to token TEXT -/// Returns `None` if there is no child corresponding to token TEXT -fn TEXT(&self) -> Option>> where Self:Sized{ - self.get_token(CSV_TEXT, 0) -} -/// Retrieves first TerminalNode corresponding to token STRING -/// Returns `None` if there is no child corresponding to token STRING -fn STRING(&self) -> Option>> where Self:Sized{ - self.get_token(CSV_STRING, 0) +impl<'input> CustomRuleContext<'input> for FieldContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = CSVParserContextType; + fn get_rule_index(&self) -> usize { + RULE_field + } + //fn type_rule_index() -> usize where Self: Sized { RULE_field } +} +antlr4rust::tid! {FieldContextExt<'a>} + +impl<'input> FieldContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + FieldContextExt { ph: PhantomData }, + )) + } } +pub trait FieldContextAttrs<'input>: + CSVParserContext<'input> + BorrowMut> +{ + /// Retrieves first TerminalNode corresponding to token TEXT + /// Returns `None` if there is no child corresponding to token TEXT + fn TEXT(&self) -> Option>> + where + Self: Sized, + { + self.get_token(CSV_TEXT, 0) + } + /// Retrieves first TerminalNode corresponding to token STRING + /// Returns `None` if there is no child corresponding to token STRING + fn STRING(&self) -> Option>> + where + Self: Sized, + { + self.get_token(CSV_STRING, 0) + } } -impl<'input> FieldContextAttrs<'input> for FieldContext<'input>{} +impl<'input> FieldContextAttrs<'input> for FieldContext<'input> {} impl<'input, I> CSVParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn field(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = FieldContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn field(&mut self) -> Result>, ANTLRError> { + let mut recog = self; + let _parentctx = recog.ctx.take(); + let mut _localctx = FieldContextExt::new(_parentctx.clone(), recog.base.get_state()); recog.base.enter_rule(_localctx.clone(), 6, RULE_field); let mut _localctx: Rc = _localctx; - let result: Result<(), ANTLRError> = (|| { - - recog.base.set_state(32); - recog.err_handler.sync(&mut recog.base)?; - match recog.base.input.la(1) { - CSV_TEXT - => { - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - recog.base.set_state(29); - recog.base.match_token(CSV_TEXT,&mut recog.err_handler)?; - - } - } - - CSV_STRING - => { - //recog.base.enter_outer_alt(_localctx.clone(), 2)?; - recog.base.enter_outer_alt(None, 2)?; - { - recog.base.set_state(30); - recog.base.match_token(CSV_STRING,&mut recog.err_handler)?; - - } - } - - CSV_T__0 |CSV_T__1 |CSV_T__2 - => { - //recog.base.enter_outer_alt(_localctx.clone(), 3)?; - recog.base.enter_outer_alt(None, 3)?; - { - } - } - - _ => Err(ANTLRError::NoAltError(NoViableAltError::new(&mut recog.base)))? - } - 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) - } -} - lazy_static!{ + let result: Result<(), ANTLRError> = (|| { + recog.base.set_state(32); + recog.err_handler.sync(&mut recog.base)?; + match recog.base.input.la(1) { + CSV_TEXT => { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + recog.base.set_state(29); + recog.base.match_token(CSV_TEXT, &mut recog.err_handler)?; + } + } + + CSV_STRING => { + //recog.base.enter_outer_alt(_localctx.clone(), 2)?; + recog.base.enter_outer_alt(None, 2)?; + { + recog.base.set_state(30); + recog.base.match_token(CSV_STRING, &mut recog.err_handler)?; + } + } + + CSV_T__0 | CSV_T__1 | CSV_T__2 => { + //recog.base.enter_outer_alt(_localctx.clone(), 3)?; + recog.base.enter_outer_alt(None, 3)?; + {} + } + + _ => Err(ANTLRError::NoAltError(NoViableAltError::new( + &mut recog.base, + )))?, + } + 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) + } +} +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 6, 35, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, - 0, 4, 0, 11, 8, 0, 11, 0, 12, 0, 12, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 5, - 2, 20, 8, 2, 10, 2, 12, 2, 23, 9, 2, 1, 2, 3, 2, 26, 8, 2, 1, 2, 1, 2, - 1, 3, 1, 3, 1, 3, 3, 3, 33, 8, 3, 1, 3, 0, 0, 4, 0, 2, 4, 6, 0, 0, 35, - 0, 8, 1, 0, 0, 0, 2, 14, 1, 0, 0, 0, 4, 16, 1, 0, 0, 0, 6, 32, 1, 0, 0, - 0, 8, 10, 3, 2, 1, 0, 9, 11, 3, 4, 2, 0, 10, 9, 1, 0, 0, 0, 11, 12, 1, - 0, 0, 0, 12, 10, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 1, 1, 0, 0, 0, 14, - 15, 3, 4, 2, 0, 15, 3, 1, 0, 0, 0, 16, 21, 3, 6, 3, 0, 17, 18, 5, 1, 0, - 0, 18, 20, 3, 6, 3, 0, 19, 17, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, - 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 25, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, - 24, 26, 5, 2, 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 27, 1, - 0, 0, 0, 27, 28, 5, 3, 0, 0, 28, 5, 1, 0, 0, 0, 29, 33, 5, 5, 0, 0, 30, - 33, 5, 6, 0, 0, 31, 33, 1, 0, 0, 0, 32, 29, 1, 0, 0, 0, 32, 30, 1, 0, - 0, 0, 32, 31, 1, 0, 0, 0, 33, 7, 1, 0, 0, 0, 4, 12, 21, 25, 32 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 6, 35, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 1, 0, 1, 0, 4, 0, 11, 8, 0, + 11, 0, 12, 0, 12, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 5, 2, 20, 8, 2, 10, 2, 12, 2, 23, 9, 2, 1, + 2, 3, 2, 26, 8, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 3, 3, 33, 8, 3, 1, 3, 0, 0, 4, 0, 2, 4, 6, + 0, 0, 35, 0, 8, 1, 0, 0, 0, 2, 14, 1, 0, 0, 0, 4, 16, 1, 0, 0, 0, 6, 32, 1, 0, 0, 0, 8, 10, + 3, 2, 1, 0, 9, 11, 3, 4, 2, 0, 10, 9, 1, 0, 0, 0, 11, 12, 1, 0, 0, 0, 12, 10, 1, 0, 0, 0, + 12, 13, 1, 0, 0, 0, 13, 1, 1, 0, 0, 0, 14, 15, 3, 4, 2, 0, 15, 3, 1, 0, 0, 0, 16, 21, 3, 6, + 3, 0, 17, 18, 5, 1, 0, 0, 18, 20, 3, 6, 3, 0, 19, 17, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, + 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 25, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 26, 5, 2, + 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 27, 1, 0, 0, 0, 27, 28, 5, 3, 0, 0, 28, + 5, 1, 0, 0, 0, 29, 33, 5, 5, 0, 0, 30, 33, 5, 6, 0, 0, 31, 33, 1, 0, 0, 0, 32, 29, 1, 0, 0, + 0, 32, 30, 1, 0, 0, 0, 32, 31, 1, 0, 0, 0, 33, 7, 1, 0, 0, 0, 4, 12, 21, 25, 32 + ]; } diff --git a/runtime/Rust/tests/gen/csvvisitor.rs b/runtime/Rust/tests/gen/csvvisitor.rs index ac5bdbc6d5..7944f4f2c8 100644 --- a/runtime/Rust/tests/gen/csvvisitor.rs +++ b/runtime/Rust/tests/gen/csvvisitor.rs @@ -1,96 +1,103 @@ #![allow(nonstandard_style)] // Generated from CSV.g4 by ANTLR 4.13.2 -use antlr4rust::tree::{ParseTreeVisitor,ParseTreeVisitorCompat}; use super::csvparser::*; +use antlr4rust::tree::{ParseTreeVisitor, ParseTreeVisitorCompat}; /** * This interface defines a complete generic visitor for a parse tree produced * by {@link CSVParser}. */ -pub trait CSVVisitor<'input>: ParseTreeVisitor<'input,CSVParserContextType>{ - /** - * Visit a parse tree produced by {@link CSVParser#csvFile}. - * @param ctx the parse tree - */ - fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>) { self.visit_children(ctx) } +pub trait CSVVisitor<'input>: ParseTreeVisitor<'input, CSVParserContextType> { + /** + * Visit a parse tree produced by {@link CSVParser#csvFile}. + * @param ctx the parse tree + */ + fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>) { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by {@link CSVParser#hdr}. - * @param ctx the parse tree - */ - fn visit_hdr(&mut self, ctx: &HdrContext<'input>) { self.visit_children(ctx) } + /** + * Visit a parse tree produced by {@link CSVParser#hdr}. + * @param ctx the parse tree + */ + fn visit_hdr(&mut self, ctx: &HdrContext<'input>) { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by {@link CSVParser#row}. - * @param ctx the parse tree - */ - fn visit_row(&mut self, ctx: &RowContext<'input>) { self.visit_children(ctx) } - - /** - * Visit a parse tree produced by {@link CSVParser#field}. - * @param ctx the parse tree - */ - fn visit_field(&mut self, ctx: &FieldContext<'input>) { self.visit_children(ctx) } + /** + * Visit a parse tree produced by {@link CSVParser#row}. + * @param ctx the parse tree + */ + fn visit_row(&mut self, ctx: &RowContext<'input>) { + self.visit_children(ctx) + } + /** + * Visit a parse tree produced by {@link CSVParser#field}. + * @param ctx the parse tree + */ + fn visit_field(&mut self, ctx: &FieldContext<'input>) { + self.visit_children(ctx) + } } -pub trait CSVVisitorCompat<'input>:ParseTreeVisitorCompat<'input, Node= CSVParserContextType>{ - /** - * Visit a parse tree produced by {@link CSVParser#csvFile}. - * @param ctx the parse tree - */ - fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>) -> Self::Return { - self.visit_children(ctx) - } - - /** - * Visit a parse tree produced by {@link CSVParser#hdr}. - * @param ctx the parse tree - */ - fn visit_hdr(&mut self, ctx: &HdrContext<'input>) -> Self::Return { - self.visit_children(ctx) - } +pub trait CSVVisitorCompat<'input>: + ParseTreeVisitorCompat<'input, Node = CSVParserContextType> +{ + /** + * Visit a parse tree produced by {@link CSVParser#csvFile}. + * @param ctx the parse tree + */ + fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>) -> Self::Return { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by {@link CSVParser#row}. - * @param ctx the parse tree - */ - fn visit_row(&mut self, ctx: &RowContext<'input>) -> Self::Return { - self.visit_children(ctx) - } + /** + * Visit a parse tree produced by {@link CSVParser#hdr}. + * @param ctx the parse tree + */ + fn visit_hdr(&mut self, ctx: &HdrContext<'input>) -> Self::Return { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by {@link CSVParser#field}. - * @param ctx the parse tree - */ - fn visit_field(&mut self, ctx: &FieldContext<'input>) -> Self::Return { - self.visit_children(ctx) - } + /** + * Visit a parse tree produced by {@link CSVParser#row}. + * @param ctx the parse tree + */ + fn visit_row(&mut self, ctx: &RowContext<'input>) -> Self::Return { + self.visit_children(ctx) + } + /** + * Visit a parse tree produced by {@link CSVParser#field}. + * @param ctx the parse tree + */ + fn visit_field(&mut self, ctx: &FieldContext<'input>) -> Self::Return { + self.visit_children(ctx) + } } -impl<'input,T> CSVVisitor<'input> for T +impl<'input, T> CSVVisitor<'input> for T where - T: CSVVisitorCompat<'input> + T: CSVVisitorCompat<'input>, { - fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>){ - let result = ::visit_csvFile(self, ctx); + fn visit_csvFile(&mut self, ctx: &CsvFileContext<'input>) { + let result = ::visit_csvFile(self, ctx); *::temp_result(self) = result; - } + } - fn visit_hdr(&mut self, ctx: &HdrContext<'input>){ - let result = ::visit_hdr(self, ctx); + fn visit_hdr(&mut self, ctx: &HdrContext<'input>) { + let result = ::visit_hdr(self, ctx); *::temp_result(self) = result; - } + } - fn visit_row(&mut self, ctx: &RowContext<'input>){ - let result = ::visit_row(self, ctx); + fn visit_row(&mut self, ctx: &RowContext<'input>) { + let result = ::visit_row(self, ctx); *::temp_result(self) = result; - } + } - fn visit_field(&mut self, ctx: &FieldContext<'input>){ - let result = ::visit_field(self, ctx); + fn visit_field(&mut self, ctx: &FieldContext<'input>) { + let result = ::visit_field(self, ctx); *::temp_result(self) = result; - } - -} \ No newline at end of file + } +} diff --git a/runtime/Rust/tests/gen/labelslexer.rs b/runtime/Rust/tests/gen/labelslexer.rs index b228a00d7a..1067a9de41 100644 --- a/runtime/Rust/tests/gen/labelslexer.rs +++ b/runtime/Rust/tests/gen/labelslexer.rs @@ -4,94 +4,106 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const T__0: i32 = 1; +pub const T__1: i32 = 2; +pub const T__2: i32 = 3; +pub const T__3: i32 = 4; +pub const T__4: i32 = 5; +pub const T__5: i32 = 6; +pub const ID: i32 = 7; +pub const INT: i32 = 8; +pub const WS: i32 = 9; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; + +pub const modeNames: [&'static str; 1] = ["DEFAULT_MODE"]; + +pub const ruleNames: [&'static str; 9] = [ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "ID", "INT", "WS", +]; + +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 = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} - pub const T__0:i32=1; - pub const T__1:i32=2; - pub const T__2:i32=3; - pub const T__3:i32=4; - pub const T__4:i32=5; - pub const T__5:i32=6; - pub const ID:i32=7; - pub const INT:i32=8; - pub const WS:i32=9; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;9] = [ - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "ID", "INT", "WS" - ]; - - - 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 = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = CommonTokenFactory; -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct LabelsLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,LabelsLexerActions,Input,LocalTokenFactory<'input>>, +pub struct LabelsLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, LabelsLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for LabelsLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for LabelsLexer<'input,Input>{ - type Target = BaseLexer<'input,LabelsLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for LabelsLexer<'input, Input> { + type Target = BaseLexer<'input, LabelsLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for LabelsLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for LabelsLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> LabelsLexer<'input,Input>{ +impl<'input, Input: CharStream>> LabelsLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -107,49 +119,57 @@ impl<'input, Input:CharStream >> LabelsLexer<'input,Input>{ "LabelsLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - LabelsLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> LabelsLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - LabelsLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct LabelsLexerActions { + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + LabelsLexerActions {}, + tf, + ), + } + } } -impl LabelsLexerActions{ +impl<'input, Input: CharStream>> LabelsLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + LabelsLexer::new_with_token_factory( + input, + <&LocalTokenFactory<'input> as Default>::default(), + ) + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,LabelsLexerActions,Input,LocalTokenFactory<'input>>> for LabelsLexerActions{ - } +pub struct LabelsLexerActions {} - impl<'input, Input:CharStream >> LabelsLexer<'input,Input>{ +impl LabelsLexerActions {} +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, LabelsLexerActions, Input, LocalTokenFactory<'input>>> + for LabelsLexerActions +{ } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,LabelsLexerActions,Input,LocalTokenFactory<'input>>> for LabelsLexerActions{ +impl<'input, Input: CharStream>> LabelsLexer<'input, Input> {} + +impl<'input, Input: CharStream>> + LexerRecog<'input, BaseLexer<'input, LabelsLexerActions, Input, LocalTokenFactory<'input>>> + for LabelsLexerActions +{ } -impl<'input> TokenAware<'input> for LabelsLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for LabelsLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for LabelsLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> for LabelsLexer<'input, Input> { + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -167,9 +187,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for LabelsLexe self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -180,42 +200,33 @@ impl<'input, Input:CharStream >> TokenSource<'input> for LabelsLexe } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 9, 47, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, - 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0, - 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, - 5, 1, 6, 4, 6, 35, 8, 6, 11, 6, 12, 6, 36, 1, 7, 4, 7, 40, 8, 7, 11, - 7, 12, 7, 41, 1, 8, 1, 8, 1, 8, 1, 8, 0, 0, 9, 1, 1, 3, 2, 5, 3, 7, 4, - 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 1, 0, 1, 2, 0, 10, 10, 32, 32, 48, - 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, - 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, - 0, 0, 0, 0, 17, 1, 0, 0, 0, 1, 19, 1, 0, 0, 0, 3, 21, 1, 0, 0, 0, 5, - 23, 1, 0, 0, 0, 7, 25, 1, 0, 0, 0, 9, 27, 1, 0, 0, 0, 11, 30, 1, 0, 0, - 0, 13, 34, 1, 0, 0, 0, 15, 39, 1, 0, 0, 0, 17, 43, 1, 0, 0, 0, 19, 20, - 5, 42, 0, 0, 20, 2, 1, 0, 0, 0, 21, 22, 5, 43, 0, 0, 22, 4, 1, 0, 0, - 0, 23, 24, 5, 40, 0, 0, 24, 6, 1, 0, 0, 0, 25, 26, 5, 41, 0, 0, 26, 8, - 1, 0, 0, 0, 27, 28, 5, 43, 0, 0, 28, 29, 5, 43, 0, 0, 29, 10, 1, 0, 0, - 0, 30, 31, 5, 45, 0, 0, 31, 32, 5, 45, 0, 0, 32, 12, 1, 0, 0, 0, 33, - 35, 2, 97, 122, 0, 34, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 34, 1, - 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 14, 1, 0, 0, 0, 38, 40, 2, 48, 57, 0, - 39, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 42, 1, - 0, 0, 0, 42, 16, 1, 0, 0, 0, 43, 44, 7, 0, 0, 0, 44, 45, 1, 0, 0, 0, - 45, 46, 6, 8, 0, 0, 46, 18, 1, 0, 0, 0, 3, 0, 36, 41, 1, 6, 0, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 9, 47, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, + 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, + 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 4, 6, 35, 8, 6, 11, 6, 12, 6, 36, 1, 7, 4, 7, 40, 8, 7, + 11, 7, 12, 7, 41, 1, 8, 1, 8, 1, 8, 1, 8, 0, 0, 9, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, + 7, 15, 8, 17, 9, 1, 0, 1, 2, 0, 10, 10, 32, 32, 48, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, + 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, + 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 1, 19, 1, 0, 0, 0, 3, 21, 1, 0, 0, 0, 5, 23, 1, 0, 0, 0, + 7, 25, 1, 0, 0, 0, 9, 27, 1, 0, 0, 0, 11, 30, 1, 0, 0, 0, 13, 34, 1, 0, 0, 0, 15, 39, 1, 0, + 0, 0, 17, 43, 1, 0, 0, 0, 19, 20, 5, 42, 0, 0, 20, 2, 1, 0, 0, 0, 21, 22, 5, 43, 0, 0, 22, + 4, 1, 0, 0, 0, 23, 24, 5, 40, 0, 0, 24, 6, 1, 0, 0, 0, 25, 26, 5, 41, 0, 0, 26, 8, 1, 0, 0, + 0, 27, 28, 5, 43, 0, 0, 28, 29, 5, 43, 0, 0, 29, 10, 1, 0, 0, 0, 30, 31, 5, 45, 0, 0, 31, + 32, 5, 45, 0, 0, 32, 12, 1, 0, 0, 0, 33, 35, 2, 97, 122, 0, 34, 33, 1, 0, 0, 0, 35, 36, 1, + 0, 0, 0, 36, 34, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 14, 1, 0, 0, 0, 38, 40, 2, 48, 57, 0, + 39, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 16, 1, + 0, 0, 0, 43, 44, 7, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 46, 6, 8, 0, 0, 46, 18, 1, 0, 0, 0, 3, + 0, 36, 41, 1, 6, 0, 0 + ]; +} diff --git a/runtime/Rust/tests/gen/labelslistener.rs b/runtime/Rust/tests/gen/labelslistener.rs index 5886eb5c70..fd95e991f4 100644 --- a/runtime/Rust/tests/gen/labelslistener.rs +++ b/runtime/Rust/tests/gen/labelslistener.rs @@ -1,106 +1,103 @@ #![allow(nonstandard_style)] // Generated from Labels.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::labelsparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait LabelsListener<'input> : ParseTreeListener<'input,LabelsParserContextType>{ -/** - * Enter a parse tree produced by {@link LabelsParser#s}. - * @param ctx the parse tree - */ -fn enter_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Exit a parse tree produced by {@link LabelsParser#s}. - * @param ctx the parse tree - */ -fn exit_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Enter a parse tree produced by the {@code add} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_add(&mut self, _ctx: &AddContext<'input>) { } -/** - * Exit a parse tree produced by the {@code add} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_add(&mut self, _ctx: &AddContext<'input>) { } -/** - * Enter a parse tree produced by the {@code parens} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_parens(&mut self, _ctx: &ParensContext<'input>) { } -/** - * Exit a parse tree produced by the {@code parens} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_parens(&mut self, _ctx: &ParensContext<'input>) { } -/** - * Enter a parse tree produced by the {@code mult} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_mult(&mut self, _ctx: &MultContext<'input>) { } -/** - * Exit a parse tree produced by the {@code mult} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_mult(&mut self, _ctx: &MultContext<'input>) { } -/** - * Enter a parse tree produced by the {@code dec} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_dec(&mut self, _ctx: &DecContext<'input>) { } -/** - * Exit a parse tree produced by the {@code dec} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_dec(&mut self, _ctx: &DecContext<'input>) { } -/** - * Enter a parse tree produced by the {@code anID} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_anID(&mut self, _ctx: &AnIDContext<'input>) { } -/** - * Exit a parse tree produced by the {@code anID} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_anID(&mut self, _ctx: &AnIDContext<'input>) { } -/** - * Enter a parse tree produced by the {@code anInt} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_anInt(&mut self, _ctx: &AnIntContext<'input>) { } -/** - * Exit a parse tree produced by the {@code anInt} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_anInt(&mut self, _ctx: &AnIntContext<'input>) { } -/** - * Enter a parse tree produced by the {@code inc} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn enter_inc(&mut self, _ctx: &IncContext<'input>) { } -/** - * Exit a parse tree produced by the {@code inc} - * labeled alternative in {@link LabelsParser#e}. - * @param ctx the parse tree - */ -fn exit_inc(&mut self, _ctx: &IncContext<'input>) { } - +pub trait LabelsListener<'input>: ParseTreeListener<'input, LabelsParserContextType> { + /** + * Enter a parse tree produced by {@link LabelsParser#s}. + * @param ctx the parse tree + */ + fn enter_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Exit a parse tree produced by {@link LabelsParser#s}. + * @param ctx the parse tree + */ + fn exit_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Enter a parse tree produced by the {@code add} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_add(&mut self, _ctx: &AddContext<'input>) {} + /** + * Exit a parse tree produced by the {@code add} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_add(&mut self, _ctx: &AddContext<'input>) {} + /** + * Enter a parse tree produced by the {@code parens} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_parens(&mut self, _ctx: &ParensContext<'input>) {} + /** + * Exit a parse tree produced by the {@code parens} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_parens(&mut self, _ctx: &ParensContext<'input>) {} + /** + * Enter a parse tree produced by the {@code mult} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_mult(&mut self, _ctx: &MultContext<'input>) {} + /** + * Exit a parse tree produced by the {@code mult} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_mult(&mut self, _ctx: &MultContext<'input>) {} + /** + * Enter a parse tree produced by the {@code dec} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_dec(&mut self, _ctx: &DecContext<'input>) {} + /** + * Exit a parse tree produced by the {@code dec} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_dec(&mut self, _ctx: &DecContext<'input>) {} + /** + * Enter a parse tree produced by the {@code anID} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_anID(&mut self, _ctx: &AnIDContext<'input>) {} + /** + * Exit a parse tree produced by the {@code anID} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_anID(&mut self, _ctx: &AnIDContext<'input>) {} + /** + * Enter a parse tree produced by the {@code anInt} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_anInt(&mut self, _ctx: &AnIntContext<'input>) {} + /** + * Exit a parse tree produced by the {@code anInt} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_anInt(&mut self, _ctx: &AnIntContext<'input>) {} + /** + * Enter a parse tree produced by the {@code inc} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn enter_inc(&mut self, _ctx: &IncContext<'input>) {} + /** + * Exit a parse tree produced by the {@code inc} + * labeled alternative in {@link LabelsParser#e}. + * @param ctx the parse tree + */ + fn exit_inc(&mut self, _ctx: &IncContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : LabelsListener<'input> } - - +antlr4rust::coerce_from! { 'input : LabelsListener<'input> } diff --git a/runtime/Rust/tests/gen/labelsparser.rs b/runtime/Rust/tests/gen/labelsparser.rs index 8eebc721b1..481f57a908 100644 --- a/runtime/Rust/tests/gen/labelsparser.rs +++ b/runtime/Rust/tests/gen/labelsparser.rs @@ -7,36 +7,36 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::labelslistener::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::labelslistener::*; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -45,134 +45,160 @@ const _: () = { ); }; - pub const Labels_T__0:i32=1; - pub const Labels_T__1:i32=2; - pub const Labels_T__2:i32=3; - pub const Labels_T__3:i32=4; - pub const Labels_T__4:i32=5; - pub const Labels_T__5:i32=6; - pub const Labels_ID:i32=7; - pub const Labels_INT:i32=8; - pub const Labels_WS:i32=9; - pub const Labels_EOF:i32=EOF; - 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 = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = 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 >; +pub const Labels_T__0: i32 = 1; +pub const Labels_T__1: i32 = 2; +pub const Labels_T__2: i32 = 3; +pub const Labels_T__3: i32 = 4; +pub const Labels_T__4: i32 = 5; +pub const Labels_T__5: i32 = 6; +pub const Labels_ID: i32 = 7; +pub const Labels_INT: i32 = 8; +pub const Labels_WS: i32 = 9; +pub const Labels_EOF: i32 = EOF; +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 = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = 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> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = CommonTokenFactory; -pub type LabelsTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, LabelsParserContextType , dyn LabelsListener<'input> + 'a>; +pub type LabelsTreeWalker<'input, 'a> = + ParseTreeWalker<'input, 'a, LabelsParserContextType, dyn LabelsListener<'input> + 'a>; /// Parser for Labels grammar pub struct LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - LabelsParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + LabelsParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(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 + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=LabelsParserContextType> -{} + for<'x> Listenable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = LabelsParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : LabelsParserContext<'input> } +antlr4rust::coerce_from! { 'input : LabelsParserContext<'input> } -impl<'input> LabelsParserContext<'input> for TerminalNode<'input,LabelsParserContextType> {} -impl<'input> LabelsParserContext<'input> for ErrorNode<'input,LabelsParserContextType> {} +impl<'input> LabelsParserContext<'input> for TerminalNode<'input, LabelsParserContextType> {} +impl<'input> LabelsParserContext<'input> for ErrorNode<'input, LabelsParserContextType> {} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn LabelsParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn LabelsListener<'input> + 'input } pub struct LabelsParserContextType; -antlr4rust::tid!{LabelsParserContextType} +antlr4rust::tid! {LabelsParserContextType} -impl<'input> ParserNodeType<'input> for LabelsParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn LabelsParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for LabelsParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn LabelsParserContext<'input> + 'input; } impl<'input, I> Deref for LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -181,944 +207,1286 @@ where impl<'input, I> DerefMut for LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct LabelsParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct LabelsParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> LabelsParserExt<'input>{ -} +impl<'input> LabelsParserExt<'input> {} antlr4rust::tid! { LabelsParserExt<'a> } -impl<'input> TokenAware<'input> for LabelsParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +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>> + 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"} +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_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } - fn sempred(_localctx: Option<&(dyn LabelsParserContext<'input> + 'input)>, rule_index: i32, pred_index: i32, - 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 - } - } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } + fn sempred( + _localctx: Option<&(dyn LabelsParserContext<'input> + 'input)>, + rule_index: i32, + pred_index: i32, + 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> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - fn e_sempred(_localctx: Option<&EContext<'input>>, pred_index:i32, - recog:&mut ::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 - } - } + fn e_sempred( + _localctx: Option<&EContext<'input>>, + pred_index: i32, + recog: &mut ::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>>; +pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>; #[derive(Clone)] -pub struct SContextExt<'input>{ - pub q: Option>>, -ph:PhantomData<&'input str> -} - -impl<'input> LabelsParserContext<'input> for SContext<'input>{} - -impl<'input,'a> Listenable + 'a> for SContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_s(self); - Ok(()) - }fn exit(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_s(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} - -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 } +pub struct SContextExt<'input> { + pub q: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{SContextExt<'a>} -impl<'input> SContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,SContextExt{ - q: None, +impl<'input> LabelsParserContext<'input> for SContext<'input> {} - ph:PhantomData - }), - ) - } +impl<'input, 'a> Listenable + 'a> for SContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_s(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_s(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -pub trait SContextAttrs<'input>: LabelsParserContext<'input> + BorrowMut>{ - -fn e(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) +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 } +} +antlr4rust::tid! {SContextExt<'a>} + +impl<'input> SContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + SContextExt { + q: None, + + ph: PhantomData, + }, + )) + } } +pub trait SContextAttrs<'input>: + LabelsParserContext<'input> + BorrowMut> +{ + fn e(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> SContextAttrs<'input> for SContext<'input>{} +impl<'input> SContextAttrs<'input> for SContext<'input> {} impl<'input, I> LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn s(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = SContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn s(&mut self) -> Result>, 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 = _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) - } + 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>) +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>), } -antlr4rust::tid!{EContextAll<'a>} +antlr4rust::tid! {EContextAll<'a>} -impl<'input> antlr4rust::parser_rule_context::DerefSeal for EContextAll<'input>{} +impl<'input> antlr4rust::parser_rule_context::DerefSeal for EContextAll<'input> {} -impl<'input> LabelsParserContext<'input> 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> 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 + 'a> for EContextAll<'input>{ - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { self.deref().enter(listener) } - fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { self.deref().exit(listener) } +impl<'input, 'a> Listenable + 'a> for EContextAll<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + self.deref().enter(listener) + } + fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + self.deref().exit(listener) + } } - - -pub type EContext<'input> = BaseParserRuleContext<'input,EContextExt<'input>>; +pub type EContext<'input> = BaseParserRuleContext<'input, EContextExt<'input>>; #[derive(Clone)] -pub struct EContextExt<'input>{ - pub v: String, -ph:PhantomData<&'input str> +pub struct EContextExt<'input> { + pub v: String, + ph: PhantomData<&'input str>, } -impl<'input> LabelsParserContext<'input> for EContext<'input>{} +impl<'input> LabelsParserContext<'input> for EContext<'input> {} -impl<'input,'a> Listenable + '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 } -} -antlr4rust::tid!{EContextExt<'a>} - -impl<'input> EContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - let mut _init_v = String::new(); +impl<'input, 'a> Listenable + 'a> for EContext<'input> {} - Rc::new( - EContextAll::Error( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,EContextExt{ - v: _init_v, - - ph:PhantomData - }), - ) - ) - } +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 } +} +antlr4rust::tid! {EContextExt<'a>} + +impl<'input> EContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + let mut _init_v = String::new(); + + Rc::new(EContextAll::Error(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + EContextExt { + v: _init_v, + + ph: PhantomData, + }, + ))) + } } -pub trait EContextAttrs<'input>: LabelsParserContext<'input> + BorrowMut>{ - -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; } - +pub trait EContextAttrs<'input>: + LabelsParserContext<'input> + BorrowMut> +{ + 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>{} +impl<'input> EContextAttrs<'input> for EContext<'input> {} -pub type AddContext<'input> = BaseParserRuleContext<'input,AddContextExt<'input>>; +pub type AddContext<'input> = BaseParserRuleContext<'input, AddContextExt<'input>>; -pub trait AddContextAttrs<'input>: LabelsParserContext<'input>{ - fn e_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() - } - fn e(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) - } +pub trait AddContextAttrs<'input>: LabelsParserContext<'input> { + fn e_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn e(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } } -impl<'input> AddContextAttrs<'input> for AddContext<'input>{} +impl<'input> AddContextAttrs<'input> for AddContext<'input> {} -pub struct AddContextExt<'input>{ - base:EContextExt<'input>, - pub a: Option>>, - pub b: Option>>, - ph:PhantomData<&'input str> +pub struct AddContextExt<'input> { + base: EContextExt<'input>, + pub a: Option>>, + pub b: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AddContextExt<'a>} +antlr4rust::tid! {AddContextExt<'a>} -impl<'input> LabelsParserContext<'input> for AddContext<'input>{} +impl<'input> LabelsParserContext<'input> for AddContext<'input> {} -impl<'input,'a> Listenable + 'a> for AddContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_add(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for AddContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_add(self); + Ok(()) + } } -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> 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> for AddContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for AddContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for AddContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::AddContext( - BaseParserRuleContext::copy_from(ctx,AddContextExt{ - a:None, b:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> AddContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 type ParensContext<'input> = BaseParserRuleContext<'input, ParensContextExt<'input>>; -pub trait ParensContextAttrs<'input>: LabelsParserContext<'input>{ - fn e(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) - } +pub trait ParensContextAttrs<'input>: LabelsParserContext<'input> { + fn e(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> ParensContextAttrs<'input> for ParensContext<'input>{} +impl<'input> ParensContextAttrs<'input> for ParensContext<'input> {} -pub struct ParensContextExt<'input>{ - base:EContextExt<'input>, - pub x: Option>>, - ph:PhantomData<&'input str> +pub struct ParensContextExt<'input> { + base: EContextExt<'input>, + pub x: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{ParensContextExt<'a>} +antlr4rust::tid! {ParensContextExt<'a>} -impl<'input> LabelsParserContext<'input> for ParensContext<'input>{} +impl<'input> LabelsParserContext<'input> for ParensContext<'input> {} -impl<'input,'a> Listenable + 'a> for ParensContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_parens(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for ParensContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_parens(self); + Ok(()) + } } -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> 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> for ParensContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for ParensContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for ParensContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::ParensContext( - BaseParserRuleContext::copy_from(ctx,ParensContextExt{ - x:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> ParensContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 type MultContext<'input> = BaseParserRuleContext<'input, MultContextExt<'input>>; -pub trait MultContextAttrs<'input>: LabelsParserContext<'input>{ - fn e_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() - } - fn e(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) - } +pub trait MultContextAttrs<'input>: LabelsParserContext<'input> { + fn e_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn e(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } } -impl<'input> MultContextAttrs<'input> for MultContext<'input>{} +impl<'input> MultContextAttrs<'input> for MultContext<'input> {} -pub struct MultContextExt<'input>{ - base:EContextExt<'input>, - pub a: Option>>, - pub op: Option>, - pub b: Option>>, - ph:PhantomData<&'input str> +pub struct MultContextExt<'input> { + base: EContextExt<'input>, + pub a: Option>>, + pub op: Option>, + pub b: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{MultContextExt<'a>} +antlr4rust::tid! {MultContextExt<'a>} -impl<'input> LabelsParserContext<'input> for MultContext<'input>{} +impl<'input> LabelsParserContext<'input> for MultContext<'input> {} -impl<'input,'a> Listenable + 'a> for MultContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_mult(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for MultContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_mult(self); + Ok(()) + } } -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> 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> for MultContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for MultContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for MultContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::MultContext( - BaseParserRuleContext::copy_from(ctx,MultContextExt{ - op:None, - a:None, b:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> MultContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 type DecContext<'input> = BaseParserRuleContext<'input, DecContextExt<'input>>; -pub trait DecContextAttrs<'input>: LabelsParserContext<'input>{ - fn e(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) - } +pub trait DecContextAttrs<'input>: LabelsParserContext<'input> { + fn e(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> DecContextAttrs<'input> for DecContext<'input>{} +impl<'input> DecContextAttrs<'input> for DecContext<'input> {} -pub struct DecContextExt<'input>{ - base:EContextExt<'input>, - pub x: Option>>, - ph:PhantomData<&'input str> +pub struct DecContextExt<'input> { + base: EContextExt<'input>, + pub x: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{DecContextExt<'a>} +antlr4rust::tid! {DecContextExt<'a>} -impl<'input> LabelsParserContext<'input> for DecContext<'input>{} +impl<'input> LabelsParserContext<'input> for DecContext<'input> {} -impl<'input,'a> Listenable + 'a> for DecContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_dec(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for DecContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_dec(self); + Ok(()) + } } -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> 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> for DecContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for DecContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for DecContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::DecContext( - BaseParserRuleContext::copy_from(ctx,DecContextExt{ - x:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> DecContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 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>> where Self:Sized{ - self.get_token(Labels_ID, 0) - } +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>> + where + Self: Sized, + { + self.get_token(Labels_ID, 0) + } } -impl<'input> AnIDContextAttrs<'input> for AnIDContext<'input>{} +impl<'input> AnIDContextAttrs<'input> for AnIDContext<'input> {} -pub struct AnIDContextExt<'input>{ - base:EContextExt<'input>, - pub ID: Option>, - ph:PhantomData<&'input str> +pub struct AnIDContextExt<'input> { + base: EContextExt<'input>, + pub ID: Option>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AnIDContextExt<'a>} +antlr4rust::tid! {AnIDContextExt<'a>} -impl<'input> LabelsParserContext<'input> for AnIDContext<'input>{} +impl<'input> LabelsParserContext<'input> for AnIDContext<'input> {} -impl<'input,'a> Listenable + 'a> for AnIDContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_anID(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for AnIDContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_anID(self); + Ok(()) + } } -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> 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> for AnIDContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for AnIDContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for AnIDContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::AnIDContext( - BaseParserRuleContext::copy_from(ctx,AnIDContextExt{ - ID:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> AnIDContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 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>> where Self:Sized{ - self.get_token(Labels_INT, 0) - } +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>> + where + Self: Sized, + { + self.get_token(Labels_INT, 0) + } } -impl<'input> AnIntContextAttrs<'input> for AnIntContext<'input>{} +impl<'input> AnIntContextAttrs<'input> for AnIntContext<'input> {} -pub struct AnIntContextExt<'input>{ - base:EContextExt<'input>, - pub INT: Option>, - ph:PhantomData<&'input str> +pub struct AnIntContextExt<'input> { + base: EContextExt<'input>, + pub INT: Option>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AnIntContextExt<'a>} +antlr4rust::tid! {AnIntContextExt<'a>} -impl<'input> LabelsParserContext<'input> for AnIntContext<'input>{} +impl<'input> LabelsParserContext<'input> for AnIntContext<'input> {} -impl<'input,'a> Listenable + 'a> for AnIntContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_anInt(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for AnIntContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_anInt(self); + Ok(()) + } } -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> 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> for AnIntContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for AnIntContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for AnIntContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::AnIntContext( - BaseParserRuleContext::copy_from(ctx,AnIntContextExt{ - INT:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> AnIntContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + 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 type IncContext<'input> = BaseParserRuleContext<'input, IncContextExt<'input>>; -pub trait IncContextAttrs<'input>: LabelsParserContext<'input>{ - fn e(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) - } +pub trait IncContextAttrs<'input>: LabelsParserContext<'input> { + fn e(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> IncContextAttrs<'input> for IncContext<'input>{} +impl<'input> IncContextAttrs<'input> for IncContext<'input> {} -pub struct IncContextExt<'input>{ - base:EContextExt<'input>, - pub x: Option>>, - ph:PhantomData<&'input str> +pub struct IncContextExt<'input> { + base: EContextExt<'input>, + pub x: Option>>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{IncContextExt<'a>} +antlr4rust::tid! {IncContextExt<'a>} -impl<'input> LabelsParserContext<'input> for IncContext<'input>{} +impl<'input> LabelsParserContext<'input> for IncContext<'input> {} -impl<'input,'a> Listenable + 'a> for IncContext<'input>{ - fn enter(&self,listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_inc(self); - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for IncContext<'input> { + fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_inc(self); + Ok(()) + } } -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> 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> for IncContext<'input>{ - fn borrow(&self) -> &EContextExt<'input> { &self.base } +impl<'input> Borrow> for IncContext<'input> { + fn borrow(&self) -> &EContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for IncContext<'input>{ - fn borrow_mut(&mut self) -> &mut EContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> 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> { - Rc::new( - EContextAll::IncContext( - BaseParserRuleContext::copy_from(ctx,IncContextExt{ - x:None, - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> IncContextExt<'input> { + fn new(ctx: &dyn EContextAttrs<'input>) -> Rc> { + Rc::new(EContextAll::IncContext(BaseParserRuleContext::copy_from( + ctx, + IncContextExt { + x: None, + base: ctx.borrow().clone(), + ph: PhantomData, + }, + ))) + } } impl<'input, I> LabelsParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn e(&mut self,) - -> Result>,ANTLRError> { - self.e_rec(0) - } - - fn e_rec(&mut self, _p: i32) - -> Result>,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 = _localctx; + pub fn e(&mut self) -> Result>, ANTLRError> { + self.e_rec(0) + } + + fn e_rec(&mut self, _p: i32) -> Result>, 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 = _localctx; let mut _prevctx = _localctx.clone(); - let _startState = 2; - let result: Result<(), ANTLRError> = (|| { - let mut _alt: i32; - //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) { - Labels_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(Labels_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 {unreachable!("cant cast")} .INT { it.get_text() } else { "null" } .to_owned()}.to_owned(); - if let EContextAll::AnIntContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - - Labels_T__2 - => { - { - let mut tmp = ParensContextExt::new(&**_localctx); - recog.ctx = Some(tmp.clone()); - _localctx = tmp; - _prevctx = _localctx.clone(); - recog.base.set_state(9); - recog.base.match_token(Labels_T__2,&mut recog.err_handler)?; - - /*InvokeRule e*/ - recog.base.set_state(10); - let tmp = recog.e_rec(0)?; - if let EContextAll::ParensContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.x = Some(tmp.clone()); } else {unreachable!("cant cast");} - - recog.base.set_state(11); - recog.base.match_token(Labels_T__3,&mut recog.err_handler)?; - - let tmp = { if let EContextAll::ParensContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .x.as_ref().unwrap().get_v()}.to_owned(); - if let EContextAll::ParensContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - - Labels_ID - => { - { - let mut tmp = AnIDContextExt::new(&**_localctx); - recog.ctx = Some(tmp.clone()); - _localctx = tmp; - _prevctx = _localctx.clone(); - recog.base.set_state(14); - let tmp = recog.base.match_token(Labels_ID,&mut recog.err_handler)?; - if let EContextAll::AnIDContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.ID = Some(tmp.clone()); } else {unreachable!("cant cast");} - - let tmp = { if let Some(it) = &if let EContextAll::AnIDContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .ID { it.get_text() } else { "null" } .to_owned()}.to_owned(); - if let EContextAll::AnIDContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - - _ => Err(ANTLRError::NoAltError(NoViableAltError::new(&mut recog.base)))? - } - let tmp = recog.input.lt(-1).cloned(); - recog.ctx.as_ref().unwrap().set_stop(tmp); - recog.base.set_state(36); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(2,&mut recog.base)?; - while { _alt!=2 && _alt!=INVALID_ALT } { - if _alt==1 { - recog.trigger_exit_rule_event()?; - _prevctx = _localctx.clone(); - { - recog.base.set_state(34); - recog.err_handler.sync(&mut recog.base)?; - match recog.interpreter.adaptive_predict(1,&mut recog.base)? { - 1 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = MultContextExt::new(&**EContextExt::new(_parentctx.clone(), _parentState)); - if let EContextAll::MultContext(ctx) = cast_mut::<_,EContextAll >(&mut tmp){ - ctx.a = Some(_prevctx.clone()); - } else {unreachable!("cant cast");} - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_e)?; - _localctx = tmp; - recog.base.set_state(18); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 7)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 7)".to_owned()), None))?; - } - recog.base.set_state(19); - let tmp = recog.base.match_token(Labels_T__0,&mut recog.err_handler)?; - if let EContextAll::MultContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.op = Some(tmp.clone()); } else {unreachable!("cant cast");} - - /*InvokeRule e*/ - recog.base.set_state(20); - let tmp = recog.e_rec(8)?; - if let EContextAll::MultContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.b = Some(tmp.clone()); } else {unreachable!("cant cast");} - - let tmp = { "* ".to_owned() + if let EContextAll::MultContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .a.as_ref().unwrap().get_v() + " " + if let EContextAll::MultContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .b.as_ref().unwrap().get_v()}.to_owned(); - if let EContextAll::MultContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - , - 2 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = AddContextExt::new(&**EContextExt::new(_parentctx.clone(), _parentState)); - if let EContextAll::AddContext(ctx) = cast_mut::<_,EContextAll >(&mut tmp){ - ctx.a = Some(_prevctx.clone()); - } else {unreachable!("cant cast");} - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_e)?; - _localctx = tmp; - recog.base.set_state(23); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 6)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 6)".to_owned()), None))?; - } - recog.base.set_state(24); - recog.base.match_token(Labels_T__1,&mut recog.err_handler)?; - - /*InvokeRule e*/ - recog.base.set_state(25); - let tmp = recog.e_rec(7)?; - if let EContextAll::AddContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.b = Some(tmp.clone()); } else {unreachable!("cant cast");} - - let tmp = { "+ ".to_owned() + if let EContextAll::AddContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .a.as_ref().unwrap().get_v() + " " + if let EContextAll::AddContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .b.as_ref().unwrap().get_v()}.to_owned(); - if let EContextAll::AddContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - , - 3 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = IncContextExt::new(&**EContextExt::new(_parentctx.clone(), _parentState)); - if let EContextAll::IncContext(ctx) = cast_mut::<_,EContextAll >(&mut tmp){ - ctx.x = Some(_prevctx.clone()); - } else {unreachable!("cant cast");} - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_e)?; - _localctx = tmp; - recog.base.set_state(28); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 3)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 3)".to_owned()), None))?; - } - recog.base.set_state(29); - recog.base.match_token(Labels_T__4,&mut recog.err_handler)?; - - let tmp = { " ++".to_owned() + if let EContextAll::IncContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .x.as_ref().unwrap().get_v()}.to_owned(); - if let EContextAll::IncContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - , - 4 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = DecContextExt::new(&**EContextExt::new(_parentctx.clone(), _parentState)); - if let EContextAll::DecContext(ctx) = cast_mut::<_,EContextAll >(&mut tmp){ - ctx.x = Some(_prevctx.clone()); - } else {unreachable!("cant cast");} - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_e)?; - _localctx = tmp; - recog.base.set_state(31); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 2)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 2)".to_owned()), None))?; - } - recog.base.set_state(32); - recog.base.match_token(Labels_T__5,&mut recog.err_handler)?; - - let tmp = { " --".to_owned() + if let EContextAll::DecContext(ctx) = cast::<_,EContextAll >(&*_localctx){ - ctx } else {unreachable!("cant cast")} .x.as_ref().unwrap().get_v()}.to_owned(); - if let EContextAll::DecContext(ctx) = cast_mut::<_,EContextAll >(&mut _localctx){ - ctx.set_v(tmp); } else {unreachable!("cant cast");} - } - } - - _ => {} - } - } - } - recog.base.set_state(38); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(2,&mut recog.base)?; - } - } - 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.unroll_recursion_context(_parentctx)?; - - Ok(_localctx) - } -} - lazy_static!{ + let _startState = 2; + let result: Result<(), ANTLRError> = (|| { + let mut _alt: i32; + //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) { + Labels_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(Labels_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 { + unreachable!("cant cast") + } + .INT + { + it.get_text() + } else { + "null" + } + .to_owned() + } + .to_owned(); + if let EContextAll::AnIntContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + + Labels_T__2 => { + { + let mut tmp = ParensContextExt::new(&**_localctx); + recog.ctx = Some(tmp.clone()); + _localctx = tmp; + _prevctx = _localctx.clone(); + recog.base.set_state(9); + recog + .base + .match_token(Labels_T__2, &mut recog.err_handler)?; + + /*InvokeRule e*/ + recog.base.set_state(10); + let tmp = recog.e_rec(0)?; + if let EContextAll::ParensContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.x = Some(tmp.clone()); + } else { + unreachable!("cant cast"); + } + + recog.base.set_state(11); + recog + .base + .match_token(Labels_T__3, &mut recog.err_handler)?; + + let tmp = { + if let EContextAll::ParensContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .x + .as_ref() + .unwrap() + .get_v() + } + .to_owned(); + if let EContextAll::ParensContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + } + + Labels_ID => { + let mut tmp = AnIDContextExt::new(&**_localctx); + recog.ctx = Some(tmp.clone()); + _localctx = tmp; + _prevctx = _localctx.clone(); + recog.base.set_state(14); + let tmp = recog.base.match_token(Labels_ID, &mut recog.err_handler)?; + if let EContextAll::AnIDContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.ID = Some(tmp.clone()); + } else { + unreachable!("cant cast"); + } + + let tmp = { + if let Some(it) = &if let EContextAll::AnIDContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .ID + { + it.get_text() + } else { + "null" + } + .to_owned() + } + .to_owned(); + if let EContextAll::AnIDContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + + _ => Err(ANTLRError::NoAltError(NoViableAltError::new( + &mut recog.base, + )))?, + } + let tmp = recog.input.lt(-1).cloned(); + recog.ctx.as_ref().unwrap().set_stop(tmp); + recog.base.set_state(36); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(2, &mut recog.base)?; + while { _alt != 2 && _alt != INVALID_ALT } { + if _alt == 1 { + recog.trigger_exit_rule_event()?; + _prevctx = _localctx.clone(); + { + recog.base.set_state(34); + recog.err_handler.sync(&mut recog.base)?; + match recog.interpreter.adaptive_predict(1, &mut recog.base)? { + 1 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = MultContextExt::new(&**EContextExt::new( + _parentctx.clone(), + _parentState, + )); + if let EContextAll::MultContext(ctx) = + cast_mut::<_, EContextAll>(&mut tmp) + { + ctx.a = Some(_prevctx.clone()); + } else { + unreachable!("cant cast"); + } + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_e, + )?; + _localctx = tmp; + recog.base.set_state(18); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 7) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 7)".to_owned()), + None, + ))?; + } + recog.base.set_state(19); + let tmp = recog + .base + .match_token(Labels_T__0, &mut recog.err_handler)?; + if let EContextAll::MultContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.op = Some(tmp.clone()); + } else { + unreachable!("cant cast"); + } + + /*InvokeRule e*/ + recog.base.set_state(20); + let tmp = recog.e_rec(8)?; + if let EContextAll::MultContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.b = Some(tmp.clone()); + } else { + unreachable!("cant cast"); + } + + let tmp = { + "* ".to_owned() + + if let EContextAll::MultContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .a + .as_ref() + .unwrap() + .get_v() + + " " + + if let EContextAll::MultContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .b + .as_ref() + .unwrap() + .get_v() + } + .to_owned(); + if let EContextAll::MultContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + } + 2 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = AddContextExt::new(&**EContextExt::new( + _parentctx.clone(), + _parentState, + )); + if let EContextAll::AddContext(ctx) = + cast_mut::<_, EContextAll>(&mut tmp) + { + ctx.a = Some(_prevctx.clone()); + } else { + unreachable!("cant cast"); + } + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_e, + )?; + _localctx = tmp; + recog.base.set_state(23); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 6) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 6)".to_owned()), + None, + ))?; + } + recog.base.set_state(24); + recog + .base + .match_token(Labels_T__1, &mut recog.err_handler)?; + + /*InvokeRule e*/ + recog.base.set_state(25); + let tmp = recog.e_rec(7)?; + if let EContextAll::AddContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.b = Some(tmp.clone()); + } else { + unreachable!("cant cast"); + } + + let tmp = { + "+ ".to_owned() + + if let EContextAll::AddContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .a + .as_ref() + .unwrap() + .get_v() + + " " + + if let EContextAll::AddContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .b + .as_ref() + .unwrap() + .get_v() + } + .to_owned(); + if let EContextAll::AddContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + } + 3 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = IncContextExt::new(&**EContextExt::new( + _parentctx.clone(), + _parentState, + )); + if let EContextAll::IncContext(ctx) = + cast_mut::<_, EContextAll>(&mut tmp) + { + ctx.x = Some(_prevctx.clone()); + } else { + unreachable!("cant cast"); + } + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_e, + )?; + _localctx = tmp; + recog.base.set_state(28); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 3) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 3)".to_owned()), + None, + ))?; + } + recog.base.set_state(29); + recog + .base + .match_token(Labels_T__4, &mut recog.err_handler)?; + + let tmp = { + " ++".to_owned() + + if let EContextAll::IncContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .x + .as_ref() + .unwrap() + .get_v() + } + .to_owned(); + if let EContextAll::IncContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + } + 4 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = DecContextExt::new(&**EContextExt::new( + _parentctx.clone(), + _parentState, + )); + if let EContextAll::DecContext(ctx) = + cast_mut::<_, EContextAll>(&mut tmp) + { + ctx.x = Some(_prevctx.clone()); + } else { + unreachable!("cant cast"); + } + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_e, + )?; + _localctx = tmp; + recog.base.set_state(31); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 2) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 2)".to_owned()), + None, + ))?; + } + recog.base.set_state(32); + recog + .base + .match_token(Labels_T__5, &mut recog.err_handler)?; + + let tmp = { + " --".to_owned() + + if let EContextAll::DecContext(ctx) = + cast::<_, EContextAll>(&*_localctx) + { + ctx + } else { + unreachable!("cant cast") + } + .x + .as_ref() + .unwrap() + .get_v() + } + .to_owned(); + if let EContextAll::DecContext(ctx) = + cast_mut::<_, EContextAll>(&mut _localctx) + { + ctx.set_v(tmp); + } else { + unreachable!("cant cast"); + } + } + } + + _ => {} + } + } + } + recog.base.set_state(38); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(2, &mut recog.base)?; + } + } + 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.unroll_recursion_context(_parentctx)?; + + Ok(_localctx) + } +} +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 9, 40, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 17, 8, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 5, 1, 35, 8, 1, 10, 1, 12, 1, 38, 9, 1, 1, 1, 0, 1, 2, 2, 0, - 2, 0, 0, 43, 0, 4, 1, 0, 0, 0, 2, 16, 1, 0, 0, 0, 4, 5, 3, 2, 1, 0, 5, - 1, 1, 0, 0, 0, 6, 7, 6, 1, -1, 0, 7, 8, 5, 8, 0, 0, 8, 17, 6, 1, -1, 0, - 9, 10, 5, 3, 0, 0, 10, 11, 3, 2, 1, 0, 11, 12, 5, 4, 0, 0, 12, 13, 6, - 1, -1, 0, 13, 17, 1, 0, 0, 0, 14, 15, 5, 7, 0, 0, 15, 17, 6, 1, -1, 0, - 16, 6, 1, 0, 0, 0, 16, 9, 1, 0, 0, 0, 16, 14, 1, 0, 0, 0, 17, 36, 1, 0, - 0, 0, 18, 19, 10, 7, 0, 0, 19, 20, 5, 1, 0, 0, 20, 21, 3, 2, 1, 8, 21, - 22, 6, 1, -1, 0, 22, 35, 1, 0, 0, 0, 23, 24, 10, 6, 0, 0, 24, 25, 5, 2, - 0, 0, 25, 26, 3, 2, 1, 7, 26, 27, 6, 1, -1, 0, 27, 35, 1, 0, 0, 0, 28, - 29, 10, 3, 0, 0, 29, 30, 5, 5, 0, 0, 30, 35, 6, 1, -1, 0, 31, 32, 10, - 2, 0, 0, 32, 33, 5, 6, 0, 0, 33, 35, 6, 1, -1, 0, 34, 18, 1, 0, 0, 0, - 34, 23, 1, 0, 0, 0, 34, 28, 1, 0, 0, 0, 34, 31, 1, 0, 0, 0, 35, 38, 1, - 0, 0, 0, 36, 34, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 3, 1, 0, 0, 0, 38, - 36, 1, 0, 0, 0, 3, 16, 34, 36 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 9, 40, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 3, 1, 17, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 35, 8, 1, 10, 1, 12, 1, 38, 9, 1, 1, 1, 0, 1, + 2, 2, 0, 2, 0, 0, 43, 0, 4, 1, 0, 0, 0, 2, 16, 1, 0, 0, 0, 4, 5, 3, 2, 1, 0, 5, 1, 1, 0, 0, + 0, 6, 7, 6, 1, -1, 0, 7, 8, 5, 8, 0, 0, 8, 17, 6, 1, -1, 0, 9, 10, 5, 3, 0, 0, 10, 11, 3, + 2, 1, 0, 11, 12, 5, 4, 0, 0, 12, 13, 6, 1, -1, 0, 13, 17, 1, 0, 0, 0, 14, 15, 5, 7, 0, 0, + 15, 17, 6, 1, -1, 0, 16, 6, 1, 0, 0, 0, 16, 9, 1, 0, 0, 0, 16, 14, 1, 0, 0, 0, 17, 36, 1, + 0, 0, 0, 18, 19, 10, 7, 0, 0, 19, 20, 5, 1, 0, 0, 20, 21, 3, 2, 1, 8, 21, 22, 6, 1, -1, 0, + 22, 35, 1, 0, 0, 0, 23, 24, 10, 6, 0, 0, 24, 25, 5, 2, 0, 0, 25, 26, 3, 2, 1, 7, 26, 27, 6, + 1, -1, 0, 27, 35, 1, 0, 0, 0, 28, 29, 10, 3, 0, 0, 29, 30, 5, 5, 0, 0, 30, 35, 6, 1, -1, 0, + 31, 32, 10, 2, 0, 0, 32, 33, 5, 6, 0, 0, 33, 35, 6, 1, -1, 0, 34, 18, 1, 0, 0, 0, 34, 23, + 1, 0, 0, 0, 34, 28, 1, 0, 0, 0, 34, 31, 1, 0, 0, 0, 35, 38, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, + 36, 37, 1, 0, 0, 0, 37, 3, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 3, 16, 34, 36 + ]; } diff --git a/runtime/Rust/tests/gen/referencetoatnlexer.rs b/runtime/Rust/tests/gen/referencetoatnlexer.rs index f0320d751f..893bb41d4b 100644 --- a/runtime/Rust/tests/gen/referencetoatnlexer.rs +++ b/runtime/Rust/tests/gen/referencetoatnlexer.rs @@ -4,87 +4,80 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const ID: i32 = 1; +pub const ATN: i32 = 2; +pub const WS: i32 = 3; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; + +pub const modeNames: [&'static str; 1] = ["DEFAULT_MODE"]; + +pub const ruleNames: [&'static str; 3] = ["ID", "ATN", "WS"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 0] = []; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 4] = [None, Some("ID"), Some("ATN"), Some("WS")]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} - pub const ID:i32=1; - pub const ATN:i32=2; - pub const WS:i32=3; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;3] = [ - "ID", "ATN", "WS" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;0] = [ - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;4] = [ - None, Some("ID"), Some("ATN"), Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = antlr4rust::token_factory::OwningTokenFactory; // need single quote here ' -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct ReferenceToATNLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,ReferenceToATNLexerActions,Input,LocalTokenFactory<'input>>, +pub struct ReferenceToATNLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, ReferenceToATNLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for ReferenceToATNLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for ReferenceToATNLexer<'input,Input>{ - type Target = BaseLexer<'input,ReferenceToATNLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for ReferenceToATNLexer<'input, Input> { + type Target = BaseLexer<'input, ReferenceToATNLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for ReferenceToATNLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for ReferenceToATNLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> ReferenceToATNLexer<'input,Input>{ +impl<'input, Input: CharStream>> ReferenceToATNLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -100,49 +93,61 @@ impl<'input, Input:CharStream >> ReferenceToATNLexer<'input,Input>{ "ReferenceToATNLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - ReferenceToATNLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> ReferenceToATNLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - ReferenceToATNLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct ReferenceToATNLexerActions { + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + ReferenceToATNLexerActions {}, + tf, + ), + } + } } -impl ReferenceToATNLexerActions{ +impl<'input, Input: CharStream>> ReferenceToATNLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + ReferenceToATNLexer::new_with_token_factory( + input, + <&LocalTokenFactory<'input> as Default>::default(), + ) + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,ReferenceToATNLexerActions,Input,LocalTokenFactory<'input>>> for ReferenceToATNLexerActions{ - } +pub struct ReferenceToATNLexerActions {} - impl<'input, Input:CharStream >> ReferenceToATNLexer<'input,Input>{ +impl ReferenceToATNLexerActions {} +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, ReferenceToATNLexerActions, Input, LocalTokenFactory<'input>>> + for ReferenceToATNLexerActions +{ } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,ReferenceToATNLexerActions,Input,LocalTokenFactory<'input>>> for ReferenceToATNLexerActions{ +impl<'input, Input: CharStream>> ReferenceToATNLexer<'input, Input> {} + +impl<'input, Input: CharStream>> + LexerRecog< + 'input, + BaseLexer<'input, ReferenceToATNLexerActions, Input, LocalTokenFactory<'input>>, + > for ReferenceToATNLexerActions +{ } -impl<'input> TokenAware<'input> for ReferenceToATNLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for ReferenceToATNLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for ReferenceToATNLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> + for ReferenceToATNLexer<'input, Input> +{ + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -160,9 +165,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for ReferenceT self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -173,32 +178,25 @@ impl<'input, Input:CharStream >> TokenSource<'input> for ReferenceT } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 3, 21, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 4, 0, 9, - 8, 0, 11, 0, 12, 0, 10, 1, 1, 4, 1, 14, 8, 1, 11, 1, 12, 1, 15, 1, 2, - 1, 2, 1, 2, 1, 2, 0, 0, 3, 1, 1, 3, 2, 5, 3, 1, 0, 1, 2, 0, 10, 10, 32, - 32, 22, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 1, 8, 1, - 0, 0, 0, 3, 13, 1, 0, 0, 0, 5, 17, 1, 0, 0, 0, 7, 9, 2, 97, 122, 0, 8, - 7, 1, 0, 0, 0, 9, 10, 1, 0, 0, 0, 10, 8, 1, 0, 0, 0, 10, 11, 1, 0, 0, - 0, 11, 2, 1, 0, 0, 0, 12, 14, 2, 48, 57, 0, 13, 12, 1, 0, 0, 0, 14, 15, - 1, 0, 0, 0, 15, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 4, 1, 0, 0, 0, - 17, 18, 7, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 20, 6, 2, 0, 0, 20, 6, 1, - 0, 0, 0, 3, 0, 10, 15, 1, 6, 0, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 3, 21, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 4, 0, 9, 8, 0, 11, 0, 12, 0, + 10, 1, 1, 4, 1, 14, 8, 1, 11, 1, 12, 1, 15, 1, 2, 1, 2, 1, 2, 1, 2, 0, 0, 3, 1, 1, 3, 2, 5, + 3, 1, 0, 1, 2, 0, 10, 10, 32, 32, 22, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, + 1, 8, 1, 0, 0, 0, 3, 13, 1, 0, 0, 0, 5, 17, 1, 0, 0, 0, 7, 9, 2, 97, 122, 0, 8, 7, 1, 0, 0, + 0, 9, 10, 1, 0, 0, 0, 10, 8, 1, 0, 0, 0, 10, 11, 1, 0, 0, 0, 11, 2, 1, 0, 0, 0, 12, 14, 2, + 48, 57, 0, 13, 12, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, + 16, 4, 1, 0, 0, 0, 17, 18, 7, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 20, 6, 2, 0, 0, 20, 6, 1, 0, + 0, 0, 3, 0, 10, 15, 1, 6, 0, 0 + ]; +} diff --git a/runtime/Rust/tests/gen/referencetoatnlistener.rs b/runtime/Rust/tests/gen/referencetoatnlistener.rs index b084718c31..0921eb467e 100644 --- a/runtime/Rust/tests/gen/referencetoatnlistener.rs +++ b/runtime/Rust/tests/gen/referencetoatnlistener.rs @@ -1,22 +1,21 @@ #![allow(nonstandard_style)] // Generated from ReferenceToATN.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::referencetoatnparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait ReferenceToATNListener<'input> : ParseTreeListener<'input,ReferenceToATNParserContextType>{ -/** - * Enter a parse tree produced by {@link ReferenceToATNParser#a}. - * @param ctx the parse tree - */ -fn enter_a(&mut self, _ctx: &AContext<'input>) { } -/** - * Exit a parse tree produced by {@link ReferenceToATNParser#a}. - * @param ctx the parse tree - */ -fn exit_a(&mut self, _ctx: &AContext<'input>) { } - +pub trait ReferenceToATNListener<'input>: + ParseTreeListener<'input, ReferenceToATNParserContextType> +{ + /** + * Enter a parse tree produced by {@link ReferenceToATNParser#a}. + * @param ctx the parse tree + */ + fn enter_a(&mut self, _ctx: &AContext<'input>) {} + /** + * Exit a parse tree produced by {@link ReferenceToATNParser#a}. + * @param ctx the parse tree + */ + fn exit_a(&mut self, _ctx: &AContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : ReferenceToATNListener<'input> } - - +antlr4rust::coerce_from! { 'input : ReferenceToATNListener<'input> } diff --git a/runtime/Rust/tests/gen/referencetoatnparser.rs b/runtime/Rust/tests/gen/referencetoatnparser.rs index 5b96f11034..3fc3f2373a 100644 --- a/runtime/Rust/tests/gen/referencetoatnparser.rs +++ b/runtime/Rust/tests/gen/referencetoatnparser.rs @@ -7,36 +7,36 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::referencetoatnlistener::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::referencetoatnlistener::*; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -45,126 +45,144 @@ const _: () = { ); }; - pub const ReferenceToATN_ID:i32=1; - pub const ReferenceToATN_ATN:i32=2; - pub const ReferenceToATN_WS:i32=3; - pub const ReferenceToATN_EOF:i32=EOF; - pub const RULE_a:usize = 0; - pub const ruleNames: [&'static str; 1] = [ - "a" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;0] = [ - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;4] = [ - None, Some("ID"), Some("ATN"), Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - +pub const ReferenceToATN_ID: i32 = 1; +pub const ReferenceToATN_ATN: i32 = 2; +pub const ReferenceToATN_WS: i32 = 3; +pub const ReferenceToATN_EOF: i32 = EOF; +pub const RULE_a: usize = 0; +pub const ruleNames: [&'static str; 1] = ["a"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 0] = []; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 4] = [None, Some("ID"), Some("ATN"), Some("WS")]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} -type BaseParserType<'input, I> = - BaseParser<'input,ReferenceToATNParserExt<'input>, I, ReferenceToATNParserContextType , dyn ReferenceToATNListener<'input> + 'input >; +type BaseParserType<'input, I> = BaseParser< + 'input, + ReferenceToATNParserExt<'input>, + I, + ReferenceToATNParserContextType, + dyn ReferenceToATNListener<'input> + 'input, +>; type TokenType<'input> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = antlr4rust::token_factory::OwningTokenFactory; // need single quote here ' -pub type ReferenceToATNTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, ReferenceToATNParserContextType , dyn ReferenceToATNListener<'input> + 'a>; +pub type ReferenceToATNTreeWalker<'input, 'a> = ParseTreeWalker< + 'input, + 'a, + ReferenceToATNParserContextType, + dyn ReferenceToATNListener<'input> + 'a, +>; /// Parser for ReferenceToATN grammar pub struct ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - ReferenceToATNParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + ReferenceToATNParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } /// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for ReferenceToATNParser -pub trait ReferenceToATNParserContext<'input>: - for<'x> Listenable + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=ReferenceToATNParserContextType> -{} +pub trait ReferenceToATNParserContext<'input>: for<'x> Listenable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = ReferenceToATNParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : ReferenceToATNParserContext<'input> } +antlr4rust::coerce_from! { 'input : ReferenceToATNParserContext<'input> } -impl<'input> ReferenceToATNParserContext<'input> for TerminalNode<'input,ReferenceToATNParserContextType> {} -impl<'input> ReferenceToATNParserContext<'input> for ErrorNode<'input,ReferenceToATNParserContextType> {} +impl<'input> ReferenceToATNParserContext<'input> + for TerminalNode<'input, ReferenceToATNParserContextType> +{ +} +impl<'input> ReferenceToATNParserContext<'input> + for ErrorNode<'input, ReferenceToATNParserContextType> +{ +} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn ReferenceToATNParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn ReferenceToATNListener<'input> + 'input } pub struct ReferenceToATNParserContextType; -antlr4rust::tid!{ReferenceToATNParserContextType} +antlr4rust::tid! {ReferenceToATNParserContextType} -impl<'input> ParserNodeType<'input> for ReferenceToATNParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn ReferenceToATNParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for ReferenceToATNParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn ReferenceToATNParserContext<'input> + 'input; } impl<'input, I> Deref for ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -173,196 +191,233 @@ where impl<'input, I> DerefMut for ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct ReferenceToATNParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct ReferenceToATNParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> ReferenceToATNParserExt<'input>{ -} +impl<'input> ReferenceToATNParserExt<'input> {} antlr4rust::tid! { ReferenceToATNParserExt<'a> } -impl<'input> TokenAware<'input> for ReferenceToATNParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for ReferenceToATNParserExt<'input> { + type TF = LocalTokenFactory<'input>; } -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> ParserRecog<'input, BaseParserType<'input,I>> for ReferenceToATNParserExt<'input>{} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + ParserRecog<'input, BaseParserType<'input, I>> for ReferenceToATNParserExt<'input> +{ +} -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> Actions<'input, BaseParserType<'input,I>> for ReferenceToATNParserExt<'input>{ - fn get_grammar_file_name(&self) -> & str{ "ReferenceToATN.g4"} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + Actions<'input, BaseParserType<'input, I>> for ReferenceToATNParserExt<'input> +{ + fn get_grammar_file_name(&self) -> &str { + "ReferenceToATN.g4" + } - fn get_rule_names(&self) -> &[& str] {&ruleNames} + fn get_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } } //------------------- a ---------------- pub type AContextAll<'input> = AContext<'input>; - -pub type AContext<'input> = BaseParserRuleContext<'input,AContextExt<'input>>; +pub type AContext<'input> = BaseParserRuleContext<'input, AContextExt<'input>>; #[derive(Clone)] -pub struct AContextExt<'input>{ -ph:PhantomData<&'input str> -} - -impl<'input> ReferenceToATNParserContext<'input> for AContext<'input>{} - -impl<'input,'a> Listenable + 'a> for AContext<'input>{ - fn enter(&self,listener: &mut (dyn ReferenceToATNListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_a(self); - Ok(()) - }fn exit(&self,listener: &mut (dyn ReferenceToATNListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_a(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} - -impl<'input> CustomRuleContext<'input> for AContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = ReferenceToATNParserContextType; - fn get_rule_index(&self) -> usize { RULE_a } - //fn type_rule_index() -> usize where Self: Sized { RULE_a } +pub struct AContextExt<'input> { + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AContextExt<'a>} -impl<'input> AContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,AContextExt{ +impl<'input> ReferenceToATNParserContext<'input> for AContext<'input> {} - ph:PhantomData - }), - ) - } +impl<'input, 'a> Listenable + 'a> for AContext<'input> { + fn enter( + &self, + listener: &mut (dyn ReferenceToATNListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_a(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn ReferenceToATNListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_a(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -pub trait AContextAttrs<'input>: ReferenceToATNParserContext<'input> + BorrowMut>{ - -/// Retrieves all `TerminalNode`s corresponding to token ATN in current rule -fn ATN_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() -} -/// Retrieves 'i's TerminalNode corresponding to token ATN, starting from 0. -/// Returns `None` if number of children corresponding to token ATN is less or equal than `i`. -fn ATN(&self, i: usize) -> Option>> where Self:Sized{ - self.get_token(ReferenceToATN_ATN, i) -} -/// Retrieves all `TerminalNode`s corresponding to token ID in current rule -fn ID_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() +impl<'input> CustomRuleContext<'input> for AContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = ReferenceToATNParserContextType; + fn get_rule_index(&self) -> usize { + RULE_a + } + //fn type_rule_index() -> usize where Self: Sized { RULE_a } } -/// Retrieves 'i's TerminalNode corresponding to token ID, starting from 0. -/// Returns `None` if number of children corresponding to token ID is less or equal than `i`. -fn ID(&self, i: usize) -> Option>> where Self:Sized{ - self.get_token(ReferenceToATN_ID, i) +antlr4rust::tid! {AContextExt<'a>} + +impl<'input> AContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + AContextExt { ph: PhantomData }, + )) + } } +pub trait AContextAttrs<'input>: + ReferenceToATNParserContext<'input> + BorrowMut> +{ + /// Retrieves all `TerminalNode`s corresponding to token ATN in current rule + fn ATN_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + /// Retrieves 'i's TerminalNode corresponding to token ATN, starting from 0. + /// Returns `None` if number of children corresponding to token ATN is less or equal than `i`. + fn ATN(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.get_token(ReferenceToATN_ATN, i) + } + /// Retrieves all `TerminalNode`s corresponding to token ID in current rule + fn ID_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + /// Retrieves 'i's TerminalNode corresponding to token ID, starting from 0. + /// Returns `None` if number of children corresponding to token ID is less or equal than `i`. + fn ID(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.get_token(ReferenceToATN_ID, i) + } } -impl<'input> AContextAttrs<'input> for AContext<'input>{} +impl<'input> AContextAttrs<'input> for AContext<'input> {} impl<'input, I> ReferenceToATNParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn a(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = AContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn a(&mut self) -> Result>, ANTLRError> { + let mut recog = self; + let _parentctx = recog.ctx.take(); + let mut _localctx = AContextExt::new(_parentctx.clone(), recog.base.get_state()); recog.base.enter_rule(_localctx.clone(), 0, RULE_a); let mut _localctx: Rc = _localctx; - let mut _la: i32 = -1; - let result: Result<(), ANTLRError> = (|| { - - let mut _alt: i32; - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - recog.base.set_state(5); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(0,&mut recog.base)?; - while { _alt!=2 && _alt!=INVALID_ALT } { - if _alt==1 { - { - { - recog.base.set_state(2); - _la = recog.base.input.la(1); - if { !(_la==ReferenceToATN_ID || _la==ReferenceToATN_ATN) } { - recog.err_handler.recover_inline(&mut recog.base)?; - - } - else { - if recog.base.input.la(1)==TOKEN_EOF { recog.base.matched_eof = true }; - recog.err_handler.report_match(&mut recog.base); - recog.base.consume(&mut recog.err_handler); - } - } - } - } - recog.base.set_state(7); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(0,&mut recog.base)?; - } - recog.base.set_state(9); - recog.err_handler.sync(&mut recog.base)?; - _la = recog.base.input.la(1); - if _la==ReferenceToATN_ATN { - { - recog.base.set_state(8); - recog.base.match_token(ReferenceToATN_ATN,&mut recog.err_handler)?; - - } - } - - println!("{}",{let temp = recog.base.input.lt(-1).map(|it|it.get_token_index()).unwrap_or(-1); recog.input.get_text_from_interval(recog.get_parser_rule_context().start().get_token_index(), temp)}); - } - 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) - } + let mut _la: i32 = -1; + let result: Result<(), ANTLRError> = (|| { + let mut _alt: i32; + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + recog.base.set_state(5); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(0, &mut recog.base)?; + while { _alt != 2 && _alt != INVALID_ALT } { + if _alt == 1 { + { + { + recog.base.set_state(2); + _la = recog.base.input.la(1); + if { !(_la == ReferenceToATN_ID || _la == ReferenceToATN_ATN) } { + recog.err_handler.recover_inline(&mut recog.base)?; + } else { + if recog.base.input.la(1) == TOKEN_EOF { + recog.base.matched_eof = true + }; + recog.err_handler.report_match(&mut recog.base); + recog.base.consume(&mut recog.err_handler); + } + } + } + } + recog.base.set_state(7); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(0, &mut recog.base)?; + } + recog.base.set_state(9); + recog.err_handler.sync(&mut recog.base)?; + _la = recog.base.input.la(1); + if _la == ReferenceToATN_ATN { + { + recog.base.set_state(8); + recog + .base + .match_token(ReferenceToATN_ATN, &mut recog.err_handler)?; + } + } + + println!("{}", { + let temp = recog + .base + .input + .lt(-1) + .map(|it| it.get_token_index()) + .unwrap_or(-1); + recog.input.get_text_from_interval( + recog.get_parser_rule_context().start().get_token_index(), + temp, + ) + }); + } + 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) + } } - lazy_static!{ +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 3, 14, 2, 0, 7, 0, 1, 0, 5, 0, 4, 8, 0, 10, 0, 12, 0, 7, 9, 0, 1, - 0, 3, 0, 10, 8, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 2, 14, - 0, 5, 1, 0, 0, 0, 2, 4, 7, 0, 0, 0, 3, 2, 1, 0, 0, 0, 4, 7, 1, 0, 0, 0, - 5, 3, 1, 0, 0, 0, 5, 6, 1, 0, 0, 0, 6, 9, 1, 0, 0, 0, 7, 5, 1, 0, 0, 0, - 8, 10, 5, 2, 0, 0, 9, 8, 1, 0, 0, 0, 9, 10, 1, 0, 0, 0, 10, 11, 1, 0, - 0, 0, 11, 12, 6, 0, -1, 0, 12, 1, 1, 0, 0, 0, 2, 5, 9 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 3, 14, 2, 0, 7, 0, 1, 0, 5, 0, 4, 8, 0, 10, 0, 12, 0, 7, 9, 0, 1, 0, 3, 0, 10, 8, 0, + 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 2, 14, 0, 5, 1, 0, 0, 0, 2, 4, 7, 0, 0, 0, 3, + 2, 1, 0, 0, 0, 4, 7, 1, 0, 0, 0, 5, 3, 1, 0, 0, 0, 5, 6, 1, 0, 0, 0, 6, 9, 1, 0, 0, 0, 7, + 5, 1, 0, 0, 0, 8, 10, 5, 2, 0, 0, 9, 8, 1, 0, 0, 0, 9, 10, 1, 0, 0, 0, 10, 11, 1, 0, 0, 0, + 11, 12, 6, 0, -1, 0, 12, 1, 1, 0, 0, 0, 2, 5, 9 + ]; } diff --git a/runtime/Rust/tests/gen/simplelrlexer.rs b/runtime/Rust/tests/gen/simplelrlexer.rs index daf02a05a5..8b13789179 100644 --- a/runtime/Rust/tests/gen/simplelrlexer.rs +++ b/runtime/Rust/tests/gen/simplelrlexer.rs @@ -1,199 +1 @@ -// Generated from SimpleLR.g4 by ANTLR 4.13.2 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr4rust::atn::ATN; -use antlr4rust::char_stream::CharStream; -use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; -use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; -use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; -use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; - -use std::sync::Arc; -use std::cell::RefCell; -use std::rc::Rc; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; - - - pub const ID:i32=1; - pub const WS:i32=2; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;2] = [ - "ID", "WS" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;0] = [ - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;3] = [ - None, Some("ID"), Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; -pub type LocalTokenFactory<'input> = CommonTokenFactory; - -type From<'a> = as TokenFactory<'a> >::From; - -pub struct SimpleLRLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,SimpleLRLexerActions,Input,LocalTokenFactory<'input>>, -} - -antlr4rust::tid! { impl<'input,Input> TidAble<'input> for SimpleLRLexer<'input,Input> where Input:CharStream > } - -impl<'input, Input:CharStream >> Deref for SimpleLRLexer<'input,Input>{ - type Target = BaseLexer<'input,SimpleLRLexerActions,Input,LocalTokenFactory<'input>>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, Input:CharStream >> DerefMut for SimpleLRLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - - -impl<'input, Input:CharStream >> SimpleLRLexer<'input,Input>{ - fn get_rule_names(&self) -> &'static [&'static str] { - &ruleNames - } - fn get_literal_names(&self) -> &[Option<&str>] { - &_LITERAL_NAMES - } - - fn get_symbolic_names(&self) -> &[Option<&str>] { - &_SYMBOLIC_NAMES - } - - fn get_grammar_file_name(&self) -> &'static str { - "SimpleLRLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - SimpleLRLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> SimpleLRLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - SimpleLRLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct SimpleLRLexerActions { -} - -impl SimpleLRLexerActions{ -} - -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,SimpleLRLexerActions,Input,LocalTokenFactory<'input>>> for SimpleLRLexerActions{ - } - - impl<'input, Input:CharStream >> SimpleLRLexer<'input,Input>{ - -} - -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,SimpleLRLexerActions,Input,LocalTokenFactory<'input>>> for SimpleLRLexerActions{ -} -impl<'input> TokenAware<'input> for SimpleLRLexerActions{ - type TF = LocalTokenFactory<'input>; -} - -impl<'input, Input:CharStream >> TokenSource<'input> for SimpleLRLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; - - fn next_token(&mut self) -> >::Tok { - self.base.next_token() - } - - fn get_line(&self) -> isize { - self.base.get_line() - } - - fn get_char_position_in_line(&self) -> isize { - self.base.get_char_position_in_line() - } - - fn get_input_stream(&mut self) -> Option<&mut dyn IntStream> { - self.base.get_input_stream() - } - - fn get_source_name(&self) -> String { - self.base.get_source_name() - } - - fn get_token_factory(&self) -> &'input Self::TF { - self.base.get_token_factory() - } - - fn get_dfa_string(&self) -> String { - self.base.get_dfa_string() - } -} - - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 2, 14, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 4, 0, 7, 8, 0, 11, - 0, 12, 0, 8, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2, 1, 1, 3, 2, 1, 0, 1, 2, - 0, 10, 10, 32, 32, 14, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 1, 6, 1, 0, - 0, 0, 3, 10, 1, 0, 0, 0, 5, 7, 2, 97, 122, 0, 6, 5, 1, 0, 0, 0, 7, 8, - 1, 0, 0, 0, 8, 6, 1, 0, 0, 0, 8, 9, 1, 0, 0, 0, 9, 2, 1, 0, 0, 0, 10, - 11, 7, 0, 0, 0, 11, 12, 1, 0, 0, 0, 12, 13, 6, 1, 0, 0, 13, 4, 1, 0, - 0, 0, 2, 0, 8, 1, 6, 0, 0 - ]; - } \ No newline at end of file diff --git a/runtime/Rust/tests/gen/simplelrlistener.rs b/runtime/Rust/tests/gen/simplelrlistener.rs index d2cd1c5a28..d830ceed9f 100644 --- a/runtime/Rust/tests/gen/simplelrlistener.rs +++ b/runtime/Rust/tests/gen/simplelrlistener.rs @@ -1,32 +1,29 @@ #![allow(nonstandard_style)] // Generated from SimpleLR.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::simplelrparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait SimpleLRListener<'input> : ParseTreeListener<'input,SimpleLRParserContextType>{ -/** - * Enter a parse tree produced by {@link SimpleLRParser#s}. - * @param ctx the parse tree - */ -fn enter_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Exit a parse tree produced by {@link SimpleLRParser#s}. - * @param ctx the parse tree - */ -fn exit_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Enter a parse tree produced by {@link SimpleLRParser#a}. - * @param ctx the parse tree - */ -fn enter_a(&mut self, _ctx: &AContext<'input>) { } -/** - * Exit a parse tree produced by {@link SimpleLRParser#a}. - * @param ctx the parse tree - */ -fn exit_a(&mut self, _ctx: &AContext<'input>) { } - +pub trait SimpleLRListener<'input>: ParseTreeListener<'input, SimpleLRParserContextType> { + /** + * Enter a parse tree produced by {@link SimpleLRParser#s}. + * @param ctx the parse tree + */ + fn enter_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Exit a parse tree produced by {@link SimpleLRParser#s}. + * @param ctx the parse tree + */ + fn exit_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Enter a parse tree produced by {@link SimpleLRParser#a}. + * @param ctx the parse tree + */ + fn enter_a(&mut self, _ctx: &AContext<'input>) {} + /** + * Exit a parse tree produced by {@link SimpleLRParser#a}. + * @param ctx the parse tree + */ + fn exit_a(&mut self, _ctx: &AContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : SimpleLRListener<'input> } - - +antlr4rust::coerce_from! { 'input : SimpleLRListener<'input> } diff --git a/runtime/Rust/tests/gen/simplelrparser.rs b/runtime/Rust/tests/gen/simplelrparser.rs index d51dc55372..1d3c1b35aa 100644 --- a/runtime/Rust/tests/gen/simplelrparser.rs +++ b/runtime/Rust/tests/gen/simplelrparser.rs @@ -7,36 +7,36 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::simplelrlistener::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::simplelrlistener::*; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -45,125 +45,134 @@ const _: () = { ); }; - pub const SimpleLR_ID:i32=1; - pub const SimpleLR_WS:i32=2; - pub const SimpleLR_EOF:i32=EOF; - pub const RULE_s:usize = 0; - pub const RULE_a:usize = 1; - pub const ruleNames: [&'static str; 2] = [ - "s", "a" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;0] = [ - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;3] = [ - None, Some("ID"), Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - +pub const SimpleLR_ID: i32 = 1; +pub const SimpleLR_WS: i32 = 2; +pub const SimpleLR_EOF: i32 = EOF; +pub const RULE_s: usize = 0; +pub const RULE_a: usize = 1; +pub const ruleNames: [&'static str; 2] = ["s", "a"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 0] = []; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 3] = [None, Some("ID"), Some("WS")]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} -type BaseParserType<'input, I> = - BaseParser<'input,SimpleLRParserExt<'input>, I, SimpleLRParserContextType , dyn SimpleLRListener<'input> + 'input >; +type BaseParserType<'input, I> = BaseParser< + 'input, + SimpleLRParserExt<'input>, + I, + SimpleLRParserContextType, + dyn SimpleLRListener<'input> + 'input, +>; type TokenType<'input> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = CommonTokenFactory; -pub type SimpleLRTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, SimpleLRParserContextType , dyn SimpleLRListener<'input> + 'a>; +pub type SimpleLRTreeWalker<'input, 'a> = + ParseTreeWalker<'input, 'a, SimpleLRParserContextType, dyn SimpleLRListener<'input> + 'a>; /// Parser for SimpleLR grammar pub struct SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - SimpleLRParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + SimpleLRParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } /// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for SimpleLRParser pub trait SimpleLRParserContext<'input>: - for<'x> Listenable + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=SimpleLRParserContextType> -{} + for<'x> Listenable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = SimpleLRParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : SimpleLRParserContext<'input> } +antlr4rust::coerce_from! { 'input : SimpleLRParserContext<'input> } -impl<'input> SimpleLRParserContext<'input> for TerminalNode<'input,SimpleLRParserContextType> {} -impl<'input> SimpleLRParserContext<'input> for ErrorNode<'input,SimpleLRParserContextType> {} +impl<'input> SimpleLRParserContext<'input> for TerminalNode<'input, SimpleLRParserContextType> {} +impl<'input> SimpleLRParserContext<'input> for ErrorNode<'input, SimpleLRParserContextType> {} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn SimpleLRParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn SimpleLRListener<'input> + 'input } pub struct SimpleLRParserContextType; -antlr4rust::tid!{SimpleLRParserContextType} +antlr4rust::tid! {SimpleLRParserContextType} -impl<'input> ParserNodeType<'input> for SimpleLRParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn SimpleLRParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for SimpleLRParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn SimpleLRParserContext<'input> + 'input; } impl<'input, I> Deref for SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -172,308 +181,346 @@ where impl<'input, I> DerefMut for SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct SimpleLRParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct SimpleLRParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> SimpleLRParserExt<'input>{ -} +impl<'input> SimpleLRParserExt<'input> {} antlr4rust::tid! { SimpleLRParserExt<'a> } -impl<'input> TokenAware<'input> for SimpleLRParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for SimpleLRParserExt<'input> { + type TF = LocalTokenFactory<'input>; } -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> ParserRecog<'input, BaseParserType<'input,I>> for SimpleLRParserExt<'input>{} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + ParserRecog<'input, BaseParserType<'input, I>> for SimpleLRParserExt<'input> +{ +} -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> Actions<'input, BaseParserType<'input,I>> for SimpleLRParserExt<'input>{ - fn get_grammar_file_name(&self) -> & str{ "SimpleLR.g4"} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + Actions<'input, BaseParserType<'input, I>> for SimpleLRParserExt<'input> +{ + fn get_grammar_file_name(&self) -> &str { + "SimpleLR.g4" + } - fn get_rule_names(&self) -> &[& str] {&ruleNames} + fn get_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } - fn sempred(_localctx: Option<&(dyn SimpleLRParserContext<'input> + 'input)>, rule_index: i32, pred_index: i32, - recog:&mut BaseParserType<'input,I> - )->bool{ - match rule_index { - 1 => SimpleLRParser::<'input,I>::a_sempred(_localctx.and_then(|x|x.downcast_ref()), pred_index, recog), - _ => true - } - } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } + fn sempred( + _localctx: Option<&(dyn SimpleLRParserContext<'input> + 'input)>, + rule_index: i32, + pred_index: i32, + recog: &mut BaseParserType<'input, I>, + ) -> bool { + match rule_index { + 1 => SimpleLRParser::<'input, I>::a_sempred( + _localctx.and_then(|x| x.downcast_ref()), + pred_index, + recog, + ), + _ => true, + } + } } impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - fn a_sempred(_localctx: Option<&AContext<'input>>, pred_index:i32, - recog:&mut ::Target - ) -> bool { - match pred_index { - 0=>{ - recog.precpred(None, 2) - } - _ => true - } - } + fn a_sempred( + _localctx: Option<&AContext<'input>>, + pred_index: i32, + recog: &mut ::Target, + ) -> bool { + match pred_index { + 0 => recog.precpred(None, 2), + _ => true, + } + } } //------------------- s ---------------- pub type SContextAll<'input> = SContext<'input>; - -pub type SContext<'input> = BaseParserRuleContext<'input,SContextExt<'input>>; +pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>; #[derive(Clone)] -pub struct SContextExt<'input>{ -ph:PhantomData<&'input str> +pub struct SContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input> SimpleLRParserContext<'input> for SContext<'input>{} - -impl<'input,'a> Listenable + 'a> for SContext<'input>{ - fn enter(&self,listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_s(self); - Ok(()) - }fn exit(&self,listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_s(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} +impl<'input> SimpleLRParserContext<'input> for SContext<'input> {} -impl<'input> CustomRuleContext<'input> for SContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = SimpleLRParserContextType; - fn get_rule_index(&self) -> usize { RULE_s } - //fn type_rule_index() -> usize where Self: Sized { RULE_s } +impl<'input, 'a> Listenable + 'a> for SContext<'input> { + fn enter(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_s(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_s(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{SContextExt<'a>} - -impl<'input> SContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,SContextExt{ - ph:PhantomData - }), - ) - } +impl<'input> CustomRuleContext<'input> for SContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = SimpleLRParserContextType; + fn get_rule_index(&self) -> usize { + RULE_s + } + //fn type_rule_index() -> usize where Self: Sized { RULE_s } } - -pub trait SContextAttrs<'input>: SimpleLRParserContext<'input> + BorrowMut>{ - -fn a(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) +antlr4rust::tid! {SContextExt<'a>} + +impl<'input> SContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + SContextExt { ph: PhantomData }, + )) + } } +pub trait SContextAttrs<'input>: + SimpleLRParserContext<'input> + BorrowMut> +{ + fn a(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> SContextAttrs<'input> for SContext<'input>{} +impl<'input> SContextAttrs<'input> for SContext<'input> {} impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn s(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = SContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn s(&mut self) -> Result>, 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 = _localctx; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - /*InvokeRule a*/ - recog.base.set_state(4); - recog.a_rec(0)?; - - } - let tmp = recog.input.lt(-1).cloned(); - recog.ctx.as_ref().unwrap().set_stop(tmp); - println!("test"); - 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) - } + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + /*InvokeRule a*/ + recog.base.set_state(4); + recog.a_rec(0)?; + } + let tmp = recog.input.lt(-1).cloned(); + recog.ctx.as_ref().unwrap().set_stop(tmp); + println!("test"); + 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) + } } //------------------- a ---------------- pub type AContextAll<'input> = AContext<'input>; - -pub type AContext<'input> = BaseParserRuleContext<'input,AContextExt<'input>>; +pub type AContext<'input> = BaseParserRuleContext<'input, AContextExt<'input>>; #[derive(Clone)] -pub struct AContextExt<'input>{ -ph:PhantomData<&'input str> -} - -impl<'input> SimpleLRParserContext<'input> for AContext<'input>{} - -impl<'input,'a> Listenable + 'a> for AContext<'input>{ - fn enter(&self,listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_a(self); - Ok(()) - }fn exit(&self,listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_a(self); - listener.exit_every_rule(self)?; - Ok(()) - } -} - -impl<'input> CustomRuleContext<'input> for AContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = SimpleLRParserContextType; - fn get_rule_index(&self) -> usize { RULE_a } - //fn type_rule_index() -> usize where Self: Sized { RULE_a } +pub struct AContextExt<'input> { + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AContextExt<'a>} -impl<'input> AContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,AContextExt{ +impl<'input> SimpleLRParserContext<'input> for AContext<'input> {} - ph:PhantomData - }), - ) - } +impl<'input, 'a> Listenable + 'a> for AContext<'input> { + fn enter(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_a(self); + Ok(()) + } + fn exit(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) -> Result<(), ANTLRError> { + listener.exit_a(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -pub trait AContextAttrs<'input>: SimpleLRParserContext<'input> + BorrowMut>{ - -/// Retrieves first TerminalNode corresponding to token ID -/// Returns `None` if there is no child corresponding to token ID -fn ID(&self) -> Option>> where Self:Sized{ - self.get_token(SimpleLR_ID, 0) +impl<'input> CustomRuleContext<'input> for AContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = SimpleLRParserContextType; + fn get_rule_index(&self) -> usize { + RULE_a + } + //fn type_rule_index() -> usize where Self: Sized { RULE_a } } -fn a(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) +antlr4rust::tid! {AContextExt<'a>} + +impl<'input> AContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + AContextExt { ph: PhantomData }, + )) + } } +pub trait AContextAttrs<'input>: + SimpleLRParserContext<'input> + BorrowMut> +{ + /// Retrieves first TerminalNode corresponding to token ID + /// Returns `None` if there is no child corresponding to token ID + fn ID(&self) -> Option>> + where + Self: Sized, + { + self.get_token(SimpleLR_ID, 0) + } + fn a(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } } -impl<'input> AContextAttrs<'input> for AContext<'input>{} +impl<'input> AContextAttrs<'input> for AContext<'input> {} impl<'input, I> SimpleLRParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn a(&mut self,) - -> Result>,ANTLRError> { - self.a_rec(0) - } - - fn a_rec(&mut self, _p: i32) - -> Result>,ANTLRError> { - let recog = self; - let _parentctx = recog.ctx.take(); - let _parentState = recog.base.get_state(); - let mut _localctx = AContextExt::new(_parentctx.clone(), recog.base.get_state()); - recog.base.enter_recursion_rule(_localctx.clone(), 2, RULE_a, _p); - let mut _localctx: Rc = _localctx; + pub fn a(&mut self) -> Result>, ANTLRError> { + self.a_rec(0) + } + + fn a_rec(&mut self, _p: i32) -> Result>, ANTLRError> { + let recog = self; + let _parentctx = recog.ctx.take(); + let _parentState = recog.base.get_state(); + let mut _localctx = AContextExt::new(_parentctx.clone(), recog.base.get_state()); + recog + .base + .enter_recursion_rule(_localctx.clone(), 2, RULE_a, _p); + let mut _localctx: Rc = _localctx; let mut _prevctx = _localctx.clone(); - let _startState = 2; - let result: Result<(), ANTLRError> = (|| { - let mut _alt: i32; - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - { - recog.base.set_state(7); - recog.base.match_token(SimpleLR_ID,&mut recog.err_handler)?; - - } - let tmp = recog.input.lt(-1).cloned(); - recog.ctx.as_ref().unwrap().set_stop(tmp); - recog.base.set_state(13); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(0,&mut recog.base)?; - while { _alt!=2 && _alt!=INVALID_ALT } { - if _alt==1 { - recog.trigger_exit_rule_event()?; - _prevctx = _localctx.clone(); - { - { - /*recRuleAltStartAction*/ - let mut tmp = AContextExt::new(_parentctx.clone(), _parentState); - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_a)?; - _localctx = tmp; - recog.base.set_state(9); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 2)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 2)".to_owned()), None))?; - } - recog.base.set_state(10); - recog.base.match_token(SimpleLR_ID,&mut recog.err_handler)?; - - } - } - } - recog.base.set_state(15); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(0,&mut recog.base)?; - } - } - 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.unroll_recursion_context(_parentctx)?; - - Ok(_localctx) - } + let _startState = 2; + let result: Result<(), ANTLRError> = (|| { + let mut _alt: i32; + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + { + recog.base.set_state(7); + recog + .base + .match_token(SimpleLR_ID, &mut recog.err_handler)?; + } + let tmp = recog.input.lt(-1).cloned(); + recog.ctx.as_ref().unwrap().set_stop(tmp); + recog.base.set_state(13); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(0, &mut recog.base)?; + while { _alt != 2 && _alt != INVALID_ALT } { + if _alt == 1 { + recog.trigger_exit_rule_event()?; + _prevctx = _localctx.clone(); + { + { + /*recRuleAltStartAction*/ + let mut tmp = AContextExt::new(_parentctx.clone(), _parentState); + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_a, + )?; + _localctx = tmp; + recog.base.set_state(9); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 2) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 2)".to_owned()), + None, + ))?; + } + recog.base.set_state(10); + recog + .base + .match_token(SimpleLR_ID, &mut recog.err_handler)?; + } + } + } + recog.base.set_state(15); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(0, &mut recog.base)?; + } + } + 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.unroll_recursion_context(_parentctx)?; + + Ok(_localctx) + } } - lazy_static!{ +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 2, 17, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 5, 1, 12, 8, 1, 10, 1, 12, 1, 15, 9, 1, 1, 1, 0, 1, 2, 2, 0, - 2, 0, 0, 15, 0, 4, 1, 0, 0, 0, 2, 6, 1, 0, 0, 0, 4, 5, 3, 2, 1, 0, 5, - 1, 1, 0, 0, 0, 6, 7, 6, 1, -1, 0, 7, 8, 5, 1, 0, 0, 8, 13, 1, 0, 0, 0, - 9, 10, 10, 2, 0, 0, 10, 12, 5, 1, 0, 0, 11, 9, 1, 0, 0, 0, 12, 15, 1, - 0, 0, 0, 13, 11, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 3, 1, 0, 0, 0, 15, - 13, 1, 0, 0, 0, 1, 13 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 2, 17, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 12, 8, + 1, 10, 1, 12, 1, 15, 9, 1, 1, 1, 0, 1, 2, 2, 0, 2, 0, 0, 15, 0, 4, 1, 0, 0, 0, 2, 6, 1, 0, + 0, 0, 4, 5, 3, 2, 1, 0, 5, 1, 1, 0, 0, 0, 6, 7, 6, 1, -1, 0, 7, 8, 5, 1, 0, 0, 8, 13, 1, 0, + 0, 0, 9, 10, 10, 2, 0, 0, 10, 12, 5, 1, 0, 0, 11, 9, 1, 0, 0, 0, 12, 15, 1, 0, 0, 0, 13, + 11, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 3, 1, 0, 0, 0, 15, 13, 1, 0, 0, 0, 1, 13 + ]; } diff --git a/runtime/Rust/tests/gen/visitorbasiclexer.rs b/runtime/Rust/tests/gen/visitorbasiclexer.rs index 19efccbfb5..acde63997c 100644 --- a/runtime/Rust/tests/gen/visitorbasiclexer.rs +++ b/runtime/Rust/tests/gen/visitorbasiclexer.rs @@ -4,85 +4,77 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const A: i32 = 1; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; - pub const A:i32=1; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;1] = [ - "A" - ]; - +pub const modeNames: [&'static str; 1] = ["DEFAULT_MODE"]; - pub const _LITERAL_NAMES: [Option<&'static str>;2] = [ - None, Some("'A'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;2] = [ - None, Some("A") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } +pub const ruleNames: [&'static str; 1] = ["A"]; +pub const _LITERAL_NAMES: [Option<&'static str>; 2] = [None, Some("'A'")]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 2] = [None, Some("A")]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = CommonTokenFactory; -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct VisitorBasicLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,VisitorBasicLexerActions,Input,LocalTokenFactory<'input>>, +pub struct VisitorBasicLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, VisitorBasicLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for VisitorBasicLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for VisitorBasicLexer<'input,Input>{ - type Target = BaseLexer<'input,VisitorBasicLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for VisitorBasicLexer<'input, Input> { + type Target = BaseLexer<'input, VisitorBasicLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for VisitorBasicLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for VisitorBasicLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> VisitorBasicLexer<'input,Input>{ +impl<'input, Input: CharStream>> VisitorBasicLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -98,49 +90,61 @@ impl<'input, Input:CharStream >> VisitorBasicLexer<'input,Input>{ "VisitorBasicLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - VisitorBasicLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> VisitorBasicLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - VisitorBasicLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct VisitorBasicLexerActions { + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + VisitorBasicLexerActions {}, + tf, + ), + } + } } -impl VisitorBasicLexerActions{ +impl<'input, Input: CharStream>> VisitorBasicLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + VisitorBasicLexer::new_with_token_factory( + input, + <&LocalTokenFactory<'input> as Default>::default(), + ) + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,VisitorBasicLexerActions,Input,LocalTokenFactory<'input>>> for VisitorBasicLexerActions{ - } +pub struct VisitorBasicLexerActions {} - impl<'input, Input:CharStream >> VisitorBasicLexer<'input,Input>{ +impl VisitorBasicLexerActions {} +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, VisitorBasicLexerActions, Input, LocalTokenFactory<'input>>> + for VisitorBasicLexerActions +{ } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,VisitorBasicLexerActions,Input,LocalTokenFactory<'input>>> for VisitorBasicLexerActions{ +impl<'input, Input: CharStream>> VisitorBasicLexer<'input, Input> {} + +impl<'input, Input: CharStream>> + LexerRecog< + 'input, + BaseLexer<'input, VisitorBasicLexerActions, Input, LocalTokenFactory<'input>>, + > for VisitorBasicLexerActions +{ } -impl<'input> TokenAware<'input> for VisitorBasicLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for VisitorBasicLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for VisitorBasicLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> + for VisitorBasicLexer<'input, Input> +{ + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -158,9 +162,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for VisitorBas self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -171,25 +175,19 @@ impl<'input, Input:CharStream >> TokenSource<'input> for VisitorBas } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 1, 5, 6, -1, 2, 0, 7, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 4, - 0, 1, 1, 0, 0, 0, 1, 3, 1, 0, 0, 0, 3, 4, 5, 65, 0, 0, 4, 2, 1, 0, 0, - 0, 1, 0, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 1, 5, 6, -1, 2, 0, 7, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 1, 1, 0, 0, 0, 1, + 3, 1, 0, 0, 0, 3, 4, 5, 65, 0, 0, 4, 2, 1, 0, 0, 0, 1, 0, 0 + ]; +} diff --git a/runtime/Rust/tests/gen/visitorbasiclistener.rs b/runtime/Rust/tests/gen/visitorbasiclistener.rs index 5c37a9d732..1f3e01456d 100644 --- a/runtime/Rust/tests/gen/visitorbasiclistener.rs +++ b/runtime/Rust/tests/gen/visitorbasiclistener.rs @@ -1,22 +1,21 @@ #![allow(nonstandard_style)] // Generated from VisitorBasic.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::visitorbasicparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait VisitorBasicListener<'input> : ParseTreeListener<'input,VisitorBasicParserContextType>{ -/** - * Enter a parse tree produced by {@link VisitorBasicParser#s}. - * @param ctx the parse tree - */ -fn enter_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Exit a parse tree produced by {@link VisitorBasicParser#s}. - * @param ctx the parse tree - */ -fn exit_s(&mut self, _ctx: &SContext<'input>) { } - +pub trait VisitorBasicListener<'input>: + ParseTreeListener<'input, VisitorBasicParserContextType> +{ + /** + * Enter a parse tree produced by {@link VisitorBasicParser#s}. + * @param ctx the parse tree + */ + fn enter_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Exit a parse tree produced by {@link VisitorBasicParser#s}. + * @param ctx the parse tree + */ + fn exit_s(&mut self, _ctx: &SContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : VisitorBasicListener<'input> } - - +antlr4rust::coerce_from! { 'input : VisitorBasicListener<'input> } diff --git a/runtime/Rust/tests/gen/visitorbasicparser.rs b/runtime/Rust/tests/gen/visitorbasicparser.rs index 33534add15..23e6847e14 100644 --- a/runtime/Rust/tests/gen/visitorbasicparser.rs +++ b/runtime/Rust/tests/gen/visitorbasicparser.rs @@ -7,38 +7,38 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::visitorbasiclistener::*; +use super::visitorbasicvisitor::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::visitorbasiclistener::*; -use super::visitorbasicvisitor::*; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -47,104 +47,116 @@ const _: () = { ); }; - pub const VisitorBasic_A:i32=1; - pub const VisitorBasic_EOF:i32=EOF; - pub const RULE_s:usize = 0; - pub const ruleNames: [&'static str; 1] = [ - "s" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;2] = [ - None, Some("'A'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;2] = [ - None, Some("A") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - +pub const VisitorBasic_A: i32 = 1; +pub const VisitorBasic_EOF: i32 = EOF; +pub const RULE_s: usize = 0; +pub const ruleNames: [&'static str; 1] = ["s"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 2] = [None, Some("'A'")]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 2] = [None, Some("A")]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} -type BaseParserType<'input, I> = - BaseParser<'input,VisitorBasicParserExt<'input>, I, VisitorBasicParserContextType , dyn VisitorBasicListener<'input> + 'input >; +type BaseParserType<'input, I> = BaseParser< + 'input, + VisitorBasicParserExt<'input>, + I, + VisitorBasicParserContextType, + dyn VisitorBasicListener<'input> + 'input, +>; type TokenType<'input> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = CommonTokenFactory; -pub type VisitorBasicTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, VisitorBasicParserContextType , dyn VisitorBasicListener<'input> + 'a>; +pub type VisitorBasicTreeWalker<'input, 'a> = ParseTreeWalker< + 'input, + 'a, + VisitorBasicParserContextType, + dyn VisitorBasicListener<'input> + 'a, +>; /// Parser for VisitorBasic grammar pub struct VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - VisitorBasicParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + VisitorBasicParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } /// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for VisitorBasicParser pub trait VisitorBasicParserContext<'input>: - for<'x> Listenable + 'x > + - for<'x> Visitable + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=VisitorBasicParserContextType> -{} + for<'x> Listenable + 'x> + + for<'x> Visitable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = VisitorBasicParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : VisitorBasicParserContext<'input> } +antlr4rust::coerce_from! { 'input : VisitorBasicParserContext<'input> } impl<'input, 'x, T> VisitableDyn for dyn VisitorBasicParserContext<'input> + 'input where @@ -155,26 +167,32 @@ where } } -impl<'input> VisitorBasicParserContext<'input> for TerminalNode<'input,VisitorBasicParserContextType> {} -impl<'input> VisitorBasicParserContext<'input> for ErrorNode<'input,VisitorBasicParserContextType> {} +impl<'input> VisitorBasicParserContext<'input> + for TerminalNode<'input, VisitorBasicParserContextType> +{ +} +impl<'input> VisitorBasicParserContext<'input> + for ErrorNode<'input, VisitorBasicParserContextType> +{ +} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn VisitorBasicParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn VisitorBasicListener<'input> + 'input } pub struct VisitorBasicParserContextType; -antlr4rust::tid!{VisitorBasicParserContextType} +antlr4rust::tid! {VisitorBasicParserContextType} -impl<'input> ParserNodeType<'input> for VisitorBasicParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn VisitorBasicParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for VisitorBasicParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn VisitorBasicParserContext<'input> + 'input; } impl<'input, I> Deref for VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -183,158 +201,180 @@ where impl<'input, I> DerefMut for VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct VisitorBasicParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct VisitorBasicParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> VisitorBasicParserExt<'input>{ -} +impl<'input> VisitorBasicParserExt<'input> {} antlr4rust::tid! { VisitorBasicParserExt<'a> } -impl<'input> TokenAware<'input> for VisitorBasicParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for VisitorBasicParserExt<'input> { + type TF = LocalTokenFactory<'input>; } -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> ParserRecog<'input, BaseParserType<'input,I>> for VisitorBasicParserExt<'input>{} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + ParserRecog<'input, BaseParserType<'input, I>> for VisitorBasicParserExt<'input> +{ +} -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> Actions<'input, BaseParserType<'input,I>> for VisitorBasicParserExt<'input>{ - fn get_grammar_file_name(&self) -> & str{ "VisitorBasic.g4"} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + Actions<'input, BaseParserType<'input, I>> for VisitorBasicParserExt<'input> +{ + fn get_grammar_file_name(&self) -> &str { + "VisitorBasic.g4" + } - fn get_rule_names(&self) -> &[& str] {&ruleNames} + fn get_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } } //------------------- s ---------------- pub type SContextAll<'input> = SContext<'input>; - -pub type SContext<'input> = BaseParserRuleContext<'input,SContextExt<'input>>; +pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>; #[derive(Clone)] -pub struct SContextExt<'input>{ -ph:PhantomData<&'input str> -} - -impl<'input> VisitorBasicParserContext<'input> for SContext<'input>{} - -impl<'input,'a> Listenable + 'a> for SContext<'input>{ - fn enter(&self,listener: &mut (dyn VisitorBasicListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_s(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn VisitorBasicListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_s(self); - listener.exit_every_rule(self)?; - Ok(()) - } +pub struct SContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input,'a> Visitable + 'a> for SContext<'input>{ - fn accept(&self,visitor: &mut (dyn VisitorBasicVisitor<'input> + 'a)) { - visitor.visit_s(self); - } -} +impl<'input> VisitorBasicParserContext<'input> for SContext<'input> {} -impl<'input> CustomRuleContext<'input> for SContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorBasicParserContextType; - fn get_rule_index(&self) -> usize { RULE_s } - //fn type_rule_index() -> usize where Self: Sized { RULE_s } +impl<'input, 'a> Listenable + 'a> for SContext<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorBasicListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_s(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn VisitorBasicListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_s(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{SContextExt<'a>} -impl<'input> SContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,SContextExt{ - - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for SContext<'input> { + fn accept(&self, visitor: &mut (dyn VisitorBasicVisitor<'input> + 'a)) { + visitor.visit_s(self); + } } -pub trait SContextAttrs<'input>: VisitorBasicParserContext<'input> + BorrowMut>{ - -/// Retrieves first TerminalNode corresponding to token A -/// Returns `None` if there is no child corresponding to token A -fn A(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorBasic_A, 0) +impl<'input> CustomRuleContext<'input> for SContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorBasicParserContextType; + fn get_rule_index(&self) -> usize { + RULE_s + } + //fn type_rule_index() -> usize where Self: Sized { RULE_s } } -/// Retrieves first TerminalNode corresponding to token EOF -/// Returns `None` if there is no child corresponding to token EOF -fn EOF(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorBasic_EOF, 0) +antlr4rust::tid! {SContextExt<'a>} + +impl<'input> SContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + SContextExt { ph: PhantomData }, + )) + } } +pub trait SContextAttrs<'input>: + VisitorBasicParserContext<'input> + BorrowMut> +{ + /// Retrieves first TerminalNode corresponding to token A + /// Returns `None` if there is no child corresponding to token A + fn A(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorBasic_A, 0) + } + /// Retrieves first TerminalNode corresponding to token EOF + /// Returns `None` if there is no child corresponding to token EOF + fn EOF(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorBasic_EOF, 0) + } } -impl<'input> SContextAttrs<'input> for SContext<'input>{} +impl<'input> SContextAttrs<'input> for SContext<'input> {} impl<'input, I> VisitorBasicParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn s(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = SContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn s(&mut self) -> Result>, 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 = _localctx; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - recog.base.set_state(2); - recog.base.match_token(VisitorBasic_A,&mut recog.err_handler)?; - - recog.base.set_state(3); - recog.base.match_token(VisitorBasic_EOF,&mut recog.err_handler)?; - - } - 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) - } + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + recog.base.set_state(2); + recog + .base + .match_token(VisitorBasic_A, &mut recog.err_handler)?; + + recog.base.set_state(3); + recog + .base + .match_token(VisitorBasic_EOF, &mut recog.err_handler)?; + } + 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) + } } - lazy_static!{ +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 1, 6, 2, 0, 7, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 0, - 2, 1, 0, 0, 0, 2, 3, 5, 1, 0, 0, 3, 4, 5, 0, 0, 1, 4, 1, 1, 0, 0, 0, 0 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 1, 6, 2, 0, 7, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 0, 2, 1, 0, 0, 0, 2, + 3, 5, 1, 0, 0, 3, 4, 5, 0, 0, 1, 4, 1, 1, 0, 0, 0, 0 + ]; } diff --git a/runtime/Rust/tests/gen/visitorbasicvisitor.rs b/runtime/Rust/tests/gen/visitorbasicvisitor.rs index da7cea073d..48867aff39 100644 --- a/runtime/Rust/tests/gen/visitorbasicvisitor.rs +++ b/runtime/Rust/tests/gen/visitorbasicvisitor.rs @@ -1,39 +1,42 @@ #![allow(nonstandard_style)] // Generated from VisitorBasic.g4 by ANTLR 4.13.2 -use antlr4rust::tree::{ParseTreeVisitor,ParseTreeVisitorCompat}; use super::visitorbasicparser::*; +use antlr4rust::tree::{ParseTreeVisitor, ParseTreeVisitorCompat}; /** * This interface defines a complete generic visitor for a parse tree produced * by {@link VisitorBasicParser}. */ -pub trait VisitorBasicVisitor<'input>: ParseTreeVisitor<'input,VisitorBasicParserContextType>{ - /** - * Visit a parse tree produced by {@link VisitorBasicParser#s}. - * @param ctx the parse tree - */ - fn visit_s(&mut self, ctx: &SContext<'input>) { self.visit_children(ctx) } - +pub trait VisitorBasicVisitor<'input>: + ParseTreeVisitor<'input, VisitorBasicParserContextType> +{ + /** + * Visit a parse tree produced by {@link VisitorBasicParser#s}. + * @param ctx the parse tree + */ + fn visit_s(&mut self, ctx: &SContext<'input>) { + self.visit_children(ctx) + } } -pub trait VisitorBasicVisitorCompat<'input>:ParseTreeVisitorCompat<'input, Node= VisitorBasicParserContextType>{ - /** - * Visit a parse tree produced by {@link VisitorBasicParser#s}. - * @param ctx the parse tree - */ - fn visit_s(&mut self, ctx: &SContext<'input>) -> Self::Return { - self.visit_children(ctx) - } - +pub trait VisitorBasicVisitorCompat<'input>: + ParseTreeVisitorCompat<'input, Node = VisitorBasicParserContextType> +{ + /** + * Visit a parse tree produced by {@link VisitorBasicParser#s}. + * @param ctx the parse tree + */ + fn visit_s(&mut self, ctx: &SContext<'input>) -> Self::Return { + self.visit_children(ctx) + } } -impl<'input,T> VisitorBasicVisitor<'input> for T +impl<'input, T> VisitorBasicVisitor<'input> for T where - T: VisitorBasicVisitorCompat<'input> + T: VisitorBasicVisitorCompat<'input>, { - fn visit_s(&mut self, ctx: &SContext<'input>){ - let result = ::visit_s(self, ctx); + fn visit_s(&mut self, ctx: &SContext<'input>) { + let result = ::visit_s(self, ctx); *::temp_result(self) = result; - } - -} \ No newline at end of file + } +} diff --git a/runtime/Rust/tests/gen/visitorcalclexer.rs b/runtime/Rust/tests/gen/visitorcalclexer.rs index 5cb0a5c9e0..04bc8e0e4c 100644 --- a/runtime/Rust/tests/gen/visitorcalclexer.rs +++ b/runtime/Rust/tests/gen/visitorcalclexer.rs @@ -4,91 +4,97 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const INT: i32 = 1; +pub const MUL: i32 = 2; +pub const DIV: i32 = 3; +pub const ADD: i32 = 4; +pub const SUB: i32 = 5; +pub const WS: i32 = 6; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; + +pub const modeNames: [&'static str; 1] = ["DEFAULT_MODE"]; + +pub const ruleNames: [&'static str; 6] = ["INT", "MUL", "DIV", "ADD", "SUB", "WS"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 6] = [ + None, + None, + Some("'*'"), + Some("'/'"), + Some("'+'"), + Some("'-'"), +]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 7] = [ + None, + Some("INT"), + Some("MUL"), + Some("DIV"), + Some("ADD"), + Some("SUB"), + Some("WS"), +]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} - pub const INT:i32=1; - pub const MUL:i32=2; - pub const DIV:i32=3; - pub const ADD:i32=4; - pub const SUB:i32=5; - pub const WS:i32=6; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;1] = [ - "DEFAULT_MODE" - ]; - - pub const ruleNames: [&'static str;6] = [ - "INT", "MUL", "DIV", "ADD", "SUB", "WS" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;6] = [ - None, None, Some("'*'"), Some("'/'"), Some("'+'"), Some("'-'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;7] = [ - None, Some("INT"), Some("MUL"), Some("DIV"), Some("ADD"), Some("SUB"), - Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = CommonTokenFactory; -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct VisitorCalcLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,VisitorCalcLexerActions,Input,LocalTokenFactory<'input>>, +pub struct VisitorCalcLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, VisitorCalcLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for VisitorCalcLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for VisitorCalcLexer<'input,Input>{ - type Target = BaseLexer<'input,VisitorCalcLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for VisitorCalcLexer<'input, Input> { + type Target = BaseLexer<'input, VisitorCalcLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for VisitorCalcLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for VisitorCalcLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> VisitorCalcLexer<'input,Input>{ +impl<'input, Input: CharStream>> VisitorCalcLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -104,49 +110,59 @@ impl<'input, Input:CharStream >> VisitorCalcLexer<'input,Input>{ "VisitorCalcLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - VisitorCalcLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> VisitorCalcLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - VisitorCalcLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } -} - -pub struct VisitorCalcLexerActions { + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + VisitorCalcLexerActions {}, + tf, + ), + } + } } -impl VisitorCalcLexerActions{ +impl<'input, Input: CharStream>> VisitorCalcLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + VisitorCalcLexer::new_with_token_factory( + input, + <&LocalTokenFactory<'input> as Default>::default(), + ) + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,VisitorCalcLexerActions,Input,LocalTokenFactory<'input>>> for VisitorCalcLexerActions{ - } +pub struct VisitorCalcLexerActions {} - impl<'input, Input:CharStream >> VisitorCalcLexer<'input,Input>{ +impl VisitorCalcLexerActions {} +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, VisitorCalcLexerActions, Input, LocalTokenFactory<'input>>> + for VisitorCalcLexerActions +{ } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,VisitorCalcLexerActions,Input,LocalTokenFactory<'input>>> for VisitorCalcLexerActions{ +impl<'input, Input: CharStream>> VisitorCalcLexer<'input, Input> {} + +impl<'input, Input: CharStream>> + LexerRecog<'input, BaseLexer<'input, VisitorCalcLexerActions, Input, LocalTokenFactory<'input>>> + for VisitorCalcLexerActions +{ } -impl<'input> TokenAware<'input> for VisitorCalcLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for VisitorCalcLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for VisitorCalcLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> + for VisitorCalcLexer<'input, Input> +{ + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -164,9 +180,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for VisitorCal self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -177,37 +193,29 @@ impl<'input, Input:CharStream >> TokenSource<'input> for VisitorCal } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 6, 33, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, - 4, 7, 4, 2, 5, 7, 5, 1, 0, 4, 0, 15, 8, 0, 11, 0, 12, 0, 16, 1, 1, 1, - 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 4, 5, 28, 8, 5, 11, 5, 12, - 5, 29, 1, 5, 1, 5, 0, 0, 6, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 1, 0, - 2, 1, 0, 48, 57, 2, 0, 9, 9, 32, 32, 34, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, - 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, - 0, 0, 0, 1, 14, 1, 0, 0, 0, 3, 18, 1, 0, 0, 0, 5, 20, 1, 0, 0, 0, 7, - 22, 1, 0, 0, 0, 9, 24, 1, 0, 0, 0, 11, 27, 1, 0, 0, 0, 13, 15, 7, 0, - 0, 0, 14, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 14, 1, 0, 0, 0, 16, - 17, 1, 0, 0, 0, 17, 2, 1, 0, 0, 0, 18, 19, 5, 42, 0, 0, 19, 4, 1, 0, - 0, 0, 20, 21, 5, 47, 0, 0, 21, 6, 1, 0, 0, 0, 22, 23, 5, 43, 0, 0, 23, - 8, 1, 0, 0, 0, 24, 25, 5, 45, 0, 0, 25, 10, 1, 0, 0, 0, 26, 28, 7, 1, - 0, 0, 27, 26, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, 29, - 30, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 6, 5, 0, 0, 32, 12, 1, 0, - 0, 0, 3, 0, 16, 29, 1, 0, 1, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 6, 33, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, + 1, 0, 4, 0, 15, 8, 0, 11, 0, 12, 0, 16, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, + 5, 4, 5, 28, 8, 5, 11, 5, 12, 5, 29, 1, 5, 1, 5, 0, 0, 6, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, + 6, 1, 0, 2, 1, 0, 48, 57, 2, 0, 9, 9, 32, 32, 34, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, + 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 1, 14, 1, 0, 0, 0, 3, + 18, 1, 0, 0, 0, 5, 20, 1, 0, 0, 0, 7, 22, 1, 0, 0, 0, 9, 24, 1, 0, 0, 0, 11, 27, 1, 0, 0, + 0, 13, 15, 7, 0, 0, 0, 14, 13, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 14, 1, 0, 0, 0, 16, 17, + 1, 0, 0, 0, 17, 2, 1, 0, 0, 0, 18, 19, 5, 42, 0, 0, 19, 4, 1, 0, 0, 0, 20, 21, 5, 47, 0, 0, + 21, 6, 1, 0, 0, 0, 22, 23, 5, 43, 0, 0, 23, 8, 1, 0, 0, 0, 24, 25, 5, 45, 0, 0, 25, 10, 1, + 0, 0, 0, 26, 28, 7, 1, 0, 0, 27, 26, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, + 29, 30, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 6, 5, 0, 0, 32, 12, 1, 0, 0, 0, 3, 0, 16, + 29, 1, 0, 1, 0 + ]; +} diff --git a/runtime/Rust/tests/gen/visitorcalclistener.rs b/runtime/Rust/tests/gen/visitorcalclistener.rs index 7b77f5b57c..921824b7b2 100644 --- a/runtime/Rust/tests/gen/visitorcalclistener.rs +++ b/runtime/Rust/tests/gen/visitorcalclistener.rs @@ -1,58 +1,57 @@ #![allow(nonstandard_style)] // Generated from VisitorCalc.g4 by ANTLR 4.13.2 -use antlr4rust::tree::ParseTreeListener; use super::visitorcalcparser::*; +use antlr4rust::tree::ParseTreeListener; -pub trait VisitorCalcListener<'input> : ParseTreeListener<'input,VisitorCalcParserContextType>{ -/** - * Enter a parse tree produced by {@link VisitorCalcParser#s}. - * @param ctx the parse tree - */ -fn enter_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Exit a parse tree produced by {@link VisitorCalcParser#s}. - * @param ctx the parse tree - */ -fn exit_s(&mut self, _ctx: &SContext<'input>) { } -/** - * Enter a parse tree produced by the {@code add} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn enter_add(&mut self, _ctx: &AddContext<'input>) { } -/** - * Exit a parse tree produced by the {@code add} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn exit_add(&mut self, _ctx: &AddContext<'input>) { } -/** - * Enter a parse tree produced by the {@code number} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn enter_number(&mut self, _ctx: &NumberContext<'input>) { } -/** - * Exit a parse tree produced by the {@code number} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn exit_number(&mut self, _ctx: &NumberContext<'input>) { } -/** - * Enter a parse tree produced by the {@code multiply} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn enter_multiply(&mut self, _ctx: &MultiplyContext<'input>) { } -/** - * Exit a parse tree produced by the {@code multiply} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ -fn exit_multiply(&mut self, _ctx: &MultiplyContext<'input>) { } - +pub trait VisitorCalcListener<'input>: + ParseTreeListener<'input, VisitorCalcParserContextType> +{ + /** + * Enter a parse tree produced by {@link VisitorCalcParser#s}. + * @param ctx the parse tree + */ + fn enter_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Exit a parse tree produced by {@link VisitorCalcParser#s}. + * @param ctx the parse tree + */ + fn exit_s(&mut self, _ctx: &SContext<'input>) {} + /** + * Enter a parse tree produced by the {@code add} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn enter_add(&mut self, _ctx: &AddContext<'input>) {} + /** + * Exit a parse tree produced by the {@code add} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn exit_add(&mut self, _ctx: &AddContext<'input>) {} + /** + * Enter a parse tree produced by the {@code number} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn enter_number(&mut self, _ctx: &NumberContext<'input>) {} + /** + * Exit a parse tree produced by the {@code number} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn exit_number(&mut self, _ctx: &NumberContext<'input>) {} + /** + * Enter a parse tree produced by the {@code multiply} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn enter_multiply(&mut self, _ctx: &MultiplyContext<'input>) {} + /** + * Exit a parse tree produced by the {@code multiply} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn exit_multiply(&mut self, _ctx: &MultiplyContext<'input>) {} } -antlr4rust::coerce_from!{ 'input : VisitorCalcListener<'input> } - - +antlr4rust::coerce_from! { 'input : VisitorCalcListener<'input> } diff --git a/runtime/Rust/tests/gen/visitorcalcparser.rs b/runtime/Rust/tests/gen/visitorcalcparser.rs index b450c5deab..c0c10b616a 100644 --- a/runtime/Rust/tests/gen/visitorcalcparser.rs +++ b/runtime/Rust/tests/gen/visitorcalcparser.rs @@ -7,38 +7,38 @@ #![allow(unused_mut)] #![allow(unused_braces)] #![allow(unused_parens)] -use antlr4rust::PredictionContextCache; -use antlr4rust::parser::{Parser, BaseParser, ParserRecog, ParserNodeType}; -use antlr4rust::token_stream::TokenStream; -use antlr4rust::TokenSource; -use antlr4rust::parser_atn_simulator::ParserATNSimulator; -use antlr4rust::errors::*; -use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr4rust::recognizer::{Recognizer,Actions}; +use super::visitorcalclistener::*; +use super::visitorcalcvisitor::*; +use antlr4rust::atn::{ATN, INVALID_ALT}; use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::dfa::DFA; -use antlr4rust::atn::{ATN, INVALID_ALT}; -use antlr4rust::error_strategy::{ErrorStrategy, DefaultErrorStrategy}; -use antlr4rust::parser_rule_context::{BaseParserRuleContext, ParserRuleContext,cast,cast_mut}; -use antlr4rust::tree::*; -use antlr4rust::token::{TOKEN_EOF,OwningToken,Token}; +use antlr4rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; +use antlr4rust::errors::*; use antlr4rust::int_stream::EOF; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::token_factory::{CommonTokenFactory,TokenFactory, TokenAware}; -use super::visitorcalclistener::*; -use super::visitorcalcvisitor::*; +use antlr4rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; +use antlr4rust::parser_atn_simulator::ParserATNSimulator; +use antlr4rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; +use antlr4rust::token::{OwningToken, Token, TOKEN_EOF}; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::token_stream::TokenStream; +use antlr4rust::tree::*; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; +use antlr4rust::PredictionContextCache; +use antlr4rust::TokenSource; use antlr4rust::lazy_static; -use antlr4rust::{TidAble,TidExt}; +use antlr4rust::{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::sync::Arc; +use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::convert::TryFrom; -use std::cell::RefCell; -use std::ops::{DerefMut, Deref}; -use std::borrow::{Borrow,BorrowMut}; -use std::any::{Any,TypeId}; +use std::sync::Arc; const _: () = { assert!( @@ -47,111 +47,133 @@ const _: () = { ); }; - pub const VisitorCalc_INT:i32=1; - pub const VisitorCalc_MUL:i32=2; - pub const VisitorCalc_DIV:i32=3; - pub const VisitorCalc_ADD:i32=4; - pub const VisitorCalc_SUB:i32=5; - pub const VisitorCalc_WS:i32=6; - pub const VisitorCalc_EOF:i32=EOF; - pub const RULE_s:usize = 0; - pub const RULE_expr:usize = 1; - pub const ruleNames: [&'static str; 2] = [ - "s", "expr" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;6] = [ - None, None, Some("'*'"), Some("'/'"), Some("'+'"), Some("'-'") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;7] = [ - None, Some("INT"), Some("MUL"), Some("DIV"), Some("ADD"), Some("SUB"), - Some("WS") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -type BaseParserType<'input, I> = - BaseParser<'input,VisitorCalcParserExt<'input>, I, VisitorCalcParserContextType , dyn VisitorCalcListener<'input> + 'input >; +pub const VisitorCalc_INT: i32 = 1; +pub const VisitorCalc_MUL: i32 = 2; +pub const VisitorCalc_DIV: i32 = 3; +pub const VisitorCalc_ADD: i32 = 4; +pub const VisitorCalc_SUB: i32 = 5; +pub const VisitorCalc_WS: i32 = 6; +pub const VisitorCalc_EOF: i32 = EOF; +pub const RULE_s: usize = 0; +pub const RULE_expr: usize = 1; +pub const ruleNames: [&'static str; 2] = ["s", "expr"]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 6] = [ + None, + None, + Some("'*'"), + Some("'/'"), + Some("'+'"), + Some("'-'"), +]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 7] = [ + None, + Some("INT"), + Some("MUL"), + Some("DIV"), + Some("ADD"), + Some("SUB"), + Some("WS"), +]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} + +type BaseParserType<'input, I> = BaseParser< + 'input, + VisitorCalcParserExt<'input>, + I, + VisitorCalcParserContextType, + dyn VisitorCalcListener<'input> + 'input, +>; type TokenType<'input> = as TokenFactory<'input>>::Tok; pub type LocalTokenFactory<'input> = CommonTokenFactory; -pub type VisitorCalcTreeWalker<'input,'a> = - ParseTreeWalker<'input, 'a, VisitorCalcParserContextType , dyn VisitorCalcListener<'input> + 'a>; +pub type VisitorCalcTreeWalker<'input, 'a> = + ParseTreeWalker<'input, 'a, VisitorCalcParserContextType, dyn VisitorCalcListener<'input> + 'a>; /// Parser for VisitorCalc grammar pub struct VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - base:BaseParserType<'input,I>, - interpreter:Rc, - _shared_context_cache: Box, - pub err_handler: Box > >, + base: BaseParserType<'input, I>, + interpreter: Rc, + _shared_context_cache: Box, + pub err_handler: Box>>, } impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn set_error_strategy(&mut self, strategy: Box > >) { + pub fn set_error_strategy( + &mut self, + strategy: Box>>, + ) { self.err_handler = strategy } - pub fn with_strategy(input: I, strategy: Box > >) -> Self { - let interpreter = Rc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Rc::clone(&interpreter), - VisitorCalcParserExt{ - _pd: Default::default(), - } - ), - interpreter, + pub fn with_strategy( + input: I, + strategy: Box>>, + ) -> Self { + let interpreter = Rc::new(ParserATNSimulator::new( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + )); + Self { + base: BaseParser::new_base_parser( + input, + Rc::clone(&interpreter), + VisitorCalcParserExt { + _pd: Default::default(), + }, + ), + interpreter, _shared_context_cache: Box::new(PredictionContextCache::new()), err_handler: strategy, } } - } -type DynStrategy<'input,I> = Box> + 'input>; +type DynStrategy<'input, I> = Box> + 'input>; impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn with_dyn_strategy(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn with_dyn_strategy(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn new(input: I) -> Self{ - Self::with_strategy(input,Box::new(DefaultErrorStrategy::new())) + pub fn new(input: I) -> Self { + Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) } } /// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for VisitorCalcParser pub trait VisitorCalcParserContext<'input>: - for<'x> Listenable + 'x > + - for<'x> Visitable + 'x > + - ParserRuleContext<'input, TF=LocalTokenFactory<'input>, Ctx=VisitorCalcParserContextType> -{} + for<'x> Listenable + 'x> + + for<'x> Visitable + 'x> + + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = VisitorCalcParserContextType> +{ +} -antlr4rust::coerce_from!{ 'input : VisitorCalcParserContext<'input> } +antlr4rust::coerce_from! { 'input : VisitorCalcParserContext<'input> } impl<'input, 'x, T> VisitableDyn for dyn VisitorCalcParserContext<'input> + 'input where @@ -162,26 +184,29 @@ where } } -impl<'input> VisitorCalcParserContext<'input> for TerminalNode<'input,VisitorCalcParserContextType> {} -impl<'input> VisitorCalcParserContext<'input> for ErrorNode<'input,VisitorCalcParserContextType> {} +impl<'input> VisitorCalcParserContext<'input> + for TerminalNode<'input, VisitorCalcParserContextType> +{ +} +impl<'input> VisitorCalcParserContext<'input> for ErrorNode<'input, VisitorCalcParserContextType> {} antlr4rust::tid! { impl<'input> TidAble<'input> for dyn VisitorCalcParserContext<'input> + 'input } antlr4rust::tid! { impl<'input> TidAble<'input> for dyn VisitorCalcListener<'input> + 'input } pub struct VisitorCalcParserContextType; -antlr4rust::tid!{VisitorCalcParserContextType} +antlr4rust::tid! {VisitorCalcParserContextType} -impl<'input> ParserNodeType<'input> for VisitorCalcParserContextType{ - type TF = LocalTokenFactory<'input>; - type Type = dyn VisitorCalcParserContext<'input> + 'input; +impl<'input> ParserNodeType<'input> for VisitorCalcParserContextType { + type TF = LocalTokenFactory<'input>; + type Type = dyn VisitorCalcParserContext<'input> + 'input; } impl<'input, I> Deref for VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - type Target = BaseParserType<'input,I>; + type Target = BaseParserType<'input, I>; fn deref(&self) -> &Self::Target { &self.base @@ -190,629 +215,756 @@ where impl<'input, I> DerefMut for VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.base } } -pub struct VisitorCalcParserExt<'input>{ - _pd: PhantomData<&'input str>, +pub struct VisitorCalcParserExt<'input> { + _pd: PhantomData<&'input str>, } -impl<'input> VisitorCalcParserExt<'input>{ -} +impl<'input> VisitorCalcParserExt<'input> {} antlr4rust::tid! { VisitorCalcParserExt<'a> } -impl<'input> TokenAware<'input> for VisitorCalcParserExt<'input>{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for VisitorCalcParserExt<'input> { + type TF = LocalTokenFactory<'input>; } -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> ParserRecog<'input, BaseParserType<'input,I>> for VisitorCalcParserExt<'input>{} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + ParserRecog<'input, BaseParserType<'input, I>> for VisitorCalcParserExt<'input> +{ +} -impl<'input,I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>> Actions<'input, BaseParserType<'input,I>> for VisitorCalcParserExt<'input>{ - fn get_grammar_file_name(&self) -> & str{ "VisitorCalc.g4"} +impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> + Actions<'input, BaseParserType<'input, I>> for VisitorCalcParserExt<'input> +{ + fn get_grammar_file_name(&self) -> &str { + "VisitorCalc.g4" + } - fn get_rule_names(&self) -> &[& str] {&ruleNames} + fn get_rule_names(&self) -> &[&str] { + &ruleNames + } - fn get_vocabulary(&self) -> &dyn Vocabulary { &**VOCABULARY } - fn sempred(_localctx: Option<&(dyn VisitorCalcParserContext<'input> + 'input)>, rule_index: i32, pred_index: i32, - recog:&mut BaseParserType<'input,I> - )->bool{ - match rule_index { - 1 => VisitorCalcParser::<'input,I>::expr_sempred(_localctx.and_then(|x|x.downcast_ref()), pred_index, recog), - _ => true - } - } + fn get_vocabulary(&self) -> &dyn Vocabulary { + &**VOCABULARY + } + fn sempred( + _localctx: Option<&(dyn VisitorCalcParserContext<'input> + 'input)>, + rule_index: i32, + pred_index: i32, + recog: &mut BaseParserType<'input, I>, + ) -> bool { + match rule_index { + 1 => VisitorCalcParser::<'input, I>::expr_sempred( + _localctx.and_then(|x| x.downcast_ref()), + pred_index, + recog, + ), + _ => true, + } + } } impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - fn expr_sempred(_localctx: Option<&ExprContext<'input>>, pred_index:i32, - recog:&mut ::Target - ) -> bool { - match pred_index { - 0=>{ - recog.precpred(None, 2) - } - 1=>{ - recog.precpred(None, 1) - } - _ => true - } - } + fn expr_sempred( + _localctx: Option<&ExprContext<'input>>, + pred_index: i32, + recog: &mut ::Target, + ) -> bool { + match pred_index { + 0 => recog.precpred(None, 2), + 1 => recog.precpred(None, 1), + _ => true, + } + } } //------------------- s ---------------- pub type SContextAll<'input> = SContext<'input>; - -pub type SContext<'input> = BaseParserRuleContext<'input,SContextExt<'input>>; +pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>; #[derive(Clone)] -pub struct SContextExt<'input>{ -ph:PhantomData<&'input str> -} - -impl<'input> VisitorCalcParserContext<'input> for SContext<'input>{} - -impl<'input,'a> Listenable + 'a> for SContext<'input>{ - fn enter(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_s(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_s(self); - listener.exit_every_rule(self)?; - Ok(()) - } +pub struct SContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input,'a> Visitable + 'a> for SContext<'input>{ - fn accept(&self,visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { - visitor.visit_s(self); - } -} +impl<'input> VisitorCalcParserContext<'input> for SContext<'input> {} -impl<'input> CustomRuleContext<'input> for SContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorCalcParserContextType; - fn get_rule_index(&self) -> usize { RULE_s } - //fn type_rule_index() -> usize where Self: Sized { RULE_s } +impl<'input, 'a> Listenable + 'a> for SContext<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_s(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_s(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -antlr4rust::tid!{SContextExt<'a>} - -impl<'input> SContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,SContextExt{ - ph:PhantomData - }), - ) - } +impl<'input, 'a> Visitable + 'a> for SContext<'input> { + fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { + visitor.visit_s(self); + } } -pub trait SContextAttrs<'input>: VisitorCalcParserContext<'input> + BorrowMut>{ - -fn expr(&self) -> Option>> where Self:Sized{ - self.child_of_type(0) -} -/// Retrieves first TerminalNode corresponding to token EOF -/// Returns `None` if there is no child corresponding to token EOF -fn EOF(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_EOF, 0) +impl<'input> CustomRuleContext<'input> for SContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorCalcParserContextType; + fn get_rule_index(&self) -> usize { + RULE_s + } + //fn type_rule_index() -> usize where Self: Sized { RULE_s } +} +antlr4rust::tid! {SContextExt<'a>} + +impl<'input> SContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + SContextExt { ph: PhantomData }, + )) + } } +pub trait SContextAttrs<'input>: + VisitorCalcParserContext<'input> + BorrowMut> +{ + fn expr(&self) -> Option>> + where + Self: Sized, + { + self.child_of_type(0) + } + /// Retrieves first TerminalNode corresponding to token EOF + /// Returns `None` if there is no child corresponding to token EOF + fn EOF(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_EOF, 0) + } } -impl<'input> SContextAttrs<'input> for SContext<'input>{} +impl<'input> SContextAttrs<'input> for SContext<'input> {} impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn s(&mut self,) - -> Result>,ANTLRError> { - let mut recog = self; - let _parentctx = recog.ctx.take(); - let mut _localctx = SContextExt::new(_parentctx.clone(), recog.base.get_state()); + pub fn s(&mut self) -> Result>, 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 = _localctx; - let result: Result<(), ANTLRError> = (|| { - - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - /*InvokeRule expr*/ - recog.base.set_state(4); - recog.expr_rec(0)?; - - recog.base.set_state(5); - recog.base.match_token(VisitorCalc_EOF,&mut recog.err_handler)?; - - } - 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) - } + let result: Result<(), ANTLRError> = (|| { + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + /*InvokeRule expr*/ + recog.base.set_state(4); + recog.expr_rec(0)?; + + recog.base.set_state(5); + recog + .base + .match_token(VisitorCalc_EOF, &mut recog.err_handler)?; + } + 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) + } } //------------------- expr ---------------- #[derive(Debug)] -pub enum ExprContextAll<'input>{ - AddContext(AddContext<'input>), - NumberContext(NumberContext<'input>), - MultiplyContext(MultiplyContext<'input>), -Error(ExprContext<'input>) +pub enum ExprContextAll<'input> { + AddContext(AddContext<'input>), + NumberContext(NumberContext<'input>), + MultiplyContext(MultiplyContext<'input>), + Error(ExprContext<'input>), } -antlr4rust::tid!{ExprContextAll<'a>} +antlr4rust::tid! {ExprContextAll<'a>} -impl<'input> antlr4rust::parser_rule_context::DerefSeal for ExprContextAll<'input>{} +impl<'input> antlr4rust::parser_rule_context::DerefSeal for ExprContextAll<'input> {} -impl<'input> VisitorCalcParserContext<'input> for ExprContextAll<'input>{} +impl<'input> VisitorCalcParserContext<'input> for ExprContextAll<'input> {} -impl<'input> Deref for ExprContextAll<'input>{ - type Target = dyn ExprContextAttrs<'input> + 'input; - fn deref(&self) -> &Self::Target{ - use ExprContextAll::*; - match self{ - AddContext(inner) => inner, - NumberContext(inner) => inner, - MultiplyContext(inner) => inner, -Error(inner) => inner - } - } +impl<'input> Deref for ExprContextAll<'input> { + type Target = dyn ExprContextAttrs<'input> + 'input; + fn deref(&self) -> &Self::Target { + use ExprContextAll::*; + match self { + AddContext(inner) => inner, + NumberContext(inner) => inner, + MultiplyContext(inner) => inner, + Error(inner) => inner, + } + } } -impl<'input,'a> Visitable + 'a> for ExprContextAll<'input>{ - fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { self.deref().accept(visitor) } +impl<'input, 'a> Visitable + 'a> for ExprContextAll<'input> { + fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { + self.deref().accept(visitor) + } } -impl<'input,'a> Listenable + 'a> for ExprContextAll<'input>{ - fn enter(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { self.deref().enter(listener) } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { self.deref().exit(listener) } +impl<'input, 'a> Listenable + 'a> for ExprContextAll<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + self.deref().enter(listener) + } + fn exit( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + self.deref().exit(listener) + } } - - -pub type ExprContext<'input> = BaseParserRuleContext<'input,ExprContextExt<'input>>; +pub type ExprContext<'input> = BaseParserRuleContext<'input, ExprContextExt<'input>>; #[derive(Clone)] -pub struct ExprContextExt<'input>{ -ph:PhantomData<&'input str> +pub struct ExprContextExt<'input> { + ph: PhantomData<&'input str>, } -impl<'input> VisitorCalcParserContext<'input> for ExprContext<'input>{} +impl<'input> VisitorCalcParserContext<'input> for ExprContext<'input> {} -impl<'input,'a> Listenable + 'a> for ExprContext<'input>{ -} - -impl<'input,'a> Visitable + 'a> for ExprContext<'input>{ -} +impl<'input, 'a> Listenable + 'a> for ExprContext<'input> {} -impl<'input> CustomRuleContext<'input> for ExprContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorCalcParserContextType; - fn get_rule_index(&self) -> usize { RULE_expr } - //fn type_rule_index() -> usize where Self: Sized { RULE_expr } -} -antlr4rust::tid!{ExprContextExt<'a>} +impl<'input, 'a> Visitable + 'a> for ExprContext<'input> {} -impl<'input> ExprContextExt<'input>{ - fn new(parent: Option + 'input > >, invoking_state: i32) -> Rc> { - Rc::new( - ExprContextAll::Error( - BaseParserRuleContext::new_parser_ctx(parent, invoking_state,ExprContextExt{ - - ph:PhantomData - }), - ) - ) - } +impl<'input> CustomRuleContext<'input> for ExprContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorCalcParserContextType; + fn get_rule_index(&self) -> usize { + RULE_expr + } + //fn type_rule_index() -> usize where Self: Sized { RULE_expr } +} +antlr4rust::tid! {ExprContextExt<'a>} + +impl<'input> ExprContextExt<'input> { + fn new( + parent: Option + 'input>>, + invoking_state: i32, + ) -> Rc> { + Rc::new(ExprContextAll::Error( + BaseParserRuleContext::new_parser_ctx( + parent, + invoking_state, + ExprContextExt { ph: PhantomData }, + ), + )) + } } -pub trait ExprContextAttrs<'input>: VisitorCalcParserContext<'input> + BorrowMut>{ - - +pub trait ExprContextAttrs<'input>: + VisitorCalcParserContext<'input> + BorrowMut> +{ } -impl<'input> ExprContextAttrs<'input> for ExprContext<'input>{} +impl<'input> ExprContextAttrs<'input> for ExprContext<'input> {} -pub type AddContext<'input> = BaseParserRuleContext<'input,AddContextExt<'input>>; +pub type AddContext<'input> = BaseParserRuleContext<'input, AddContextExt<'input>>; -pub trait AddContextAttrs<'input>: VisitorCalcParserContext<'input>{ - fn expr_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() - } - fn expr(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) - } - /// Retrieves first TerminalNode corresponding to token ADD - /// Returns `None` if there is no child corresponding to token ADD - fn ADD(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_ADD, 0) - } - /// Retrieves first TerminalNode corresponding to token SUB - /// Returns `None` if there is no child corresponding to token SUB - fn SUB(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_SUB, 0) - } +pub trait AddContextAttrs<'input>: VisitorCalcParserContext<'input> { + fn expr_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn expr(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } + /// Retrieves first TerminalNode corresponding to token ADD + /// Returns `None` if there is no child corresponding to token ADD + fn ADD(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_ADD, 0) + } + /// Retrieves first TerminalNode corresponding to token SUB + /// Returns `None` if there is no child corresponding to token SUB + fn SUB(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_SUB, 0) + } } -impl<'input> AddContextAttrs<'input> for AddContext<'input>{} +impl<'input> AddContextAttrs<'input> for AddContext<'input> {} -pub struct AddContextExt<'input>{ - base:ExprContextExt<'input>, - ph:PhantomData<&'input str> +pub struct AddContextExt<'input> { + base: ExprContextExt<'input>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{AddContextExt<'a>} +antlr4rust::tid! {AddContextExt<'a>} -impl<'input> VisitorCalcParserContext<'input> for AddContext<'input>{} +impl<'input> VisitorCalcParserContext<'input> for AddContext<'input> {} -impl<'input,'a> Listenable + 'a> for AddContext<'input>{ - fn enter(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_add(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_add(self); - listener.exit_every_rule(self)?; - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for AddContext<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_add(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_add(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -impl<'input,'a> Visitable + 'a> for AddContext<'input>{ - fn accept(&self,visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { - visitor.visit_add(self); - } +impl<'input, 'a> Visitable + 'a> for AddContext<'input> { + fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { + visitor.visit_add(self); + } } -impl<'input> CustomRuleContext<'input> for AddContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorCalcParserContextType; - fn get_rule_index(&self) -> usize { RULE_expr } - //fn type_rule_index() -> usize where Self: Sized { RULE_expr } +impl<'input> CustomRuleContext<'input> for AddContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorCalcParserContextType; + fn get_rule_index(&self) -> usize { + RULE_expr + } + //fn type_rule_index() -> usize where Self: Sized { RULE_expr } } -impl<'input> Borrow> for AddContext<'input>{ - fn borrow(&self) -> &ExprContextExt<'input> { &self.base } +impl<'input> Borrow> for AddContext<'input> { + fn borrow(&self) -> &ExprContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for AddContext<'input>{ - fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> for AddContext<'input> { + fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { + &mut self.base + } } impl<'input> ExprContextAttrs<'input> for AddContext<'input> {} -impl<'input> AddContextExt<'input>{ - fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { - Rc::new( - ExprContextAll::AddContext( - BaseParserRuleContext::copy_from(ctx,AddContextExt{ - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> AddContextExt<'input> { + fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { + Rc::new(ExprContextAll::AddContext( + BaseParserRuleContext::copy_from( + ctx, + AddContextExt { + base: ctx.borrow().clone(), + ph: PhantomData, + }, + ), + )) + } } -pub type NumberContext<'input> = BaseParserRuleContext<'input,NumberContextExt<'input>>; +pub type NumberContext<'input> = BaseParserRuleContext<'input, NumberContextExt<'input>>; -pub trait NumberContextAttrs<'input>: VisitorCalcParserContext<'input>{ - /// Retrieves first TerminalNode corresponding to token INT - /// Returns `None` if there is no child corresponding to token INT - fn INT(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_INT, 0) - } +pub trait NumberContextAttrs<'input>: VisitorCalcParserContext<'input> { + /// Retrieves first TerminalNode corresponding to token INT + /// Returns `None` if there is no child corresponding to token INT + fn INT(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_INT, 0) + } } -impl<'input> NumberContextAttrs<'input> for NumberContext<'input>{} +impl<'input> NumberContextAttrs<'input> for NumberContext<'input> {} -pub struct NumberContextExt<'input>{ - base:ExprContextExt<'input>, - ph:PhantomData<&'input str> +pub struct NumberContextExt<'input> { + base: ExprContextExt<'input>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{NumberContextExt<'a>} +antlr4rust::tid! {NumberContextExt<'a>} -impl<'input> VisitorCalcParserContext<'input> for NumberContext<'input>{} +impl<'input> VisitorCalcParserContext<'input> for NumberContext<'input> {} -impl<'input,'a> Listenable + 'a> for NumberContext<'input>{ - fn enter(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_number(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_number(self); - listener.exit_every_rule(self)?; - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for NumberContext<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_number(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_number(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -impl<'input,'a> Visitable + 'a> for NumberContext<'input>{ - fn accept(&self,visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { - visitor.visit_number(self); - } +impl<'input, 'a> Visitable + 'a> for NumberContext<'input> { + fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { + visitor.visit_number(self); + } } -impl<'input> CustomRuleContext<'input> for NumberContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorCalcParserContextType; - fn get_rule_index(&self) -> usize { RULE_expr } - //fn type_rule_index() -> usize where Self: Sized { RULE_expr } +impl<'input> CustomRuleContext<'input> for NumberContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorCalcParserContextType; + fn get_rule_index(&self) -> usize { + RULE_expr + } + //fn type_rule_index() -> usize where Self: Sized { RULE_expr } } -impl<'input> Borrow> for NumberContext<'input>{ - fn borrow(&self) -> &ExprContextExt<'input> { &self.base } +impl<'input> Borrow> for NumberContext<'input> { + fn borrow(&self) -> &ExprContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for NumberContext<'input>{ - fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> for NumberContext<'input> { + fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { + &mut self.base + } } impl<'input> ExprContextAttrs<'input> for NumberContext<'input> {} -impl<'input> NumberContextExt<'input>{ - fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { - Rc::new( - ExprContextAll::NumberContext( - BaseParserRuleContext::copy_from(ctx,NumberContextExt{ - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> NumberContextExt<'input> { + fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { + Rc::new(ExprContextAll::NumberContext( + BaseParserRuleContext::copy_from( + ctx, + NumberContextExt { + base: ctx.borrow().clone(), + ph: PhantomData, + }, + ), + )) + } } -pub type MultiplyContext<'input> = BaseParserRuleContext<'input,MultiplyContextExt<'input>>; +pub type MultiplyContext<'input> = BaseParserRuleContext<'input, MultiplyContextExt<'input>>; -pub trait MultiplyContextAttrs<'input>: VisitorCalcParserContext<'input>{ - fn expr_all(&self) -> Vec>> where Self:Sized{ - self.children_of_type() - } - fn expr(&self, i: usize) -> Option>> where Self:Sized{ - self.child_of_type(i) - } - /// Retrieves first TerminalNode corresponding to token MUL - /// Returns `None` if there is no child corresponding to token MUL - fn MUL(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_MUL, 0) - } - /// Retrieves first TerminalNode corresponding to token DIV - /// Returns `None` if there is no child corresponding to token DIV - fn DIV(&self) -> Option>> where Self:Sized{ - self.get_token(VisitorCalc_DIV, 0) - } +pub trait MultiplyContextAttrs<'input>: VisitorCalcParserContext<'input> { + fn expr_all(&self) -> Vec>> + where + Self: Sized, + { + self.children_of_type() + } + fn expr(&self, i: usize) -> Option>> + where + Self: Sized, + { + self.child_of_type(i) + } + /// Retrieves first TerminalNode corresponding to token MUL + /// Returns `None` if there is no child corresponding to token MUL + fn MUL(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_MUL, 0) + } + /// Retrieves first TerminalNode corresponding to token DIV + /// Returns `None` if there is no child corresponding to token DIV + fn DIV(&self) -> Option>> + where + Self: Sized, + { + self.get_token(VisitorCalc_DIV, 0) + } } -impl<'input> MultiplyContextAttrs<'input> for MultiplyContext<'input>{} +impl<'input> MultiplyContextAttrs<'input> for MultiplyContext<'input> {} -pub struct MultiplyContextExt<'input>{ - base:ExprContextExt<'input>, - ph:PhantomData<&'input str> +pub struct MultiplyContextExt<'input> { + base: ExprContextExt<'input>, + ph: PhantomData<&'input str>, } -antlr4rust::tid!{MultiplyContextExt<'a>} +antlr4rust::tid! {MultiplyContextExt<'a>} -impl<'input> VisitorCalcParserContext<'input> for MultiplyContext<'input>{} +impl<'input> VisitorCalcParserContext<'input> for MultiplyContext<'input> {} -impl<'input,'a> Listenable + 'a> for MultiplyContext<'input>{ - fn enter(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.enter_every_rule(self)?; - listener.enter_multiply(self); - Ok(()) - } - fn exit(&self,listener: &mut (dyn VisitorCalcListener<'input> + 'a)) -> Result<(), ANTLRError> { - listener.exit_multiply(self); - listener.exit_every_rule(self)?; - Ok(()) - } +impl<'input, 'a> Listenable + 'a> for MultiplyContext<'input> { + fn enter( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.enter_every_rule(self)?; + listener.enter_multiply(self); + Ok(()) + } + fn exit( + &self, + listener: &mut (dyn VisitorCalcListener<'input> + 'a), + ) -> Result<(), ANTLRError> { + listener.exit_multiply(self); + listener.exit_every_rule(self)?; + Ok(()) + } } -impl<'input,'a> Visitable + 'a> for MultiplyContext<'input>{ - fn accept(&self,visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { - visitor.visit_multiply(self); - } +impl<'input, 'a> Visitable + 'a> for MultiplyContext<'input> { + fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { + visitor.visit_multiply(self); + } } -impl<'input> CustomRuleContext<'input> for MultiplyContextExt<'input>{ - type TF = LocalTokenFactory<'input>; - type Ctx = VisitorCalcParserContextType; - fn get_rule_index(&self) -> usize { RULE_expr } - //fn type_rule_index() -> usize where Self: Sized { RULE_expr } +impl<'input> CustomRuleContext<'input> for MultiplyContextExt<'input> { + type TF = LocalTokenFactory<'input>; + type Ctx = VisitorCalcParserContextType; + fn get_rule_index(&self) -> usize { + RULE_expr + } + //fn type_rule_index() -> usize where Self: Sized { RULE_expr } } -impl<'input> Borrow> for MultiplyContext<'input>{ - fn borrow(&self) -> &ExprContextExt<'input> { &self.base } +impl<'input> Borrow> for MultiplyContext<'input> { + fn borrow(&self) -> &ExprContextExt<'input> { + &self.base + } } -impl<'input> BorrowMut> for MultiplyContext<'input>{ - fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { &mut self.base } +impl<'input> BorrowMut> for MultiplyContext<'input> { + fn borrow_mut(&mut self) -> &mut ExprContextExt<'input> { + &mut self.base + } } impl<'input> ExprContextAttrs<'input> for MultiplyContext<'input> {} -impl<'input> MultiplyContextExt<'input>{ - fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { - Rc::new( - ExprContextAll::MultiplyContext( - BaseParserRuleContext::copy_from(ctx,MultiplyContextExt{ - base: ctx.borrow().clone(), - ph:PhantomData - }) - ) - ) - } +impl<'input> MultiplyContextExt<'input> { + fn new(ctx: &dyn ExprContextAttrs<'input>) -> Rc> { + Rc::new(ExprContextAll::MultiplyContext( + BaseParserRuleContext::copy_from( + ctx, + MultiplyContextExt { + base: ctx.borrow().clone(), + ph: PhantomData, + }, + ), + )) + } } impl<'input, I> VisitorCalcParser<'input, I> where - I: TokenStream<'input, TF = LocalTokenFactory<'input> > + TidAble<'input>, + I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, { - pub fn expr(&mut self,) - -> Result>,ANTLRError> { - self.expr_rec(0) - } - - fn expr_rec(&mut self, _p: i32) - -> Result>,ANTLRError> { - let recog = self; - let _parentctx = recog.ctx.take(); - let _parentState = recog.base.get_state(); - let mut _localctx = ExprContextExt::new(_parentctx.clone(), recog.base.get_state()); - recog.base.enter_recursion_rule(_localctx.clone(), 2, RULE_expr, _p); - let mut _localctx: Rc = _localctx; + pub fn expr(&mut self) -> Result>, ANTLRError> { + self.expr_rec(0) + } + + fn expr_rec(&mut self, _p: i32) -> Result>, ANTLRError> { + let recog = self; + let _parentctx = recog.ctx.take(); + let _parentState = recog.base.get_state(); + let mut _localctx = ExprContextExt::new(_parentctx.clone(), recog.base.get_state()); + recog + .base + .enter_recursion_rule(_localctx.clone(), 2, RULE_expr, _p); + let mut _localctx: Rc = _localctx; let mut _prevctx = _localctx.clone(); - let _startState = 2; - let mut _la: i32 = -1; - let result: Result<(), ANTLRError> = (|| { - let mut _alt: i32; - //recog.base.enter_outer_alt(_localctx.clone(), 1)?; - recog.base.enter_outer_alt(None, 1)?; - { - { - let mut tmp = NumberContextExt::new(&**_localctx); - recog.ctx = Some(tmp.clone()); - _localctx = tmp; - _prevctx = _localctx.clone(); - - recog.base.set_state(8); - recog.base.match_token(VisitorCalc_INT,&mut recog.err_handler)?; - - } - let tmp = recog.input.lt(-1).cloned(); - recog.ctx.as_ref().unwrap().set_stop(tmp); - recog.base.set_state(18); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(1,&mut recog.base)?; - while { _alt!=2 && _alt!=INVALID_ALT } { - if _alt==1 { - recog.trigger_exit_rule_event()?; - _prevctx = _localctx.clone(); - { - recog.base.set_state(16); - recog.err_handler.sync(&mut recog.base)?; - match recog.interpreter.adaptive_predict(0,&mut recog.base)? { - 1 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = MultiplyContextExt::new(&**ExprContextExt::new(_parentctx.clone(), _parentState)); - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_expr)?; - _localctx = tmp; - recog.base.set_state(10); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 2)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 2)".to_owned()), None))?; - } - recog.base.set_state(11); - _la = recog.base.input.la(1); - if { !(_la==VisitorCalc_MUL || _la==VisitorCalc_DIV) } { - recog.err_handler.recover_inline(&mut recog.base)?; - - } - else { - if recog.base.input.la(1)==TOKEN_EOF { recog.base.matched_eof = true }; - recog.err_handler.report_match(&mut recog.base); - recog.base.consume(&mut recog.err_handler); - } - /*InvokeRule expr*/ - recog.base.set_state(12); - recog.expr_rec(3)?; - - } - } - , - 2 =>{ - { - /*recRuleLabeledAltStartAction*/ - let mut tmp = AddContextExt::new(&**ExprContextExt::new(_parentctx.clone(), _parentState)); - recog.push_new_recursion_context(tmp.clone(), _startState, RULE_expr)?; - _localctx = tmp; - recog.base.set_state(13); - if !({let _localctx = Some(_localctx.clone()); - recog.precpred(None, 1)}) { - Err(FailedPredicateError::new(&mut recog.base, Some("recog.precpred(None, 1)".to_owned()), None))?; - } - recog.base.set_state(14); - _la = recog.base.input.la(1); - if { !(_la==VisitorCalc_ADD || _la==VisitorCalc_SUB) } { - recog.err_handler.recover_inline(&mut recog.base)?; - - } - else { - if recog.base.input.la(1)==TOKEN_EOF { recog.base.matched_eof = true }; - recog.err_handler.report_match(&mut recog.base); - recog.base.consume(&mut recog.err_handler); - } - /*InvokeRule expr*/ - recog.base.set_state(15); - recog.expr_rec(2)?; - - } - } - - _ => {} - } - } - } - recog.base.set_state(20); - recog.err_handler.sync(&mut recog.base)?; - _alt = recog.interpreter.adaptive_predict(1,&mut recog.base)?; - } - } - 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.unroll_recursion_context(_parentctx)?; - - Ok(_localctx) - } -} - lazy_static!{ + let _startState = 2; + let mut _la: i32 = -1; + let result: Result<(), ANTLRError> = (|| { + let mut _alt: i32; + //recog.base.enter_outer_alt(_localctx.clone(), 1)?; + recog.base.enter_outer_alt(None, 1)?; + { + { + let mut tmp = NumberContextExt::new(&**_localctx); + recog.ctx = Some(tmp.clone()); + _localctx = tmp; + _prevctx = _localctx.clone(); + + recog.base.set_state(8); + recog + .base + .match_token(VisitorCalc_INT, &mut recog.err_handler)?; + } + let tmp = recog.input.lt(-1).cloned(); + recog.ctx.as_ref().unwrap().set_stop(tmp); + recog.base.set_state(18); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(1, &mut recog.base)?; + while { _alt != 2 && _alt != INVALID_ALT } { + if _alt == 1 { + recog.trigger_exit_rule_event()?; + _prevctx = _localctx.clone(); + { + recog.base.set_state(16); + recog.err_handler.sync(&mut recog.base)?; + match recog.interpreter.adaptive_predict(0, &mut recog.base)? { + 1 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = + MultiplyContextExt::new(&**ExprContextExt::new( + _parentctx.clone(), + _parentState, + )); + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_expr, + )?; + _localctx = tmp; + recog.base.set_state(10); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 2) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 2)".to_owned()), + None, + ))?; + } + recog.base.set_state(11); + _la = recog.base.input.la(1); + if { !(_la == VisitorCalc_MUL || _la == VisitorCalc_DIV) } { + recog.err_handler.recover_inline(&mut recog.base)?; + } else { + if recog.base.input.la(1) == TOKEN_EOF { + recog.base.matched_eof = true + }; + recog.err_handler.report_match(&mut recog.base); + recog.base.consume(&mut recog.err_handler); + } + /*InvokeRule expr*/ + recog.base.set_state(12); + recog.expr_rec(3)?; + } + } + 2 => { + { + /*recRuleLabeledAltStartAction*/ + let mut tmp = AddContextExt::new(&**ExprContextExt::new( + _parentctx.clone(), + _parentState, + )); + recog.push_new_recursion_context( + tmp.clone(), + _startState, + RULE_expr, + )?; + _localctx = tmp; + recog.base.set_state(13); + if !({ + let _localctx = Some(_localctx.clone()); + recog.precpred(None, 1) + }) { + Err(FailedPredicateError::new( + &mut recog.base, + Some("recog.precpred(None, 1)".to_owned()), + None, + ))?; + } + recog.base.set_state(14); + _la = recog.base.input.la(1); + if { !(_la == VisitorCalc_ADD || _la == VisitorCalc_SUB) } { + recog.err_handler.recover_inline(&mut recog.base)?; + } else { + if recog.base.input.la(1) == TOKEN_EOF { + recog.base.matched_eof = true + }; + recog.err_handler.report_match(&mut recog.base); + recog.base.consume(&mut recog.err_handler); + } + /*InvokeRule expr*/ + recog.base.set_state(15); + recog.expr_rec(2)?; + } + } + + _ => {} + } + } + } + recog.base.set_state(20); + recog.err_handler.sync(&mut recog.base)?; + _alt = recog.interpreter.adaptive_predict(1, &mut recog.base)?; + } + } + 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.unroll_recursion_context(_parentctx)?; + + Ok(_localctx) + } +} +lazy_static! { static ref _ATN: Arc = Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); static ref _decision_to_DFA: Arc>> = { let mut dfa = Vec::new(); let size = _ATN.decision_to_state.len() as i32; for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) } Arc::new(dfa) }; - static ref _serializedATN: Vec = vec![ - 4, 1, 6, 22, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 17, 8, 1, 10, 1, 12, 1, 20, - 9, 1, 1, 1, 0, 1, 2, 2, 0, 2, 0, 2, 1, 0, 2, 3, 1, 0, 4, 5, 21, 0, 4, - 1, 0, 0, 0, 2, 7, 1, 0, 0, 0, 4, 5, 3, 2, 1, 0, 5, 6, 5, 0, 0, 1, 6, 1, - 1, 0, 0, 0, 7, 8, 6, 1, -1, 0, 8, 9, 5, 1, 0, 0, 9, 18, 1, 0, 0, 0, 10, - 11, 10, 2, 0, 0, 11, 12, 7, 0, 0, 0, 12, 17, 3, 2, 1, 3, 13, 14, 10, 1, - 0, 0, 14, 15, 7, 1, 0, 0, 15, 17, 3, 2, 1, 2, 16, 10, 1, 0, 0, 0, 16, - 13, 1, 0, 0, 0, 17, 20, 1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, - 0, 0, 19, 3, 1, 0, 0, 0, 20, 18, 1, 0, 0, 0, 2, 16, 18 - ]; + static ref _serializedATN: Vec = vec![ + 4, 1, 6, 22, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 5, 1, 17, 8, 1, 10, 1, 12, 1, 20, 9, 1, 1, 1, 0, 1, 2, 2, 0, 2, 0, 2, 1, + 0, 2, 3, 1, 0, 4, 5, 21, 0, 4, 1, 0, 0, 0, 2, 7, 1, 0, 0, 0, 4, 5, 3, 2, 1, 0, 5, 6, 5, 0, + 0, 1, 6, 1, 1, 0, 0, 0, 7, 8, 6, 1, -1, 0, 8, 9, 5, 1, 0, 0, 9, 18, 1, 0, 0, 0, 10, 11, 10, + 2, 0, 0, 11, 12, 7, 0, 0, 0, 12, 17, 3, 2, 1, 3, 13, 14, 10, 1, 0, 0, 14, 15, 7, 1, 0, 0, + 15, 17, 3, 2, 1, 2, 16, 10, 1, 0, 0, 0, 16, 13, 1, 0, 0, 0, 17, 20, 1, 0, 0, 0, 18, 16, 1, + 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 3, 1, 0, 0, 0, 20, 18, 1, 0, 0, 0, 2, 16, 18 + ]; } diff --git a/runtime/Rust/tests/gen/visitorcalcvisitor.rs b/runtime/Rust/tests/gen/visitorcalcvisitor.rs index b3e254cff4..bc2a448348 100644 --- a/runtime/Rust/tests/gen/visitorcalcvisitor.rs +++ b/runtime/Rust/tests/gen/visitorcalcvisitor.rs @@ -1,102 +1,111 @@ #![allow(nonstandard_style)] // Generated from VisitorCalc.g4 by ANTLR 4.13.2 -use antlr4rust::tree::{ParseTreeVisitor,ParseTreeVisitorCompat}; use super::visitorcalcparser::*; +use antlr4rust::tree::{ParseTreeVisitor, ParseTreeVisitorCompat}; /** * This interface defines a complete generic visitor for a parse tree produced * by {@link VisitorCalcParser}. */ -pub trait VisitorCalcVisitor<'input>: ParseTreeVisitor<'input,VisitorCalcParserContextType>{ - /** - * Visit a parse tree produced by {@link VisitorCalcParser#s}. - * @param ctx the parse tree - */ - fn visit_s(&mut self, ctx: &SContext<'input>) { self.visit_children(ctx) } - - /** - * Visit a parse tree produced by the {@code add} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_add(&mut self, ctx: &AddContext<'input>) { self.visit_children(ctx) } +pub trait VisitorCalcVisitor<'input>: + ParseTreeVisitor<'input, VisitorCalcParserContextType> +{ + /** + * Visit a parse tree produced by {@link VisitorCalcParser#s}. + * @param ctx the parse tree + */ + fn visit_s(&mut self, ctx: &SContext<'input>) { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by the {@code number} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_number(&mut self, ctx: &NumberContext<'input>) { self.visit_children(ctx) } + /** + * Visit a parse tree produced by the {@code add} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_add(&mut self, ctx: &AddContext<'input>) { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by the {@code multiply} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>) { self.visit_children(ctx) } + /** + * Visit a parse tree produced by the {@code number} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_number(&mut self, ctx: &NumberContext<'input>) { + self.visit_children(ctx) + } + /** + * Visit a parse tree produced by the {@code multiply} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>) { + self.visit_children(ctx) + } } -pub trait VisitorCalcVisitorCompat<'input>:ParseTreeVisitorCompat<'input, Node= VisitorCalcParserContextType>{ - /** - * Visit a parse tree produced by {@link VisitorCalcParser#s}. - * @param ctx the parse tree - */ - fn visit_s(&mut self, ctx: &SContext<'input>) -> Self::Return { - self.visit_children(ctx) - } - - /** - * Visit a parse tree produced by the {@code add} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_add(&mut self, ctx: &AddContext<'input>) -> Self::Return { - self.visit_children(ctx) - } +pub trait VisitorCalcVisitorCompat<'input>: + ParseTreeVisitorCompat<'input, Node = VisitorCalcParserContextType> +{ + /** + * Visit a parse tree produced by {@link VisitorCalcParser#s}. + * @param ctx the parse tree + */ + fn visit_s(&mut self, ctx: &SContext<'input>) -> Self::Return { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by the {@code number} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_number(&mut self, ctx: &NumberContext<'input>) -> Self::Return { - self.visit_children(ctx) - } + /** + * Visit a parse tree produced by the {@code add} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_add(&mut self, ctx: &AddContext<'input>) -> Self::Return { + self.visit_children(ctx) + } - /** - * Visit a parse tree produced by the {@code multiply} - * labeled alternative in {@link VisitorCalcParser#expr}. - * @param ctx the parse tree - */ - fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>) -> Self::Return { - self.visit_children(ctx) - } + /** + * Visit a parse tree produced by the {@code number} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_number(&mut self, ctx: &NumberContext<'input>) -> Self::Return { + self.visit_children(ctx) + } + /** + * Visit a parse tree produced by the {@code multiply} + * labeled alternative in {@link VisitorCalcParser#expr}. + * @param ctx the parse tree + */ + fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>) -> Self::Return { + self.visit_children(ctx) + } } -impl<'input,T> VisitorCalcVisitor<'input> for T +impl<'input, T> VisitorCalcVisitor<'input> for T where - T: VisitorCalcVisitorCompat<'input> + T: VisitorCalcVisitorCompat<'input>, { - fn visit_s(&mut self, ctx: &SContext<'input>){ - let result = ::visit_s(self, ctx); + fn visit_s(&mut self, ctx: &SContext<'input>) { + let result = ::visit_s(self, ctx); *::temp_result(self) = result; - } + } - fn visit_add(&mut self, ctx: &AddContext<'input>){ - let result = ::visit_add(self, ctx); + fn visit_add(&mut self, ctx: &AddContext<'input>) { + let result = ::visit_add(self, ctx); *::temp_result(self) = result; - } + } - fn visit_number(&mut self, ctx: &NumberContext<'input>){ - let result = ::visit_number(self, ctx); + fn visit_number(&mut self, ctx: &NumberContext<'input>) { + let result = ::visit_number(self, ctx); *::temp_result(self) = result; - } + } - fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>){ - let result = ::visit_multiply(self, ctx); + fn visit_multiply(&mut self, ctx: &MultiplyContext<'input>) { + let result = ::visit_multiply(self, ctx); *::temp_result(self) = result; - } - -} \ No newline at end of file + } +} diff --git a/runtime/Rust/tests/gen/xmllexer.rs b/runtime/Rust/tests/gen/xmllexer.rs index ce511d8ee3..3a671aa385 100644 --- a/runtime/Rust/tests/gen/xmllexer.rs +++ b/runtime/Rust/tests/gen/xmllexer.rs @@ -4,109 +4,155 @@ #![allow(unused_imports)] #![allow(unused_variables)] use antlr4rust::atn::ATN; +use antlr4rust::atn_deserializer::ATNDeserializer; use antlr4rust::char_stream::CharStream; +use antlr4rust::dfa::DFA; +use antlr4rust::error_listener::ErrorListener; use antlr4rust::int_stream::IntStream; -use antlr4rust::tree::ParseTree; use antlr4rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr4rust::atn_deserializer::ATNDeserializer; -use antlr4rust::dfa::DFA; -use antlr4rust::lexer_atn_simulator::{LexerATNSimulator, ILexerATNSimulator}; +use antlr4rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; +use antlr4rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; +use antlr4rust::recognizer::{Actions, Recognizer}; +use antlr4rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; +use antlr4rust::token::*; +use antlr4rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; +use antlr4rust::tree::ParseTree; +use antlr4rust::vocabulary::{Vocabulary, VocabularyImpl}; use antlr4rust::PredictionContextCache; -use antlr4rust::recognizer::{Recognizer,Actions}; -use antlr4rust::error_listener::ErrorListener; use antlr4rust::TokenSource; -use antlr4rust::token_factory::{TokenFactory,CommonTokenFactory,TokenAware}; -use antlr4rust::token::*; -use antlr4rust::rule_context::{BaseRuleContext,EmptyCustomRuleContext,EmptyContext}; -use antlr4rust::parser_rule_context::{ParserRuleContext,BaseParserRuleContext,cast}; -use antlr4rust::vocabulary::{Vocabulary,VocabularyImpl}; -use antlr4rust::{lazy_static,Tid,TidAble,TidExt}; +use antlr4rust::{lazy_static, Tid, TidAble, TidExt}; -use std::sync::Arc; use std::cell::RefCell; -use std::rc::Rc; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::rc::Rc; +use std::sync::Arc; +pub const COMMENT: i32 = 1; +pub const CDATA: i32 = 2; +pub const DTD: i32 = 3; +pub const EntityRef: i32 = 4; +pub const CharRef: i32 = 5; +pub const SEA_WS: i32 = 6; +pub const OPEN: i32 = 7; +pub const XMLDeclOpen: i32 = 8; +pub const TEXT: i32 = 9; +pub const CLOSE: i32 = 10; +pub const SPECIAL_CLOSE: i32 = 11; +pub const SLASH_CLOSE: i32 = 12; +pub const SLASH: i32 = 13; +pub const EQUALS: i32 = 14; +pub const STRING: i32 = 15; +pub const Name: i32 = 16; +pub const S: i32 = 17; +pub const PI: i32 = 18; +pub const channelNames: [&'static str; 0 + 2] = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]; + +pub const modeNames: [&'static str; 3] = ["DEFAULT_MODE", "INSIDE", "PROC_INSTR"]; + +pub const ruleNames: [&'static str; 24] = [ + "COMMENT", + "CDATA", + "DTD", + "EntityRef", + "CharRef", + "SEA_WS", + "OPEN", + "XMLDeclOpen", + "SPECIAL_OPEN", + "TEXT", + "CLOSE", + "SPECIAL_CLOSE", + "SLASH_CLOSE", + "SLASH", + "EQUALS", + "STRING", + "Name", + "S", + "HEXDIGIT", + "DIGIT", + "NameChar", + "NameStartChar", + "PI", + "IGNORE", +]; + +pub const _LITERAL_NAMES: [Option<&'static str>; 15] = [ + None, + None, + None, + None, + None, + None, + None, + Some("'<'"), + None, + None, + Some("'>'"), + None, + Some("'/>'"), + Some("'/'"), + Some("'='"), +]; +pub const _SYMBOLIC_NAMES: [Option<&'static str>; 19] = [ + None, + Some("COMMENT"), + Some("CDATA"), + Some("DTD"), + Some("EntityRef"), + Some("CharRef"), + Some("SEA_WS"), + Some("OPEN"), + Some("XMLDeclOpen"), + Some("TEXT"), + Some("CLOSE"), + Some("SPECIAL_CLOSE"), + Some("SLASH_CLOSE"), + Some("SLASH"), + Some("EQUALS"), + Some("STRING"), + Some("Name"), + Some("S"), + Some("PI"), +]; +lazy_static! { + static ref _shared_context_cache: Arc = + Arc::new(PredictionContextCache::new()); + static ref VOCABULARY: Box = Box::new(VocabularyImpl::new( + _LITERAL_NAMES.iter(), + _SYMBOLIC_NAMES.iter(), + None + )); +} - pub const COMMENT:i32=1; - pub const CDATA:i32=2; - pub const DTD:i32=3; - pub const EntityRef:i32=4; - pub const CharRef:i32=5; - pub const SEA_WS:i32=6; - pub const OPEN:i32=7; - pub const XMLDeclOpen:i32=8; - pub const TEXT:i32=9; - pub const CLOSE:i32=10; - pub const SPECIAL_CLOSE:i32=11; - pub const SLASH_CLOSE:i32=12; - pub const SLASH:i32=13; - pub const EQUALS:i32=14; - pub const STRING:i32=15; - pub const Name:i32=16; - pub const S:i32=17; - pub const PI:i32=18; - pub const channelNames: [&'static str;0+2] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - ]; - - pub const modeNames: [&'static str;3] = [ - "DEFAULT_MODE", "INSIDE", "PROC_INSTR" - ]; - - pub const ruleNames: [&'static str;24] = [ - "COMMENT", "CDATA", "DTD", "EntityRef", "CharRef", "SEA_WS", "OPEN", "XMLDeclOpen", - "SPECIAL_OPEN", "TEXT", "CLOSE", "SPECIAL_CLOSE", "SLASH_CLOSE", "SLASH", - "EQUALS", "STRING", "Name", "S", "HEXDIGIT", "DIGIT", "NameChar", "NameStartChar", - "PI", "IGNORE" - ]; - - - pub const _LITERAL_NAMES: [Option<&'static str>;15] = [ - None, None, None, None, None, None, None, Some("'<'"), None, None, Some("'>'"), - None, Some("'/>'"), Some("'/'"), Some("'='") - ]; - pub const _SYMBOLIC_NAMES: [Option<&'static str>;19] = [ - None, Some("COMMENT"), Some("CDATA"), Some("DTD"), Some("EntityRef"), - Some("CharRef"), Some("SEA_WS"), Some("OPEN"), Some("XMLDeclOpen"), Some("TEXT"), - Some("CLOSE"), Some("SPECIAL_CLOSE"), Some("SLASH_CLOSE"), Some("SLASH"), - Some("EQUALS"), Some("STRING"), Some("Name"), Some("S"), Some("PI") - ]; - lazy_static!{ - static ref _shared_context_cache: Arc = Arc::new(PredictionContextCache::new()); - static ref VOCABULARY: Box = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None)); - } - - -pub type LexerContext<'input> = BaseRuleContext<'input,EmptyCustomRuleContext<'input,LocalTokenFactory<'input> >>; +pub type LexerContext<'input> = + BaseRuleContext<'input, EmptyCustomRuleContext<'input, LocalTokenFactory<'input>>>; pub type LocalTokenFactory<'input> = CommonTokenFactory; -type From<'a> = as TokenFactory<'a> >::From; +type From<'a> = as TokenFactory<'a>>::From; -pub struct XMLLexer<'input, Input:CharStream >> { - base: BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>>, +pub struct XMLLexer<'input, Input: CharStream>> { + base: BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>, } antlr4rust::tid! { impl<'input,Input> TidAble<'input> for XMLLexer<'input,Input> where Input:CharStream > } -impl<'input, Input:CharStream >> Deref for XMLLexer<'input,Input>{ - type Target = BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>>; +impl<'input, Input: CharStream>> Deref for XMLLexer<'input, Input> { + type Target = BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>; - fn deref(&self) -> &Self::Target { - &self.base - } + fn deref(&self) -> &Self::Target { + &self.base + } } -impl<'input, Input:CharStream >> DerefMut for XMLLexer<'input,Input>{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } +impl<'input, Input: CharStream>> DerefMut for XMLLexer<'input, Input> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.base + } } - -impl<'input, Input:CharStream >> XMLLexer<'input,Input>{ +impl<'input, Input: CharStream>> XMLLexer<'input, Input> { fn get_rule_names(&self) -> &'static [&'static str] { &ruleNames } @@ -122,92 +168,100 @@ impl<'input, Input:CharStream >> XMLLexer<'input,Input>{ "XMLLexer.g4" } - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - Self { - base: BaseLexer::new_base_lexer( - input, - LexerATNSimulator::new_lexer_atnsimulator( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - ), - XMLLexerActions{}, - tf - ) - } - } -} - -impl<'input, Input:CharStream >> XMLLexer<'input,Input> where &'input LocalTokenFactory<'input>:Default{ - pub fn new(input: Input) -> Self{ - XMLLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) - } + pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { + Self { + base: BaseLexer::new_base_lexer( + input, + LexerATNSimulator::new_lexer_atnsimulator( + _ATN.clone(), + _decision_to_DFA.clone(), + _shared_context_cache.clone(), + ), + XMLLexerActions {}, + tf, + ), + } + } } -pub struct XMLLexerActions { +impl<'input, Input: CharStream>> XMLLexer<'input, Input> +where + &'input LocalTokenFactory<'input>: Default, +{ + pub fn new(input: Input) -> Self { + XMLLexer::new_with_token_factory(input, <&LocalTokenFactory<'input> as Default>::default()) + } } -impl XMLLexerActions{ +pub struct XMLLexerActions {} + +impl XMLLexerActions {} + +impl<'input, Input: CharStream>> + Actions<'input, BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>> + for XMLLexerActions +{ + fn action( + _localctx: Option<&EmptyContext<'input, LocalTokenFactory<'input>>>, + rule_index: i32, + action_index: i32, + recog: &mut BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>, + ) { + match rule_index { + 10 => XMLLexer::<'input>::CLOSE_action(None, action_index, recog), + _ => {} + } + } + fn sempred( + _localctx: Option<&EmptyContext<'input, LocalTokenFactory<'input>>>, + rule_index: i32, + pred_index: i32, + recog: &mut BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>, + ) -> bool { + match rule_index { + 0 => XMLLexer::<'input>::COMMENT_sempred(None, pred_index, recog), + _ => true, + } + } } -impl<'input, Input:CharStream >> Actions<'input,BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>>> for XMLLexerActions{ - - fn action(_localctx: Option<&EmptyContext<'input,LocalTokenFactory<'input>> >, rule_index: i32, action_index: i32, - recog:&mut BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>> - ){ - match rule_index { - 10 => - XMLLexer::<'input>::CLOSE_action(None, action_index, recog), - _ => {} - } - } - fn sempred(_localctx: Option<&EmptyContext<'input,LocalTokenFactory<'input>> >, rule_index: i32, pred_index: i32, - recog:&mut BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>> - ) -> bool { - match rule_index { - 0 => - XMLLexer::<'input>::COMMENT_sempred(None, pred_index, recog), - _ => true - } - } - - } - - impl<'input, Input:CharStream >> XMLLexer<'input,Input>{ - - fn CLOSE_action(_localctx: Option<&LexerContext<'input>>, action_index: i32, - recog:&mut ::Target - ) { - match action_index { - 0=>{ - recog.pop_mode(); - }, - - _ => {} - } - } - fn COMMENT_sempred(_localctx: Option<&LexerContext<'input>>, pred_index:i32, - recog:&mut ::Target - ) -> bool { - match pred_index { - 0=>{ - true - } - _ => true - } - } - - +impl<'input, Input: CharStream>> XMLLexer<'input, Input> { + fn CLOSE_action( + _localctx: Option<&LexerContext<'input>>, + action_index: i32, + recog: &mut ::Target, + ) { + match action_index { + 0 => { + recog.pop_mode(); + } + + _ => {} + } + } + fn COMMENT_sempred( + _localctx: Option<&LexerContext<'input>>, + pred_index: i32, + recog: &mut ::Target, + ) -> bool { + match pred_index { + 0 => true, + _ => true, + } + } } -impl<'input, Input:CharStream >> LexerRecog<'input,BaseLexer<'input,XMLLexerActions,Input,LocalTokenFactory<'input>>> for XMLLexerActions{ +impl<'input, Input: CharStream>> + LexerRecog<'input, BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>> + for XMLLexerActions +{ } -impl<'input> TokenAware<'input> for XMLLexerActions{ - type TF = LocalTokenFactory<'input>; +impl<'input> TokenAware<'input> for XMLLexerActions { + type TF = LocalTokenFactory<'input>; } -impl<'input, Input:CharStream >> TokenSource<'input> for XMLLexer<'input,Input>{ - type TF = LocalTokenFactory<'input>; +impl<'input, Input: CharStream>> TokenSource<'input> for XMLLexer<'input, Input> { + type TF = LocalTokenFactory<'input>; fn next_token(&mut self) -> >::Tok { self.base.next_token() @@ -225,9 +279,9 @@ impl<'input, Input:CharStream >> TokenSource<'input> for XMLLexer<' self.base.get_input_stream() } - fn get_source_name(&self) -> String { - self.base.get_source_name() - } + fn get_source_name(&self) -> String { + self.base.get_source_name() + } fn get_token_factory(&self) -> &'input Self::TF { self.base.get_token_factory() @@ -238,128 +292,99 @@ impl<'input, Input:CharStream >> TokenSource<'input> for XMLLexer<' } } - - lazy_static!{ - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len() as i32; - for i in 0..size { - dfa.push(DFA::new( - _ATN.clone(), - _ATN.get_decision_state(i), - i, - ).into()) - } - Arc::new(dfa) - }; - static ref _serializedATN: Vec = vec![ - 4, 0, 18, 230, 6, -1, 6, -1, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, - 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, - 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, - 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, - 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, - 23, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 5, 0, 58, 8, 0, 10, 0, 12, 0, - 61, 9, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 80, 8, 1, 10, 1, 12, - 1, 83, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 93, - 8, 2, 10, 2, 12, 2, 96, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, - 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 4, 4, 110, 8, 4, 11, 4, 12, 4, 111, - 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 4, 4, 121, 8, 4, 11, 4, 12, - 4, 122, 1, 4, 1, 4, 3, 4, 127, 8, 4, 1, 5, 1, 5, 3, 5, 131, 8, 5, 1, - 5, 3, 5, 134, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, - 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, - 1, 8, 1, 8, 1, 9, 4, 9, 159, 8, 9, 11, 9, 12, 9, 160, 1, 10, 1, 10, 1, - 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, - 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 5, 15, 182, 8, 15, 10, - 15, 12, 15, 185, 9, 15, 1, 15, 1, 15, 1, 15, 5, 15, 190, 8, 15, 10, 15, - 12, 15, 193, 9, 15, 1, 15, 3, 15, 196, 8, 15, 1, 16, 1, 16, 5, 16, 200, - 8, 16, 10, 16, 12, 16, 203, 9, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, - 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 3, 20, 217, 8, 20, 1, - 21, 3, 21, 220, 8, 21, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, - 1, 23, 1, 23, 3, 59, 81, 94, 0, 24, 3, 1, 5, 2, 7, 3, 9, 4, 11, 5, 13, - 6, 15, 7, 17, 8, 19, 0, 21, 9, 23, 10, 25, 11, 27, 12, 29, 13, 31, 14, - 33, 15, 35, 16, 37, 17, 39, 0, 41, 0, 43, 0, 45, 0, 47, 18, 49, 0, 3, - 0, 1, 2, 9, 2, 0, 9, 9, 32, 32, 2, 0, 38, 38, 60, 60, 2, 0, 34, 34, 60, - 60, 2, 0, 39, 39, 60, 60, 3, 0, 9, 10, 13, 13, 32, 32, 3, 0, 48, 57, - 65, 70, 97, 102, 1, 0, 48, 57, 3, 0, 183, 183, 768, 879, 8255, 8256, - 8, 0, 58, 58, 65, 90, 97, 122, 8304, 8591, 11264, 12271, 12289, 55295, - 63744, 64975, 65008, 65533, 239, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, - 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, - 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, - 0, 0, 0, 1, 23, 1, 0, 0, 0, 1, 25, 1, 0, 0, 0, 1, 27, 1, 0, 0, 0, 1, - 29, 1, 0, 0, 0, 1, 31, 1, 0, 0, 0, 1, 33, 1, 0, 0, 0, 1, 35, 1, 0, 0, - 0, 1, 37, 1, 0, 0, 0, 2, 47, 1, 0, 0, 0, 2, 49, 1, 0, 0, 0, 3, 51, 1, - 0, 0, 0, 5, 68, 1, 0, 0, 0, 7, 88, 1, 0, 0, 0, 9, 101, 1, 0, 0, 0, 11, - 126, 1, 0, 0, 0, 13, 133, 1, 0, 0, 0, 15, 135, 1, 0, 0, 0, 17, 139, 1, - 0, 0, 0, 19, 149, 1, 0, 0, 0, 21, 158, 1, 0, 0, 0, 23, 162, 1, 0, 0, - 0, 25, 165, 1, 0, 0, 0, 27, 170, 1, 0, 0, 0, 29, 175, 1, 0, 0, 0, 31, - 177, 1, 0, 0, 0, 33, 195, 1, 0, 0, 0, 35, 197, 1, 0, 0, 0, 37, 204, 1, - 0, 0, 0, 39, 208, 1, 0, 0, 0, 41, 210, 1, 0, 0, 0, 43, 216, 1, 0, 0, - 0, 45, 219, 1, 0, 0, 0, 47, 221, 1, 0, 0, 0, 49, 226, 1, 0, 0, 0, 51, - 52, 5, 60, 0, 0, 52, 53, 5, 33, 0, 0, 53, 54, 5, 45, 0, 0, 54, 55, 5, - 45, 0, 0, 55, 59, 1, 0, 0, 0, 56, 58, 9, 0, 0, 0, 57, 56, 1, 0, 0, 0, - 58, 61, 1, 0, 0, 0, 59, 60, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 62, 1, - 0, 0, 0, 61, 59, 1, 0, 0, 0, 62, 63, 5, 45, 0, 0, 63, 64, 5, 45, 0, 0, - 64, 65, 5, 62, 0, 0, 65, 66, 1, 0, 0, 0, 66, 67, 4, 0, 0, 0, 67, 4, 1, - 0, 0, 0, 68, 69, 5, 60, 0, 0, 69, 70, 5, 33, 0, 0, 70, 71, 5, 91, 0, - 0, 71, 72, 5, 67, 0, 0, 72, 73, 5, 68, 0, 0, 73, 74, 5, 65, 0, 0, 74, - 75, 5, 84, 0, 0, 75, 76, 5, 65, 0, 0, 76, 77, 5, 91, 0, 0, 77, 81, 1, - 0, 0, 0, 78, 80, 9, 0, 0, 0, 79, 78, 1, 0, 0, 0, 80, 83, 1, 0, 0, 0, - 81, 82, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 82, 84, 1, 0, 0, 0, 83, 81, 1, - 0, 0, 0, 84, 85, 5, 93, 0, 0, 85, 86, 5, 93, 0, 0, 86, 87, 5, 62, 0, - 0, 87, 6, 1, 0, 0, 0, 88, 89, 5, 60, 0, 0, 89, 90, 5, 33, 0, 0, 90, 94, - 1, 0, 0, 0, 91, 93, 9, 0, 0, 0, 92, 91, 1, 0, 0, 0, 93, 96, 1, 0, 0, - 0, 94, 95, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 97, 1, 0, 0, 0, 96, 94, - 1, 0, 0, 0, 97, 98, 5, 62, 0, 0, 98, 99, 1, 0, 0, 0, 99, 100, 6, 2, 0, - 0, 100, 8, 1, 0, 0, 0, 101, 102, 5, 38, 0, 0, 102, 103, 3, 35, 16, 0, - 103, 104, 5, 59, 0, 0, 104, 10, 1, 0, 0, 0, 105, 106, 5, 38, 0, 0, 106, - 107, 5, 35, 0, 0, 107, 109, 1, 0, 0, 0, 108, 110, 3, 41, 19, 0, 109, - 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, - 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 114, 5, 59, 0, 0, 114, 127, 1, - 0, 0, 0, 115, 116, 5, 38, 0, 0, 116, 117, 5, 35, 0, 0, 117, 118, 5, 120, - 0, 0, 118, 120, 1, 0, 0, 0, 119, 121, 3, 39, 18, 0, 120, 119, 1, 0, 0, - 0, 121, 122, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 122, 123, 1, 0, 0, 0, - 123, 124, 1, 0, 0, 0, 124, 125, 5, 59, 0, 0, 125, 127, 1, 0, 0, 0, 126, - 105, 1, 0, 0, 0, 126, 115, 1, 0, 0, 0, 127, 12, 1, 0, 0, 0, 128, 134, - 7, 0, 0, 0, 129, 131, 5, 13, 0, 0, 130, 129, 1, 0, 0, 0, 130, 131, 1, - 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 134, 5, 10, 0, 0, 133, 128, 1, 0, - 0, 0, 133, 130, 1, 0, 0, 0, 134, 14, 1, 0, 0, 0, 135, 136, 5, 60, 0, - 0, 136, 137, 1, 0, 0, 0, 137, 138, 6, 6, 1, 0, 138, 16, 1, 0, 0, 0, 139, - 140, 5, 60, 0, 0, 140, 141, 5, 63, 0, 0, 141, 142, 5, 120, 0, 0, 142, - 143, 5, 109, 0, 0, 143, 144, 5, 108, 0, 0, 144, 145, 1, 0, 0, 0, 145, - 146, 3, 37, 17, 0, 146, 147, 1, 0, 0, 0, 147, 148, 6, 7, 1, 0, 148, 18, - 1, 0, 0, 0, 149, 150, 5, 60, 0, 0, 150, 151, 5, 63, 0, 0, 151, 152, 1, - 0, 0, 0, 152, 153, 3, 35, 16, 0, 153, 154, 1, 0, 0, 0, 154, 155, 6, 8, - 2, 0, 155, 156, 6, 8, 3, 0, 156, 20, 1, 0, 0, 0, 157, 159, 8, 1, 0, 0, - 158, 157, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, 158, 1, 0, 0, 0, 160, - 161, 1, 0, 0, 0, 161, 22, 1, 0, 0, 0, 162, 163, 5, 62, 0, 0, 163, 164, - 6, 10, 4, 0, 164, 24, 1, 0, 0, 0, 165, 166, 5, 63, 0, 0, 166, 167, 5, - 62, 0, 0, 167, 168, 1, 0, 0, 0, 168, 169, 6, 11, 5, 0, 169, 26, 1, 0, - 0, 0, 170, 171, 5, 47, 0, 0, 171, 172, 5, 62, 0, 0, 172, 173, 1, 0, 0, - 0, 173, 174, 6, 12, 5, 0, 174, 28, 1, 0, 0, 0, 175, 176, 5, 47, 0, 0, - 176, 30, 1, 0, 0, 0, 177, 178, 5, 61, 0, 0, 178, 32, 1, 0, 0, 0, 179, - 183, 5, 34, 0, 0, 180, 182, 8, 2, 0, 0, 181, 180, 1, 0, 0, 0, 182, 185, - 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 186, 1, - 0, 0, 0, 185, 183, 1, 0, 0, 0, 186, 196, 5, 34, 0, 0, 187, 191, 5, 39, - 0, 0, 188, 190, 8, 3, 0, 0, 189, 188, 1, 0, 0, 0, 190, 193, 1, 0, 0, - 0, 191, 189, 1, 0, 0, 0, 191, 192, 1, 0, 0, 0, 192, 194, 1, 0, 0, 0, - 193, 191, 1, 0, 0, 0, 194, 196, 5, 39, 0, 0, 195, 179, 1, 0, 0, 0, 195, - 187, 1, 0, 0, 0, 196, 34, 1, 0, 0, 0, 197, 201, 3, 45, 21, 0, 198, 200, - 3, 43, 20, 0, 199, 198, 1, 0, 0, 0, 200, 203, 1, 0, 0, 0, 201, 199, 1, - 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 36, 1, 0, 0, 0, 203, 201, 1, 0, 0, - 0, 204, 205, 7, 4, 0, 0, 205, 206, 1, 0, 0, 0, 206, 207, 6, 17, 0, 0, - 207, 38, 1, 0, 0, 0, 208, 209, 7, 5, 0, 0, 209, 40, 1, 0, 0, 0, 210, - 211, 7, 6, 0, 0, 211, 42, 1, 0, 0, 0, 212, 217, 3, 45, 21, 0, 213, 217, - 2, 45, 46, 0, 214, 217, 3, 41, 19, 0, 215, 217, 7, 7, 0, 0, 216, 212, - 1, 0, 0, 0, 216, 213, 1, 0, 0, 0, 216, 214, 1, 0, 0, 0, 216, 215, 1, - 0, 0, 0, 217, 44, 1, 0, 0, 0, 218, 220, 7, 8, 0, 0, 219, 218, 1, 0, 0, - 0, 220, 46, 1, 0, 0, 0, 221, 222, 5, 63, 0, 0, 222, 223, 5, 62, 0, 0, - 223, 224, 1, 0, 0, 0, 224, 225, 6, 22, 5, 0, 225, 48, 1, 0, 0, 0, 226, - 227, 9, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 229, 6, 23, 2, 0, 229, 50, - 1, 0, 0, 0, 18, 0, 1, 2, 59, 81, 94, 111, 122, 126, 130, 133, 160, 183, - 191, 195, 201, 216, 219, 6, 6, 0, 0, 5, 1, 0, 3, 0, 0, 5, 2, 0, 1, 10, - 0, 4, 0, 0 - ]; - } \ No newline at end of file +lazy_static! { + static ref _ATN: Arc = + Arc::new(ATNDeserializer::new(None).deserialize(&mut _serializedATN.iter())); + static ref _decision_to_DFA: Arc>> = { + let mut dfa = Vec::new(); + let size = _ATN.decision_to_state.len() as i32; + for i in 0..size { + dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i).into()) + } + Arc::new(dfa) + }; + static ref _serializedATN: Vec = vec![ + 4, 0, 18, 230, 6, -1, 6, -1, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, + 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, + 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, + 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 1, 0, 1, + 0, 1, 0, 1, 0, 1, 0, 1, 0, 5, 0, 58, 8, 0, 10, 0, 12, 0, 61, 9, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 80, 8, + 1, 10, 1, 12, 1, 83, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 93, 8, 2, + 10, 2, 12, 2, 96, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, + 1, 4, 4, 4, 110, 8, 4, 11, 4, 12, 4, 111, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 4, 4, + 121, 8, 4, 11, 4, 12, 4, 122, 1, 4, 1, 4, 3, 4, 127, 8, 4, 1, 5, 1, 5, 3, 5, 131, 8, 5, 1, + 5, 3, 5, 134, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, + 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 4, 9, 159, 8, 9, 11, 9, + 12, 9, 160, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, + 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 5, 15, 182, 8, 15, 10, 15, 12, 15, + 185, 9, 15, 1, 15, 1, 15, 1, 15, 5, 15, 190, 8, 15, 10, 15, 12, 15, 193, 9, 15, 1, 15, 3, + 15, 196, 8, 15, 1, 16, 1, 16, 5, 16, 200, 8, 16, 10, 16, 12, 16, 203, 9, 16, 1, 17, 1, 17, + 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 3, 20, 217, 8, 20, 1, + 21, 3, 21, 220, 8, 21, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 3, + 59, 81, 94, 0, 24, 3, 1, 5, 2, 7, 3, 9, 4, 11, 5, 13, 6, 15, 7, 17, 8, 19, 0, 21, 9, 23, + 10, 25, 11, 27, 12, 29, 13, 31, 14, 33, 15, 35, 16, 37, 17, 39, 0, 41, 0, 43, 0, 45, 0, 47, + 18, 49, 0, 3, 0, 1, 2, 9, 2, 0, 9, 9, 32, 32, 2, 0, 38, 38, 60, 60, 2, 0, 34, 34, 60, 60, + 2, 0, 39, 39, 60, 60, 3, 0, 9, 10, 13, 13, 32, 32, 3, 0, 48, 57, 65, 70, 97, 102, 1, 0, 48, + 57, 3, 0, 183, 183, 768, 879, 8255, 8256, 8, 0, 58, 58, 65, 90, 97, 122, 8304, 8591, 11264, + 12271, 12289, 55295, 63744, 64975, 65008, 65533, 239, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, + 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, + 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 1, 23, 1, 0, 0, 0, 1, 25, 1, 0, + 0, 0, 1, 27, 1, 0, 0, 0, 1, 29, 1, 0, 0, 0, 1, 31, 1, 0, 0, 0, 1, 33, 1, 0, 0, 0, 1, 35, 1, + 0, 0, 0, 1, 37, 1, 0, 0, 0, 2, 47, 1, 0, 0, 0, 2, 49, 1, 0, 0, 0, 3, 51, 1, 0, 0, 0, 5, 68, + 1, 0, 0, 0, 7, 88, 1, 0, 0, 0, 9, 101, 1, 0, 0, 0, 11, 126, 1, 0, 0, 0, 13, 133, 1, 0, 0, + 0, 15, 135, 1, 0, 0, 0, 17, 139, 1, 0, 0, 0, 19, 149, 1, 0, 0, 0, 21, 158, 1, 0, 0, 0, 23, + 162, 1, 0, 0, 0, 25, 165, 1, 0, 0, 0, 27, 170, 1, 0, 0, 0, 29, 175, 1, 0, 0, 0, 31, 177, 1, + 0, 0, 0, 33, 195, 1, 0, 0, 0, 35, 197, 1, 0, 0, 0, 37, 204, 1, 0, 0, 0, 39, 208, 1, 0, 0, + 0, 41, 210, 1, 0, 0, 0, 43, 216, 1, 0, 0, 0, 45, 219, 1, 0, 0, 0, 47, 221, 1, 0, 0, 0, 49, + 226, 1, 0, 0, 0, 51, 52, 5, 60, 0, 0, 52, 53, 5, 33, 0, 0, 53, 54, 5, 45, 0, 0, 54, 55, 5, + 45, 0, 0, 55, 59, 1, 0, 0, 0, 56, 58, 9, 0, 0, 0, 57, 56, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, + 59, 60, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 62, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 62, 63, 5, + 45, 0, 0, 63, 64, 5, 45, 0, 0, 64, 65, 5, 62, 0, 0, 65, 66, 1, 0, 0, 0, 66, 67, 4, 0, 0, 0, + 67, 4, 1, 0, 0, 0, 68, 69, 5, 60, 0, 0, 69, 70, 5, 33, 0, 0, 70, 71, 5, 91, 0, 0, 71, 72, + 5, 67, 0, 0, 72, 73, 5, 68, 0, 0, 73, 74, 5, 65, 0, 0, 74, 75, 5, 84, 0, 0, 75, 76, 5, 65, + 0, 0, 76, 77, 5, 91, 0, 0, 77, 81, 1, 0, 0, 0, 78, 80, 9, 0, 0, 0, 79, 78, 1, 0, 0, 0, 80, + 83, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 82, 84, 1, 0, 0, 0, 83, 81, 1, 0, + 0, 0, 84, 85, 5, 93, 0, 0, 85, 86, 5, 93, 0, 0, 86, 87, 5, 62, 0, 0, 87, 6, 1, 0, 0, 0, 88, + 89, 5, 60, 0, 0, 89, 90, 5, 33, 0, 0, 90, 94, 1, 0, 0, 0, 91, 93, 9, 0, 0, 0, 92, 91, 1, 0, + 0, 0, 93, 96, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 95, 97, 1, 0, 0, 0, 96, + 94, 1, 0, 0, 0, 97, 98, 5, 62, 0, 0, 98, 99, 1, 0, 0, 0, 99, 100, 6, 2, 0, 0, 100, 8, 1, 0, + 0, 0, 101, 102, 5, 38, 0, 0, 102, 103, 3, 35, 16, 0, 103, 104, 5, 59, 0, 0, 104, 10, 1, 0, + 0, 0, 105, 106, 5, 38, 0, 0, 106, 107, 5, 35, 0, 0, 107, 109, 1, 0, 0, 0, 108, 110, 3, 41, + 19, 0, 109, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 109, 1, 0, 0, 0, 111, 112, 1, 0, 0, + 0, 112, 113, 1, 0, 0, 0, 113, 114, 5, 59, 0, 0, 114, 127, 1, 0, 0, 0, 115, 116, 5, 38, 0, + 0, 116, 117, 5, 35, 0, 0, 117, 118, 5, 120, 0, 0, 118, 120, 1, 0, 0, 0, 119, 121, 3, 39, + 18, 0, 120, 119, 1, 0, 0, 0, 121, 122, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 122, 123, 1, 0, 0, + 0, 123, 124, 1, 0, 0, 0, 124, 125, 5, 59, 0, 0, 125, 127, 1, 0, 0, 0, 126, 105, 1, 0, 0, 0, + 126, 115, 1, 0, 0, 0, 127, 12, 1, 0, 0, 0, 128, 134, 7, 0, 0, 0, 129, 131, 5, 13, 0, 0, + 130, 129, 1, 0, 0, 0, 130, 131, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 134, 5, 10, 0, 0, + 133, 128, 1, 0, 0, 0, 133, 130, 1, 0, 0, 0, 134, 14, 1, 0, 0, 0, 135, 136, 5, 60, 0, 0, + 136, 137, 1, 0, 0, 0, 137, 138, 6, 6, 1, 0, 138, 16, 1, 0, 0, 0, 139, 140, 5, 60, 0, 0, + 140, 141, 5, 63, 0, 0, 141, 142, 5, 120, 0, 0, 142, 143, 5, 109, 0, 0, 143, 144, 5, 108, 0, + 0, 144, 145, 1, 0, 0, 0, 145, 146, 3, 37, 17, 0, 146, 147, 1, 0, 0, 0, 147, 148, 6, 7, 1, + 0, 148, 18, 1, 0, 0, 0, 149, 150, 5, 60, 0, 0, 150, 151, 5, 63, 0, 0, 151, 152, 1, 0, 0, 0, + 152, 153, 3, 35, 16, 0, 153, 154, 1, 0, 0, 0, 154, 155, 6, 8, 2, 0, 155, 156, 6, 8, 3, 0, + 156, 20, 1, 0, 0, 0, 157, 159, 8, 1, 0, 0, 158, 157, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, + 158, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 22, 1, 0, 0, 0, 162, 163, 5, 62, 0, 0, 163, + 164, 6, 10, 4, 0, 164, 24, 1, 0, 0, 0, 165, 166, 5, 63, 0, 0, 166, 167, 5, 62, 0, 0, 167, + 168, 1, 0, 0, 0, 168, 169, 6, 11, 5, 0, 169, 26, 1, 0, 0, 0, 170, 171, 5, 47, 0, 0, 171, + 172, 5, 62, 0, 0, 172, 173, 1, 0, 0, 0, 173, 174, 6, 12, 5, 0, 174, 28, 1, 0, 0, 0, 175, + 176, 5, 47, 0, 0, 176, 30, 1, 0, 0, 0, 177, 178, 5, 61, 0, 0, 178, 32, 1, 0, 0, 0, 179, + 183, 5, 34, 0, 0, 180, 182, 8, 2, 0, 0, 181, 180, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, + 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 183, 1, 0, 0, 0, 186, + 196, 5, 34, 0, 0, 187, 191, 5, 39, 0, 0, 188, 190, 8, 3, 0, 0, 189, 188, 1, 0, 0, 0, 190, + 193, 1, 0, 0, 0, 191, 189, 1, 0, 0, 0, 191, 192, 1, 0, 0, 0, 192, 194, 1, 0, 0, 0, 193, + 191, 1, 0, 0, 0, 194, 196, 5, 39, 0, 0, 195, 179, 1, 0, 0, 0, 195, 187, 1, 0, 0, 0, 196, + 34, 1, 0, 0, 0, 197, 201, 3, 45, 21, 0, 198, 200, 3, 43, 20, 0, 199, 198, 1, 0, 0, 0, 200, + 203, 1, 0, 0, 0, 201, 199, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 36, 1, 0, 0, 0, 203, 201, + 1, 0, 0, 0, 204, 205, 7, 4, 0, 0, 205, 206, 1, 0, 0, 0, 206, 207, 6, 17, 0, 0, 207, 38, 1, + 0, 0, 0, 208, 209, 7, 5, 0, 0, 209, 40, 1, 0, 0, 0, 210, 211, 7, 6, 0, 0, 211, 42, 1, 0, 0, + 0, 212, 217, 3, 45, 21, 0, 213, 217, 2, 45, 46, 0, 214, 217, 3, 41, 19, 0, 215, 217, 7, 7, + 0, 0, 216, 212, 1, 0, 0, 0, 216, 213, 1, 0, 0, 0, 216, 214, 1, 0, 0, 0, 216, 215, 1, 0, 0, + 0, 217, 44, 1, 0, 0, 0, 218, 220, 7, 8, 0, 0, 219, 218, 1, 0, 0, 0, 220, 46, 1, 0, 0, 0, + 221, 222, 5, 63, 0, 0, 222, 223, 5, 62, 0, 0, 223, 224, 1, 0, 0, 0, 224, 225, 6, 22, 5, 0, + 225, 48, 1, 0, 0, 0, 226, 227, 9, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 229, 6, 23, 2, 0, + 229, 50, 1, 0, 0, 0, 18, 0, 1, 2, 59, 81, 94, 111, 122, 126, 130, 133, 160, 183, 191, 195, + 201, 216, 219, 6, 6, 0, 0, 5, 1, 0, 3, 0, 0, 5, 2, 0, 1, 10, 0, 4, 0, 0 + ]; +} From af34337b0b883c5407dbbf29eac733a08ec8a47c Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Mon, 2 Mar 2026 18:55:58 -0500 Subject: [PATCH 09/10] ci: run fmt on gen code prior to validating Signed-off-by: Alex Snaps --- .github/workflows/hosted.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml index 229fad5797..b35274eef2 100644 --- a/.github/workflows/hosted.yml +++ b/.github/workflows/hosted.yml @@ -391,7 +391,7 @@ jobs: - name: Run tests run: cargo test --verbose - name: Formatting - run: cargo fmt -- --check + run: cargo fmt -- tests/gen/*.rs && cargo fmt -- --check - uses: actions/checkout@v3 if: ${{ github.event_name == 'push' }} with: From 77f66b0e9032c94c8ae0f76e84ed7af2ee2b38e8 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Mon, 2 Mar 2026 19:03:07 -0500 Subject: [PATCH 10/10] chore: clean up imports Signed-off-by: Alex Snaps --- runtime/Rust/src/parser.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/Rust/src/parser.rs b/runtime/Rust/src/parser.rs index 359b126b04..63657cda4d 100644 --- a/runtime/Rust/src/parser.rs +++ b/runtime/Rust/src/parser.rs @@ -4,7 +4,6 @@ use std::cell::{Cell, RefCell}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use std::sync::Arc; use crate::atn::ATN; use crate::atn_simulator::IATNSimulator;