oak_graphql/parser/
mod.rs1pub mod element_type;
3
4use crate::{language::GraphQLLanguage, lexer::GraphQLLexer, parser::element_type::GraphQLElementType};
5use oak_core::{
6 GreenNode, OakError,
7 parser::{ParseCache, ParseOutput, Parser, parse_with_lexer},
8 source::{Source, TextEdit},
9};
10
11pub struct GraphQLParser<'config> {
13 pub(crate) config: &'config GraphQLLanguage,
15}
16
17impl<'config> GraphQLParser<'config> {
18 pub fn new(config: &'config GraphQLLanguage) -> Self {
20 Self { config }
21 }
22}
23
24impl<'config> Parser<GraphQLLanguage> for GraphQLParser<'config> {
25 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<GraphQLLanguage>) -> ParseOutput<'a, GraphQLLanguage> {
26 let lexer = GraphQLLexer::new(&self.config);
27 parse_with_lexer(&lexer, text, edits, cache, |state| {
28 let checkpoint = state.checkpoint();
29
30 while state.not_at_end() {
31 state.advance()
32 }
33
34 Ok(state.finish_at(checkpoint, GraphQLElementType::SourceFile))
35 })
36 }
37}