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
//! dsl.rs §28: the open-extension mechanism — unknown `#name(args){body}`
//! becomes a top-level macro call (`{! m!{...}}` 4-segment protocol), plus
//! the manual top-level / in-impl forms.
//! (split from the former single-file `tests/dsl.rs`)
use ;
// ============================================================
// 28. Open extension mechanism: user macros expand to items based on the trait
// `usize #batch_preprocess_test(add,inc){*self+1}` expands to a top-level
// macro call `{ ! batch_preprocess_test!{(add,inc){*self+1} trait AddInc {...}} }`
// — the `!` marks top-level emission: the spec body `{usize}` is prepended
// to the macro input (4 segments) and the macro emits its own impl.
// The manual in-impl form `T {m!{...}}` (no `!`) keeps the call in the
// impl body (associated items); `T {! m!{...}}` is the top-level form
// with a user-written input. batch_preprocess_test! parses
// method names/body/trait and generates fn definitions (or a full impl
// in the top-level form), equivalent to handing `#fill` to a user macro
// (each type can carry its own; the trait is not duplicated)
// ============================================================
// Top-level form with a user-written macro call (`{! ...}` attach): the spec
// body `{T}` is prepended — the macro receives 4 segments and emits its own
// impl, same as the `#cmd` form.
// Manual in-impl form: the macro call lands in the impl body (no `!`) — the
// user writes the full input including the trait; the macro emits associated
// fn definitions.