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
use super::ast::Ast;

use crate::error::Result;

use rvs_parser;
use rvs_parser::ast;

pub struct Parser {
    search_path: rvs_parser::SearchPath,
    ast: Ast,
}

impl Parser {
    pub fn new(search_path: &rvs_parser::SearchPath) -> Parser {
        Parser {
            // FIXME: Remove clone
            search_path: search_path.clone(),
            ast: Ast::new(),
        }
    }

    pub fn parse(&mut self, s: &str) -> Result<()> {
        // FIXME: Remove clone
        let parser = rvs_parser::Parser::new(self.search_path.clone());
        let nodes = parser.parse(s)?;
        self.ast.add_nodes(nodes);

        Ok(())
    }

    pub fn ast(&self) -> &[Box<ast::Node>] {
        self.ast.get()
    }
}