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
use erl_pp::{self, Preprocessor};
use erl_tokenize::{Lexer, LexicalToken};

use {Result, TokenReader, Parser};
use cst::ModuleDecl;
use traits::TokenRead;

#[derive(Debug)]
pub struct ModuleParser<'a>(Parser<TokenReader<Preprocessor<Lexer<&'a str>>, erl_pp::Error>>);
impl<'a> ModuleParser<'a> {
    pub fn new(tokens: Preprocessor<Lexer<&'a str>>) -> Self {
        ModuleParser(Parser::new(TokenReader::new(tokens)))
    }
    pub fn parse_module(&mut self) -> Result<ModuleDecl> {
        track!(self.0.parse(), "next={:?}", self.0.parse::<LexicalToken>())
    }
    pub fn preprocessor(&self) -> &Preprocessor<Lexer<&'a str>> {
        self.0.reader().inner()
    }
    pub fn preprocessor_mut(&mut self) -> &mut Preprocessor<Lexer<&'a str>> {
        self.0.reader_mut().inner_mut()
    }
}

pub fn parse_module(tokens: &mut TokenRead) -> Result<ModuleDecl> {
    Parser::new(tokens).parse()
}