oak_wit_component/parser/
mod.rs1pub mod element_type;
7
8use crate::{
9 language::WitLanguage,
10 lexer::{WitLexer, token_type::WitTokenType},
11 parser::element_type::WitElementType,
12};
13use oak_core::{
14 TextEdit,
15 parser::{ParseCache, Parser},
16 source::Source,
17};
18
19pub struct WitParser<'config> {
23 pub(crate) config: &'config WitLanguage,
24}
25
26impl<'config> WitParser<'config> {
27 pub fn new(config: &'config WitLanguage) -> Self {
29 Self { config }
30 }
31}
32
33impl<'config> Parser<WitLanguage> for WitParser<'config> {
34 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<WitLanguage>) -> oak_core::ParseOutput<'a, WitLanguage> {
35 let lexer = WitLexer::new(&self.config);
36 oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
37 let checkpoint = state.checkpoint();
38
39 while state.not_at_end() {
40 let _token = state.advance();
41 }
43
44 Ok(state.finish_at(checkpoint, crate::parser::element_type::WitElementType::Root))
45 })
46 }
47}