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