diff --git a/build.rs b/build.rs deleted file mode 100644 index 60efa3a..0000000 --- a/build.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::convert::TryInto; -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; - -fn main() { - let grammars = vec![ - "CSV", - "ReferenceToATN", - "XMLLexer", - "SimpleLR", - "Labels", - "FHIRPath", - ]; - let additional_args = vec![Some("-visitor"), None, None, None, None]; - let antlr_path = "/home/rrevenantt/dev/antlr4/tool/target/antlr4-4.8-2-SNAPSHOT-complete.jar"; - - 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); - } - - 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"); -} - -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); - - let input = env::current_dir().unwrap().join("grammars"); - let file_name = grammar_file_name.to_owned() + ".g4"; - - let c = Command::new("java") - .current_dir(input) - .arg("-cp") - .arg(antlr_path) - .arg("org.antlr.v4.Tool") - .arg("-Dlanguage=Rust") - .arg("-o") - .arg("../tests/gen") - .arg(&file_name) - .args(additional_arg) - .spawn() - .expect("antlr tool failed to start") - .wait_with_output()?; - // .unwrap() - // .stdout; - // eprintln!("xx{}",String::from_utf8(x).unwrap()); - - println!("cargo:rerun-if-changed=grammars/{}", file_name); - Ok(()) -} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..0efd119 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2021-07-25 diff --git a/src/atn_config_set.rs b/src/atn_config_set.rs index c44bcc0..7dd3936 100644 --- a/src/atn_config_set.rs +++ b/src/atn_config_set.rs @@ -59,15 +59,15 @@ impl Hash for Key { impl Debug for ATNConfigSet { fn fmt(&self, _f: &mut Formatter<'_>) -> Result<(), Error> { - _f.write_str("ATNConfigSet")?; + _f.write_str("ATNConfigSet,hash:")?; _f.debug_list().entries(self.configs.iter()).finish()?; if self.has_semantic_context { _f.write_str(",hasSemanticContext=true")? } if self.conflicting_alts.is_empty() { - _f.write_fmt(format_args!(",uniqueAlt={}", self.unique_alt)) + _f.write_fmt(format_args!(",hash={},uniqueAlt={}", self.cached_hash, self.unique_alt)) } else { - _f.write_fmt(format_args!(",conflictingAlts={:?}", self.conflicting_alts)) + _f.write_fmt(format_args!(",hash={},conflictingAlts={:?}", self.cached_hash,self.conflicting_alts)) } } } diff --git a/src/lib.rs b/src/lib.rs index 6d691af..243856e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ #![crate_type = "lib"] #![feature(try_blocks)] -//#![feature(nll)] -#![feature(raw)] #![feature(is_sorted)] #![feature(cell_update)] #![feature(get_mut_unchecked)] @@ -13,7 +11,6 @@ // #![feature(generic_associated_types)] #![warn(rust_2018_idioms)] #![warn(missing_docs)] // warn if there is missing docs -#![warn(missing_debug_implementations)] #![warn(trivial_numeric_casts)] #![allow(incomplete_features)] diff --git a/src/parser_rule_context.rs b/src/parser_rule_context.rs index 4926ad8..4762020 100644 --- a/src/parser_rule_context.rs +++ b/src/parser_rule_context.rs @@ -25,6 +25,8 @@ pub trait ParserRuleContext<'input>: ParseTree<'input> + RuleContext<'input> + Debug + Tid<'input> { fn set_exception(&self, _e: ANTLRError) {} + fn has_exception(&self) -> bool { false } + fn get_exception(&self) -> Option> { None } fn set_start(&self, _t: Option<>::Tok>) {} @@ -234,7 +236,7 @@ pub struct BaseParserRuleContext<'input, Ctx: CustomRuleContext<'input>> { start: RefCell<>::Tok>, stop: RefCell<>::Tok>, /// error if there was any in this node - pub exception: Option>, + pub exception: RefCell>>, /// List of children of current node pub(crate) children: RefCell>::Type>>>, } @@ -302,7 +304,31 @@ impl<'input, Ctx: CustomRuleContext<'input>> BorrowMut for BaseParserRuleCo impl<'input, Ctx: CustomRuleContext<'input> + TidAble<'input>> ParserRuleContext<'input> for BaseParserRuleContext<'input, Ctx> { - fn set_exception(&self, _e: ANTLRError) { /*self.exception = Some(Box::new(e));*/ + fn set_exception(&self, e: ANTLRError) { + { + if self.exception.try_borrow_mut().is_err() { + eprintln!("Unable to borrow as mutable: {:?}", self); + return; + } + } + self.exception.replace(Some(Box::new(e))); + } + + fn has_exception(&self) -> bool { + if let Ok(exc) = self.exception.try_borrow() { + exc.is_some() + } else { + true + } + } + + fn get_exception(&self) -> Option> { + if let Ok(exc) = self.exception.try_borrow() { + exc.clone() + } else { + eprintln!("Unable to check exception: {:?}", self); + None + } } fn set_start(&self, t: Option<>::Tok>) { @@ -433,7 +459,7 @@ impl<'input, Ctx: CustomRuleContext<'input> + 'input> BaseParserRuleContext<'inp base: BaseRuleContext::new_parser_ctx(parent_ctx, invoking_state, ext), start: RefCell::new(Ctx::TF::create_invalid()), stop: RefCell::new(Ctx::TF::create_invalid()), - exception: None, + exception: RefCell::new(None), children: RefCell::new(vec![]), } } @@ -449,7 +475,7 @@ impl<'input, Ctx: CustomRuleContext<'input> + 'input> BaseParserRuleContext<'inp ), start: RefCell::new(ctx.start_mut().clone()), stop: RefCell::new(ctx.stop_mut().clone()), - exception: None, + exception: RefCell::new(None), children: RefCell::new(ctx.get_children().collect()), } } @@ -474,6 +500,8 @@ where I: ParserRuleContext<'input> + 'input + ?Sized, { fn set_exception(&self, e: ANTLRError) { self.deref().set_exception(e) } + fn has_exception(&self) -> bool { self.deref().has_exception() } + fn get_exception(&self) -> Option> { self.deref().get_exception() } fn set_start(&self, t: Option<>::Tok>) { self.deref().set_start(t) diff --git a/tests/my_test.rs b/tests/my_test.rs index 7c79311..9212913 100644 --- a/tests/my_test.rs +++ b/tests/my_test.rs @@ -1,6 +1,4 @@ #![feature(try_blocks)] -#![feature(inner_deref)] -#![feature(specialization)] #![feature(coerce_unsized)] //! Integration tests @@ -9,7 +7,6 @@ mod gen { use std::fmt::Write; - use std::io::Read; use std::iter::FromIterator; use antlr_rust::common_token_stream::CommonTokenStream; diff --git a/tests/perf.rs b/tests/perf.rs index 101b6ab..f9560b4 100644 --- a/tests/perf.rs +++ b/tests/perf.rs @@ -1,5 +1,4 @@ #![feature(try_blocks)] -#![feature(inner_deref)] #![feature(test)] #[macro_use] extern crate lazy_static;