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
113
114
115
116
117
118
use super::ast::Ast;
use super::ast::AstImpl;
use super::errors::ParseErrors;
use super::symbols::Symbol;
use super::text::Text;
use super::tokens::TokenRepository;
use super::tokens::TokenRepositoryImpl;
pub struct ParseResult {
terminals: &'static [Symbol],
variables: &'static [Symbol],
virtuals: &'static [Symbol],
text: Text,
errors: ParseErrors,
tokens: TokenRepositoryImpl,
ast: AstImpl
}
impl<'a> ParseResult {
pub fn new(
terminals: &'static [Symbol],
variables: &'static [Symbol],
virtuals: &'static [Symbol],
text: Text
) -> ParseResult {
ParseResult {
terminals,
variables,
virtuals,
text,
errors: ParseErrors::new(),
tokens: TokenRepositoryImpl::new(),
ast: AstImpl::new()
}
}
pub fn get_terminals(&self) -> &'static [Symbol] {
self.terminals
}
pub fn get_variables(&self) -> &'static [Symbol] {
self.variables
}
pub fn get_virtuals(&self) -> &'static [Symbol] {
self.virtuals
}
pub fn get_input(&self) -> &Text {
&self.text
}
pub fn is_success(&self) -> bool {
self.ast.has_root()
}
pub fn get_errors(&self) -> &ParseErrors {
&self.errors
}
pub fn get_tokens(&self) -> TokenRepository {
TokenRepository::new(&self.terminals, &self.text, &self.tokens)
}
pub fn get_ast(&self) -> Ast {
Ast::new(
TokenRepository::new(&self.terminals, &self.text, &self.tokens),
self.variables,
self.virtuals,
&self.ast
)
}
pub fn get_parsing_data(&mut self) -> (TokenRepository, &mut ParseErrors, Ast) {
(
TokenRepository::new_mut(&self.terminals, &self.text, &mut self.tokens),
&mut self.errors,
Ast::new_mut(self.variables, self.virtuals, &mut self.ast)
)
}
}