Skip to main content

oak_cobol/parser/
mod.rs

1use crate::{language::CobolLanguage, lexer::CobolLexer};
2use oak_core::{
3    parser::{ParseCache, ParseOutput, Parser, parse_with_lexer},
4    source::{Source, TextEdit},
5};
6
7/// Element type definitions for COBOL syntax tree nodes.
8///
9/// This module provides [`CobolElementType`] which defines all element types
10/// used in the COBOL parse tree, including structural elements like divisions
11/// and paragraphs, as well as token-derived elements.
12pub mod element_type;
13
14pub use element_type::CobolElementType;
15
16/// COBOL parser.
17pub struct CobolParser;
18
19impl CobolParser {
20    /// Create a new COBOL parser.
21    pub fn new() -> Self {
22        Self
23    }
24}
25
26impl Parser<CobolLanguage> for CobolParser {
27    fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<CobolLanguage>) -> ParseOutput<'a, CobolLanguage> {
28        let lexer = CobolLexer::new();
29        parse_with_lexer(&lexer, text, edits, cache, |state| {
30            let cp = state.checkpoint();
31            while state.not_at_end() {
32                state.bump();
33            }
34            Ok(state.finish_at(cp, CobolElementType::Root))
35        })
36    }
37}