quiltlang 0.6.0

Quilt, a polyglot metaprogramming language: source code with arrow-bracket syntax for embedding and manipulating code fragments of other languages at code-generation time.
Documentation
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//! The SQL target language.
//!
//! SQL is only ever a *quoted* language (e.g. `sql↖ … ↗` inside Rust): Quilt
//! parses SQL fragments into a `QTerm` and the host language's `MetaLanguage`
//! (Rust's) drives expansion. There is therefore no `SqlMetaLanguage` — only
//! this `Language` impl, built on the shared tree-sitter helper.
//!
//! The point of quoting SQL rather than concatenating strings is that a value
//! spliced with `↑` becomes a *literal node*, not text: `LiftTo<Sql> for str`
//! (see [`crate::lift`]) builds a `literal` whose spelling is a standard SQL
//! string with every `'` doubled, so a value can never close the literal and
//! continue the statement. The conformance battery reparses every lifted
//! literal in this grammar, which is what keeps that claim honest (#219).
//!
//! Two shapes of fragment are accepted, mirroring how the grammar is layered:
//!
//! * A **statement** — `sql↖SELECT * FROM t WHERE id = ↙id.↑↘↗` — parses on its
//!   own, since `program` is a repeat of statements.
//! * A bare **expression** — `sql↖id = ↙id.↑↘↗`, the shape a composable
//!   predicate takes — does not: `program` holds statements, so a lone
//!   expression is a parse error. [`SqlLanguage`] retries such a fragment
//!   inside [`SELECT_PREFIX`] and strips the wrapper back off, the same
//!   technique `langs::lean::lang` uses with `#check …`.
//!
//! The same wrapper serves a hole standing where a whole *statement* goes
//! (`↙stmt↘;` on its own line), which a bare identifier cannot occupy either —
//! see [`statement_hole_ordinals`] (#234).

use crate::{
    lang::{Arity, Comments, FlatNode, InnerKind, Language, LanguagePost},
    prelude::*,
    qterm::QTerm,
    term::CmdOrHole,
    treesitter::{TSLanguage, TSLanguagePost, TSProvider},
};
use miette::{bail, Result};
use tree_sitter::Parser;

/**************************************************************/

pub struct SqlProvider(tree_sitter::Parser);

impl Default for SqlProvider {
    fn default() -> Self {
        let mut parser = Parser::new();
        parser
            .set_language(&crate::grammars::sql::LANGUAGE.into())
            .expect("Error loading SQL parser");
        Self(parser)
    }
}

impl TSProvider for SqlProvider {
    fn parser(&mut self) -> &mut tree_sitter::Parser {
        &mut self.0
    }

    /// The machine for SQL is a database connection: a live `sqlite3` whose
    /// temp tables and attached state are its definitions — which makes SQL
    /// the first *target-only* language with a machine
    /// (docs/design/machines.md). A query is any SQL expression (spelled
    /// through `SELECT …;`), the typing judgment is sqlite's `typeof`, and
    /// `-bail` keeps the contract that a rejected feed is an `Err` rather
    /// than a silently-logged diagnostic. The sentinel is a `SELECT` of a
    /// string literal, which prints as its own line.
    /// Registered in `machine::repl_spec`; see `PythonProvider::machine_spec`.
    fn repl_spec(&self) -> Option<crate::machine::ReplSpec> {
        crate::machine::repl_spec("sql")
    }

