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, ParserState, parse_with_lexer},
8 source::{Source, TextEdit},
9};
10
11pub(crate) type State<'a, S> = ParserState<'a, GraphQLLanguage, S>;
12
13pub struct GraphQLParser<'config> {
15 pub(crate) config: &'config GraphQLLanguage,
17}
18
19impl<'config> GraphQLParser<'config> {
20 pub fn new(config: &'config GraphQLLanguage) -> Self {
22 Self { config }
23 }
24}
25
26impl<'config> Parser<GraphQLLanguage> for GraphQLParser<'config> {
27 fn parse<'a, S: Source + ?Sized>(&self, text: &'a S, edits: &[TextEdit], cache: &'a mut impl ParseCache<GraphQLLanguage>) -> ParseOutput<'a, GraphQLLanguage> {
28 let lexer = GraphQLLexer::new(&self.config);
29 parse_with_lexer(&lexer, text, edits, cache, |state| {
30 let checkpoint = state.checkpoint();
31
32 while state.not_at_end() {
33 state.advance()
34 }
35
36 Ok(state.finish_at(checkpoint, GraphQLElementType::SourceFile))
37 })
38 }
39}