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