Skip to main content

oak_coq/parser/
mod.rs

1use crate::{language::CoqLanguage, lexer::CoqLexer};
2use oak_core::{
3    parser::{ParseCache, ParseOutput, Parser},
4    source::{Source, TextEdit},
5};
6
7mod parse;
8
9/// Coq parser implementation.
10pub struct CoqParser<'config> {
11    #[allow(dead_code)]
12    pub(crate) config: &'config CoqLanguage,
13}
14
15impl<'config> CoqParser<'config> {
16    /// Creates a new Coq parser with the given language configuration.
17    pub fn new(config: &'config CoqLanguage) -> Self {
18        Self { config }
19    }
20}
21
22impl<'config> Parser<CoqLanguage> for CoqParser<'config> {
23    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<CoqLanguage>) -> ParseOutput<'a, CoqLanguage> {
24        let lexer = CoqLexer::new(&self.config);
25        oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
26    }
27}