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
use miette::Diagnostic;
#[derive(Error, Diagnostic, Debug)]
pub enum GrammarAnalysisError {
#[error("Grammar contains left-recursions")]
#[diagnostic(
help("Left-recursions detected. Please rework your grammar to remove these recursions"),
code(parol::analysis::left_recursion)
)]
LeftRecursion {
#[related]
recursions: Vec<RecursiveNonTerminal>,
},
#[error("Grammar contains unreachable non-terminals")]
#[diagnostic(
help("If not used they can safely be removed"),
code(parol::analysis::unreachable_non_terminals)
)]
UnreachableNonTerminals {
#[related]
non_terminals: Vec<RelatedHint>,
},
#[error("Grammar contains nonproductive non-terminals")]
#[diagnostic(
help("If not used they can safely be removed"),
code(parol::analysis::nonproductive_non_terminals)
)]
NonProductiveNonTerminals {
#[related]
non_terminals: Vec<RelatedHint>,
},
#[error("Maximum lookahead of {max_k} exceeded")]
#[diagnostic(
help("Please examine your grammar"),
code(parol::analysis::max_k_exceeded)
)]
MaxKExceeded {
max_k: usize,
},
}
#[derive(Error, Diagnostic, Debug)]
#[error("Recursive non-terminal #{number}: '{name}'")]
pub struct RecursiveNonTerminal {
pub number: usize,
pub name: String,
}
#[derive(Error, Diagnostic, Debug)]
#[error("{topic}: {hint}")]
pub struct RelatedHint {
pub topic: String,
pub hint: String,
}