Skip to main content

oak_handlebars/parser/
mod.rs

1pub mod element_type;
2
3use crate::{language::HandlebarsLanguage, lexer::HandlebarsLexer, parser::element_type::HandlebarsElementType};
4use oak_core::{
5    Parser,
6    parser::{ParseCache, ParseOutput, parse_with_lexer},
7    source::{Source, TextEdit},
8};
9
10/// Handlebars 语言解析器
11pub struct HandlebarsParser<'config> {
12    /// 语言配置
13    pub(crate) config: &'config HandlebarsLanguage,
14}
15
16impl<'config> HandlebarsParser<'config> {
17    pub fn new(config: &'config HandlebarsLanguage) -> Self {
18        Self { config }
19    }
20}
21
22impl<'config> Parser<HandlebarsLanguage> for HandlebarsParser<'config> {
23    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<HandlebarsLanguage>) -> ParseOutput<'a, HandlebarsLanguage> {
24        let lexer = HandlebarsLexer::new(&self.config);
25        parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
26    }
27}
28
29mod parse_top_level;