Skip to main content

oak_hlsl/parser/
mod.rs

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