1#![doc = include_str!("readme.md")]
2
3pub mod element_type;
4
5use crate::{language::VomlLanguage, lexer::VomlLexer};
6use oak_core::{
7 Source, TextEdit,
8 parser::{ParseCache, ParseOutput, Parser, ParserState, parse_with_lexer},
9};
10
11pub struct VomlParser<'config> {
13 pub(crate) config: &'config VomlLanguage,
15}
16
17impl<'config> VomlParser<'config> {
18 pub fn new(config: &'config VomlLanguage) -> Self {
20 Self { config }
21 }
22}
23
24impl<'config> Parser<VomlLanguage> for VomlParser<'config> {
25 fn parse<'a, S: Source + ?Sized>(&self, source: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<VomlLanguage>) -> ParseOutput<'a, VomlLanguage> {
26 let lexer = VomlLexer::new(self.config);
27 parse_with_lexer(&lexer, source, edits, cache, |state| {
28 let checkpoint = state.checkpoint();
29 while state.not_at_end() {
30 state.advance();
31 }
32 Ok(state.finish_at(checkpoint, element_type::VomlElementType::SourceFile))
33 })
34 }
35}