Skip to main content

oak_r/parser/
mod.rs

1use crate::{language::RLanguage, lexer::RLexer};
2use oak_core::{
3    TextEdit,
4    parser::{ParseCache, ParseOutput, Parser, ParserState},
5    source::Source,
6};
7
8mod parse;
9
10pub(crate) type State<'a, S> = ParserState<'a, RLanguage, S>;
11
12pub struct RParser<'config> {
13    pub(crate) config: &'config RLanguage,
14}
15
16impl<'config> RParser<'config> {
17    pub fn new(config: &'config RLanguage) -> Self {
18        Self { config }
19    }
20}
21
22impl<'config> Parser<RLanguage> for RParser<'config> {
23    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<RLanguage>) -> ParseOutput<'a, RLanguage> {
24        let lexer = RLexer::new(&self.config);
25        oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
26    }
27}