Skip to main content

oak_vampire/parser/
mod.rs

1pub mod element_type;
2pub use element_type::VampireElementType;
3
4use crate::{
5    language::VampireLanguage,
6    lexer::{VampireLexer, VampireTokenType},
7};
8use oak_core::{
9    GreenNode, OakError,
10    parser::{ParseCache, ParseOutput, Parser, ParserState, parse_with_lexer},
11    source::{Source, TextEdit},
12};
13
14pub(crate) type State<'a, S> = ParserState<'a, VampireLanguage, S>;
15
16pub struct VampireParser<'config> {
17    pub(crate) config: &'config VampireLanguage,
18}
19
20impl<'config> VampireParser<'config> {
21    pub fn new(config: &'config VampireLanguage) -> Self {
22        Self { config }
23    }
24}
25
26impl<'config> Parser<VampireLanguage> for VampireParser<'config> {
27    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<VampireLanguage>) -> ParseOutput<'a, VampireLanguage> {
28        let lexer = VampireLexer::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, VampireElementType::Root))
35        })
36    }
37}