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