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
//! Parser syntax-error channel.
//!
//! Markdown itself is never syntactically invalid — every byte sequence is some
//! lossless CST — so the block/inline parsers emit no diagnostics. Embedded
//! *sublanguages* are different: hashpipe and frontmatter YAML can be malformed,
//! and (later) LaTeX math or raw HTML may be validated too. When the parser
//! validates such a region it already knows the verdict and offset; rather than
//! discard it and force a downstream re-parse, it records a host-ranged
//! [`SyntaxError`] here, mirroring rust-analyzer's `Parse { green, errors }`.
//!
//! The CST is unchanged — invalid YAML still becomes opaque tokens. This channel
//! is purely the *diagnostic* the parser already computed, surfaced instead of
//! thrown away. It is empty for pure Markdown.
use RefCell;
use Rc;
use TextRange;
/// Which sublanguage validation produced a [`SyntaxError`]. Lets downstream
/// consumers (the linter) map to the right diagnostic code without the parser
/// knowing linter codes.
/// A syntax error the parser found in an embedded sublanguage, with a
/// **host-aligned** byte range (ready to turn into a diagnostic without any
/// offset remapping).
/// Interior-mutable sink the single-pass parser pushes into while building.
///
/// Cloning shares the same backing store (it is an `Rc`), so it threads through
/// the block dispatcher (on `BlockContext`) as an owned value — sidestepping any
/// `&self` borrow that would clash with the `&mut GreenNodeBuilder` held during
/// emission. The handful of clones per parse are cheap pointer bumps.