Skip to main content

oak_wit_component/parser/
mod.rs

1/// Element type definitions for WIT (WebAssembly Interface Types) syntax tree nodes.
2///
3/// This module provides [`WitElementType`] which defines all element types
4/// used in the WIT parse tree, including structural elements like worlds,
5/// interfaces, packages, and type definitions.
6pub 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
19// type WitToken = Token<WitTokenType>;
20
21/// WIT Parser
22pub struct WitParser<'config> {
23    pub(crate) config: &'config WitLanguage,
24}
25
26impl<'config> WitParser<'config> {
27    /// Creates a new WIT parser
28    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                // TODO: Complete WIT parsing logic
42            }
43
44            Ok(state.finish_at(checkpoint, crate::parser::element_type::WitElementType::Root))
45        })
46    }
47}