    fn hole_str(&self) -> &'static str {
        // `__QUILT_HOLE__` matches this grammar's `_identifier` regex
        // (`/[A-Za-z_À-ſ][0-9A-Za-z_À-ſ]*/`), so it parses
        // as an `identifier` wherever one may appear — predicate operand,
        // select expression, relation name, `IN` list element — with **no
        // grammar patch at all**, the same free ride nix and lean get. The
        // range-based hole detection in `treesitter.rs` then recognises it by
        // its byte range. `test/corpus/quilt.txt` in the fork pins those four
        // positions.
        //
        // The one position this does *not* reach unaided is a bare hole as a
        // whole statement (`SELECT 1; ↙stmt↘; SELECT 2;`): no SQL statement
        // starts with a bare identifier, so that is a parse error. That case is
        // handled a level up, by the `SELECT …` wrapper retry in
        // `SqlLanguage::parse_pre` — see `statement_hole_ordinals` (#234).
        "__QUILT_HOLE__"
    }

    fn hashbang(&self) -> Option<&'static str> {
        // SQL is executed by a database, not by an interpreter reading a
        // shebang, and `#!` is not comment syntax in SQL.
        None
    }

    /// Derived from the grammar's `REPEAT` rules by `bin/gen-arity`, not
    /// hand-curated — see `quilt/src/langs/arity.rs` (#202).
    fn arity(&self, tag: &str) -> Arity {
        Arity::from_table(crate::langs::arity::SQL, tag)
    }

    /// `,` for the kinds `bin/gen-arity` finds comma-separated (#293).
    fn separator(&self, tag: &str) -> Option<&'static str> {
        crate::lang::comma_separator(crate::langs::arity::SQL_COMMA_SEPARATED, tag)
    }

    /// SQL is layered `program` → statement → clause → expression, so the tag
    /// alone answers this: the three things `program`'s repeat holds are
    /// statement-like, everything else is a value or a part of one.
    fn typ(&self, tag: &str) -> InnerKind {
        match tag {
            "program" => InnerKind::File,
            // The `choice` inside `program`'s repeat: a plain statement, a
            // `BEGIN … COMMIT` transaction, or a T-SQL `BEGIN … END` block.
            "statement" | "transaction" | "block" => InnerKind::Stmt,
            // Clauses (`select`, `from`, `where`, …) and operands alike. SQL
            // has no kind between "statement" and "value", and clauses are
            // spliced the same way operands are.
            _ => InnerKind::Expr,
        }
    }

    /// Squash the `program` wrapper around a single quoted fragment so the term
    /// is the fragment itself. A fragment with several statements (or one with
    /// its terminating `;`) stays a `program`, since dropping the wrapper would
    /// lose the separators.
    fn unwrap(&self, qterm: QTerm, ikind: Option<InnerKind>) -> Result<(QTerm, InnerKind)> {
        let QTerm::Tuple { tag, terms, .. } = &qterm else {
            return Ok((qterm, InnerKind::default()));
        };
        if &**tag != "program" {
            return Ok((qterm, InnerKind::default()));
        }
        if terms.len() != 1 {
            // Empty, several statements, or a statement plus its trailing `;`.
            // `classify_term` recognises the last of those as a `Stmt`.
            let kind = self.classify_term(&qterm);
            return Ok((qterm, kind));
        }
        let kind = self.classify_term(&terms[0]);
        Ok((qterm.squash(), ikind.unwrap_or(kind)))
    }

    /// Classify a fully-parsed SQL term as expression / statement / file.
    ///
    /// Needed (rather than plain [`typ`](TSProvider::typ)) because a
    /// single-statement fragment arrives wrapped in `program` — and, when it
    /// keeps its terminating `;`, wrapped in a *two*-child `program` whose root
    /// tag alone would read `File` for what is really one statement.
    ///
    /// One more override: a *parenthesized* select at statement level — the
    /// grammar's `statement("(", select, ")")` — classifies as
    /// [`Expr`](InnerKind::Expr). Parentheses are exactly how SQL marks "the
    /// value of this query" (a scalar subquery), and machine-eval routing
    /// rides classification: `db.↓(…)` on a parenthesized query must
    /// *answer* it, not feed it as an effect.
    fn classify_term(&self, term: &QTerm) -> InnerKind {
        match term {
            QTerm::Tuple { tag, terms, .. } if &**tag == "program" => match terms.len() {
                1 => self.classify_term(&terms[0]),
                // A single statement plus its trailing `;`: still a `Stmt`.
                2 if is_semi(&terms[1]) => self.classify_term(&terms[0]),
                // Empty (0) or several statements (3+): a whole script.
                _ => InnerKind::File,
            },
            // Only the opener is checked: with a splice hole in the body the
            // parser can hang the closing `)` off the inner `select` instead
            // of the `statement`, so requiring the 3-child shape would read
            // the same source two ways depending on whether it was spliced.
            QTerm::Tuple { tag, terms, .. }
                if &**tag == "statement"
                    && matches!(
                        terms.first().map(AsRef::as_ref),
                        Some(QTerm::Tuple { tag, .. }) if &**tag == "("
                    ) =>
            {
                InnerKind::Expr
            }
            QTerm::Tuple { tag, .. } => self.typ(tag),
            _ => InnerKind::default(),
        }
    }
}

