Skip to main content

quilt/
node.rs

1mod parse;
2pub use parse::{constructs, scan, Constructs, ParseError, Token, TokenKind};
3
4use crate::strcmd::PrefixWriter;
5use crate::term::Term;
6use crate::{prelude::*, term::STerm};
7use std::{borrow::Borrow, fmt::Debug, iter::empty, sync::Arc};
8
9/**************************************************************/
10
11// The glyph set and the `\` escape are facts about the surface syntax with no
12// parser in them, and the runtime-only build needs them to render a term back
13// as `.quilt` source (#223) — so they live in `crate::glyphs`, which is not
14// behind the `parse` feature, and are re-exported here, where every caller
15// already looks for them.
16pub use crate::glyphs::{escape, unescape, ARROW_LEN, ESCAPE_LEN, GLYPHS, MACHINE};
17
18// The spellings the writer below shares with the parser, so the two cannot
19// drift apart.
20use parse::{NAME, Q_BLOCK_EMPTY, TYPE};
21
22/**************************************************************/
23
24/// Raw Quilt AST with unparsed string content
25#[derive(Debug, PartialEq, Eq, Clone, Hash)]
26pub enum Node {
27    Content(Box<str>),
28    NewLine,
29    Quote {
30        anno: Box<str>,
31        nodes: Box<[Arc<Node>]>,
32        /// Byte range of the whole `anno↖…↗` in the parsed source.
33        span: Span,
34    },
35    Unquote {
36        anno: Box<str>,
37        nodes: Box<[Arc<Node>]>,
38        /// Byte range of the whole `anno↙…↘` in the parsed source.
39        span: Span,
40    },
41    Lift,
42    Reduce {
43        /// The meta-language annotation on `↓`, e.g. `"py"` for `py↓`.
44        /// Empty string means homogeneous (use the current meta-language).
45        anno: Box<str>,
46    },
47    Emit,
48    Type,
49    Name,
50    /// `⟨M⟩` — an expression obtaining a machine (issue #273).
51    Machine {
52        /// The language annotation, e.g. `"sql"` for `sql⟨M⟩`. Empty means
53        /// the chain's default embedded language, resolved exactly as a bare
54        /// `↖…↗` resolves it.
55        anno: Box<str>,
56    },
57    /// Plain `// …` line comment: passes through verbatim to output.
58    /// The `/.*/` in the grammar consumes the rest of the line as raw text,
59    /// so Quilt special chars inside are not interpreted.
60    PlainLineComment(Box<str>),
61    /// Plain `/* … */` block comment: passes through verbatim to output.
62    PlainBlockComment(Box<str>),
63}
64
65impl Node {
66    /// Parse a source string into a list of [`Node`]s.
67    ///
68    /// Hand-written recursive descent over Quilt's surface syntax, straight to
69    /// the term structure (issue #254). [`scan`] is the recovering half of the
70    /// same parser, for callers that want every diagnostic and a tree anyway.
71    ///
72    /// Malformed bracket structure is a diagnostic, not a panic: an unbalanced
73    /// `↖`/`↙` or a stray `↗`/`↘` returns an `Err` carrying a labelled span, so
74    /// `quilt check` — whose whole job is reporting diagnostics — keeps
75    /// reporting instead of aborting.
76    pub fn parse(code: &str) -> Result<Box<[Self]>> {
77        parse::parse(code)
78    }
79
80    pub fn coparse(nodes: &[Self]) -> Box<str> {
81        let mut buf = std::io::BufWriter::new(Vec::new());
82        let mut writer = PrefixWriter::new(&mut buf);
83        Self::write_seq(nodes, false, &mut writer);
84        let bytes = buf.into_inner().unwrap();
85        String::from_utf8(bytes).unwrap().into()
86    }
87
88    /// Write a run of siblings, with the separators the surface syntax needs
89    /// for the result to parse back (issue #256).
90    ///
91    /// Writing each node's own spelling one after another is not enough:
92    /// Quilt's comment tokens are the one place where a node's text can reach
93    /// past its own end, and two nodes that are perfectly well-formed apart can
94    /// lex as one token together.
95    ///
96    /// * A `// …` comment runs to the end of its line, closing brackets
97    ///   included, so *anything* written after one on the same line vanishes
98    ///   into it. A tree can hold that shape without being malformed —
99    ///   `//c⟨/*⟩x⟨*/⟩↖q↗` parses fine, and the Quilt comment takes the newline
100    ///   with it — and the printed form then had a `↗` with no opener. Only a
101    ///   newline ends a line comment, so that is what goes in. Inside a
102    ///   bracket (`bracketed`) an opener or an escaped arrow interrupts the
103    ///   comment instead, so one may follow it on the line: that is how a
104    ///   quoted `// built from ↙x↘` is written, and a newline there would move
105    ///   the hole out of the comment.
106    /// * A `/` ending one node and a `/` or `*` starting the next spell a
107    ///   comment introducer that neither node contains. The gap between them
108    ///   was a Quilt comment the parser dropped (`a/⟨/*⟩z⟨*/⟩/b` is two content
109    ///   nodes), so an empty [`Q_BLOCK_EMPTY`] comment puts a gap back — the
110    ///   one separator Quilt has that leaves no text behind.
111    ///
112    /// Both separators are idempotent: re-parsing what they produce yields a
113    /// sequence this writes the same way again.
114    fn write_seq<N: Borrow<Self>, W: std::io::Write>(
115        nodes: &[N],
116        bracketed: bool,
117        writer: &mut PrefixWriter<'_, W>,
118    ) {
119        // What the text written so far ends in, as the lexer will read it back:
120        // a `\` still waiting to pair with the next character; a `/` that would
121        // begin a token, so a `/` or `*` after it spells a comment; and a
122        // `// …` comment still holding its line open.
123        //
124        // The pairing is why `bare_slash` is not just "the last byte is `/`":
125        // content is lexed in `\X` units, so the `/` ending `a\/` is the second
126        // half of one and cannot start anything — `a\/// x` prints itself
127        // unchanged, and separating it would be a bug, not a fix.
128        //
129        // A trailing `*` before a `/` is likewise not a seam. It would spell
130        // `*/`, which matters only if some earlier `/*` is still open — and one
131        // cannot be, because two nodes are only ever adjacent where a
132        // `⟨/*⟩…⟨*/⟩` was dropped, and that spells a `*/` in the source, so the
133        // earlier `/*` was a `/* … */` comment there and the node before the
134        // seam is that comment rather than content. Separating anyway would be
135        // worse than useless: the separator carries a `*/` of its own.
136        let mut pending_escape = false;
137        let mut bare_slash = false;
138        let mut in_line_comment = false;
139        for n in nodes {
140            let n = n.borrow();
141            // A node that writes nothing leaves the seam exactly where it was.
142            let Some(first) = n.first_byte() else {
143                continue;
144            };
145            if in_line_comment && first != b'\n' && !(bracketed && n.interrupts_comment()) {
146                writer.newline();
147            } else if bare_slash && matches!(first, b'/' | b'*') {
148                writer.write(Q_BLOCK_EMPTY);
149            }
150            n.write(writer);
151            match n {
152                Node::Content(s) => {
153                    for c in escape(s).chars() {
154                        if pending_escape {
155                            pending_escape = false;
156                            bare_slash = false;
157                        } else if c == '\\' {
158                            pending_escape = true;
159                            bare_slash = false;
160                        } else {
161                            bare_slash = c == '/';
162                        }
163                    }
164                    in_line_comment = false;
165                }
166                // Every other node is a whole token: it leaves nothing dangling
167                // for the next one to join onto.
168                Node::PlainLineComment(_) => {
169                    pending_escape = false;
170                    bare_slash = false;
171                    in_line_comment = true;
172                }
173                _ => {
174                    pending_escape = false;
175                    bare_slash = false;
176                    in_line_comment = false;
177                }
178            }
179        }
180    }
181
182    /// Whether this node, written right after a `// …` comment inside a
183    /// bracket, interrupts the comment rather than being swallowed by it: an
184    /// opener, or an escaped arrow (see `parse::Parser::comment`).
185    fn interrupts_comment(&self) -> bool {
186        match self {
187            Node::Quote { .. } | Node::Unquote { .. } => true,
188            Node::Content(s) => s.starts_with(['↖', '↗', '↙', '↘']),
189            _ => false,
190        }
191    }
192
193    /// The first byte [`STerm::write`] emits for this node, or `None` if it
194    /// emits nothing. Only `\n`, `/` and `*` are load-bearing in
195    /// [`Self::write_seq`], but the whole answer is cheaper to state than three
196    /// special cases are to keep in step with the writer.
197    fn first_byte(&self) -> Option<u8> {
198        let first = |s: &str| s.as_bytes().first().copied();
199        match self {
200            // `escape` only ever *prepends* a `\` to a glyph.
201            Node::Content(s) => match s.chars().next() {
202                Some(c) if GLYPHS.contains(&c) => Some(b'\\'),
203                _ => first(s),
204            },
205            Node::NewLine => Some(b'\n'),
206            Node::Quote { anno, .. } => first(anno).or_else(|| first("↖")),
207            Node::Unquote { anno, .. } => first(anno).or_else(|| first("↙")),
208            Node::Reduce { anno } => first(anno).or_else(|| first("↓")),
209            Node::Lift => first("↑"),
210            Node::Emit => first("←"),
211            Node::Type => first(TYPE),
212            Node::Name => first(NAME),
213            Node::Machine { anno } => first(anno).or_else(|| first(MACHINE)),
214            Node::PlainLineComment(s) | Node::PlainBlockComment(s) => first(s),
215        }
216    }
217}
218
219/**************************************************************/
220
221pub enum NodeTag {
222    Content,
223    NewLine,
224    Quote,
225    Unquote,
226    Lift,
227    Reduce,
228    Emit,
229    Name,
230    Type,
231    Machine,
232    PlainLineComment,
233    PlainBlockComment,
234}
235
236impl Term for Node {
237    type Tag = NodeTag;
238
239    fn tag(&self) -> Self::Tag {
240        match self {
241            Node::Content(_) => NodeTag::Content,
242            Node::NewLine => NodeTag::NewLine,
243            Node::Quote { .. } => NodeTag::Quote,
244            Node::Unquote { .. } => NodeTag::Unquote,
245            Node::Lift => NodeTag::Lift,
246            Node::Reduce { .. } => NodeTag::Reduce,
247            Node::Emit => NodeTag::Emit,
248            Node::Type => NodeTag::Type,
249            Node::Name => NodeTag::Name,
250            Node::Machine { .. } => NodeTag::Machine,
251            Node::PlainLineComment(_) => NodeTag::PlainLineComment,
252            Node::PlainBlockComment(_) => NodeTag::PlainBlockComment,
253        }
254    }
255
256    fn children(&self) -> impl Iterator<Item = &Self> {
257        let ret: Box<dyn Iterator<Item = _>> = match self {
258            Node::Quote { nodes, .. } | Node::Unquote { nodes, .. } => {
259                bx(nodes.iter().map(|x| x.as_ref()))
260            }
261            _ => bx(empty()),
262        };
263        ret
264    }
265
266    fn len(&self) -> usize {
267        match self {
268            Node::Quote { nodes, .. } | Node::Unquote { nodes, .. } => nodes.len(),
269            _ => 0,
270        }
271    }
272
273    fn is_empty(&self) -> bool {
274        match self {
275            Node::Quote { nodes, .. } | Node::Unquote { nodes, .. } => nodes.is_empty(),
276            _ => true,
277        }
278    }
279}
280
281impl STerm for Node {
282    fn write<W: std::io::Write>(&self, writer: &mut crate::strcmd::PrefixWriter<'_, W>) {
283        match self {
284            Node::Content(s) => writer.write(&escape(s)),
285            Node::NewLine => writer.newline(),
286            Node::Quote { anno, nodes, .. } => {
287                writer.write(anno);
288                writer.write("↖");
289                Node::write_seq(nodes, true, writer);
290                writer.write("↗");
291            }
292            Node::Unquote { anno, nodes, .. } => {
293                writer.write(anno);
294                writer.write("↙");
295                Node::write_seq(nodes, true, writer);
296                writer.write("↘");
297            }
298            Node::Lift => writer.write("↑"),
299            Node::Reduce { anno } => {
300                writer.write(anno);
301                writer.write("↓");
302            }
303            Node::Emit => writer.write("←"),
304            Node::Type => writer.write(TYPE),
305            Node::Name => writer.write(NAME),
306            Node::Machine { anno } => {
307                writer.write(anno);
308                writer.write(MACHINE);
309            }
310            Node::PlainLineComment(s) | Node::PlainBlockComment(s) => writer.write(s),
311        }
312    }
313}
314
315/**************************************************************/
316
317#[cfg(test)]
318mod tests {
319    use super::*;
320
321    #[test]
322    fn node() -> Result<()> {
323        let source_code = indoc::indoc! {"
324            Some Python: py↖1+2↗
325            ↑↓
326        "};
327        let nodes = Node::parse(source_code)?;
328        dbg!(&nodes);
329        let source_code2 = &*Node::coparse(&nodes);
330        assert_eq!(source_code, source_code2);
331        Ok(())
332    }
333
334    #[test]
335    fn plain_comments_coparse() -> Result<()> {
336        let source_code = "// line comment\n/* block comment */\ncode\n";
337        let nodes = Node::parse(source_code)?;
338        assert!(matches!(&nodes[0], Node::PlainLineComment(s) if &**s == "// line comment"));
339        assert!(matches!(&nodes[2], Node::PlainBlockComment(s) if &**s == "/* block comment */"));
340        assert_eq!(&*Node::coparse(&nodes), source_code);
341        Ok(())
342    }
343
344    /// What `coparse` prints must parse, and print the same thing again.
345    ///
346    /// The law `fuzz/fuzz_targets/escape_roundtrip.rs` states, against the
347    /// inputs that broke it (issue #256). Every case here is *valid* Quilt
348    /// whose parse leaves a node sequence that cannot simply be concatenated
349    /// back: Quilt's own comments are dropped from the tree, so they leave
350    /// behind a seam that the surrounding text closes over when it is re-read.
351    #[test]
352    fn coparse_output_parses_and_is_a_fixpoint() {
353        let cases = [
354            // The crash libFuzzer found. `⟨/*⟩…⟨*/⟩` takes the newline in front
355            // of it, so the `//n//` line comment reached the `↖` and swallowed
356            // it, leaving `↗` with no opener.
357            "ea//n//\n⟨/*⟩↖K//n*⟨*/⟩↖\n\0\0\0\0\0\0\0x↗;fft/",
358            // The same shape, minimised, at ground level and inside a bracket.
359            "//c\n⟨/*⟩z⟨*/⟩↖b↗",
360            "↖//c\n⟨/*⟩z⟨*/⟩↖b↗↗",
361            // A `//` that exists in neither node: the dropped comment was the
362            // only thing keeping the two slashes apart.
363            "a/⟨/*⟩z⟨*/⟩/↖b↗",
364            // And the `/*` and `*/` spellings of the same seam.
365            "a/⟨/*⟩z⟨*/⟩*↖b↗",
366            "a/⟨/*⟩z⟨*/⟩*↖b*/↗",
367            "a/⟨/*⟩z⟨*/⟩/* c */↖b↗",
368            // Seams that must *not* grow a separator.
369            "a/b/c",
370            "// line\n/* block */\ncode\n",
371            "↖//c↗",
372        ];
373        for src in cases {
374            let nodes = Node::parse(src).unwrap_or_else(|e| panic!("{src:?} does not parse: {e}"));
375            let printed = Node::coparse(&nodes);
376            let reparsed = Node::parse(&printed).unwrap_or_else(|e| {
377                panic!("{src:?} printed {printed:?}, which does not parse: {e}")
378            });
379            assert_eq!(
380                &*Node::coparse(&reparsed),
381                &*printed,
382                "{src:?} printed {printed:?}, which does not print itself"
383            );
384        }
385    }
386
387    /// The separators are only written where they are needed. Both of these
388    /// have a case in them that a separator would *break*, and both came out
389    /// of the sweep in `tests/parser_corpus.rs` rather than out of thinking
390    /// about it:
391    ///
392    /// * `a\/// x` is content `a\/` and a comment `// x`. The `/` ending the
393    ///   content is the second half of a `\/` unit and cannot start a token,
394    ///   so the two are already adjacent in valid source.
395    /// * `↑/*//` ends its content with `*`, not `/`. Separating there would put
396    ///   the separator's own `*/` where it closes the still-open `/*`, in the
397    ///   middle of a `⟨*/⟩` — leaving a stray `⟩` and no parse at all.
398    #[test]
399    fn separators_are_not_written_where_the_source_already_parses() -> Result<()> {
400        for src in [
401            "// line\n/* block */\ncode\n",
402            "a/b/c ↖x↗ /* c */ // done\n",
403            "↖//c↗",
404            "↖a/↗/b",
405            "a\\/// x",
406            "↑/*//",
407        ] {
408            assert_eq!(&*Node::coparse(&Node::parse(src)?), src, "{src:?}");
409        }
410        Ok(())
411    }
412
413    /// An empty `⟨/*⟩⟨*/⟩` really is inert — that is the whole reason
414    /// `write_seq` can use it as a separator.
415    #[test]
416    fn the_empty_block_comment_writes_nothing() -> Result<()> {
417        assert!(Node::parse(Q_BLOCK_EMPTY)?.is_empty());
418        assert_eq!(&*Node::coparse(&Node::parse("a⟨/*⟩⟨*/⟩b")?), "ab");
419        Ok(())
420    }
421
422    #[test]
423    fn annotated_reduce() -> Result<()> {
424        let source_code = "↓ py↓ rs↓";
425        let nodes = Node::parse(source_code)?;
426        assert_eq!(nodes.len(), 5); // ↓, space, py↓, space, rs↓
427        assert!(matches!(&nodes[0], Node::Reduce { anno } if anno.is_empty()));
428        assert!(matches!(&nodes[2], Node::Reduce { anno } if &**anno == "py"));
429        assert!(matches!(&nodes[4], Node::Reduce { anno } if &**anno == "rs"));
430        let roundtrip = &*Node::coparse(&nodes);
431        assert_eq!(roundtrip, source_code);
432        Ok(())
433    }
434
435    /// An annotation may carry digits after its first letter, in all three
436    /// annotated openers — so the registered alias `lean4` can be *written*
437    /// (issue #222). It could not be, under the old `[a-z]*↖`: `lean4↖…↗` was
438    /// the content `lean4` followed by an un-annotated quote, and the mistake
439    /// surfaced somewhere else entirely.
440    #[test]
441    fn annotations_take_digits_after_the_first_letter() -> Result<()> {
442        let source_code = "lean4↖x↗ lean4↙y↘ lean4↓";
443        let nodes = Node::parse(source_code)?;
444        assert_eq!(nodes.len(), 5); // quote, space, unquote, space, reduce
445        assert!(matches!(&nodes[0], Node::Quote { anno, .. } if &**anno == "lean4"));
446        assert!(matches!(&nodes[2], Node::Unquote { anno, .. } if &**anno == "lean4"));
447        assert!(matches!(&nodes[4], Node::Reduce { anno } if &**anno == "lean4"));
448        assert_eq!(&*Node::coparse(&nodes), source_code);
449        Ok(())
450    }
451
452    /// The other half of that rule, and the reason it is not simply
453    /// `[a-z0-9]*`: a *number* abutting the glyph stays content. `42↖…↗` is the
454    /// literal `42` and a bare quote — which defaults to the host language —
455    /// not a quote of some language named "42".
456    #[test]
457    fn a_bare_number_is_not_an_annotation() -> Result<()> {
458        let source_code = "x = 42↖1↗";
459        let nodes = Node::parse(source_code)?;
460        assert!(matches!(&nodes[0], Node::Content(s) if &**s == "x = 42"));
461        assert!(matches!(&nodes[1], Node::Quote { anno, .. } if anno.is_empty()));
462        assert_eq!(&*Node::coparse(&nodes), source_code);
463        Ok(())
464    }
465
466    /// Malformed bracket structure is an `Err`, never a panic. Each of these
467    /// used to abort the process via an `unreachable!` in the tree-sitter
468    /// parser — including under `quilt check`, which exists to report
469    /// diagnostics and which lost the whole run (exit 101) to a single stray
470    /// glyph.
471    ///
472    /// Only *surface* malformation belongs here. A top-level `↙x↘` is
473    /// well-formed syntax — an unquote with no enclosing quote is a depth error,
474    /// caught later by the expander with its own diagnostic
475    /// (`Expander::expand` → `unquote_depth_error`).
476    #[test]
477    fn malformed_brackets_are_errors_not_panics() {
478        for src in [
479            "fn main() { let x = ↖1 + 2; }", // unclosed quote
480            "fn main() { let x = 1 ↗ 2; }",  // stray quote close
481            "fn main() { ↘ }",               // stray unquote close
482            "↖↙↗",                           // closer/opener interleaved
483            "py↖",                           // annotated opener, nothing after
484        ] {
485            let err = Node::parse(src)
486                .expect_err("malformed Quilt source should be an Err, not Ok or a panic");
487            assert!(
488                err.to_string().contains("malformed Quilt syntax"),
489                "diagnostic should name the syntax error, got: {err}"
490            );
491        }
492    }
493
494    /// A well-formed nesting of every bracket form still parses, so the
495    /// `has_error` gate isn't rejecting valid input.
496    #[test]
497    fn well_formed_brackets_still_parse() -> Result<()> {
498        for src in ["↖↗", "↖\n↗", "py↖1+2↗", "rs↖ wgsl↖ ↙x↘ ↗ ↗", "↖↙↖↙x↘↗↘↗"]
499        {
500            let nodes = Node::parse(src).map_err(|e| e.wrap_err(format!("parsing {src:?}")))?;
501            assert_eq!(&*Node::coparse(&nodes), src, "{src:?} did not round-trip");
502        }
503        Ok(())
504    }
505
506    /// The error span points *inside* the offending source rather than at the
507    /// whole file, so the rendered diagnostic underlines something useful.
508    #[test]
509    fn syntax_error_span_is_narrow() {
510        let src = "aaaaaaaaaa↗bbbbbbbbbb";
511        let err = Node::parse(src).expect_err("stray `↗` should not parse");
512        let labels: Vec<_> = err.labels().into_iter().flatten().collect();
513        assert_eq!(labels.len(), 1, "expected exactly one label: {err}");
514        let len = labels[0].len();
515        assert!(
516            len < src.len(),
517            "label should be narrower than the whole source, got {len} of {}",
518            src.len()
519        );
520    }
521
522    /// Every glyph in [`GLYPHS`] is escapable: `\<glyph>` parses to plain
523    /// content holding the bare glyph, and `coparse` puts the `\` back, so the
524    /// source round-trips. Before issue #141 only `↑` and `↓` were re-escaped
525    /// on output (and `←` was not escapable at all), so `\⟨` and friends were
526    /// lossy.
527    #[test]
528    fn every_glyph_round_trips() -> Result<()> {
529        for g in GLYPHS {
530            let glyph = g.to_string();
531            let source_code = format!("a \\{g} b");
532            let nodes = Node::parse(&source_code)?;
533            assert!(
534                nodes
535                    .iter()
536                    .any(|n| matches!(n, Node::Content(s) if **s == *glyph)),
537                "`\\{g}` did not parse to content holding `{g}`: {nodes:?}"
538            );
539            assert_eq!(
540                &*Node::coparse(&nodes),
541                source_code,
542                "`\\{g}` lost its escape"
543            );
544        }
545        Ok(())
546    }
547
548    /// `escape` and `unescape` are inverses over the whole glyph set, and a
549    /// backslash before a *non*-glyph (`_non_escape` in the grammar) is left
550    /// alone in both directions.
551    #[test]
552    fn escape_unescape_are_inverses() {
553        let raw = "x ← y ↑ z ⟨ w ↖ v";
554        let escaped = "x \\← y \\↑ z \\⟨ w \\↖ v";
555        assert_eq!(&*escape(raw), escaped);
556        assert_eq!(&*unescape(escaped), raw);
557        // `\n` here is a literal backslash-n, not a newline: not a glyph, so it
558        // survives unescaping verbatim rather than losing its backslash.
559        assert_eq!(&*unescape("a \\n b"), "a \\n b");
560        assert_eq!(&*escape("no glyphs here"), "no glyphs here");
561    }
562
563    /// [`ARROW_LEN`] is one constant for the whole glyph set, and `quilt-lsp`'s
564    /// `regions`/`code_actions` do byte arithmetic with it (`body.end +
565    /// ARROW_LEN`), so *every* glyph must be that wide — not just the six arrows
566    /// this test used to cover. Adding a glyph of another width to [`GLYPHS`]
567    /// fails here rather than silently shifting LSP ranges.
568    #[test]
569    fn glyph_lengths_are_uniform() {
570        for g in GLYPHS {
571            assert_eq!(
572                g.len_utf8(),
573                ARROW_LEN,
574                "glyph {g:?} is {} bytes, but ARROW_LEN is {ARROW_LEN}",
575                g.len_utf8()
576            );
577        }
578        assert_eq!(ESCAPE_LEN, 1, "the escape introducer is a one-byte `\\`");
579    }
580}