Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kjp/better exceptions #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions build.rs

This file was deleted.

1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2021-07-25
6 changes: 3 additions & 3 deletions src/atn_config_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![crate_type = "lib"]
#![feature(try_blocks)]
//#![feature(nll)]
#![feature(raw)]
#![feature(is_sorted)]
#![feature(cell_update)]
#![feature(get_mut_unchecked)]
Expand All @@ -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)]

Expand Down
36 changes: 32 additions & 4 deletions src/parser_rule_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<ANTLRError>> { None }

fn set_start(&self, _t: Option<<Self::TF as TokenFactory<'input>>::Tok>) {}

Expand Down Expand Up @@ -234,7 +236,7 @@ pub struct BaseParserRuleContext<'input, Ctx: CustomRuleContext<'input>> {
start: RefCell<<Ctx::TF as TokenFactory<'input>>::Tok>,
stop: RefCell<<Ctx::TF as TokenFactory<'input>>::Tok>,
/// error if there was any in this node
pub exception: Option<Box<ANTLRError>>,
pub exception: RefCell<Option<Box<ANTLRError>>>,
/// List of children of current node
pub(crate) children: RefCell<Vec<Rc<<Ctx::Ctx as ParserNodeType<'input>>::Type>>>,
}
Expand Down Expand Up @@ -302,7 +304,31 @@ impl<'input, Ctx: CustomRuleContext<'input>> BorrowMut<Ctx> 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<Box<ANTLRError>> {
if let Ok(exc) = self.exception.try_borrow() {
exc.clone()
} else {
eprintln!("Unable to check exception: {:?}", self);
None
}
}

fn set_start(&self, t: Option<<Ctx::TF as TokenFactory<'input>>::Tok>) {
Expand Down Expand Up @@ -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![]),
}
}
Expand All @@ -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()),
}
}
Expand All @@ -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<Box<ANTLRError>> { self.deref().get_exception() }

fn set_start(&self, t: Option<<Self::TF as TokenFactory<'input>>::Tok>) {
self.deref().set_start(t)
Expand Down
3 changes: 0 additions & 3 deletions tests/my_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![feature(try_blocks)]
#![feature(inner_deref)]
#![feature(specialization)]
#![feature(coerce_unsized)]
//! Integration tests

Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tests/perf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(try_blocks)]
#![feature(inner_deref)]
#![feature(test)]
#[macro_use]
extern crate lazy_static;
Expand Down