Skip to main content

oak_django/parser/
mod.rs

1use crate::{language::DjangoLanguage, lexer::DjangoLexer};
2use oak_core::{
3    TextEdit,
4    parser::{ParseCache, Parser, ParserState},
5    source::Source,
6};
7
8mod parse;
9
10pub(crate) type State<'a, S> = ParserState<'a, DjangoLanguage, S>;
11
12pub struct DjangoParser<'config> {
13    pub(crate) _config: &'config DjangoLanguage,
14}
15
16impl<'config> DjangoParser<'config> {
17    pub fn new(config: &'config DjangoLanguage) -> Self {
18        Self { _config: config }
19    }
20}
21
22impl<'config> Parser<DjangoLanguage> for DjangoParser<'config> {
23    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<DjangoLanguage>) -> oak_core::ParseOutput<'a, DjangoLanguage> {
24        let lexer = DjangoLexer::new(self._config);
25        oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
26    }
27}