granit_parser/options.rs
1/// Options controlling parser and scanner behavior and resource usage.
2///
3/// Construct this type with [`crate::options!`] so that code remains compatible when new options
4/// are added in future releases.
5///
6/// # Examples
7///
8/// ```rust
9/// let options = granit_parser::options! {
10/// max_buffered_comment_events: 64,
11/// emit_comments: false,
12/// flow_nesting_limit: 512,
13/// };
14///
15/// assert_eq!(options.max_buffered_comment_events, 64);
16/// assert!(!options.emit_comments);
17/// assert_eq!(options.flow_nesting_limit, 512);
18/// ```
19#[non_exhaustive]
20#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct Options {
22 /// Whether scanners emit comment tokens and parsers emit comment events.
23 ///
24 /// The default is `true`. When this is `false`, comments are still recognized and validated
25 /// as YAML syntax, but their text is not captured and no comment tokens or events are emitted.
26 /// Comment bytes are still consumed, so this is not an input-size or processing-time limit.
27 /// [`Self::max_buffered_comment_events`] has no effect while comment emission is disabled.
28 pub emit_comments: bool,
29 /// Maximum number of consecutive comment events buffered while resolving an ambiguous
30 /// collection entry.
31 ///
32 /// The default is 96. A value of zero rejects the first comment that would need buffering.
33 pub max_buffered_comment_events: usize,
34 /// Maximum number of characters inspected while resolving a simple key.
35 ///
36 /// The default is 1024, matching YAML's simple-key length restriction. A key at exactly this
37 /// limit is accepted. Lower values impose a stricter resource limit; higher values relax that
38 /// YAML restriction.
39 pub simple_key_max_lookahead: usize,
40 /// Maximum number of simultaneously nested flow collections.
41 ///
42 /// The default is 255. A value of zero rejects the first flow collection opener.
43 pub flow_nesting_limit: usize,
44}
45
46impl Default for Options {
47 fn default() -> Self {
48 Self {
49 emit_comments: true,
50 max_buffered_comment_events: 96,
51 simple_key_max_lookahead: 1024,
52 flow_nesting_limit: 255,
53 }
54 }
55}