libgraphql_parser/graphql_parser_config.rs
1/// Configuration for [`GraphQLParser`](crate::GraphQLParser)
2/// controlling parser behavior.
3///
4/// All flags default to their full-fidelity values. Set individual
5/// flags to `false` to discard specific elements for leaner output.
6///
7/// # Example
8///
9/// ```rust
10/// use libgraphql_parser::GraphQLParserConfig;
11///
12/// // Full-fidelity (default)
13/// let full = GraphQLParserConfig::default();
14/// assert!(full.retain_syntax);
15///
16/// // Lean mode: skip populating syntax structs
17/// let lean = GraphQLParserConfig::lean();
18/// assert!(!lean.retain_syntax);
19/// ```
20#[derive(Clone, Debug, PartialEq)]
21pub struct GraphQLParserConfig {
22 /// Whether the parser should populate `*Syntax` structs on AST
23 /// nodes with the concrete tokens that make up each construct
24 /// (punctuation, keywords, etc.).
25 ///
26 /// When `false`, all `syntax` fields on AST nodes remain `None`,
27 /// saving allocations when only semantic data is needed.
28 pub retain_syntax: bool,
29}
30
31impl GraphQLParserConfig {
32 /// Returns a lean config that skips populating syntax structs.
33 /// Useful when only semantic AST data is needed.
34 pub fn lean() -> Self {
35 Self {
36 retain_syntax: false,
37 }
38 }
39}
40
41impl Default for GraphQLParserConfig {
42 fn default() -> Self {
43 Self {
44 retain_syntax: true,
45 }
46 }
47}