1#![doc = include_str!("readme.md")]
2pub mod element_type;
3
4pub use element_type::BatElementType;
5
6use crate::{
7 language::BatLanguage,
8 lexer::{BatLexer, BatTokenType},
9};
10use oak_core::{
11 OakError, TextEdit,
12 parser::{ParseCache, Parser, ParserState},
13 source::Source,
14};
15
16pub(crate) type State<'a, S> = ParserState<'a, BatLanguage, S>;
17
18pub struct BatParser<'config> {
19 pub(crate) _config: &'config BatLanguage,
20}
21
22impl<'config> BatParser<'config> {
23 pub fn new(config: &'config BatLanguage) -> Self {
24 Self { _config: config }
25 }
26}
27
28impl<'config> Parser<BatLanguage> for BatParser<'config> {
29 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<BatLanguage>) -> oak_core::ParseOutput<'a, BatLanguage> {
30 let lexer = BatLexer::new(self._config);
31 oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
32 let checkpoint = state.checkpoint();
33 while state.not_at_end() && !state.at(BatTokenType::Eof) {
34 state.bump()
35 }
36 Ok(state.finish_at(checkpoint, BatElementType::Root))
37 })
38 }
39}