Skip to main content

oak_csv/parser/
mod.rs

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