From e30849d17eb7d83059763d0c3c260ba7c0a959e4 Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Thu, 29 Jul 2021 10:17:02 -0600 Subject: [PATCH 1/6] Fixup errors/warnings --- build.rs | 9 ++------- src/atn_config_set.rs | 6 +++--- src/lib.rs | 1 - tests/my_test.rs | 3 --- tests/perf.rs | 1 - 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index 60efa3a..52118ce 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,5 @@ -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() { @@ -33,14 +28,14 @@ fn gen_for_grammar( grammar_file_name: &str, antlr_path: &str, additional_arg: Option<&str>, -) -> Result<(), Box> { +) -> 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") + let _c = Command::new("java") .current_dir(input) .arg("-cp") .arg(antlr_path) 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..1a07bde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,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/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; From bb69ec646336c021b908ce3aa0e170e2465b193b Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Thu, 29 Jul 2021 10:21:53 -0600 Subject: [PATCH 2/6] Remove 'raw' feature (deprecated/removed) --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1a07bde..d9714ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![crate_type = "lib"] #![feature(try_blocks)] //#![feature(nll)] -#![feature(raw)] #![feature(is_sorted)] #![feature(cell_update)] #![feature(get_mut_unchecked)] From 2c25625b7f8762e4485359ce51d37286704ff6fc Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Fri, 20 Aug 2021 09:25:47 -0600 Subject: [PATCH 3/6] Add rust-toolchain --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..bf867e0 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly From 7d0888321a9ec053a2d5c56d00404f1a67fd81b0 Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Fri, 20 Aug 2021 10:44:43 -0600 Subject: [PATCH 4/6] Update rust-toolchain --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index bf867e0..0efd119 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly +nightly-2021-07-25 From 0d248e2887cbbc80bf7af2d2995293434e8c8771 Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Thu, 26 Aug 2021 11:30:30 -0600 Subject: [PATCH 5/6] build.rs is broken -- renamed for now --- build.rs | 57 -------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 build.rs diff --git a/build.rs b/build.rs deleted file mode 100644 index 52118ce..0000000 --- a/build.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::env; -use std::error::Error; -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(()) -} From 685bf2ac627e8b98e99259904d4104d3ed836ac5 Mon Sep 17 00:00:00 2001 From: Ken Platz Date: Wed, 20 Oct 2021 14:39:56 -0600 Subject: [PATCH 6/6] Implement exceptions in BaseParserContext --- src/lib.rs | 1 - src/parser_rule_context.rs | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d9714ce..243856e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![crate_type = "lib"] #![feature(try_blocks)] -//#![feature(nll)] #![feature(is_sorted)] #![feature(cell_update)] #![feature(get_mut_unchecked)] 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)