oak_fortran/parser/
mod.rs1use crate::{kind::FortranSyntaxKind, language::FortranLanguage};
2use oak_core::{
3 GreenNode, OakError,
4 parser::{ParseCache, ParseOutput, Parser, ParserState, parse_with_lexer},
5 source::{Source, TextEdit},
6};
7
8pub(crate) type State<'a, S> = ParserState<'a, FortranLanguage, S>;
9
10pub struct FortranParser<'config> {
11 pub(crate) _config: &'config FortranLanguage,
12}
13
14impl<'config> FortranParser<'config> {
15 pub fn new(config: &'config FortranLanguage) -> Self {
16 Self { _config: config }
17 }
18
19 pub(crate) fn parse_root_internal<'a, S: Source + ?Sized>(&self, state: &mut State<'a, S>) -> Result<&'a GreenNode<'a, FortranLanguage>, OakError> {
20 let checkpoint = state.checkpoint();
21
22 while state.not_at_end() {
23 state.advance();
24 }
25
26 Ok(state.finish_at(checkpoint, FortranSyntaxKind::Root.into()))
27 }
28}
29
30impl<'config> Parser<FortranLanguage> for FortranParser<'config> {
31 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<FortranLanguage>) -> ParseOutput<'a, FortranLanguage> {
32 let lexer = crate::lexer::FortranLexer::new(self._config);
33 parse_with_lexer(&lexer, text, edits, cache, |state| self.parse_root_internal(state))
34 }
35}