diff --git a/.github/workflows/antlr.yml b/.github/workflows/antlr.yml index 03b9ebb..a278cad 100644 --- a/.github/workflows/antlr.yml +++ b/.github/workflows/antlr.yml @@ -27,11 +27,6 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - name: Cache local Maven repository uses: actions/cache@v2 with: @@ -41,18 +36,24 @@ jobs: ${{ runner.os }}-maven- - name: Build with Maven run : mvn -DskipTests install -q + - uses: actions/upload-artifact@v2 + with: + name: antlr-tool + path: tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true - name : Maven tests + env: + ANTLR4_PATH: skip run: | mvn test -Dtest=rust.* -q rc=$?; cat target/surefire-reports/*.dumpstream || true; exit $rc working-directory: runtime-testsuite - - uses: actions/upload-artifact@v2 - if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} - with: - name: antlr-tool - path: tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar tests-rust: name: cargo test @@ -62,6 +63,8 @@ jobs: strategy: matrix: rust_version: [ 1.52 , stable] + env: + ANTLR4_PATH: antlr4-4.8-2-SNAPSHOT-complete.jar steps: - uses: actions/checkout@v2 - name: Install Rust @@ -70,12 +73,23 @@ jobs: toolchain: ${{ matrix.rust_version }} default: true components: rustfmt + - name: Wait for antlr-tool being built + # todo find out better way to do that + run: sleep 60s + - uses: actions/download-artifact@v2 + with: + name: antlr-tool - name: Build - run: cargo build --verbose + run: cargo build -vv - name: Run tests run: cargo test --verbose - name: Formatting - run: cargo fmt -- --check + run: | + cargo fmt + rm antlr4-4.8-2-SNAPSHOT-complete.jar + if [[ $(git status --porcelain | wc -l) != "0" ]]; then + exit 1 + fi - uses: actions/checkout@v2 if: ${{ github.event_name == 'push' }} with: diff --git a/.gitignore b/.gitignore index 98380a7..36b99ae 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /target /tests/gen/*.tokens /tests/gen/*.interp +/tests/gen/* **/*.rs.bk *.iml Cargo.lock diff --git a/build.rs b/build.rs index 5cf97ab..803d771 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,11 @@ -use std::convert::TryInto; +//! Used to generate tests. +//! Not uploaded to crates.io, so this build script should not affect users if this crate is used as a regular crates.io dependency +//! +//! set ANTLR4_PATH=download if you don't want/need a full rebuild of antlr tool, +//! and it will download a corresponding artifact right from github releases use std::env; use std::env::VarError; use std::error::Error; -use std::fs::{read_dir, DirEntry, File}; -use std::io::Write; use std::path::Path; use std::process::Command; @@ -16,7 +18,6 @@ fn main() { "XMLLexer", "SimpleLR", "Labels", - "FHIRPath", ]; let additional_args = vec![ Some("-visitor"), @@ -27,30 +28,65 @@ fn main() { None, None, ]; - let antlr_path = "/home/rrevenantt/dev/antlr4/tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar"; + + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-env-changed=ANTLR4_PATH"); + + let antlr_path = match env::var("ANTLR4_PATH").as_deref() { + Ok("download") => { + let url = format!( + "https://github.com/rrevenantt/antlr4rust/releases/download/antlr4-4.8-2-Rust{}/antlr4-4.8-2-SNAPSHOT-complete.jar", + env::var("CARGO_PKG_VERSION").unwrap() + ); + let path = Path::new(&env::var("OUT_DIR").unwrap()).join("tool.jar"); + Command::new("curl") + .arg(url) + .arg("-L") + .arg("-o") + .arg(&path) + .spawn() + .unwrap() + .wait_with_output() + .expect("error running curl"); + path.to_str().unwrap().to_string() + } + Ok("skip") => return, + Ok(x) => Path::new(x) + .canonicalize() + .unwrap() + .to_str() + .unwrap() + .to_string(), + Err(VarError::NotUnicode(_)) => panic!("non unicode env variable"), + Err(_) => { + let default_path = env::current_dir() + .unwrap() + .join("../../tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar") + .canonicalize(); + match default_path { + Ok(x) if !x.exists() => return, + Err(_) => return, + Ok(x) => x.to_str().unwrap().to_string(), + } + } + }; for (grammar, arg) in grammars.into_iter().zip(additional_args) { - //ignoring error because we do not need to run anything when deploying to crates.io - let _ = gen_for_grammar(grammar, antlr_path, arg); + gen_for_grammar(grammar, &antlr_path, arg).expect("error running antlr tool"); } - println!("cargo:rerun-if-changed=build.rs"); - - println!("cargo:rerun-if-changed=/home/rrevenantt/dev/antlr4/tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar"); + println!("cargo:rerun-if-changed={}", antlr_path); } fn gen_for_grammar( grammar_file_name: &str, antlr_path: &str, additional_arg: Option<&str>, -) -> Result<(), Box> { - // let out_dir = env::var("OUT_DIR").unwrap(); - // let dest_path = Path::new(&out_dir); - +) -> Result<(), Box> { let input = env::current_dir().unwrap().join("grammars"); let file_name = grammar_file_name.to_owned() + ".g4"; - let c = Command::new("java") + Command::new("java") .current_dir(input) .arg("-cp") .arg(antlr_path) @@ -60,12 +96,8 @@ fn gen_for_grammar( .arg("../tests/gen") .arg(&file_name) .args(additional_arg) - .spawn() - .expect("antlr tool failed to start") + .spawn()? .wait_with_output()?; - // .unwrap() - // .stdout; - // eprintln!("xx{}",String::from_utf8(x).unwrap()); println!("cargo:rerun-if-changed=grammars/{}", file_name); Ok(()) diff --git a/tests/gen/csvlexer.rs b/tests/gen/csvlexer.rs deleted file mode 100644 index beec6b9..0000000 --- a/tests/gen/csvlexer.rs +++ /dev/null @@ -1,219 +0,0 @@ -// Generated from CSV.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const T__0: isize = 1; -pub const T__1: isize = 2; -pub const T__2: isize = 3; -pub const WS: isize = 4; -pub const TEXT: isize = 5; -pub const STRING: isize = 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 LocalTokenFactory<'input> = antlr_rust::token_factory::ArenaCommonFactory<'input>; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct CSVLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, CSVLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> CSVLexer<'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 { - "CSVLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 {} - -impl CSVLexerActions {} - -impl<'input, Input: CharStream>> - Actions<'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, Input: CharStream>> TokenSource<'input> for CSVLexer<'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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x08\x2c\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x04\x04\x09\x04\x04\x05\ - \x09\x05\x04\x06\x09\x06\x04\x07\x09\x07\x03\x02\x03\x02\x03\x03\x03\x03\ - \x03\x04\x03\x04\x03\x05\x06\x05\x17\x0a\x05\x0d\x05\x0e\x05\x18\x03\x05\ - \x03\x05\x03\x06\x06\x06\x1e\x0a\x06\x0d\x06\x0e\x06\x1f\x03\x07\x03\x07\ - \x03\x07\x03\x07\x07\x07\x26\x0a\x07\x0c\x07\x0e\x07\x29\x0b\x07\x03\x07\ - \x03\x07\x02\x02\x08\x03\x03\x05\x04\x07\x05\x09\x06\x0b\x07\x0d\x08\x03\ - \x02\x05\x03\x02\x22\x22\x07\x02\x0c\x0c\x0f\x0f\x22\x22\x24\x24\x2e\x2e\ - \x03\x02\x24\x24\x02\x2f\x02\x03\x03\x02\x02\x02\x02\x05\x03\x02\x02\x02\ - \x02\x07\x03\x02\x02\x02\x02\x09\x03\x02\x02\x02\x02\x0b\x03\x02\x02\x02\ - \x02\x0d\x03\x02\x02\x02\x03\x0f\x03\x02\x02\x02\x05\x11\x03\x02\x02\x02\ - \x07\x13\x03\x02\x02\x02\x09\x16\x03\x02\x02\x02\x0b\x1d\x03\x02\x02\x02\ - \x0d\x21\x03\x02\x02\x02\x0f\x10\x07\x2e\x02\x02\x10\x04\x03\x02\x02\x02\ - \x11\x12\x07\x0f\x02\x02\x12\x06\x03\x02\x02\x02\x13\x14\x07\x0c\x02\x02\ - \x14\x08\x03\x02\x02\x02\x15\x17\x09\x02\x02\x02\x16\x15\x03\x02\x02\x02\ - \x17\x18\x03\x02\x02\x02\x18\x16\x03\x02\x02\x02\x18\x19\x03\x02\x02\x02\ - \x19\x1a\x03\x02\x02\x02\x1a\x1b\x08\x05\x02\x02\x1b\x0a\x03\x02\x02\x02\ - \x1c\x1e\x0a\x03\x02\x02\x1d\x1c\x03\x02\x02\x02\x1e\x1f\x03\x02\x02\x02\ - \x1f\x1d\x03\x02\x02\x02\x1f\x20\x03\x02\x02\x02\x20\x0c\x03\x02\x02\x02\ - \x21\x27\x07\x24\x02\x02\x22\x23\x07\x24\x02\x02\x23\x26\x07\x24\x02\x02\ - \x24\x26\x0a\x04\x02\x02\x25\x22\x03\x02\x02\x02\x25\x24\x03\x02\x02\x02\ - \x26\x29\x03\x02\x02\x02\x27\x25\x03\x02\x02\x02\x27\x28\x03\x02\x02\x02\ - \x28\x2a\x03\x02\x02\x02\x29\x27\x03\x02\x02\x02\x2a\x2b\x07\x24\x02\x02\ - \x2b\x0e\x03\x02\x02\x02\x07\x02\x18\x1f\x25\x27\x03\x02\x03\x02"; diff --git a/tests/gen/csvlistener.rs b/tests/gen/csvlistener.rs deleted file mode 100644 index d063ce6..0000000 --- a/tests/gen/csvlistener.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from CSV.g4 by ANTLR 4.8 -use super::csvparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : CSVListener<'input> } diff --git a/tests/gen/csvparser.rs b/tests/gen/csvparser.rs deleted file mode 100644 index afb9bfe..0000000 --- a/tests/gen/csvparser.rs +++ /dev/null @@ -1,788 +0,0 @@ -// Generated from CSV.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::csvlistener::*; -use super::csvvisitor::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::lazy_static; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const T__0: isize = 1; -pub const T__1: isize = 2; -pub const T__2: isize = 3; -pub const WS: isize = 4; -pub const TEXT: isize = 5; -pub const STRING: isize = 6; -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> = antlr_rust::token_factory::ArenaCommonFactory<'input>; - -pub type CSVTreeWalker<'input, 'a> = - ParseTreeWalker<'input, 'a, CSVParserContextType, dyn CSVListener<'input> + 'a>; - -/// Parser for CSV grammar -pub struct CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - CSVParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> CSVParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> CSVParser<'input, I, DefaultErrorStrategy<'input, CSVParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for CSVParser -pub trait CSVParserContext<'input>: - for<'x> Listenable + 'x> - + for<'x> Visitable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = CSVParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : CSVParserContext<'input> } - -impl<'input, 'x, T> VisitableDyn for dyn CSVParserContext<'input> + 'input -where - T: CSVVisitor<'input> + 'x, -{ - fn accept_dyn(&self, visitor: &mut T) { - self.accept(visitor as &mut (dyn CSVVisitor<'input> + 'x)) - } -} - -impl<'input> CSVParserContext<'input> for TerminalNode<'input, CSVParserContextType> {} -impl<'input> CSVParserContext<'input> for ErrorNode<'input, CSVParserContextType> {} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn CSVParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn CSVListener<'input> + 'input } - -pub struct CSVParserContextType; -antlr_rust::tid! {CSVParserContextType} - -impl<'input> ParserNodeType<'input> for CSVParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn CSVParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct CSVParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> CSVParserExt<'input> {} -antlr_rust::tid! { CSVParserExt<'a> } - -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>> - 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_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } -} -//------------------- csvFile ---------------- -pub type CsvFileContextAll<'input> = CsvFileContext<'input>; - -pub type CsvFileContext<'input> = BaseParserRuleContext<'input, CsvFileContextExt<'input>>; - -#[derive(Clone)] -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)) { - listener.enter_every_rule(self); - listener.enter_csvFile(self); - } - fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) { - listener.exit_csvFile(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {CsvFileContextExt<'a>} - -impl<'input> CsvFileContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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, I, H> CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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: isize = -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) - & ((1usize << T__0) - | (1usize << T__1) - | (1usize << T__2) - | (1usize << TEXT) - | (1usize << STRING))) - != 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>>; - -#[derive(Clone)] -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)) { - listener.enter_every_rule(self); - listener.enter_hdr(self); - } - fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) { - listener.exit_hdr(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {HdrContextExt<'a>} - -impl<'input> HdrContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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, I, H> CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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) - } -} -//------------------- row ---------------- -pub type RowContextAll<'input> = RowContext<'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)) { - listener.enter_every_rule(self); - listener.enter_row(self); - } - fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) { - listener.exit_row(self); - listener.exit_every_rule(self); - } -} - -impl<'input, 'a> Visitable + 'a> for RowContext<'input> { - fn accept(&self, visitor: &mut (dyn CSVVisitor<'input> + 'a)) { - visitor.visit_row(self); - } -} - -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 } -} -antlr_rust::tid! {RowContextExt<'a>} - -impl<'input> RowContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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, I, H> CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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: isize = -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 == T__0 { - { - { - recog.base.set_state(17); - recog.base.match_token(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 == T__1 { - { - recog.base.set_state(24); - recog.base.match_token(T__1, &mut recog.err_handler)?; - } - } - - recog.base.set_state(27); - recog.base.match_token(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>>; - -#[derive(Clone)] -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)) { - listener.enter_every_rule(self); - listener.enter_field(self); - } - fn exit(&self, listener: &mut (dyn CSVListener<'input> + 'a)) { - listener.exit_field(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {FieldContextExt<'a>} - -impl<'input> FieldContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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(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(STRING, 0) - } -} - -impl<'input> FieldContextAttrs<'input> for FieldContext<'input> {} - -impl<'input, I, H> CSVParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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) { - 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(TEXT, &mut recog.err_handler)?; - } - } - - 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(STRING, &mut recog.err_handler)?; - } - } - - T__0 | T__1 | 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(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x08\x25\x04\x02\x09\x02\x04\x03\x09\x03\x04\x04\x09\x04\x04\x05\x09\x05\ - \x03\x02\x03\x02\x06\x02\x0d\x0a\x02\x0d\x02\x0e\x02\x0e\x03\x03\x03\x03\ - \x03\x04\x03\x04\x03\x04\x07\x04\x16\x0a\x04\x0c\x04\x0e\x04\x19\x0b\x04\ - \x03\x04\x05\x04\x1c\x0a\x04\x03\x04\x03\x04\x03\x05\x03\x05\x03\x05\x05\ - \x05\x23\x0a\x05\x03\x05\x02\x02\x06\x02\x04\x06\x08\x02\x02\x02\x25\x02\ - \x0a\x03\x02\x02\x02\x04\x10\x03\x02\x02\x02\x06\x12\x03\x02\x02\x02\x08\ - \x22\x03\x02\x02\x02\x0a\x0c\x05\x04\x03\x02\x0b\x0d\x05\x06\x04\x02\x0c\ - \x0b\x03\x02\x02\x02\x0d\x0e\x03\x02\x02\x02\x0e\x0c\x03\x02\x02\x02\x0e\ - \x0f\x03\x02\x02\x02\x0f\x03\x03\x02\x02\x02\x10\x11\x05\x06\x04\x02\x11\ - \x05\x03\x02\x02\x02\x12\x17\x05\x08\x05\x02\x13\x14\x07\x03\x02\x02\x14\ - \x16\x05\x08\x05\x02\x15\x13\x03\x02\x02\x02\x16\x19\x03\x02\x02\x02\x17\ - \x15\x03\x02\x02\x02\x17\x18\x03\x02\x02\x02\x18\x1b\x03\x02\x02\x02\x19\ - \x17\x03\x02\x02\x02\x1a\x1c\x07\x04\x02\x02\x1b\x1a\x03\x02\x02\x02\x1b\ - \x1c\x03\x02\x02\x02\x1c\x1d\x03\x02\x02\x02\x1d\x1e\x07\x05\x02\x02\x1e\ - \x07\x03\x02\x02\x02\x1f\x23\x07\x07\x02\x02\x20\x23\x07\x08\x02\x02\x21\ - \x23\x03\x02\x02\x02\x22\x1f\x03\x02\x02\x02\x22\x20\x03\x02\x02\x02\x22\ - \x21\x03\x02\x02\x02\x23\x09\x03\x02\x02\x02\x06\x0e\x17\x1b\x22"; diff --git a/tests/gen/csvvisitor.rs b/tests/gen/csvvisitor.rs deleted file mode 100644 index 3d63ae8..0000000 --- a/tests/gen/csvvisitor.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from CSV.g4 by ANTLR 4.8 -use super::csvparser::*; -use antlr_rust::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) - } - - /** - * 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) - } -} - -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) - } - - /** - * 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 -where - T: CSVVisitorCompat<'input>, -{ - 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); - *::temp_result(self) = result; - } - - 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); - *::temp_result(self) = result; - } -} diff --git a/tests/gen/labelslexer.rs b/tests/gen/labelslexer.rs deleted file mode 100644 index f8960be..0000000 --- a/tests/gen/labelslexer.rs +++ /dev/null @@ -1,237 +0,0 @@ -// Generated from Labels.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const T__0: isize = 1; -pub const T__1: isize = 2; -pub const T__2: isize = 3; -pub const T__3: isize = 4; -pub const T__4: isize = 5; -pub const T__5: isize = 6; -pub const ID: isize = 7; -pub const INT: isize = 8; -pub const WS: isize = 9; -pub const 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 LocalTokenFactory<'input> = CommonTokenFactory; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct LabelsLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, LabelsLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> LabelsLexer<'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 { - "LabelsLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 {} - -impl LabelsLexerActions {} - -impl<'input, Input: CharStream>> - Actions<'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, Input: CharStream>> TokenSource<'input> for LabelsLexer<'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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x0b\x31\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x04\x04\x09\x04\x04\x05\ - \x09\x05\x04\x06\x09\x06\x04\x07\x09\x07\x04\x08\x09\x08\x04\x09\x09\x09\ - \x04\x0a\x09\x0a\x03\x02\x03\x02\x03\x03\x03\x03\x03\x04\x03\x04\x03\x05\ - \x03\x05\x03\x06\x03\x06\x03\x06\x03\x07\x03\x07\x03\x07\x03\x08\x06\x08\ - \x25\x0a\x08\x0d\x08\x0e\x08\x26\x03\x09\x06\x09\x2a\x0a\x09\x0d\x09\x0e\ - \x09\x2b\x03\x0a\x03\x0a\x03\x0a\x03\x0a\x02\x02\x0b\x03\x03\x05\x04\x07\ - \x05\x09\x06\x0b\x07\x0d\x08\x0f\x09\x11\x0a\x13\x0b\x03\x02\x03\x04\x02\ - \x0c\x0c\x22\x22\x02\x32\x02\x03\x03\x02\x02\x02\x02\x05\x03\x02\x02\x02\ - \x02\x07\x03\x02\x02\x02\x02\x09\x03\x02\x02\x02\x02\x0b\x03\x02\x02\x02\ - \x02\x0d\x03\x02\x02\x02\x02\x0f\x03\x02\x02\x02\x02\x11\x03\x02\x02\x02\ - \x02\x13\x03\x02\x02\x02\x03\x15\x03\x02\x02\x02\x05\x17\x03\x02\x02\x02\ - \x07\x19\x03\x02\x02\x02\x09\x1b\x03\x02\x02\x02\x0b\x1d\x03\x02\x02\x02\ - \x0d\x20\x03\x02\x02\x02\x0f\x24\x03\x02\x02\x02\x11\x29\x03\x02\x02\x02\ - \x13\x2d\x03\x02\x02\x02\x15\x16\x07\x2c\x02\x02\x16\x04\x03\x02\x02\x02\ - \x17\x18\x07\x2d\x02\x02\x18\x06\x03\x02\x02\x02\x19\x1a\x07\x2a\x02\x02\ - \x1a\x08\x03\x02\x02\x02\x1b\x1c\x07\x2b\x02\x02\x1c\x0a\x03\x02\x02\x02\ - \x1d\x1e\x07\x2d\x02\x02\x1e\x1f\x07\x2d\x02\x02\x1f\x0c\x03\x02\x02\x02\ - \x20\x21\x07\x2f\x02\x02\x21\x22\x07\x2f\x02\x02\x22\x0e\x03\x02\x02\x02\ - \x23\x25\x04\x63\x7c\x02\x24\x23\x03\x02\x02\x02\x25\x26\x03\x02\x02\x02\ - \x26\x24\x03\x02\x02\x02\x26\x27\x03\x02\x02\x02\x27\x10\x03\x02\x02\x02\ - \x28\x2a\x04\x32\x3b\x02\x29\x28\x03\x02\x02\x02\x2a\x2b\x03\x02\x02\x02\ - \x2b\x29\x03\x02\x02\x02\x2b\x2c\x03\x02\x02\x02\x2c\x12\x03\x02\x02\x02\ - \x2d\x2e\x09\x02\x02\x02\x2e\x2f\x03\x02\x02\x02\x2f\x30\x08\x0a\x02\x02\ - \x30\x14\x03\x02\x02\x02\x05\x02\x26\x2b\x03\x08\x02\x02"; diff --git a/tests/gen/labelslistener.rs b/tests/gen/labelslistener.rs deleted file mode 100644 index 2448b8a..0000000 --- a/tests/gen/labelslistener.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from Labels.g4 by ANTLR 4.8 -use super::labelsparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : LabelsListener<'input> } diff --git a/tests/gen/labelsparser.rs b/tests/gen/labelsparser.rs deleted file mode 100644 index 2f93a7a..0000000 --- a/tests/gen/labelsparser.rs +++ /dev/null @@ -1,1462 +0,0 @@ -// Generated from Labels.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::labelslistener::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::lazy_static; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const T__0: isize = 1; -pub const T__1: isize = 2; -pub const T__2: isize = 3; -pub const T__3: isize = 4; -pub const T__4: isize = 5; -pub const T__5: isize = 6; -pub const ID: isize = 7; -pub const INT: isize = 8; -pub const WS: isize = 9; -pub const RULE_s: usize = 0; -pub const RULE_e: usize = 1; -pub const ruleNames: [&'static str; 2] = ["s", "e"]; - -pub const _LITERAL_NAMES: [Option<&'static str>; 7] = [ - None, - Some("'*'"), - Some("'+'"), - Some("'('"), - Some("')'"), - Some("'++'"), - Some("'--'"), -]; -pub const _SYMBOLIC_NAMES: [Option<&'static str>; 10] = [ - None, - None, - None, - None, - None, - None, - None, - Some("ID"), - Some("INT"), - Some("WS"), -]; -lazy_static! { - static ref _shared_context_cache: Arc = - 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>; - -/// Parser for Labels grammar -pub struct LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - LabelsParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> LabelsParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> LabelsParser<'input, I, DefaultErrorStrategy<'input, LabelsParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for LabelsParser -pub trait LabelsParserContext<'input>: - for<'x> Listenable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = LabelsParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : LabelsParserContext<'input> } - -impl<'input> LabelsParserContext<'input> for TerminalNode<'input, LabelsParserContextType> {} -impl<'input> LabelsParserContext<'input> for ErrorNode<'input, LabelsParserContextType> {} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn LabelsParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn LabelsListener<'input> + 'input } - -pub struct LabelsParserContextType; -antlr_rust::tid! {LabelsParserContextType} - -impl<'input> ParserNodeType<'input> for LabelsParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn LabelsParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct LabelsParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> LabelsParserExt<'input> {} -antlr_rust::tid! { LabelsParserExt<'a> } - -impl<'input> TokenAware<'input> for LabelsParserExt<'input> { - type TF = LocalTokenFactory<'input>; -} - -impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> - ParserRecog<'input, BaseParserType<'input, I>> for LabelsParserExt<'input> -{ -} - -impl<'input, I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>> - Actions<'input, BaseParserType<'input, I>> for LabelsParserExt<'input> -{ - fn get_grammar_file_name(&self) -> &str { - "Labels.g4" - } - - fn get_rule_names(&self) -> &[&str] { - &ruleNames - } - - fn get_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } - fn sempred( - _localctx: Option<&(dyn LabelsParserContext<'input> + 'input)>, - rule_index: isize, - pred_index: isize, - recog: &mut BaseParserType<'input, I>, - ) -> bool { - match rule_index { - 1 => LabelsParser::<'input, I, _>::e_sempred( - _localctx.and_then(|x| x.downcast_ref()), - pred_index, - recog, - ), - _ => true, - } - } -} - -impl<'input, I> LabelsParser<'input, I, DefaultErrorStrategy<'input, LabelsParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - fn e_sempred( - _localctx: Option<&EContext<'input>>, - pred_index: isize, - recog: &mut ::Target, - ) -> bool { - match pred_index { - 0 => recog.precpred(None, 7), - 1 => recog.precpred(None, 6), - 2 => recog.precpred(None, 3), - 3 => recog.precpred(None, 2), - _ => true, - } - } -} -//------------------- s ---------------- -pub type SContextAll<'input> = SContext<'input>; - -pub type SContext<'input> = BaseParserRuleContext<'input, SContextExt<'input>>; - -#[derive(Clone)] -pub struct SContextExt<'input> { - pub q: Option>>, - 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)) { - listener.enter_every_rule(self); - listener.enter_s(self); - } - fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.exit_s(self); - listener.exit_every_rule(self); - } -} - -impl<'input> CustomRuleContext<'input> for SContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_s - } - //fn type_rule_index() -> usize where Self: Sized { RULE_s } -} -antlr_rust::tid! {SContextExt<'a>} - -impl<'input> SContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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, I, H> LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn s(&mut self) -> Result>, 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) - } -} -//------------------- e ---------------- -#[derive(Debug)] -pub enum EContextAll<'input> { - AddContext(AddContext<'input>), - ParensContext(ParensContext<'input>), - MultContext(MultContext<'input>), - DecContext(DecContext<'input>), - AnIDContext(AnIDContext<'input>), - AnIntContext(AnIntContext<'input>), - IncContext(IncContext<'input>), - Error(EContext<'input>), -} -antlr_rust::tid! {EContextAll<'a>} - -impl<'input> antlr_rust::parser_rule_context::DerefSeal for EContextAll<'input> {} - -impl<'input> LabelsParserContext<'input> for EContextAll<'input> {} - -impl<'input> Deref for EContextAll<'input> { - type Target = dyn EContextAttrs<'input> + 'input; - fn deref(&self) -> &Self::Target { - use EContextAll::*; - match self { - AddContext(inner) => inner, - ParensContext(inner) => inner, - MultContext(inner) => inner, - DecContext(inner) => inner, - AnIDContext(inner) => inner, - AnIntContext(inner) => inner, - IncContext(inner) => inner, - Error(inner) => inner, - } - } -} -impl<'input, 'a> Listenable + 'a> for EContextAll<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - self.deref().enter(listener) - } - fn exit(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - self.deref().exit(listener) - } -} - -pub type EContext<'input> = BaseParserRuleContext<'input, EContextExt<'input>>; - -#[derive(Clone)] -pub struct EContextExt<'input> { - pub v: String, - ph: PhantomData<&'input str>, -} - -impl<'input> LabelsParserContext<'input> for EContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for EContext<'input> {} - -impl<'input> CustomRuleContext<'input> for EContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} -antlr_rust::tid! {EContextExt<'a>} - -impl<'input> EContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> Rc> { - Rc::new(EContextAll::Error(BaseParserRuleContext::new_parser_ctx( - parent, - invoking_state, - EContextExt { - v: Default::default(), - 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; - } -} - -impl<'input> EContextAttrs<'input> for EContext<'input> {} - -pub type AddContext<'input> = BaseParserRuleContext<'input, AddContextExt<'input>>; - -pub trait AddContextAttrs<'input>: LabelsParserContext<'input> { - fn e_all(&self) -> Vec>> - 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> {} - -pub struct AddContextExt<'input> { - base: EContextExt<'input>, - pub a: Option>>, - pub b: Option>>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {AddContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for AddContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for AddContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_add(self); - } -} - -impl<'input> CustomRuleContext<'input> for AddContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ))) - } -} - -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) - } -} - -impl<'input> ParensContextAttrs<'input> for ParensContext<'input> {} - -pub struct ParensContextExt<'input> { - base: EContextExt<'input>, - pub x: Option>>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {ParensContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for ParensContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for ParensContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_parens(self); - } -} - -impl<'input> CustomRuleContext<'input> for ParensContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ), - )) - } -} - -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) - } -} - -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>, -} - -antlr_rust::tid! {MultContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for MultContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for MultContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_mult(self); - } -} - -impl<'input> CustomRuleContext<'input> for MultContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ))) - } -} - -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) - } -} - -impl<'input> DecContextAttrs<'input> for DecContext<'input> {} - -pub struct DecContextExt<'input> { - base: EContextExt<'input>, - pub x: Option>>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {DecContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for DecContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for DecContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_dec(self); - } -} - -impl<'input> CustomRuleContext<'input> for DecContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ))) - } -} - -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(ID, 0) - } -} - -impl<'input> AnIDContextAttrs<'input> for AnIDContext<'input> {} - -pub struct AnIDContextExt<'input> { - base: EContextExt<'input>, - pub ID: Option>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {AnIDContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for AnIDContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for AnIDContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_anID(self); - } -} - -impl<'input> CustomRuleContext<'input> for AnIDContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ))) - } -} - -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(INT, 0) - } -} - -impl<'input> AnIntContextAttrs<'input> for AnIntContext<'input> {} - -pub struct AnIntContextExt<'input> { - base: EContextExt<'input>, - pub INT: Option>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {AnIntContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for AnIntContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for AnIntContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_anInt(self); - } -} - -impl<'input> CustomRuleContext<'input> for AnIntContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, - }, - ))) - } -} - -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) - } -} - -impl<'input> IncContextAttrs<'input> for IncContext<'input> {} - -pub struct IncContextExt<'input> { - base: EContextExt<'input>, - pub x: Option>>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {IncContextExt<'a>} - -impl<'input> LabelsParserContext<'input> for IncContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for IncContext<'input> { - fn enter(&self, listener: &mut (dyn LabelsListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_inc(self); - } -} - -impl<'input> CustomRuleContext<'input> for IncContextExt<'input> { - type TF = LocalTokenFactory<'input>; - type Ctx = LabelsParserContextType; - fn get_rule_index(&self) -> usize { - RULE_e - } - //fn type_rule_index() -> usize where Self: Sized { RULE_e } -} - -impl<'input> Borrow> 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> 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, I, H> LabelsParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn e(&mut self) -> Result>, ANTLRError> { - self.e_rec(0) - } - - fn e_rec(&mut self, _p: isize) -> 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: isize; - //recog.base.enter_outer_alt(_localctx.clone(), 1); - recog.base.enter_outer_alt(None, 1); - { - recog.base.set_state(16); - recog.err_handler.sync(&mut recog.base)?; - match recog.base.input.la(1) { - INT => { - let mut tmp = AnIntContextExt::new(&**_localctx); - recog.ctx = Some(tmp.clone()); - _localctx = tmp; - _prevctx = _localctx.clone(); - - recog.base.set_state(7); - let tmp = recog.base.match_token(INT, &mut recog.err_handler)?; - if let EContextAll::AnIntContext(ctx) = - cast_mut::<_, EContextAll>(&mut _localctx) - { - ctx.INT = Some(tmp.clone()); - } else { - unreachable!("cant cast"); - } - - let tmp = { - if let Some(it) = &if let EContextAll::AnIntContext(ctx) = - cast::<_, EContextAll>(&*_localctx) - { - ctx - } else { - 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"); - } - } - - 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(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(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"); - } - } - } - - 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(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 !({ 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(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 !({ 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(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 !({ 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(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 !({ 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(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(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x0b\x2a\x04\x02\x09\x02\x04\x03\x09\x03\x03\x02\x03\x02\x03\x03\x03\x03\ - \x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x05\x03\ - \x13\x0a\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\ - \x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x07\ - \x03\x25\x0a\x03\x0c\x03\x0e\x03\x28\x0b\x03\x03\x03\x02\x03\x04\x04\x02\ - \x04\x02\x02\x02\x2d\x02\x06\x03\x02\x02\x02\x04\x12\x03\x02\x02\x02\x06\ - \x07\x05\x04\x03\x02\x07\x03\x03\x02\x02\x02\x08\x09\x08\x03\x01\x02\x09\ - \x0a\x07\x0a\x02\x02\x0a\x13\x08\x03\x01\x02\x0b\x0c\x07\x05\x02\x02\x0c\ - \x0d\x05\x04\x03\x02\x0d\x0e\x07\x06\x02\x02\x0e\x0f\x08\x03\x01\x02\x0f\ - \x13\x03\x02\x02\x02\x10\x11\x07\x09\x02\x02\x11\x13\x08\x03\x01\x02\x12\ - \x08\x03\x02\x02\x02\x12\x0b\x03\x02\x02\x02\x12\x10\x03\x02\x02\x02\x13\ - \x26\x03\x02\x02\x02\x14\x15\x0c\x09\x02\x02\x15\x16\x07\x03\x02\x02\x16\ - \x17\x05\x04\x03\x0a\x17\x18\x08\x03\x01\x02\x18\x25\x03\x02\x02\x02\x19\ - \x1a\x0c\x08\x02\x02\x1a\x1b\x07\x04\x02\x02\x1b\x1c\x05\x04\x03\x09\x1c\ - \x1d\x08\x03\x01\x02\x1d\x25\x03\x02\x02\x02\x1e\x1f\x0c\x05\x02\x02\x1f\ - \x20\x07\x07\x02\x02\x20\x25\x08\x03\x01\x02\x21\x22\x0c\x04\x02\x02\x22\ - \x23\x07\x08\x02\x02\x23\x25\x08\x03\x01\x02\x24\x14\x03\x02\x02\x02\x24\ - \x19\x03\x02\x02\x02\x24\x1e\x03\x02\x02\x02\x24\x21\x03\x02\x02\x02\x25\ - \x28\x03\x02\x02\x02\x26\x24\x03\x02\x02\x02\x26\x27\x03\x02\x02\x02\x27\ - \x05\x03\x02\x02\x02\x28\x26\x03\x02\x02\x02\x05\x12\x24\x26"; diff --git a/tests/gen/referencetoatnlexer.rs b/tests/gen/referencetoatnlexer.rs deleted file mode 100644 index 28c9291..0000000 --- a/tests/gen/referencetoatnlexer.rs +++ /dev/null @@ -1,203 +0,0 @@ -// Generated from ReferenceToATN.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const ID: isize = 1; -pub const ATN: isize = 2; -pub const WS: isize = 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 LocalTokenFactory<'input> = antlr_rust::token_factory::OwningTokenFactory; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct ReferenceToATNLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, ReferenceToATNLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> ReferenceToATNLexer<'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 { - "ReferenceToATNLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 {} - -impl ReferenceToATNLexerActions {} - -impl<'input, Input: CharStream>> - Actions<'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, Input: CharStream>> TokenSource<'input> - for ReferenceToATNLexer<'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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x05\x17\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x04\x04\x09\x04\x03\x02\ - \x06\x02\x0b\x0a\x02\x0d\x02\x0e\x02\x0c\x03\x03\x06\x03\x10\x0a\x03\x0d\ - \x03\x0e\x03\x11\x03\x04\x03\x04\x03\x04\x03\x04\x02\x02\x05\x03\x03\x05\ - \x04\x07\x05\x03\x02\x03\x04\x02\x0c\x0c\x22\x22\x02\x18\x02\x03\x03\x02\ - \x02\x02\x02\x05\x03\x02\x02\x02\x02\x07\x03\x02\x02\x02\x03\x0a\x03\x02\ - \x02\x02\x05\x0f\x03\x02\x02\x02\x07\x13\x03\x02\x02\x02\x09\x0b\x04\x63\ - \x7c\x02\x0a\x09\x03\x02\x02\x02\x0b\x0c\x03\x02\x02\x02\x0c\x0a\x03\x02\ - \x02\x02\x0c\x0d\x03\x02\x02\x02\x0d\x04\x03\x02\x02\x02\x0e\x10\x04\x32\ - \x3b\x02\x0f\x0e\x03\x02\x02\x02\x10\x11\x03\x02\x02\x02\x11\x0f\x03\x02\ - \x02\x02\x11\x12\x03\x02\x02\x02\x12\x06\x03\x02\x02\x02\x13\x14\x09\x02\ - \x02\x02\x14\x15\x03\x02\x02\x02\x15\x16\x08\x04\x02\x02\x16\x08\x03\x02\ - \x02\x02\x05\x02\x0c\x11\x03\x08\x02\x02"; diff --git a/tests/gen/referencetoatnlistener.rs b/tests/gen/referencetoatnlistener.rs deleted file mode 100644 index c4208b7..0000000 --- a/tests/gen/referencetoatnlistener.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from ReferenceToATN.g4 by ANTLR 4.8 -use super::referencetoatnparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : ReferenceToATNListener<'input> } diff --git a/tests/gen/referencetoatnparser.rs b/tests/gen/referencetoatnparser.rs deleted file mode 100644 index 2b72959..0000000 --- a/tests/gen/referencetoatnparser.rs +++ /dev/null @@ -1,414 +0,0 @@ -// Generated from ReferenceToATN.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::referencetoatnlistener::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::lazy_static; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const ID: isize = 1; -pub const ATN: isize = 2; -pub const WS: isize = 3; -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 TokenType<'input> = as TokenFactory<'input>>::Tok; - -pub type LocalTokenFactory<'input> = antlr_rust::token_factory::OwningTokenFactory; - -pub type ReferenceToATNTreeWalker<'input, 'a> = ParseTreeWalker< - 'input, - 'a, - ReferenceToATNParserContextType, - dyn ReferenceToATNListener<'input> + 'a, ->; - -/// Parser for ReferenceToATN grammar -pub struct ReferenceToATNParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> ReferenceToATNParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - ReferenceToATNParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> ReferenceToATNParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> - ReferenceToATNParser<'input, I, DefaultErrorStrategy<'input, ReferenceToATNParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for ReferenceToATNParser -pub trait ReferenceToATNParserContext<'input>: for<'x> Listenable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = ReferenceToATNParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : ReferenceToATNParserContext<'input> } - -impl<'input> ReferenceToATNParserContext<'input> - for TerminalNode<'input, ReferenceToATNParserContextType> -{ -} -impl<'input> ReferenceToATNParserContext<'input> - for ErrorNode<'input, ReferenceToATNParserContextType> -{ -} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn ReferenceToATNParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn ReferenceToATNListener<'input> + 'input } - -pub struct ReferenceToATNParserContextType; -antlr_rust::tid! {ReferenceToATNParserContextType} - -impl<'input> ParserNodeType<'input> for ReferenceToATNParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn ReferenceToATNParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for ReferenceToATNParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for ReferenceToATNParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct ReferenceToATNParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> ReferenceToATNParserExt<'input> {} -antlr_rust::tid! { ReferenceToATNParserExt<'a> } - -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>> - 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_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } -} -//------------------- a ---------------- -pub type AContextAll<'input> = AContext<'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)) { - listener.enter_every_rule(self); - listener.enter_a(self); - } - fn exit(&self, listener: &mut (dyn ReferenceToATNListener<'input> + 'a)) { - listener.exit_a(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {AContextExt<'a>} - -impl<'input> AContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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(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(ID, i) - } -} - -impl<'input> AContextAttrs<'input> for AContext<'input> {} - -impl<'input, I, H> ReferenceToATNParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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: isize = -1; - let result: Result<(), ANTLRError> = (|| { - let mut _alt: isize; - //recog.base.enter_outer_alt(_localctx.clone(), 1); - recog.base.enter_outer_alt(None, 1); - { - recog.base.set_state(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 == ID || _la == 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 == ATN { - { - recog.base.set_state(8); - recog.base.match_token(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! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x05\x10\x04\x02\x09\x02\x03\x02\x07\x02\x06\x0a\x02\x0c\x02\x0e\x02\x09\ - \x0b\x02\x03\x02\x05\x02\x0c\x0a\x02\x03\x02\x03\x02\x03\x02\x02\x02\x03\ - \x02\x02\x03\x03\x02\x03\x04\x02\x10\x02\x07\x03\x02\x02\x02\x04\x06\x09\ - \x02\x02\x02\x05\x04\x03\x02\x02\x02\x06\x09\x03\x02\x02\x02\x07\x05\x03\ - \x02\x02\x02\x07\x08\x03\x02\x02\x02\x08\x0b\x03\x02\x02\x02\x09\x07\x03\ - \x02\x02\x02\x0a\x0c\x07\x04\x02\x02\x0b\x0a\x03\x02\x02\x02\x0b\x0c\x03\ - \x02\x02\x02\x0c\x0d\x03\x02\x02\x02\x0d\x0e\x08\x02\x01\x02\x0e\x03\x03\ - \x02\x02\x02\x04\x07\x0b"; diff --git a/tests/gen/simplelrlexer.rs b/tests/gen/simplelrlexer.rs deleted file mode 100644 index 2a06f23..0000000 --- a/tests/gen/simplelrlexer.rs +++ /dev/null @@ -1,193 +0,0 @@ -// Generated from SimpleLR.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const ID: isize = 1; -pub const WS: isize = 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>>, -} - -antlr_rust::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 { - antlr_rust::recognizer::check_version("0", "3"); - 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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x04\x10\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x03\x02\x06\x02\x09\x0a\ - \x02\x0d\x02\x0e\x02\x0a\x03\x03\x03\x03\x03\x03\x03\x03\x02\x02\x04\x03\ - \x03\x05\x04\x03\x02\x03\x04\x02\x0c\x0c\x22\x22\x02\x10\x02\x03\x03\x02\ - \x02\x02\x02\x05\x03\x02\x02\x02\x03\x08\x03\x02\x02\x02\x05\x0c\x03\x02\ - \x02\x02\x07\x09\x04\x63\x7c\x02\x08\x07\x03\x02\x02\x02\x09\x0a\x03\x02\ - \x02\x02\x0a\x08\x03\x02\x02\x02\x0a\x0b\x03\x02\x02\x02\x0b\x04\x03\x02\ - \x02\x02\x0c\x0d\x09\x02\x02\x02\x0d\x0e\x03\x02\x02\x02\x0e\x0f\x08\x03\ - \x02\x02\x0f\x06\x03\x02\x02\x02\x04\x02\x0a\x03\x08\x02\x02"; diff --git a/tests/gen/simplelrlistener.rs b/tests/gen/simplelrlistener.rs deleted file mode 100644 index 89e9d5f..0000000 --- a/tests/gen/simplelrlistener.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from SimpleLR.g4 by ANTLR 4.8 -use super::simplelrparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : SimpleLRListener<'input> } diff --git a/tests/gen/simplelrparser.rs b/tests/gen/simplelrparser.rs deleted file mode 100644 index 9355d53..0000000 --- a/tests/gen/simplelrparser.rs +++ /dev/null @@ -1,513 +0,0 @@ -// Generated from SimpleLR.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::simplelrlistener::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::lazy_static; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const ID: isize = 1; -pub const WS: isize = 2; -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 TokenType<'input> = as TokenFactory<'input>>::Tok; -pub type LocalTokenFactory<'input> = CommonTokenFactory; - -pub type SimpleLRTreeWalker<'input, 'a> = - ParseTreeWalker<'input, 'a, SimpleLRParserContextType, dyn SimpleLRListener<'input> + 'a>; - -/// Parser for SimpleLR grammar -pub struct SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - SimpleLRParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> SimpleLRParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> SimpleLRParser<'input, I, DefaultErrorStrategy<'input, SimpleLRParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for SimpleLRParser -pub trait SimpleLRParserContext<'input>: - for<'x> Listenable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = SimpleLRParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : SimpleLRParserContext<'input> } - -impl<'input> SimpleLRParserContext<'input> for TerminalNode<'input, SimpleLRParserContextType> {} -impl<'input> SimpleLRParserContext<'input> for ErrorNode<'input, SimpleLRParserContextType> {} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn SimpleLRParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn SimpleLRListener<'input> + 'input } - -pub struct SimpleLRParserContextType; -antlr_rust::tid! {SimpleLRParserContextType} - -impl<'input> ParserNodeType<'input> for SimpleLRParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn SimpleLRParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct SimpleLRParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> SimpleLRParserExt<'input> {} -antlr_rust::tid! { SimpleLRParserExt<'a> } - -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>> - 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_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } - fn sempred( - _localctx: Option<&(dyn SimpleLRParserContext<'input> + 'input)>, - rule_index: isize, - pred_index: isize, - 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, DefaultErrorStrategy<'input, SimpleLRParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - fn a_sempred( - _localctx: Option<&AContext<'input>>, - pred_index: isize, - 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>>; - -#[derive(Clone)] -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)) { - listener.enter_every_rule(self); - listener.enter_s(self); - } - fn exit(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) { - listener.exit_s(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {SContextExt<'a>} - -impl<'input> SContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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, I, H> SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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) - } -} -//------------------- a ---------------- -pub type AContextAll<'input> = AContext<'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)) { - listener.enter_every_rule(self); - listener.enter_a(self); - } - fn exit(&self, listener: &mut (dyn SimpleLRListener<'input> + 'a)) { - listener.exit_a(self); - listener.exit_every_rule(self); - } -} - -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 } -} -antlr_rust::tid! {AContextExt<'a>} - -impl<'input> AContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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(ID, 0) - } - fn a(&self) -> Option>> - where - Self: Sized, - { - self.child_of_type(0) - } -} - -impl<'input> AContextAttrs<'input> for AContext<'input> {} - -impl<'input, I, H> SimpleLRParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn a(&mut self) -> Result>, ANTLRError> { - self.a_rec(0) - } - - fn a_rec(&mut self, _p: isize) -> 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: isize; - //recog.base.enter_outer_alt(_localctx.clone(), 1); - recog.base.enter_outer_alt(None, 1); - { - { - recog.base.set_state(7); - recog.base.match_token(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 !({ 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(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! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x04\x13\x04\x02\x09\x02\x04\x03\x09\x03\x03\x02\x03\x02\x03\x03\x03\x03\ - \x03\x03\x03\x03\x03\x03\x07\x03\x0e\x0a\x03\x0c\x03\x0e\x03\x11\x0b\x03\ - \x03\x03\x02\x03\x04\x04\x02\x04\x02\x02\x02\x11\x02\x06\x03\x02\x02\x02\ - \x04\x08\x03\x02\x02\x02\x06\x07\x05\x04\x03\x02\x07\x03\x03\x02\x02\x02\ - \x08\x09\x08\x03\x01\x02\x09\x0a\x07\x03\x02\x02\x0a\x0f\x03\x02\x02\x02\ - \x0b\x0c\x0c\x04\x02\x02\x0c\x0e\x07\x03\x02\x02\x0d\x0b\x03\x02\x02\x02\ - \x0e\x11\x03\x02\x02\x02\x0f\x0d\x03\x02\x02\x02\x0f\x10\x03\x02\x02\x02\ - \x10\x05\x03\x02\x02\x02\x11\x0f\x03\x02\x02\x02\x03\x0f"; diff --git a/tests/gen/visitorbasiclexer.rs b/tests/gen/visitorbasiclexer.rs deleted file mode 100644 index 4f81bd8..0000000 --- a/tests/gen/visitorbasiclexer.rs +++ /dev/null @@ -1,191 +0,0 @@ -// Generated from VisitorBasic.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const A: isize = 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 _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 LocalTokenFactory<'input> = CommonTokenFactory; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct VisitorBasicLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, VisitorBasicLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> VisitorBasicLexer<'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 { - "VisitorBasicLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 {} - -impl VisitorBasicLexerActions {} - -impl<'input, Input: CharStream>> - Actions<'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, Input: CharStream>> TokenSource<'input> - for VisitorBasicLexer<'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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x03\x07\x08\x01\x04\x02\x09\x02\x03\x02\x03\x02\x02\x02\x03\x03\x03\x03\ - \x02\x02\x02\x06\x02\x03\x03\x02\x02\x02\x03\x05\x03\x02\x02\x02\x05\x06\ - \x07\x43\x02\x02\x06\x04\x03\x02\x02\x02\x03\x02\x02"; diff --git a/tests/gen/visitorbasiclistener.rs b/tests/gen/visitorbasiclistener.rs deleted file mode 100644 index d87b335..0000000 --- a/tests/gen/visitorbasiclistener.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from VisitorBasic.g4 by ANTLR 4.8 -use super::visitorbasicparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : VisitorBasicListener<'input> } diff --git a/tests/gen/visitorbasicparser.rs b/tests/gen/visitorbasicparser.rs deleted file mode 100644 index 94fc461..0000000 --- a/tests/gen/visitorbasicparser.rs +++ /dev/null @@ -1,367 +0,0 @@ -// Generated from VisitorBasic.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::visitorbasiclistener::*; -use super::visitorbasicvisitor::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::lazy_static; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const A: isize = 1; -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 TokenType<'input> = as TokenFactory<'input>>::Tok; -pub type LocalTokenFactory<'input> = CommonTokenFactory; - -pub type VisitorBasicTreeWalker<'input, 'a> = ParseTreeWalker< - 'input, - 'a, - VisitorBasicParserContextType, - dyn VisitorBasicListener<'input> + 'a, ->; - -/// Parser for VisitorBasic grammar -pub struct VisitorBasicParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> VisitorBasicParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - VisitorBasicParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> VisitorBasicParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> - VisitorBasicParser<'input, I, DefaultErrorStrategy<'input, VisitorBasicParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for VisitorBasicParser -pub trait VisitorBasicParserContext<'input>: - for<'x> Listenable + 'x> - + for<'x> Visitable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = VisitorBasicParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : VisitorBasicParserContext<'input> } - -impl<'input, 'x, T> VisitableDyn for dyn VisitorBasicParserContext<'input> + 'input -where - T: VisitorBasicVisitor<'input> + 'x, -{ - fn accept_dyn(&self, visitor: &mut T) { - self.accept(visitor as &mut (dyn VisitorBasicVisitor<'input> + 'x)) - } -} - -impl<'input> VisitorBasicParserContext<'input> - for TerminalNode<'input, VisitorBasicParserContextType> -{ -} -impl<'input> VisitorBasicParserContext<'input> - for ErrorNode<'input, VisitorBasicParserContextType> -{ -} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn VisitorBasicParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn VisitorBasicListener<'input> + 'input } - -pub struct VisitorBasicParserContextType; -antlr_rust::tid! {VisitorBasicParserContextType} - -impl<'input> ParserNodeType<'input> for VisitorBasicParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn VisitorBasicParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for VisitorBasicParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for VisitorBasicParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct VisitorBasicParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> VisitorBasicParserExt<'input> {} -antlr_rust::tid! { VisitorBasicParserExt<'a> } - -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>> - 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_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } -} -//------------------- s ---------------- -pub type SContextAll<'input> = SContext<'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)) { - listener.enter_every_rule(self); - listener.enter_s(self); - } - fn exit(&self, listener: &mut (dyn VisitorBasicListener<'input> + 'a)) { - listener.exit_s(self); - listener.exit_every_rule(self); - } -} - -impl<'input, 'a> Visitable + 'a> for SContext<'input> { - fn accept(&self, visitor: &mut (dyn VisitorBasicVisitor<'input> + 'a)) { - visitor.visit_s(self); - } -} - -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 } -} -antlr_rust::tid! {SContextExt<'a>} - -impl<'input> SContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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(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(EOF, 0) - } -} - -impl<'input> SContextAttrs<'input> for SContext<'input> {} - -impl<'input, I, H> VisitorBasicParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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(A, &mut recog.err_handler)?; - - recog.base.set_state(3); - recog.base.match_token(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! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x03\x08\x04\x02\x09\x02\x03\x02\x03\x02\x03\x02\x03\x02\x02\x02\x03\x02\ - \x02\x02\x02\x06\x02\x04\x03\x02\x02\x02\x04\x05\x07\x03\x02\x02\x05\x06\ - \x07\x02\x02\x03\x06\x03\x03\x02\x02\x02\x02"; diff --git a/tests/gen/visitorbasicvisitor.rs b/tests/gen/visitorbasicvisitor.rs deleted file mode 100644 index 9c8d027..0000000 --- a/tests/gen/visitorbasicvisitor.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from VisitorBasic.g4 by ANTLR 4.8 -use super::visitorbasicparser::*; -use antlr_rust::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 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 -where - T: VisitorBasicVisitorCompat<'input>, -{ - fn visit_s(&mut self, ctx: &SContext<'input>) { - let result = ::visit_s(self, ctx); - *::temp_result(self) = result; - } -} diff --git a/tests/gen/visitorcalclexer.rs b/tests/gen/visitorcalclexer.rs deleted file mode 100644 index b4dc3a7..0000000 --- a/tests/gen/visitorcalclexer.rs +++ /dev/null @@ -1,224 +0,0 @@ -// Generated from VisitorCalc.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const INT: isize = 1; -pub const MUL: isize = 2; -pub const DIV: isize = 3; -pub const ADD: isize = 4; -pub const SUB: isize = 5; -pub const WS: isize = 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 LocalTokenFactory<'input> = CommonTokenFactory; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct VisitorCalcLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, VisitorCalcLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> VisitorCalcLexer<'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 { - "VisitorCalcLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 {} - -impl VisitorCalcLexerActions {} - -impl<'input, Input: CharStream>> - Actions<'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, Input: CharStream>> TokenSource<'input> - for VisitorCalcLexer<'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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x08\x23\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x04\x04\x09\x04\x04\x05\ - \x09\x05\x04\x06\x09\x06\x04\x07\x09\x07\x03\x02\x06\x02\x11\x0a\x02\x0d\ - \x02\x0e\x02\x12\x03\x03\x03\x03\x03\x04\x03\x04\x03\x05\x03\x05\x03\x06\ - \x03\x06\x03\x07\x06\x07\x1e\x0a\x07\x0d\x07\x0e\x07\x1f\x03\x07\x03\x07\ - \x02\x02\x08\x03\x03\x05\x04\x07\x05\x09\x06\x0b\x07\x0d\x08\x03\x02\x04\ - \x03\x02\x32\x3b\x04\x02\x0b\x0b\x22\x22\x02\x24\x02\x03\x03\x02\x02\x02\ - \x02\x05\x03\x02\x02\x02\x02\x07\x03\x02\x02\x02\x02\x09\x03\x02\x02\x02\ - \x02\x0b\x03\x02\x02\x02\x02\x0d\x03\x02\x02\x02\x03\x10\x03\x02\x02\x02\ - \x05\x14\x03\x02\x02\x02\x07\x16\x03\x02\x02\x02\x09\x18\x03\x02\x02\x02\ - \x0b\x1a\x03\x02\x02\x02\x0d\x1d\x03\x02\x02\x02\x0f\x11\x09\x02\x02\x02\ - \x10\x0f\x03\x02\x02\x02\x11\x12\x03\x02\x02\x02\x12\x10\x03\x02\x02\x02\ - \x12\x13\x03\x02\x02\x02\x13\x04\x03\x02\x02\x02\x14\x15\x07\x2c\x02\x02\ - \x15\x06\x03\x02\x02\x02\x16\x17\x07\x31\x02\x02\x17\x08\x03\x02\x02\x02\ - \x18\x19\x07\x2d\x02\x02\x19\x0a\x03\x02\x02\x02\x1a\x1b\x07\x2f\x02\x02\ - \x1b\x0c\x03\x02\x02\x02\x1c\x1e\x09\x03\x02\x02\x1d\x1c\x03\x02\x02\x02\ - \x1e\x1f\x03\x02\x02\x02\x1f\x1d\x03\x02\x02\x02\x1f\x20\x03\x02\x02\x02\ - \x20\x21\x03\x02\x02\x02\x21\x22\x08\x07\x02\x02\x22\x0e\x03\x02\x02\x02\ - \x05\x02\x12\x1f\x03\x02\x03\x02"; diff --git a/tests/gen/visitorcalclistener.rs b/tests/gen/visitorcalclistener.rs deleted file mode 100644 index 9d95352..0000000 --- a/tests/gen/visitorcalclistener.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from VisitorCalc.g4 by ANTLR 4.8 -use super::visitorcalcparser::*; -use antlr_rust::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>) {} -} - -antlr_rust::coerce_from! { 'input : VisitorCalcListener<'input> } diff --git a/tests/gen/visitorcalcparser.rs b/tests/gen/visitorcalcparser.rs deleted file mode 100644 index c354274..0000000 --- a/tests/gen/visitorcalcparser.rs +++ /dev/null @@ -1,927 +0,0 @@ -// Generated from VisitorCalc.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_mut)] -#![allow(unused_braces)] -use super::visitorcalclistener::*; -use super::visitorcalcvisitor::*; -use antlr_rust::atn::{ATN, INVALID_ALT}; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::dfa::DFA; -use antlr_rust::error_strategy::{DefaultErrorStrategy, ErrorStrategy}; -use antlr_rust::errors::*; -use antlr_rust::int_stream::EOF; -use antlr_rust::parser::{BaseParser, Parser, ParserNodeType, ParserRecog}; -use antlr_rust::parser_atn_simulator::ParserATNSimulator; -use antlr_rust::parser_rule_context::{cast, cast_mut, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, CustomRuleContext, RuleContext}; -use antlr_rust::token::{OwningToken, Token, TOKEN_EOF}; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::*; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::lazy_static; -use antlr_rust::{TidAble, TidExt}; - -use std::any::{Any, TypeId}; -use std::borrow::{Borrow, BorrowMut}; -use std::cell::RefCell; -use std::convert::TryFrom; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const INT: isize = 1; -pub const MUL: isize = 2; -pub const DIV: isize = 3; -pub const ADD: isize = 4; -pub const SUB: isize = 5; -pub const WS: isize = 6; -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>; - -/// Parser for VisitorCalc grammar -pub struct VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - base: BaseParserType<'input, I>, - interpreter: Arc, - _shared_context_cache: Box, - pub err_handler: H, -} - -impl<'input, I, H> VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn get_serialized_atn() -> &'static str { - _serializedATN - } - - pub fn set_error_strategy(&mut self, strategy: H) { - self.err_handler = strategy - } - - pub fn with_strategy(input: I, strategy: H) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - let interpreter = Arc::new(ParserATNSimulator::new( - _ATN.clone(), - _decision_to_DFA.clone(), - _shared_context_cache.clone(), - )); - Self { - base: BaseParser::new_base_parser( - input, - Arc::clone(&interpreter), - VisitorCalcParserExt { - _pd: Default::default(), - }, - ), - interpreter, - _shared_context_cache: Box::new(PredictionContextCache::new()), - err_handler: strategy, - } - } -} - -type DynStrategy<'input, I> = Box> + 'input>; - -impl<'input, I> VisitorCalcParser<'input, I, DynStrategy<'input, I>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn with_dyn_strategy(input: I) -> Self { - Self::with_strategy(input, Box::new(DefaultErrorStrategy::new())) - } -} - -impl<'input, I> - VisitorCalcParser<'input, I, DefaultErrorStrategy<'input, VisitorCalcParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - pub fn new(input: I) -> Self { - Self::with_strategy(input, DefaultErrorStrategy::new()) - } -} - -/// Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for VisitorCalcParser -pub trait VisitorCalcParserContext<'input>: - for<'x> Listenable + 'x> - + for<'x> Visitable + 'x> - + ParserRuleContext<'input, TF = LocalTokenFactory<'input>, Ctx = VisitorCalcParserContextType> -{ -} - -antlr_rust::coerce_from! { 'input : VisitorCalcParserContext<'input> } - -impl<'input, 'x, T> VisitableDyn for dyn VisitorCalcParserContext<'input> + 'input -where - T: VisitorCalcVisitor<'input> + 'x, -{ - fn accept_dyn(&self, visitor: &mut T) { - self.accept(visitor as &mut (dyn VisitorCalcVisitor<'input> + 'x)) - } -} - -impl<'input> VisitorCalcParserContext<'input> - for TerminalNode<'input, VisitorCalcParserContextType> -{ -} -impl<'input> VisitorCalcParserContext<'input> for ErrorNode<'input, VisitorCalcParserContextType> {} - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn VisitorCalcParserContext<'input> + 'input } - -antlr_rust::tid! { impl<'input> TidAble<'input> for dyn VisitorCalcListener<'input> + 'input } - -pub struct VisitorCalcParserContextType; -antlr_rust::tid! {VisitorCalcParserContextType} - -impl<'input> ParserNodeType<'input> for VisitorCalcParserContextType { - type TF = LocalTokenFactory<'input>; - type Type = dyn VisitorCalcParserContext<'input> + 'input; -} - -impl<'input, I, H> Deref for VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - type Target = BaseParserType<'input, I>; - - fn deref(&self) -> &Self::Target { - &self.base - } -} - -impl<'input, I, H> DerefMut for VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.base - } -} - -pub struct VisitorCalcParserExt<'input> { - _pd: PhantomData<&'input str>, -} - -impl<'input> VisitorCalcParserExt<'input> {} -antlr_rust::tid! { VisitorCalcParserExt<'a> } - -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>> - 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_vocabulary(&self) -> &dyn Vocabulary { - &**VOCABULARY - } - fn sempred( - _localctx: Option<&(dyn VisitorCalcParserContext<'input> + 'input)>, - rule_index: isize, - pred_index: isize, - 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, DefaultErrorStrategy<'input, VisitorCalcParserContextType>> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, -{ - fn expr_sempred( - _localctx: Option<&ExprContext<'input>>, - pred_index: isize, - 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>>; - -#[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)) { - listener.enter_every_rule(self); - listener.enter_s(self); - } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.exit_s(self); - listener.exit_every_rule(self); - } -} - -impl<'input, 'a> Visitable + 'a> for SContext<'input> { - fn accept(&self, visitor: &mut (dyn VisitorCalcVisitor<'input> + 'a)) { - visitor.visit_s(self); - } -} - -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 } -} -antlr_rust::tid! {SContextExt<'a>} - -impl<'input> SContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> 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(EOF, 0) - } -} - -impl<'input> SContextAttrs<'input> for SContext<'input> {} - -impl<'input, I, H> VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - 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(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>), -} -antlr_rust::tid! {ExprContextAll<'a>} - -impl<'input> antlr_rust::parser_rule_context::DerefSeal 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, '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)) { - self.deref().enter(listener) - } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - self.deref().exit(listener) - } -} - -pub type ExprContext<'input> = BaseParserRuleContext<'input, ExprContextExt<'input>>; - -#[derive(Clone)] -pub struct ExprContextExt<'input> { - ph: PhantomData<&'input str>, -} - -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> 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 } -} -antlr_rust::tid! {ExprContextExt<'a>} - -impl<'input> ExprContextExt<'input> { - fn new( - parent: Option + 'input>>, - invoking_state: isize, - ) -> Rc> { - Rc::new(ExprContextAll::Error( - BaseParserRuleContext::new_parser_ctx( - parent, - invoking_state, - ExprContextExt { ph: PhantomData }, - ), - )) - } -} - -pub trait ExprContextAttrs<'input>: - VisitorCalcParserContext<'input> + BorrowMut> -{ -} - -impl<'input> ExprContextAttrs<'input> for ExprContext<'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(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(SUB, 0) - } -} - -impl<'input> AddContextAttrs<'input> for AddContext<'input> {} - -pub struct AddContextExt<'input> { - base: ExprContextExt<'input>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {AddContextExt<'a>} - -impl<'input> VisitorCalcParserContext<'input> for AddContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for AddContext<'input> { - fn enter(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_add(self); - } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.exit_add(self); - listener.exit_every_rule(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> 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> 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, - }, - ), - )) - } -} - -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(INT, 0) - } -} - -impl<'input> NumberContextAttrs<'input> for NumberContext<'input> {} - -pub struct NumberContextExt<'input> { - base: ExprContextExt<'input>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {NumberContextExt<'a>} - -impl<'input> VisitorCalcParserContext<'input> for NumberContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for NumberContext<'input> { - fn enter(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_number(self); - } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.exit_number(self); - listener.exit_every_rule(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> 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> 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, - }, - ), - )) - } -} - -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(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(DIV, 0) - } -} - -impl<'input> MultiplyContextAttrs<'input> for MultiplyContext<'input> {} - -pub struct MultiplyContextExt<'input> { - base: ExprContextExt<'input>, - ph: PhantomData<&'input str>, -} - -antlr_rust::tid! {MultiplyContextExt<'a>} - -impl<'input> VisitorCalcParserContext<'input> for MultiplyContext<'input> {} - -impl<'input, 'a> Listenable + 'a> for MultiplyContext<'input> { - fn enter(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.enter_every_rule(self); - listener.enter_multiply(self); - } - fn exit(&self, listener: &mut (dyn VisitorCalcListener<'input> + 'a)) { - listener.exit_multiply(self); - listener.exit_every_rule(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> 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> 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, I, H> VisitorCalcParser<'input, I, H> -where - I: TokenStream<'input, TF = LocalTokenFactory<'input>> + TidAble<'input>, - H: ErrorStrategy<'input, BaseParserType<'input, I>>, -{ - pub fn expr(&mut self) -> Result>, ANTLRError> { - self.expr_rec(0) - } - - fn expr_rec(&mut self, _p: isize) -> 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: isize = -1; - let result: Result<(), ANTLRError> = (|| { - let mut _alt: isize; - //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(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 !({ 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 == MUL || _la == 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 !({ 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 == ADD || _la == 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(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x03\ - \x08\x18\x04\x02\x09\x02\x04\x03\x09\x03\x03\x02\x03\x02\x03\x02\x03\x03\ - \x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x07\x03\ - \x13\x0a\x03\x0c\x03\x0e\x03\x16\x0b\x03\x03\x03\x02\x03\x04\x04\x02\x04\ - \x02\x04\x03\x02\x04\x05\x03\x02\x06\x07\x02\x17\x02\x06\x03\x02\x02\x02\ - \x04\x09\x03\x02\x02\x02\x06\x07\x05\x04\x03\x02\x07\x08\x07\x02\x02\x03\ - \x08\x03\x03\x02\x02\x02\x09\x0a\x08\x03\x01\x02\x0a\x0b\x07\x03\x02\x02\ - \x0b\x14\x03\x02\x02\x02\x0c\x0d\x0c\x04\x02\x02\x0d\x0e\x09\x02\x02\x02\ - \x0e\x13\x05\x04\x03\x05\x0f\x10\x0c\x03\x02\x02\x10\x11\x09\x03\x02\x02\ - \x11\x13\x05\x04\x03\x04\x12\x0c\x03\x02\x02\x02\x12\x0f\x03\x02\x02\x02\ - \x13\x16\x03\x02\x02\x02\x14\x12\x03\x02\x02\x02\x14\x15\x03\x02\x02\x02\ - \x15\x05\x03\x02\x02\x02\x16\x14\x03\x02\x02\x02\x04\x12\x14"; diff --git a/tests/gen/visitorcalcvisitor.rs b/tests/gen/visitorcalcvisitor.rs deleted file mode 100644 index be022c2..0000000 --- a/tests/gen/visitorcalcvisitor.rs +++ /dev/null @@ -1,111 +0,0 @@ -#![allow(nonstandard_style)] -// Generated from VisitorCalc.g4 by ANTLR 4.8 -use super::visitorcalcparser::*; -use antlr_rust::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) - } - - /** - * 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) - } - - /** - * 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 -where - T: VisitorCalcVisitorCompat<'input>, -{ - 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); - *::temp_result(self) = result; - } - - 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); - *::temp_result(self) = result; - } -} diff --git a/tests/gen/xmllexer.rs b/tests/gen/xmllexer.rs deleted file mode 100644 index 3d73ded..0000000 --- a/tests/gen/xmllexer.rs +++ /dev/null @@ -1,432 +0,0 @@ -// Generated from XMLLexer.g4 by ANTLR 4.8 -#![allow(dead_code)] -#![allow(nonstandard_style)] -#![allow(unused_imports)] -#![allow(unused_variables)] -use antlr_rust::atn::ATN; -use antlr_rust::atn_deserializer::ATNDeserializer; -use antlr_rust::char_stream::CharStream; -use antlr_rust::dfa::DFA; -use antlr_rust::error_listener::ErrorListener; -use antlr_rust::int_stream::IntStream; -use antlr_rust::lexer::{BaseLexer, Lexer, LexerRecog}; -use antlr_rust::lexer_atn_simulator::{ILexerATNSimulator, LexerATNSimulator}; -use antlr_rust::parser_rule_context::{cast, BaseParserRuleContext, ParserRuleContext}; -use antlr_rust::recognizer::{Actions, Recognizer}; -use antlr_rust::rule_context::{BaseRuleContext, EmptyContext, EmptyCustomRuleContext}; -use antlr_rust::token::*; -use antlr_rust::token_factory::{CommonTokenFactory, TokenAware, TokenFactory}; -use antlr_rust::vocabulary::{Vocabulary, VocabularyImpl}; -use antlr_rust::PredictionContextCache; -use antlr_rust::TokenSource; - -use antlr_rust::{lazy_static, Tid, TidAble, TidExt}; - -use std::cell::RefCell; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; -use std::sync::Arc; - -pub const COMMENT: isize = 1; -pub const CDATA: isize = 2; -pub const DTD: isize = 3; -pub const EntityRef: isize = 4; -pub const CharRef: isize = 5; -pub const SEA_WS: isize = 6; -pub const OPEN: isize = 7; -pub const XMLDeclOpen: isize = 8; -pub const TEXT: isize = 9; -pub const CLOSE: isize = 10; -pub const SPECIAL_CLOSE: isize = 11; -pub const SLASH_CLOSE: isize = 12; -pub const SLASH: isize = 13; -pub const EQUALS: isize = 14; -pub const STRING: isize = 15; -pub const Name: isize = 16; -pub const S: isize = 17; -pub const PI: isize = 18; -pub const INSIDE: usize = 1; -pub const PROC_INSTR: usize = 2; -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 LocalTokenFactory<'input> = CommonTokenFactory; - -type From<'a> = as TokenFactory<'a>>::From; - -pub struct XMLLexer<'input, Input: CharStream>> { - base: BaseLexer<'input, XMLLexerActions, Input, LocalTokenFactory<'input>>, -} - -antlr_rust::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>>; - - 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>> XMLLexer<'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 { - "XMLLexer.g4" - } - - pub fn new_with_token_factory(input: Input, tf: &'input LocalTokenFactory<'input>) -> Self { - antlr_rust::recognizer::check_version("0", "3"); - 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 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: isize, - action_index: isize, - 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: isize, - pred_index: isize, - 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: isize, - recog: &mut ::Target, - ) { - match action_index { - 0 => { - recog.pop_mode(); - } - - _ => {} - } - } - fn COMMENT_sempred( - _localctx: Option<&LexerContext<'input>>, - pred_index: isize, - 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> TokenAware<'input> for XMLLexerActions { - 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() - } - - 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() - } -} - -lazy_static! { - static ref _ATN: Arc = - Arc::new(ATNDeserializer::new(None).deserialize(_serializedATN.chars())); - static ref _decision_to_DFA: Arc>> = { - let mut dfa = Vec::new(); - let size = _ATN.decision_to_state.len(); - for i in 0..size { - dfa.push(DFA::new(_ATN.clone(), _ATN.get_decision_state(i), i as isize).into()) - } - Arc::new(dfa) - }; -} - -const _serializedATN: &'static str = - "\x03\u{608b}\u{a72a}\u{8133}\u{b9ed}\u{417c}\u{3be7}\u{7786}\u{5964}\x02\ - \x14\u{e8}\x08\x01\x08\x01\x08\x01\x04\x02\x09\x02\x04\x03\x09\x03\x04\ - \x04\x09\x04\x04\x05\x09\x05\x04\x06\x09\x06\x04\x07\x09\x07\x04\x08\x09\ - \x08\x04\x09\x09\x09\x04\x0a\x09\x0a\x04\x0b\x09\x0b\x04\x0c\x09\x0c\x04\ - \x0d\x09\x0d\x04\x0e\x09\x0e\x04\x0f\x09\x0f\x04\x10\x09\x10\x04\x11\x09\ - \x11\x04\x12\x09\x12\x04\x13\x09\x13\x04\x14\x09\x14\x04\x15\x09\x15\x04\ - \x16\x09\x16\x04\x17\x09\x17\x04\x18\x09\x18\x04\x19\x09\x19\x03\x02\x03\ - \x02\x03\x02\x03\x02\x03\x02\x03\x02\x07\x02\x3c\x0a\x02\x0c\x02\x0e\x02\ - \x3f\x0b\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x03\x03\ - \x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\ - \x03\x07\x03\x52\x0a\x03\x0c\x03\x0e\x03\x55\x0b\x03\x03\x03\x03\x03\x03\ - \x03\x03\x03\x03\x04\x03\x04\x03\x04\x03\x04\x07\x04\x5f\x0a\x04\x0c\x04\ - \x0e\x04\x62\x0b\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x05\x03\x05\x03\ - \x05\x03\x05\x03\x06\x03\x06\x03\x06\x03\x06\x06\x06\x70\x0a\x06\x0d\x06\ - \x0e\x06\x71\x03\x06\x03\x06\x03\x06\x03\x06\x03\x06\x03\x06\x03\x06\x06\ - \x06\x7b\x0a\x06\x0d\x06\x0e\x06\x7c\x03\x06\x03\x06\x05\x06\u{81}\x0a\ - \x06\x03\x07\x03\x07\x05\x07\u{85}\x0a\x07\x03\x07\x05\x07\u{88}\x0a\x07\ - \x03\x08\x03\x08\x03\x08\x03\x08\x03\x09\x03\x09\x03\x09\x03\x09\x03\x09\ - \x03\x09\x03\x09\x03\x09\x03\x09\x03\x09\x03\x0a\x03\x0a\x03\x0a\x03\x0a\ - \x03\x0a\x03\x0a\x03\x0a\x03\x0a\x03\x0b\x06\x0b\u{a1}\x0a\x0b\x0d\x0b\ - \x0e\x0b\u{a2}\x03\x0c\x03\x0c\x03\x0c\x03\x0d\x03\x0d\x03\x0d\x03\x0d\ - \x03\x0d\x03\x0e\x03\x0e\x03\x0e\x03\x0e\x03\x0e\x03\x0f\x03\x0f\x03\x10\ - \x03\x10\x03\x11\x03\x11\x07\x11\u{b8}\x0a\x11\x0c\x11\x0e\x11\u{bb}\x0b\ - \x11\x03\x11\x03\x11\x03\x11\x07\x11\u{c0}\x0a\x11\x0c\x11\x0e\x11\u{c3}\ - \x0b\x11\x03\x11\x05\x11\u{c6}\x0a\x11\x03\x12\x03\x12\x07\x12\u{ca}\x0a\ - \x12\x0c\x12\x0e\x12\u{cd}\x0b\x12\x03\x13\x03\x13\x03\x13\x03\x13\x03\ - \x14\x03\x14\x03\x15\x03\x15\x03\x16\x03\x16\x03\x16\x03\x16\x05\x16\u{db}\ - \x0a\x16\x03\x17\x05\x17\u{de}\x0a\x17\x03\x18\x03\x18\x03\x18\x03\x18\ - \x03\x18\x03\x19\x03\x19\x03\x19\x03\x19\x05\x3d\x53\x60\x02\x1a\x05\x03\ - \x07\x04\x09\x05\x0b\x06\x0d\x07\x0f\x08\x11\x09\x13\x0a\x15\x02\x17\x0b\ - \x19\x0c\x1b\x0d\x1d\x0e\x1f\x0f\x21\x10\x23\x11\x25\x12\x27\x13\x29\x02\ - \x2b\x02\x2d\x02\x2f\x02\x31\x14\x33\x02\x05\x02\x03\x04\x0b\x04\x02\x0b\ - \x0b\x22\x22\x04\x02\x28\x28\x3e\x3e\x04\x02\x24\x24\x3e\x3e\x04\x02\x29\ - \x29\x3e\x3e\x05\x02\x0b\x0c\x0f\x0f\x22\x22\x05\x02\x32\x3b\x43\x48\x63\ - \x68\x03\x02\x32\x3b\x05\x02\u{b9}\u{b9}\u{302}\u{371}\u{2041}\u{2042}\ - \x0a\x02\x3c\x3c\x43\x5c\x63\x7c\u{2072}\u{2191}\u{2c02}\u{2ff1}\u{3003}\ - \u{10801}\u{f902}\u{fdd1}\u{fdf2}\u{ffff}\x02\u{f1}\x02\x05\x03\x02\x02\ - \x02\x02\x07\x03\x02\x02\x02\x02\x09\x03\x02\x02\x02\x02\x0b\x03\x02\x02\ - \x02\x02\x0d\x03\x02\x02\x02\x02\x0f\x03\x02\x02\x02\x02\x11\x03\x02\x02\ - \x02\x02\x13\x03\x02\x02\x02\x02\x15\x03\x02\x02\x02\x02\x17\x03\x02\x02\ - \x02\x03\x19\x03\x02\x02\x02\x03\x1b\x03\x02\x02\x02\x03\x1d\x03\x02\x02\ - \x02\x03\x1f\x03\x02\x02\x02\x03\x21\x03\x02\x02\x02\x03\x23\x03\x02\x02\ - \x02\x03\x25\x03\x02\x02\x02\x03\x27\x03\x02\x02\x02\x04\x31\x03\x02\x02\ - \x02\x04\x33\x03\x02\x02\x02\x05\x35\x03\x02\x02\x02\x07\x46\x03\x02\x02\ - \x02\x09\x5a\x03\x02\x02\x02\x0b\x67\x03\x02\x02\x02\x0d\u{80}\x03\x02\ - \x02\x02\x0f\u{87}\x03\x02\x02\x02\x11\u{89}\x03\x02\x02\x02\x13\u{8d}\ - \x03\x02\x02\x02\x15\u{97}\x03\x02\x02\x02\x17\u{a0}\x03\x02\x02\x02\x19\ - \u{a4}\x03\x02\x02\x02\x1b\u{a7}\x03\x02\x02\x02\x1d\u{ac}\x03\x02\x02\ - \x02\x1f\u{b1}\x03\x02\x02\x02\x21\u{b3}\x03\x02\x02\x02\x23\u{c5}\x03\ - \x02\x02\x02\x25\u{c7}\x03\x02\x02\x02\x27\u{ce}\x03\x02\x02\x02\x29\u{d2}\ - \x03\x02\x02\x02\x2b\u{d4}\x03\x02\x02\x02\x2d\u{da}\x03\x02\x02\x02\x2f\ - \u{dd}\x03\x02\x02\x02\x31\u{df}\x03\x02\x02\x02\x33\u{e4}\x03\x02\x02\ - \x02\x35\x36\x07\x3e\x02\x02\x36\x37\x07\x23\x02\x02\x37\x38\x07\x2f\x02\ - \x02\x38\x39\x07\x2f\x02\x02\x39\x3d\x03\x02\x02\x02\x3a\x3c\x0b\x02\x02\ - \x02\x3b\x3a\x03\x02\x02\x02\x3c\x3f\x03\x02\x02\x02\x3d\x3e\x03\x02\x02\ - \x02\x3d\x3b\x03\x02\x02\x02\x3e\x40\x03\x02\x02\x02\x3f\x3d\x03\x02\x02\ - \x02\x40\x41\x07\x2f\x02\x02\x41\x42\x07\x2f\x02\x02\x42\x43\x07\x40\x02\ - \x02\x43\x44\x03\x02\x02\x02\x44\x45\x06\x02\x02\x02\x45\x06\x03\x02\x02\ - \x02\x46\x47\x07\x3e\x02\x02\x47\x48\x07\x23\x02\x02\x48\x49\x07\x5d\x02\ - \x02\x49\x4a\x07\x45\x02\x02\x4a\x4b\x07\x46\x02\x02\x4b\x4c\x07\x43\x02\ - \x02\x4c\x4d\x07\x56\x02\x02\x4d\x4e\x07\x43\x02\x02\x4e\x4f\x07\x5d\x02\ - \x02\x4f\x53\x03\x02\x02\x02\x50\x52\x0b\x02\x02\x02\x51\x50\x03\x02\x02\ - \x02\x52\x55\x03\x02\x02\x02\x53\x54\x03\x02\x02\x02\x53\x51\x03\x02\x02\ - \x02\x54\x56\x03\x02\x02\x02\x55\x53\x03\x02\x02\x02\x56\x57\x07\x5f\x02\ - \x02\x57\x58\x07\x5f\x02\x02\x58\x59\x07\x40\x02\x02\x59\x08\x03\x02\x02\ - \x02\x5a\x5b\x07\x3e\x02\x02\x5b\x5c\x07\x23\x02\x02\x5c\x60\x03\x02\x02\ - \x02\x5d\x5f\x0b\x02\x02\x02\x5e\x5d\x03\x02\x02\x02\x5f\x62\x03\x02\x02\ - \x02\x60\x61\x03\x02\x02\x02\x60\x5e\x03\x02\x02\x02\x61\x63\x03\x02\x02\ - \x02\x62\x60\x03\x02\x02\x02\x63\x64\x07\x40\x02\x02\x64\x65\x03\x02\x02\ - \x02\x65\x66\x08\x04\x02\x02\x66\x0a\x03\x02\x02\x02\x67\x68\x07\x28\x02\ - \x02\x68\x69\x05\x25\x12\x02\x69\x6a\x07\x3d\x02\x02\x6a\x0c\x03\x02\x02\ - \x02\x6b\x6c\x07\x28\x02\x02\x6c\x6d\x07\x25\x02\x02\x6d\x6f\x03\x02\x02\ - \x02\x6e\x70\x05\x2b\x15\x02\x6f\x6e\x03\x02\x02\x02\x70\x71\x03\x02\x02\ - \x02\x71\x6f\x03\x02\x02\x02\x71\x72\x03\x02\x02\x02\x72\x73\x03\x02\x02\ - \x02\x73\x74\x07\x3d\x02\x02\x74\u{81}\x03\x02\x02\x02\x75\x76\x07\x28\ - \x02\x02\x76\x77\x07\x25\x02\x02\x77\x78\x07\x7a\x02\x02\x78\x7a\x03\x02\ - \x02\x02\x79\x7b\x05\x29\x14\x02\x7a\x79\x03\x02\x02\x02\x7b\x7c\x03\x02\ - \x02\x02\x7c\x7a\x03\x02\x02\x02\x7c\x7d\x03\x02\x02\x02\x7d\x7e\x03\x02\ - \x02\x02\x7e\x7f\x07\x3d\x02\x02\x7f\u{81}\x03\x02\x02\x02\u{80}\x6b\x03\ - \x02\x02\x02\u{80}\x75\x03\x02\x02\x02\u{81}\x0e\x03\x02\x02\x02\u{82}\ - \u{88}\x09\x02\x02\x02\u{83}\u{85}\x07\x0f\x02\x02\u{84}\u{83}\x03\x02\ - \x02\x02\u{84}\u{85}\x03\x02\x02\x02\u{85}\u{86}\x03\x02\x02\x02\u{86}\ - \u{88}\x07\x0c\x02\x02\u{87}\u{82}\x03\x02\x02\x02\u{87}\u{84}\x03\x02\ - \x02\x02\u{88}\x10\x03\x02\x02\x02\u{89}\u{8a}\x07\x3e\x02\x02\u{8a}\u{8b}\ - \x03\x02\x02\x02\u{8b}\u{8c}\x08\x08\x03\x02\u{8c}\x12\x03\x02\x02\x02\ - \u{8d}\u{8e}\x07\x3e\x02\x02\u{8e}\u{8f}\x07\x41\x02\x02\u{8f}\u{90}\x07\ - \x7a\x02\x02\u{90}\u{91}\x07\x6f\x02\x02\u{91}\u{92}\x07\x6e\x02\x02\u{92}\ - \u{93}\x03\x02\x02\x02\u{93}\u{94}\x05\x27\x13\x02\u{94}\u{95}\x03\x02\ - \x02\x02\u{95}\u{96}\x08\x09\x03\x02\u{96}\x14\x03\x02\x02\x02\u{97}\u{98}\ - \x07\x3e\x02\x02\u{98}\u{99}\x07\x41\x02\x02\u{99}\u{9a}\x03\x02\x02\x02\ - \u{9a}\u{9b}\x05\x25\x12\x02\u{9b}\u{9c}\x03\x02\x02\x02\u{9c}\u{9d}\x08\ - \x0a\x04\x02\u{9d}\u{9e}\x08\x0a\x05\x02\u{9e}\x16\x03\x02\x02\x02\u{9f}\ - \u{a1}\x0a\x03\x02\x02\u{a0}\u{9f}\x03\x02\x02\x02\u{a1}\u{a2}\x03\x02\ - \x02\x02\u{a2}\u{a0}\x03\x02\x02\x02\u{a2}\u{a3}\x03\x02\x02\x02\u{a3}\ - \x18\x03\x02\x02\x02\u{a4}\u{a5}\x07\x40\x02\x02\u{a5}\u{a6}\x08\x0c\x06\ - \x02\u{a6}\x1a\x03\x02\x02\x02\u{a7}\u{a8}\x07\x41\x02\x02\u{a8}\u{a9}\ - \x07\x40\x02\x02\u{a9}\u{aa}\x03\x02\x02\x02\u{aa}\u{ab}\x08\x0d\x07\x02\ - \u{ab}\x1c\x03\x02\x02\x02\u{ac}\u{ad}\x07\x31\x02\x02\u{ad}\u{ae}\x07\ - \x40\x02\x02\u{ae}\u{af}\x03\x02\x02\x02\u{af}\u{b0}\x08\x0e\x07\x02\u{b0}\ - \x1e\x03\x02\x02\x02\u{b1}\u{b2}\x07\x31\x02\x02\u{b2}\x20\x03\x02\x02\ - \x02\u{b3}\u{b4}\x07\x3f\x02\x02\u{b4}\x22\x03\x02\x02\x02\u{b5}\u{b9}\ - \x07\x24\x02\x02\u{b6}\u{b8}\x0a\x04\x02\x02\u{b7}\u{b6}\x03\x02\x02\x02\ - \u{b8}\u{bb}\x03\x02\x02\x02\u{b9}\u{b7}\x03\x02\x02\x02\u{b9}\u{ba}\x03\ - \x02\x02\x02\u{ba}\u{bc}\x03\x02\x02\x02\u{bb}\u{b9}\x03\x02\x02\x02\u{bc}\ - \u{c6}\x07\x24\x02\x02\u{bd}\u{c1}\x07\x29\x02\x02\u{be}\u{c0}\x0a\x05\ - \x02\x02\u{bf}\u{be}\x03\x02\x02\x02\u{c0}\u{c3}\x03\x02\x02\x02\u{c1}\ - \u{bf}\x03\x02\x02\x02\u{c1}\u{c2}\x03\x02\x02\x02\u{c2}\u{c4}\x03\x02\ - \x02\x02\u{c3}\u{c1}\x03\x02\x02\x02\u{c4}\u{c6}\x07\x29\x02\x02\u{c5}\ - \u{b5}\x03\x02\x02\x02\u{c5}\u{bd}\x03\x02\x02\x02\u{c6}\x24\x03\x02\x02\ - \x02\u{c7}\u{cb}\x05\x2f\x17\x02\u{c8}\u{ca}\x05\x2d\x16\x02\u{c9}\u{c8}\ - \x03\x02\x02\x02\u{ca}\u{cd}\x03\x02\x02\x02\u{cb}\u{c9}\x03\x02\x02\x02\ - \u{cb}\u{cc}\x03\x02\x02\x02\u{cc}\x26\x03\x02\x02\x02\u{cd}\u{cb}\x03\ - \x02\x02\x02\u{ce}\u{cf}\x09\x06\x02\x02\u{cf}\u{d0}\x03\x02\x02\x02\u{d0}\ - \u{d1}\x08\x13\x02\x02\u{d1}\x28\x03\x02\x02\x02\u{d2}\u{d3}\x09\x07\x02\ - \x02\u{d3}\x2a\x03\x02\x02\x02\u{d4}\u{d5}\x09\x08\x02\x02\u{d5}\x2c\x03\ - \x02\x02\x02\u{d6}\u{db}\x05\x2f\x17\x02\u{d7}\u{db}\x04\x2f\x30\x02\u{d8}\ - \u{db}\x05\x2b\x15\x02\u{d9}\u{db}\x09\x09\x02\x02\u{da}\u{d6}\x03\x02\ - \x02\x02\u{da}\u{d7}\x03\x02\x02\x02\u{da}\u{d8}\x03\x02\x02\x02\u{da}\ - \u{d9}\x03\x02\x02\x02\u{db}\x2e\x03\x02\x02\x02\u{dc}\u{de}\x09\x0a\x02\ - \x02\u{dd}\u{dc}\x03\x02\x02\x02\u{de}\x30\x03\x02\x02\x02\u{df}\u{e0}\ - \x07\x41\x02\x02\u{e0}\u{e1}\x07\x40\x02\x02\u{e1}\u{e2}\x03\x02\x02\x02\ - \u{e2}\u{e3}\x08\x18\x07\x02\u{e3}\x32\x03\x02\x02\x02\u{e4}\u{e5}\x0b\ - \x02\x02\x02\u{e5}\u{e6}\x03\x02\x02\x02\u{e6}\u{e7}\x08\x19\x04\x02\u{e7}\ - \x34\x03\x02\x02\x02\x14\x02\x03\x04\x3d\x53\x60\x71\x7c\u{80}\u{84}\u{87}\ - \u{a2}\u{b9}\u{c1}\u{c5}\u{cb}\u{da}\u{dd}\x08\x08\x02\x02\x07\x03\x02\ - \x05\x02\x02\x07\x04\x02\x03\x0c\x02\x06\x02\x02";