oak_jasm/parser/
mod.rs

1use crate::{language::JasmLanguage, lexer::JasmLexer};
2use oak_core::{
3    parser::{ParseCache, ParseOutput, Parser, ParserState, parse_with_lexer},
4    source::{Source, TextEdit},
5};
6
7mod parse;
8
9pub(crate) type State<'a, S> = ParserState<'a, JasmLanguage, S>;
10
11pub struct JasmParser<'config> {
12    pub(crate) config: &'config JasmLanguage,
13}
14
15impl<'config> JasmParser<'config> {
16    pub fn new(config: &'config JasmLanguage) -> Self {
17        Self { config }
18    }
19}
20
21impl<'config> Parser<JasmLanguage> for JasmParser<'config> {
22    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<JasmLanguage>) -> ParseOutput<'a, JasmLanguage> {
23        let lexer = JasmLexer::new(self.config);
24        parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
25    }
26}