/// Is this term the anonymous `;` statement terminator?
fn is_semi(term: &QTerm) -> bool {
    matches!(term, QTerm::Tuple { tag, terms, .. } if &**tag == ";" && terms.is_empty())
}

/**************************************************************/

/// The synthetic statement a bare *expression* fragment is parsed inside.
///
/// SQL's `program` holds **statements**, so `sql↖id = 1↗` is a parse error on
/// its own — unlike Rust or Python, whose `source_file` accepts a bare
/// expression. Since expression-level composition is much of the point of
/// quoting (`sql↖SELECT * FROM t WHERE ↙pred↘↗`), [`SqlLanguage`] retries a
/// failed parse inside `SELECT …`, the smallest SQL statement that takes an
/// arbitrary expression, and then strips the wrapper back off. See
/// [`strip_select`].
const SELECT_PREFIX: &str = "SELECT ";

/// Undo the [`SELECT_PREFIX`] wrapper: given the parsed statement, return just
/// the expression it wrapped.
///
/// The input is what [`SqlProvider::unwrap`] hands back, so the `program` root
/// has already been squashed away and this starts at the `statement`. The rest
/// of the chain is fixed by the grammar — `statement` → `select` →
/// `select_expression` → `term` → the expression — and every link is checked
/// here rather than assumed, because the retry can succeed on input that is not
/// a lone expression at all (`SELECT a, b` gives a two-`term`
/// `select_expression`; `SELECT 1; DROP TABLE t` leaves the multi-statement
/// `program` unsquashed). Anything but the exact single-expression shape is
/// refused, and the caller then reports the *original* parse error.
fn strip_select(qterm: &QTerm) -> Result<Arc<QTerm>> {
    /// The single child of a tuple with the expected tag, or an error.
    fn only_child<'a>(term: &'a QTerm, want: &str) -> Result<&'a Arc<QTerm>> {
        let QTerm::Tuple { tag, terms, .. } = term else {
            bail!("sql: expected a {want:?} tuple after wrapping, got a quote/unquote");
        };
        if &**tag != want || terms.len() != 1 {
            bail!("sql: expected a 1-child {want:?} tuple after wrapping, got {tag:?}");
        }
        Ok(&terms[0])
    }

    let select = only_child(qterm, "statement")?;
    // `select` is `seq(keyword_select, optional(keyword_distinct),
    // select_expression)`, so an un-aliased one has exactly two children.
    let QTerm::Tuple { tag, terms, cmds } = &**select else {
        bail!("sql: expected a `select` tuple after wrapping, got a quote/unquote");
    };
    if &**tag != "select" || terms.len() != 2 {
        bail!("sql: expected a 2-child `select` tuple after wrapping, got {tag:?}");
    }
    // Nothing may follow the select expression, or dropping the wrapper would
    // lose text.
    let last_hole = cmds
        .iter()
        .rposition(|c| matches!(c, CmdOrHole::Hole))
        .expect("select tuple has children");
    if cmds[last_hole + 1..]
        .iter()
        .any(|c| !matches!(c, CmdOrHole::Cmd(StrCmd::Write(s)) if s.is_empty()))
    {
        bail!("sql: unexpected trailing text after the `SELECT` wrapper's expression");
    }
    // Peel the two wrapper layers, `select_expression` then `term`.
    //
    // Either can be *absent*, and that is not a failure. `select_expression`,
    // `term` and the expression beneath them span exactly the same bytes when
    // the fragment is a lone hole (`sql↖↙v↘↗`), and `build_nodes` replaces the
    // outermost node whose range matches the hole — so the layers are simply
    // not in the tree. A layer that *is* present must hold exactly one child:
    // `SELECT a, b` gives `select_expression` two `term`s and `SELECT x AS y`
    // gives `term` an alias sibling, and neither is a lone expression.
    let mut inner = terms[1].clone();
    for layer in ["select_expression", "term"] {
        let QTerm::Tuple { tag, terms, .. } = &*inner else {
            bail!("sql: expected a tuple inside the `SELECT` wrapper, got a quote/unquote");
        };
        if &**tag != layer {
            break;
        }
        if terms.len() != 1 {
            bail!("sql: the `SELECT` wrapper holds a {layer:?} with {} children, not a lone expression", terms.len());
        }
        let next = terms[0].clone();
        inner = next;
    }
    Ok(inner)
}

