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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use crate::atn::ATN;
use crate::tree::RuleNode;
use crate::vocabulary::Vocabulary;
/// Major version of this runtime.
/// Used by generated parser to verify that it is compatible with current version of runtime
pub const VERSION_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
/// Major version of this runtime.
/// Used by generated parser to verify that it is compatible with current version of runtime
pub const VERSION_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
// todo move to compile time check when it will be possible to compare strings in constants
/// Used by generated parser to verify that it is compatible with current version of runtime
pub fn check_version(major: &str, minor: &str) {
assert!(major == VERSION_MAJOR && minor == VERSION_MINOR,
"parser is not compatible with current runtime version, please generate parser with the latest version of ANTLR")
}
//todo just a reminder to update version to be inserted in generated parser,
//const _:[();0-!(VERSION_MAJOR == "0" && VERSION_MINOR == "2") as usize] = [];
/// **! Usually generated by ANTLR !**
pub trait Recognizer<'input, 'arena>
where
'input: 'arena,
{
type Node: RuleNode<'input, 'arena>;
fn sempred(
&mut self,
_localctx: Option<&'arena Self::Node>,
_rule_index: i32,
_action_index: i32,
) -> bool
where
Self: Sized,
{
true
}
fn action(
&mut self,
_localctx: Option<&'arena Self::Node>,
_rule_index: i32,
_action_index: i32,
) where
Self: Sized,
{
}
/// Returns array of rule names.
/// Used for debugging and error reporting
fn get_rule_names(&self) -> &[&str] {
&[]
}
fn get_vocabulary(&self) -> &dyn Vocabulary {
unimplemented!()
}
/// Name of the file this recognizer was generated from
fn get_grammar_file_name(&self) -> &str {
""
}
fn get_atn(&self) -> &ATN {
unimplemented!()
}
}
/// **! Usually generated by ANTLR !**
///
/// Used to make user predicates and actions callable by parser
/// Generated by ANTLR tool from actions and predicated added in grammar file
pub trait Actions<'input, 'arena, P>
where
'input: 'arena,
P: Recognizer<'input, 'arena>,
{
fn sempred(
_localctx: Option<&'arena P::Node>,
_rule_index: i32,
_action_index: i32,
_recog: &mut P,
) -> bool {
true
}
fn action(
_localctx: Option<&'arena P::Node>,
_rule_index: i32,
_action_index: i32,
_recog: &mut P,
) {
}
/// Returns array of rule names.
/// Used for debugging and error reporting
fn get_rule_names(&self) -> &[&str] {
&[]
}
fn get_vocabulary(&self) -> &dyn Vocabulary {
unimplemented!()
}
/// Name of the file this recognizer was generated from
fn get_grammar_file_name(&self) -> &str {
""
}
fn get_atn(&self) -> &ATN {
unimplemented!()
}
}