1use crate::{kind::TomlSyntaxKind, language::TomlLanguage};
2use oak_core::{Parser, source::Source};
3
4pub struct TomlParser<'config> {
6 pub(crate) config: &'config TomlLanguage,
8}
9
10impl<'config> TomlParser<'config> {
11 pub fn new(config: &'config TomlLanguage) -> Self {
12 Self { config }
13 }
14}
15
16impl<'config> Parser<TomlLanguage> for TomlParser<'config> {
17 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[oak_core::TextEdit], cache: &'a mut impl oak_core::ParseCache<TomlLanguage>) -> oak_core::ParseOutput<'a, TomlLanguage> {
18 let lexer = crate::lexer::TomlLexer::new(&self.config);
19 oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
20 let checkpoint = state.checkpoint();
21
22 while state.current().is_some() {
24 state.bump();
25 }
26
27 Ok(state.finish_at(checkpoint, TomlSyntaxKind::Root.into()))
28 })
29 }
30}