Skip to content

Commit 3f11ace

Browse files
committed
spec: reuse type_to_code in signatures.typ
1 parent 3e8e40c commit 3f11ace

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

spec/signatures.typ

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#import "/book.typ": book-page
22
#import "/src.typ": load_signatures, load_config
3+
#import "/expr.typ": type_to_code
34

45
#show: book-page("signatures.typ")
56

67
#let config = load_config()
78
#let signatures = load_signatures(config)
89

9-
// Render a type
10-
#let render_type(typ) = {
11-
let res = ``
12-
while type(typ) == array {
13-
res += `[` + raw(str(typ.at(1))) + `]`
14-
typ = typ.at(0)
15-
}
16-
raw(typ) + res
17-
}
18-
1910
// Render a signature
2011
#let render_signature(sig) = {
2112
let (lb, rb) = if sig.kind == "interaction" {
@@ -29,11 +20,11 @@
2920
raw(cond) + ` => `
3021
} else {``}
3122

32-
let input_str = sig.input.map(render_type).join(`, `)
23+
let input_str = sig.input.map(type_to_code).join(`, `)
3324

3425
let output = sig.at("output", default: none)
3526
let output_str = if output != none {
36-
render_type(output) + `; `
27+
type_to_code(output) + `; `
3728
} else {``}
3829

3930
return [#cond_str#raw(sig.tag)#lb#output_str#input_str#rb]

0 commit comments

Comments
 (0)