1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Parser and emitter configuration utilities.
//!
//! This module centralizes the construction of libfyaml configuration structures.
use *;
use ptr;
/// Creates a parse configuration for single-document parsing with diagnostic capture.
///
/// Enables:
/// - `FYPCF_QUIET`: Suppress stderr output
/// - `FYPCF_KEEP_COMMENTS`: Preserve comments for roundtrip
///
/// The diag pointer allows capturing parse errors with location information.
/// Creates a parse configuration for stream/multi-document parsing with diagnostic capture.
///
/// Enables:
/// - `FYPCF_QUIET`: Suppress stderr output (always enabled for no-stderr guarantee)
/// - `FYPCF_DISABLE_BUFFERING`: Don't buffer input
/// - `FYPCF_RESOLVE_DOCUMENT`: Resolve document after parsing
/// - `FYPCF_KEEP_COMMENTS`: Preserve comments for roundtrip
///
/// The diag pointer allows capturing parse errors with location information.
/// FYPCF_QUIET is always enabled to guarantee no stderr output, regardless of
/// whether a custom diag is provided.
/// Returns emitter flags that preserve original formatting and comments.
///
/// # Upstream bug workaround: `FYECF_WIDTH_INF`
///
/// libfyaml's emitter wraps long lines at the configured width (default
/// 80) by inserting a trailing `\` line-continuation. That escape is
/// only valid in double-quoted style: in single-quoted (and plain)
/// scalars the `\` is a literal character, so the emitted YAML no
/// longer round-trips (re-parsing yields a spurious `\` + folded
/// space in the value).
///
/// Reproduction (fy-tool, both v1.0.0-alpha7 and master @ ac6c0fc):
/// ```text
/// $ python3 -c "print(\"key: '\" + 'x'*81 + \"'\")" | fy-tool --dump --width=80 -
/// key: 'xxx...xxx\
/// xxxxxxx' <- re-parses as "...xxx\ xxxxxxx" (corrupted)
/// ```
///
/// We force infinite width, the same workaround fy-tool itself applies
/// when stdout is not a tty (see `src/tool/fy-tool.c`: "if we're
/// dumping to a non tty stdout width is infinite").
///
/// TODO(upstream): re-test against new libfyaml releases
/// (<https://github.com/pantoniou/libfyaml>) with the reproduction
/// above; once finite-width wrapping of single-quoted scalars
/// round-trips correctly, `FYECF_WIDTH_INF` can be dropped. The
/// regression test `emit_long_single_quoted_scalar_round_trips` in
/// `tests/integration.rs` guards this.