/// Ordinals (into the fragment's hole sequence) of holes that stand where a
/// whole **statement** goes:
///
/// ```text
/// SELECT 1;
/// ↙stmt↘;
/// SELECT 2;
/// ```
///
/// `program` is `repeat(seq(choice(statement, transaction, block), ';'))` and no
/// SQL statement begins with a bare identifier, so such a hole is a parse error
/// on its own. Wrapping just these holes in [`SELECT_PREFIX`] makes them
/// statements; [`strip_wrapped_selects`] removes the wrapper again.
///
/// A hole qualifies when nothing but whitespace precedes it on its line and
/// nothing but whitespace and **at most one `;`** follows it. The `;` is the
/// difference from the Lean version this is modelled on
/// (`langs::lean::lang::line_hole_ordinals`): SQL statements are terminated, so
/// the natural spelling puts the separator right after the hole. Allowing the
/// bare form too covers the trailing statement `program` lets go unterminated.
///
/// Deliberately line-based rather than `;`-scanning: a `;` inside a string
/// literal is ordinary text in the flat node stream, and a scanner that split on
/// it would wrap holes that are not in statement position at all. Anything this
/// declines simply falls back to the original parse error.
fn statement_hole_ordinals(code: &[FlatNode]) -> Vec<usize> {
    /// The text on one side of a hole, up to the nearest line break — or `None`
    /// if another hole intervenes, which means this one is not alone.
    fn text_run<'a>(nodes: impl Iterator<Item = &'a FlatNode<'a>>) -> Option<String> {
        let mut out = String::new();
        for node in nodes {
            match node {
                FlatNode::NewLine => break,
                FlatNode::Str(s) => out.push_str(s),
                FlatNode::Hole | FlatNode::Splice => return None,
            }
        }
        Some(out)
    }

    let mut out = Vec::new();
    for (i, node) in code.iter().enumerate() {
        if !node.is_hole() {
            continue;
        }
        let ordinal = code[..i].iter().filter(|n| n.is_hole()).count();
        let before = text_run(code[..i].iter().rev());
        let after = text_run(code[i + 1..].iter());
        let alone = matches!(before, Some(ref b) if b.trim().is_empty())
            && matches!(after, Some(ref a) if matches!(a.trim(), "" | ";"));
        if alone {
            out.push(ordinal);
        }
    }
    out
}

/// Rebuild `code` with [`SELECT_PREFIX`] inserted before each hole whose ordinal
/// is in `targets`.
fn wrap_statement_holes<'a>(code: &[FlatNode<'a>], targets: &[usize]) -> Vec<FlatNode<'a>> {
    let mut out = Vec::with_capacity(code.len() + targets.len());
    let mut ordinal = 0usize;
    for node in code {
        if node.is_hole() {
            if targets.contains(&ordinal) {
                out.push(FlatNode::Str(SELECT_PREFIX));
            }
            ordinal += 1;
        }
        out.push(node.clone());
    }
    out
}

