1#![doc = include_str!("readme.md")]
2pub mod element_type;
3
4pub use element_type::CmdElementType;
5
6use crate::{
7 language::CmdLanguage,
8 lexer::{CmdLexer, CmdTokenType},
9};
10use oak_core::{
11 OakError, TextEdit,
12 parser::{ParseCache, Parser, ParserState},
13 source::Source,
14};
15
16pub(crate) type State<'a, S> = ParserState<'a, CmdLanguage, S>;
17
18pub struct CmdParser<'config> {
19 pub(crate) _config: &'config CmdLanguage,
20}
21
22impl<'config> CmdParser<'config> {
23 pub fn new(config: &'config CmdLanguage) -> Self {
24 Self { _config: config }
25 }
26}
27
28impl<'config> Parser<CmdLanguage> for CmdParser<'config> {
29 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<CmdLanguage>) -> oak_core::ParseOutput<'a, CmdLanguage> {
30 let lexer = CmdLexer::new(self._config);
31 oak_core::parser::parse_with_lexer(&lexer, text, edits, cache, |state| {
32 let checkpoint = state.checkpoint();
33 while state.not_at_end() && !state.at(CmdTokenType::Eof) {
34 state.bump()
35 }
36 Ok(state.finish_at(checkpoint, CmdElementType::Root))
37 })
38 }
39}