Skip to main content

oak_d2/lexer/
mod.rs

1pub mod token_type;
2
3use crate::language::D2Language;
4use oak_core::{
5    Lexer, LexerCache, LexerState,
6    lexer::LexOutput,
7    source::{Source, TextEdit},
8};
9
10pub struct D2Lexer<'config> {
11    config: &'config D2Language,
12}
13
14impl<'config> D2Lexer<'config> {
15    pub fn new(config: &'config D2Language) -> Self {
16        Self { config }
17    }
18}
19
20impl<'config> Lexer<D2Language> for D2Lexer<'config> {
21    fn lex<'a, S: Source + ?Sized>(&self, source: &S, _edits: &[TextEdit], cache: &'a mut impl LexerCache<D2Language>) -> LexOutput<D2Language> {
22        let mut state = LexerState::new(source);
23        // Minimal lexing implementation
24        while state.not_at_end() {
25            if let Some(ch) = state.peek() {
26                state.advance(ch.len_utf8());
27            }
28        }
29        state.add_eof();
30        state.finish_with_cache(Ok(()), cache)
31    }
32}