Skip to main content

oak_vampire/parser/
mod.rs

1/// Element type definitions for the Vampire parser.
2pub mod element_type;
3/// Re-export of VampireElementType from the element_type module.
4pub 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
18/// Parser for the Vampire language.
19pub struct VampireParser<'config> {
20    pub(crate) config: &'config VampireLanguage,
21}
22
23impl<'config> VampireParser<'config> {
24    /// Creates a new VampireParser with the given language configuration.
25    pub fn new(config: &'config VampireLanguage) -> Self {
26        Self { config }
27    }
28}
29
30impl<'config> Parser<VampireLanguage> for VampireParser<'config> {
31    /// Parses the input text and produces a green tree for the Vampire language.
32    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}