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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Direct term-lifting for the Python meta-language.
//!
//! These helpers build the `Arc<QTerm>` that *reconstructs* a term by writing
//! constructor source (`tb(..).c(child)..b()`, `quote(..)`, ...) directly and
//! splicing child terms at holes. The emitted source is **Python**, targeting a
//! `quilt` Python runtime whose builder mirrors the Rust `QTermBuilder` fluent
//! API (`tb`/`.c`/`.w`/`.n`/`.p`/`.x`/`.e`/`.b`, `quote`/`unquote`, `leaf`/`sym`,
//! `cmd`/`write`/`push`/`NL`/`POP`/`HOLE`).
//!
//! The fold that assembles those chains is shared with the Rust and TypeScript
//! metas — see [`crate::langs::chain`]. All that is Python-specific is which
//! fragments it writes, which is a generated table, and the escaping below.
//!
//! One difference is not a spelling and so is not in the table: a variadic node
//! is a fluent `.e()` emit chain rather than Rust's imperative
//! `{ let mut b_ = ..; ..; b_.b() }` block, which has no Python
//! expression-context equivalent. (A consequence: statement-context splicing —
//! control flow inside `↙..↘` that emits into a named `b_` — is not expressible
//! in Python and is unsupported.)
use crate;
use crate*;
use crateCmdOrHole;
/**************************************************************/
/// Render a Python double-quoted string literal, escaping `\` and `"` and the
/// control characters a one-line literal cannot hold.
///
/// Escaping only `"` used to be enough by accident: no literal it was handed
/// held a newline. A multi-line token whose continuation line sits outside the
/// prefix is now written as a raw `"\n"` (so it is not re-indented), which in
/// an unescaped `"…"` is a syntax error. And an unescaped `\` was always wrong:
/// `"a\\nb"` in a quoted string came out as `"a\nb"`, a different string.
/// The shared builder-call fold, spelled for Python.
const CHAIN: Chain = new;
/**************************************************************/
/// Build code that reconstructs a tuple: `tb(tag).w(..).c(child)..b()`, using
/// the `sym`/`leaf` shorthands when possible. `children` are the already-built
/// child expressions spliced at hole positions.
/// Build `quote(tag, index, lang, <term>, [..cmds..])`, splicing `term`.
/// Build `unquote(tag, index, lang, <term>, [..cmds..])`, splicing `term`.
/// Build a variadic node as a fluent emit chain:
/// `tb(tag).e(child).p("..").n()..b()`. `children` are the already-expanded
/// terms; each is emitted with `.e(..)` (which, like Rust's `.emit(&mut b_)`,
/// appends one-or-more children). Unlike Rust's variadic, there is no named
/// `b_`, so statement-context splicing is unsupported (see module docs).
/**************************************************************/
/// Make an identifier term (the `⟨N⟩` operator).