oak_wit/parser/
mod.rs

1use crate::{kind::WitSyntaxKind, language::WitLanguage, lexer::WitLexer};
2use oak_core::{
3    TextEdit,
4    parser::{ParseCache, Parser},
5    source::Source,
6};
7
8// type WitToken = Token<WitSyntaxKind>;
9
10/// WIT Parser
11pub struct WitParser<'config> {
12    pub(crate) config: &'config WitLanguage,
13}
14
15impl<'config> WitParser<'config> {
16    /// Creates a new WIT parser
17    pub fn new(config: &'config WitLanguage) -> Self {
18        Self { config }
19    }
20}
21
22impl<'config> Parser<WitLanguage> for WitParser<'config> {
23    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<WitLanguage>) -> oak_core::ParseOutput<'a, WitLanguage> {
24        let lexer = WitLexer::new(self.config);
25        oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
26            let checkpoint = state.checkpoint();
27
28            while state.not_at_end() {
29                let _token = state.advance();
30                // TODO: 完整的 WIT 解析逻辑
31            }
32
33            Ok(state.finish_at(checkpoint, WitSyntaxKind::Root))
34        })
35    }
36}