Skip to main content

oak_r/parser/
mod.rs

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