1pub mod element_type;
4
5use crate::{language::DLanguage, lexer::DLexer};
6use oak_core::{
7 TextEdit,
8 parser::{Parser, ParserState},
9 source::Source,
10};
11
12pub(crate) type State<'a, S> = ParserState<'a, DLanguage, S>;
14
15pub struct DParser<'config> {
17 pub(crate) config: &'config DLanguage,
18}
19
20impl<'config> DParser<'config> {
21 pub fn new(config: &'config DLanguage) -> Self {
23 Self { config }
24 }
25}
26
27impl<'config> Parser<DLanguage> for DParser<'config> {
28 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl oak_core::ParseCache<DLanguage>) -> oak_core::ParseOutput<'a, DLanguage> {
29 let lexer = DLexer::new(self.config);
30 oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
31 let checkpoint = state.checkpoint();
32
33 while state.not_at_end() {
34 state.advance();
35 }
36
37 Ok(state.finish_at(checkpoint, crate::parser::element_type::DElementType::Root))
38 })
39 }
40}