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
mod incompatible_definitions;
use incompatible_definitions::*;
use super::ProgramContext;
use crate::diagnostics::Diagnostic;
use crate::evaluator_rules::Rule;
use crate::grammar::StmtList;
trait Validator<'a> {
fn validate(
stmt_list: &StmtList,
source: &'a str,
context: &ProgramContext,
evaluator_rules: &[Rule],
) -> Vec<Diagnostic>;
}
macro_rules! register_validators {
($($validator:ident,)*) => {
enum PEValidator {
$($validator),*
}
impl PEValidator {
fn validate<'a>(
&self,
stmt_list: &StmtList,
source: &'a str,
context: &ProgramContext,
evaluator_rules: &[Rule],
) -> Vec<Diagnostic> {
match self {
$(Self::$validator => $validator::validate(
stmt_list, source, context, evaluator_rules)),*
}
}
}
pub(super) fn validate<'a>(
stmt_list: &StmtList,
source: &'a str,
context: &ProgramContext,
evaluator_rules: &[Rule],
) -> Vec<Diagnostic> {
[$(PEValidator::$validator),*]
.iter()
.flat_map(|v| v.validate(stmt_list, source, context, evaluator_rules))
.collect()
}
}
}
register_validators! {
IncompatibleDefinitionsValidator,
}