oak_vampire/parser/
mod.rs1pub mod element_type;
3pub use element_type::VampireElementType;
5
6use crate::{
7 language::VampireLanguage,
8 lexer::{VampireLexer, VampireTokenType},
9};
10use oak_core::{
11 GreenNode, OakError,
12 parser::{ParseCache, ParseOutput, Parser, ParserState, parse_with_lexer},
13 source::{Source, TextEdit},
14};
15
16pub(crate) type State<'a, S> = ParserState<'a, VampireLanguage, S>;
17
18pub struct VampireParser<'config> {
20 pub(crate) config: &'config VampireLanguage,
21}
22
23impl<'config> VampireParser<'config> {
24 pub fn new(config: &'config VampireLanguage) -> Self {
26 Self { config }
27 }
28}
29
30impl<'config> Parser<VampireLanguage> for VampireParser<'config> {
31 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<VampireLanguage>) -> ParseOutput<'a, VampireLanguage> {
33 let lexer = VampireLexer::new(&self.config);
34 parse_with_lexer(&lexer, text, edits, cache, |state| {
35 let checkpoint = state.checkpoint();
36 while state.not_at_end() {
37 state.bump()
38 }
39 Ok(state.finish_at(checkpoint, VampireElementType::Root))
40 })
41 }
42}