/// Undo [`wrap_statement_holes`] in the parsed tree: replace each `statement`
/// that wraps one of the holes we wrapped with that hole itself.
///
/// Only the wrappers *we* introduced are removed — holes are counted in tree
/// order and matched against `targets` — so a genuine `SELECT ↙col↘` written by
/// the author survives untouched.
///
/// The shape searched for is `statement(select(keyword_select, <hole>))`: the
/// hole spans the same bytes as the `select_expression`, `term` and `field` that
/// would otherwise sit between, and `build_nodes` replaces the outermost node
/// whose range matches, so those layers are not in the tree. That is the same
/// collapse [`strip_select`] peels through.
///
/// Returns the rewritten term and **how many wrappers were removed**. The caller
/// requires that to equal `targets.len()` and discards the retry otherwise: a
/// target that did not come back in the expected shape means the prefix landed
/// somewhere other than statement position — inside a string literal, say — and
/// keeping such a tree would silently splice a stray `SELECT` into the output.
/// Failing there costs only the original parse error, which is what the user
/// would have seen anyway.
fn strip_wrapped_selects(
    term: &Arc<QTerm>,
    hole_str: &str,
    targets: &[usize],
) -> (Arc<QTerm>, usize) {
    /// Is this the `statement(select(keyword_select, <hole>))` we introduced?
    fn wrapped_hole<'a>(terms: &'a [Arc<QTerm>], hole_str: &str) -> Option<&'a Arc<QTerm>> {
        let [only] = terms else { return None };
        let QTerm::Tuple {
            tag: sel,
            terms: sel_terms,
            ..
        } = &**only
        else {
            return None;
        };
        if &**sel != "select" {
            return None;
        }
        let [_keyword, hole] = &sel_terms[..] else {
            return None;
        };
        matches!(&**hole, QTerm::Tuple { tag, .. } if &**tag == hole_str).then_some(hole)
    }

    fn walk(
        term: &Arc<QTerm>,
        hole_str: &str,
        targets: &[usize],
        ordinal: &mut usize,
        stripped: &mut usize,
    ) -> Arc<QTerm> {
        let QTerm::Tuple { tag, terms, cmds } = &**term else {
            // Quotes/unquotes cannot appear inside a freshly parsed fragment.
            return term.clone();
        };

        if &**tag == "statement" {
            if let Some(hole) = wrapped_hole(terms, hole_str) {
                if targets.contains(ordinal) {
                    *ordinal += 1;
                    *stripped += 1;
                    return hole.clone();
                }
            }
        }

        if &**tag == hole_str {
            *ordinal += 1;
            return term.clone();
        }

        let children: Vec<Arc<QTerm>> = terms
            .iter()
            .map(|t| walk(t, hole_str, targets, ordinal, stripped))
            .collect();
        tuple(tag, &children, cmds)
    }

    let mut ordinal = 0usize;
    let mut stripped = 0usize;
    let out = walk(term, hole_str, targets, &mut ordinal, &mut stripped);
    (out, stripped)
}

/// The SQL `Language`: [`TSLanguage<SqlProvider>`] plus the bare-expression
/// retry described on [`SELECT_PREFIX`], and the statement-position hole
/// wrapper described on [`statement_hole_ordinals`].
#[derive(Default)]
pub struct SqlLanguage(TSLanguage<SqlProvider>);

impl Comments for SqlLanguage {
    /// `--` is the one line comment every dialect agrees on; `#` is a `MySQL`
    /// extension, and this one spelling has to serve `sql`, `mysql` and
    /// `mariadb` alike.
    const LINE: Option<&'static str> = Some("--");
}

impl Language for SqlLanguage {
    type Post = TSLanguagePost;

