Skip to main content

syntaqlite_syntax/parser/
config.rs

1// Copyright 2025 The syntaqlite Authors. All rights reserved.
2// Licensed under the Apache License, Version 2.0.
3
4/// Controls optional parser behavior beyond core AST construction.
5///
6/// Keep defaults for pure parsing. Enable extras only when your tool needs
7/// them (for example, token-level highlighting or parser debugging).
8#[derive(Debug, Default, Clone, Copy)]
9pub struct ParserConfig {
10    trace: bool,
11    collect_tokens: bool,
12    macro_fallback: bool,
13}
14
15impl ParserConfig {
16    /// Whether parser debug trace logging is enabled. Default: `false`.
17    ///
18    /// Useful when debugging grammar behavior; usually disabled in production.
19    pub fn trace(&self) -> bool {
20        self.trace
21    }
22
23    /// Whether parser tokens/comments are recorded for each statement. Default: `false`.
24    ///
25    /// Enable this for tooling that needs precise token streams (formatters,
26    /// diagnostics, semantic highlighting).
27    pub fn collect_tokens(&self) -> bool {
28        self.collect_tokens
29    }
30
31    /// Enable or disable parser trace logging.
32    #[must_use]
33    pub fn with_trace(mut self, trace: bool) -> Self {
34        self.trace = trace;
35        self
36    }
37
38    /// Enable or disable token/comment capture on parse results.
39    #[must_use]
40    pub fn with_collect_tokens(mut self, collect_tokens: bool) -> Self {
41        self.collect_tokens = collect_tokens;
42        self
43    }
44
45    /// Whether macro fallback is enabled. Default: `false`.
46    ///
47    /// When enabled and the dialect uses Rust-style macros, unregistered
48    /// `name!(args)` calls are consumed as a single `TK_ID` token instead
49    /// of causing a parse error. A `MacroRegion` is recorded so the
50    /// formatter can emit the call verbatim.
51    pub fn macro_fallback(&self) -> bool {
52        self.macro_fallback
53    }
54
55    /// Enable or disable macro fallback for unregistered macro calls.
56    #[must_use]
57    pub fn with_macro_fallback(mut self, macro_fallback: bool) -> Self {
58        self.macro_fallback = macro_fallback;
59        self
60    }
61}