Skip to main content

oak_wolfram/parser/
mod.rs

1use crate::{kind::WolframSyntaxKind, language::WolframLanguage, lexer::WolframLexer};
2use oak_core::{
3    parser::{ParseCache, ParseOutput, Parser, parse_with_lexer},
4    source::{Source, TextEdit},
5};
6
7/// Wolfram Parser
8#[derive(Debug, Clone)]
9pub struct WolframParser<'config> {
10    config: &'config WolframLanguage,
11}
12
13impl<'config> WolframParser<'config> {
14    pub fn new(config: &'config WolframLanguage) -> Self {
15        Self { config }
16    }
17}
18
19impl<'config> Parser<WolframLanguage> for WolframParser<'config> {
20    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<WolframLanguage>) -> ParseOutput<'a, WolframLanguage> {
21        let lexer = WolframLexer::new(&self.config);
22        parse_with_lexer(&lexer, text, edits, cache, |state| {
23            let checkpoint = state.checkpoint();
24
25            while state.not_at_end() {
26                // Very simplified parsing for now
27                state.advance();
28            }
29
30            let root = state.finish_at(checkpoint, WolframSyntaxKind::Root.into());
31            Ok(root)
32        })
33    }
34}