    fn parse_pre(&mut self, ikind: Option<InnerKind>, code: &[FlatNode]) -> Result<Self::Post> {
        // A statement fragment (and a whole script) parses on its own; only a
        // bare expression needs the wrapper, so try plain first and keep this a
        // no-op for everything else.
        let err = match self.0.parse_pre(ikind, code) {
            Ok(post) => return Ok(post),
            Err(e) => e,
        };

        let mut wrapped = Vec::with_capacity(code.len() + 1);
        wrapped.push(FlatNode::Str(SELECT_PREFIX));
        wrapped.extend_from_slice(code);

        // Report the *original* error whenever the retry doesn't yield a clean
        // single-expression `SELECT` — the wrapper is an implementation detail,
        // and naming it would only mislead.
        if let Some(post) = self
            .0
            .parse_pre(Some(InnerKind::Expr), &wrapped)
            .ok()
            .and_then(|post| {
                let qterm = strip_select(&post.qterm).ok()?;
                Some(TSLanguagePost {
                    qterm: (*qterm).clone(),
                    ..post
                })
            })
        {
            return Ok(post);
        }

        // Last resort: holes at *statement* position, which a bare identifier
        // cannot occupy. Wrap only those holes and strip the wrappers back out
        // of the tree, leaving every other hole alone.
        let targets = statement_hole_ordinals(code);
        if !targets.is_empty() {
            let wrapped = wrap_statement_holes(code, &targets);
            if let Some(post) = self.0.parse_pre(ikind, &wrapped).ok().and_then(|post| {
                let hole_str = post.hole_str;
                let (qterm, stripped) =
                    strip_wrapped_selects(&arc(post.qterm.clone()), hole_str, &targets);
                // Every wrapper we added must have come back out; see
                // `strip_wrapped_selects`.
                if stripped != targets.len() {
                    return None;
                }
                // The wrapped holes were measured against the *wrapper*'s
                // position, so they came back `Expr` (a select expression).
                // What can actually fill them is a statement — the same answer
                // `langs::lean::lang::hole_kind` gives a hole in a `by`/`do`
                // body, and what `multi.rs` threads into the host parse of the
                // unquote body.
                let mut holes = post.holes.into_vec();
                for &t in &targets {
                    if let Some(hole) = holes.get_mut(t) {
                        hole.ikind = Some(InnerKind::Stmt);
                    }
                }
                Some(TSLanguagePost {
                    qterm: (*qterm).clone(),
                    holes: holes.into_boxed_slice(),
                    hole_str,
                })
            }) {
                return Ok(post);
            }
        }

        Err(err)
    }

    fn arity(&self, tag: &str) -> Arity {
        self.0.arity(tag)
    }

    fn separator(&self, tag: &str) -> Option<&'static str> {
        self.0.separator(tag)
    }

    fn typ(&self, tag: &str) -> InnerKind {
        self.0.typ(tag)
    }

    fn classify_term(&self, term: &QTerm) -> InnerKind {
        self.0.classify_term(term)
    }

    fn hashbang(&self) -> Option<&'static str> {
        self.0.hashbang()
    }

    fn machine_spec(&self) -> Option<crate::machine::MachineSpec> {
        self.0.machine_spec()
    }

    fn repl_spec(&self) -> Option<crate::machine::ReplSpec> {
        self.0.repl_spec()
    }
}

/// Boxed-`Post` form of [`SqlLanguage`], for the dynamic registry.
#[derive(Default)]
pub struct DynSqlLanguage(SqlLanguage);

impl Language for DynSqlLanguage {
    type Post = Box<dyn LanguagePost>;

    fn parse_pre(&mut self, ikind: Option<InnerKind>, code: &[FlatNode]) -> Result<Self::Post> {
        Ok(bx(self.0.parse_pre(ikind, code)?) as Self::Post)
    }

    fn arity(&self, tag: &str) -> Arity {
        self.0.arity(tag)
    }

    fn separator(&self, tag: &str) -> Option<&'static str> {
        self.0.separator(tag)
    }

    fn typ(&self, tag: &str) -> InnerKind {
        self.0.typ(tag)
    }

    fn classify_term(&self, term: &QTerm) -> InnerKind {
        self.0.classify_term(term)
    }

    fn hashbang(&self) -> Option<&'static str> {
        self.0.hashbang()
    }

    fn machine_spec(&self) -> Option<crate::machine::MachineSpec> {
        self.0.machine_spec()
    }

    fn repl_spec(&self) -> Option<crate::machine::ReplSpec> {
        self.0.repl_spec()
    }
}