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)
)
}
}