1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use std::fmt::{Display, Error, Formatter};
use std::hash::{Hash, Hasher};
use murmur3::murmur3_32::MurmurHasher;
use crate::atn_config_set::ATNConfigSet;
use crate::lexer_action_executor::LexerActionExecutor;
use crate::semantic_context::SemanticContext;
#[derive(Eq, PartialEq, Debug)]
pub struct PredPrediction {
pub(crate) alt: isize,
pub(crate) pred: SemanticContext,
}
impl Display for PredPrediction {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
f.write_fmt(format_args!("({},{:?})", self.alt, self.pred))
}
}
pub type DFAStateRef = usize;
#[derive(Eq, Debug)]
pub struct DFAState {
pub state_number: usize,
pub configs: Box<ATNConfigSet>,
pub edges: Vec<DFAStateRef>,
pub is_accept_state: bool,
pub prediction: isize,
pub(crate) lexer_action_executor: Option<Box<LexerActionExecutor>>,
pub requires_full_context: bool,
pub predicates: Vec<PredPrediction>,
}
impl PartialEq for DFAState {
fn eq(&self, other: &Self) -> bool { self.configs == other.configs }
}
impl Hash for DFAState {
fn hash<H: Hasher>(&self, state: &mut H) { self.configs.hash(state); }
}
impl DFAState {
pub fn default_hash(&self) -> u64 {
let mut hasher = MurmurHasher::default();
self.hash(&mut hasher);
hasher.finish()
}
pub fn new_dfastate(state_number: usize, configs: Box<ATNConfigSet>) -> DFAState {
DFAState {
state_number,
configs,
edges: Vec::new(),
is_accept_state: false,
prediction: 0,
lexer_action_executor: None,
requires_full_context: false,
predicates: Vec::new(),
}
}
}