Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
# - name: Formatting
# run: cargo fmt -- --check
- name: Formatting
run: cargo fmt -- tests/gen/*.rs && cargo fmt -- --check
- uses: actions/checkout@v3
if: ${{ github.event_name == 'push' }}
with:
Expand Down
12 changes: 4 additions & 8 deletions runtime/Rust/src/atn_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PartialEq for ATNConfig {
fn eq(&self, other: &Self) -> bool {
self.get_state() == other.get_state()
&& self.get_alt() == other.get_alt()
// Arc is optimized to not do a deep equalitiy if arc pointers are equal so that's enough
// Arc is optimized to not do a deep equality if arc pointers are equal so that's enough
&& self.context == other.context
&& self.get_type() == other.get_type()
&& self.semantic_context == other.semantic_context
Expand All @@ -42,8 +42,8 @@ impl PartialEq for ATNConfig {

impl Hash for ATNConfig {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write_i32(self.get_state() as i32);
state.write_i32(self.get_alt() as i32);
state.write_i32(self.get_state());
state.write_i32(self.get_alt());
match self.get_context() {
None => state.write_i32(0),
Some(c) => c.hash(state),
Expand Down Expand Up @@ -110,11 +110,7 @@ impl ATNConfig {
})
}

pub fn new(
state: ATNStateRef,
alt: i32,
context: Option<Arc<PredictionContext>>,
) -> ATNConfig {
pub fn new(state: ATNStateRef, alt: i32, context: Option<Arc<PredictionContext>>) -> ATNConfig {
ATNConfig {
precedence_filter_suppressed: false,
state,
Expand Down
4 changes: 1 addition & 3 deletions runtime/Rust/src/atn_deserialization_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ impl ATNDeserializationOptions {

impl Default for ATNDeserializationOptions {
fn default() -> Self {
ATNDeserializationOptions {
verify_atn: true,
}
ATNDeserializationOptions { verify_atn: true }
}
}
43 changes: 17 additions & 26 deletions runtime/Rust/src/atn_deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ impl ATNDeserializer {
}

pub fn deserialize(&self, data: &mut Iter<i32>) -> ATN {


self.check_version(*data.next().unwrap());

let mut atn = self.read_atn(data);
Expand All @@ -65,7 +63,7 @@ impl ATNDeserializer {

self.read_edges(&mut atn, data, &sets);
self.read_decisions(&mut atn, data);
if atn.grammar_type == ATNType::LEXER {
if atn.grammar_type == ATNType::Lexer {
self.read_lexer_actions(&mut atn, data);
}
self.mark_precedence_decisions(&mut atn, data);
Expand Down Expand Up @@ -95,8 +93,8 @@ impl ATNDeserializer {
fn read_atn(&self, data: &mut Iter<i32>) -> ATN {
ATN::new_atn(
match data.next() {
Some(0) => ATNType::LEXER,
Some(1) => ATNType::PARSER,
Some(0) => ATNType::Lexer,
Some(1) => ATNType::Parser,
_ => panic!("invalid ATN type"),
},
*data.next().unwrap(),
Expand Down Expand Up @@ -125,9 +123,7 @@ impl ATNDeserializer {
state: ATNDecisionState::BlockStartState { end_state, .. },
..
} => *end_state = *data.next().unwrap(),
ATNStateType::LoopEndState(loop_back) => {
*loop_back = *data.next().unwrap()
}
ATNStateType::LoopEndState(loop_back) => *loop_back = *data.next().unwrap(),
_ => (),
}
atn.add_state(state);
Expand Down Expand Up @@ -170,7 +166,7 @@ impl ATNDeserializer {
for i in 0..nrules {
let s = *data.next().unwrap();
atn.rule_to_start_state[i] = s;
if atn.grammar_type == ATNType::LEXER {
if atn.grammar_type == ATNType::Lexer {
let token_type = *data.next().unwrap();

atn.rule_to_token_type.push(token_type);
Expand Down Expand Up @@ -206,11 +202,7 @@ impl ATNDeserializer {
}
}

fn read_sets(
&self,
_atn: &mut ATN,
data: &mut Iter<i32>,
) -> Vec<IntervalSet> {
fn read_sets(&self, _atn: &mut ATN, data: &mut Iter<i32>) -> Vec<IntervalSet> {
let nsets = *data.next().unwrap();
let mut sets = Vec::new();
for _i in 0..nsets {
Expand All @@ -232,12 +224,7 @@ impl ATNDeserializer {
sets
}

fn read_edges(
&self,
atn: &mut ATN,
data: &mut Iter<i32>,
sets: &Vec<IntervalSet>,
) {
fn read_edges(&self, atn: &mut ATN, data: &mut Iter<i32>, sets: &Vec<IntervalSet>) {
let nedges = *data.next().unwrap();

for _i in 0..nedges {
Expand All @@ -250,7 +237,10 @@ impl ATNDeserializer {

let transition = self.edge_factory(atn, ttype, src, trg, arg1, arg2, arg3, sets);

atn.states.get_mut(src as usize).unwrap().add_transition(transition);
atn.states
.get_mut(src as usize)
.unwrap()
.add_transition(transition);
}

let mut new_tr = Vec::new();
Expand All @@ -272,7 +262,7 @@ impl ATNDeserializer {
.get_state_type()
{
if tr.precedence == 0 {
target.get_rule_index() as i32
target.get_rule_index()
} else {
-1
}
Expand Down Expand Up @@ -368,8 +358,9 @@ impl ATNDeserializer {
if let ATNStateType::RuleStartState {
is_left_recursive: true,
..
} =
_atn.states[_atn.rule_to_start_state[state.get_rule_index() as usize] as usize].get_state_type()
} = _atn.states
[_atn.rule_to_start_state[state.get_rule_index() as usize] as usize]
.get_state_type()
{
let maybe_loop_end =
state.get_transitions().iter().last().unwrap().get_target();
Expand All @@ -378,7 +369,7 @@ impl ATNDeserializer {
if maybe_loop_end.has_epsilon_only_transitions() {
if let ATNStateType::RuleStopState = _atn.states
[maybe_loop_end.get_transitions()[0].get_target() as usize]
.get_state_type()
.get_state_type()
{
precedence_states.push(state.get_state_number())
}
Expand Down Expand Up @@ -417,7 +408,7 @@ impl ATNDeserializer {
arg1: i32,
arg2: i32,
arg3: i32,
sets: &Vec<IntervalSet>,
sets: &[IntervalSet],
) -> Box<dyn Transition> {
// // let target = atn.states.get
// let mut base = BaseTransition {
Expand Down
32 changes: 7 additions & 25 deletions runtime/Rust/src/atn_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub trait ATNState: Sync + Send + Debug {
fn has_epsilon_only_transitions(&self) -> bool;

fn get_rule_index(&self) -> i32;
fn set_rule_index(&self, v: i32);

fn get_next_tokens_within_rule(&self) -> &OnceCell<IntervalSet>;
// fn set_next_token_within_rule(&mut self, v: IntervalSet);
Expand All @@ -82,10 +81,8 @@ pub trait ATNState: Sync + Send + Debug {
fn get_state_type_id(&self) -> i32;

fn get_state_number(&self) -> i32;
fn set_state_number(&self, state_number: i32);

fn get_transitions(&self) -> &Vec<Box<dyn Transition>>;
fn set_transitions(&self, t: Vec<Box<dyn Transition>>);
fn add_transition(&mut self, trans: Box<dyn Transition>);
}

Expand Down Expand Up @@ -129,10 +126,6 @@ impl ATNState for BaseATNState {
self.rule_index
}

fn set_rule_index(&self, _v: i32) {
unimplemented!()
}

fn get_next_tokens_within_rule(&self) -> &OnceCell<IntervalSet> {
&self.next_tokens_within_rule
}
Expand All @@ -153,18 +146,10 @@ impl ATNState for BaseATNState {
self.state_number
}

fn set_state_number(&self, _state_number: i32) {
unimplemented!()
}

fn get_transitions(&self) -> &Vec<Box<dyn Transition>> {
&self.transitions
}

fn set_transitions(&self, _t: Vec<Box<dyn Transition>>) {
unimplemented!()
}

fn add_transition(&mut self, trans: Box<dyn Transition>) {
if self.transitions.is_empty() {
self.epsilon_only_transitions = trans.is_epsilon()
Expand All @@ -174,17 +159,14 @@ impl ATNState for BaseATNState {

let mut already_present = false;
for existing in self.transitions.iter() {
if existing.get_target() == trans.get_target() {
if existing.get_label().is_some()
if existing.get_target() == trans.get_target()
&& ((existing.get_label().is_some()
&& trans.get_label().is_some()
&& existing.get_label() == trans.get_label()
{
already_present = true;
break;
} else if existing.is_epsilon() && trans.is_epsilon() {
already_present = true;
break;
}
&& existing.get_label() == trans.get_label())
|| (existing.is_epsilon() && trans.is_epsilon()))
{
already_present = true;
break;
}
}
if !already_present {
Expand Down
4 changes: 2 additions & 2 deletions runtime/Rust/src/atn_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[doc(hidden)]
#[derive(Eq, PartialEq, Debug)]
pub enum ATNType {
LEXER = 0,
PARSER,
Lexer = 0,
Parser,
}
3 changes: 1 addition & 2 deletions runtime/Rust/src/common_token_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'input, T: TokenSource<'input>> CommonTokenStream<'input, T> {
}
r
}

pub fn get_dfa_string(&self) -> String {
self.base.get_dfa_string()
}
Expand Down Expand Up @@ -313,5 +313,4 @@ impl<'input, T: TokenSource<'input>> CommonTokenStream<'input, T> {
}

// fn get_number_of_on_channel_tokens(&self) -> int { unimplemented!() }

}
Loading
Loading