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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
|
(.module: {#.doc "Functions for extracting information from the state of the compiler."}
[lux #*
[control
[functor (#+ Functor)]
[apply (#+ Apply)]
["." monad (#+ do Monad)]]
[data
["." product]
[ident ("ident/" Codec<Text,Ident> Equivalence<Ident>)]
["." maybe]
["e" error]
["." number ("nat/" Codec<Text,Nat>)]
["." text ("text/" Monoid<Text> Equivalence<Text>)]
[collection
["." list ("list/" Monoid<List> Monad<List>)]]]]
[/
["." code]])
## (type: (Meta a)
## (-> Lux (e.Error [Lux a])))
(structure: #export _ (Functor Meta)
(def: (map f fa)
(function (_ compiler)
(case (fa compiler)
(#e.Error msg)
(#e.Error msg)
(#e.Success [compiler' a])
(#e.Success [compiler' (f a)])))))
(structure: #export _ (Apply Meta)
(def: functor Functor<Meta>)
(def: (apply ff fa)
(function (_ compiler)
(case (ff compiler)
(#e.Success [compiler' f])
(case (fa compiler')
(#e.Success [compiler'' a])
(#e.Success [compiler'' (f a)])
(#e.Error msg)
(#e.Error msg))
(#e.Error msg)
(#e.Error msg)))))
(structure: #export _ (Monad Meta)
(def: functor Functor<Meta>)
(def: (wrap x)
(function (_ compiler)
(#e.Success [compiler x])))
(def: (join mma)
(function (_ compiler)
(case (mma compiler)
(#e.Error msg)
(#e.Error msg)
(#e.Success [compiler' ma])
(ma compiler')))))
(def: (get k plist)
(All [a]
(-> Text (List [Text a]) (Maybe a)))
(case plist
#.Nil
#.None
(#.Cons [k' v] plist')
(if (text/= k k')
(#.Some v)
(get k plist'))))
(def: #export (run' compiler action)
(All [a] (-> Lux (Meta a) (e.Error [Lux a])))
(action compiler))
(def: #export (run compiler action)
(All [a] (-> Lux (Meta a) (e.Error a)))
(case (action compiler)
(#e.Error error)
(#e.Error error)
(#e.Success [_ output])
(#e.Success output)))
(def: #export (either left right)
{#.doc "Pick whichever computation succeeds."}
(All [a] (-> (Meta a) (Meta a) (Meta a)))
(function (_ compiler)
(case (left compiler)
(#e.Error error)
(right compiler)
(#e.Success [compiler' output])
(#e.Success [compiler' output]))))
(def: #export (assert message test)
{#.doc "Fails with the given message if the test is #0."}
(-> Text Bit (Meta Any))
(function (_ compiler)
(if test
(#e.Success [compiler []])
(#e.Error message))))
(def: #export (fail msg)
{#.doc "Fails with the given message."}
(All [a]
(-> Text (Meta a)))
(function (_ _)
(#e.Error msg)))
(def: #export (find-module name)
(-> Text (Meta Module))
(function (_ compiler)
(case (get name (get@ #.modules compiler))
(#.Some module)
(#e.Success [compiler module])
_
(#e.Error ($_ text/compose "Unknown module: " name)))))
(def: #export current-module-name
(Meta Text)
(function (_ compiler)
(case (get@ #.current-module compiler)
(#.Some current-module)
(#e.Success [compiler current-module])
_
(#e.Error "No current module.")
)))
(def: #export current-module
(Meta Module)
(do Monad<Meta>
[this-module-name current-module-name]
(find-module this-module-name)))
(def: #export (get-ann tag anns)
{#.doc "Looks-up a particular annotation's value within the set of annotations."}
(-> Ident Code (Maybe Code))
(case anns
[_ (#.Record anns)]
(loop [anns anns]
(case anns
(#.Cons [key value] anns')
(case key
[_ (#.Tag tag')]
(if (ident/= tag tag')
(#.Some value)
(recur anns'))
_
(recur anns'))
#.Nil
#.None))
_
#.None))
(do-template [<name> <tag> <type>]
[(def: #export (<name> tag anns)
(-> Ident Code (Maybe <type>))
(case (get-ann tag anns)
(#.Some [_ (<tag> value)])
(#.Some value)
_
#.None))]
[get-bit-ann #.Bit Bit]
[get-int-ann #.Int Int]
[get-frac-ann #.Frac Frac]
[get-text-ann #.Text Text]
[get-symbol-ann #.Symbol Ident]
[get-tag-ann #.Tag Ident]
[get-form-ann #.Form (List Code)]
[get-tuple-ann #.Tuple (List Code)]
[get-record-ann #.Record (List [Code Code])]
)
(def: #export (get-doc anns)
{#.doc "Looks-up a definition's documentation."}
(-> Code (Maybe Text))
(get-text-ann (ident-for #.doc) anns))
(def: #export (flag-set? flag-name anns)
{#.doc "Finds out whether an annotation-as-a-flag is set (has value '#1')."}
(-> Ident Code Bit)
(maybe.default #0 (get-bit-ann flag-name anns)))
(do-template [<name> <tag> <desc>]
[(def: #export <name>
{#.doc (code.text ($_ text/compose "Checks whether a definition is " <desc> "."))}
(-> Code Bit)
(flag-set? (ident-for <tag>)))]
[export? #.export? "exported"]
[macro? #.macro? "a macro"]
[type? #.type? "a type"]
[struct? #.struct? "a structure"]
[type-rec? #.type-rec? "a recursive type"]
[sig? #.sig? "a signature"]
)
(def: #export (aliased? annotations)
(-> Code Bit)
(case (get-symbol-ann (ident-for #.alias) annotations)
(#.Some _)
#1
#.None
#0))
(do-template [<name> <tag> <type>]
[(def: (<name> input)
(-> Code (Maybe <type>))
(case input
[_ (<tag> actual-value)]
(#.Some actual-value)
_
#.None))]
[parse-tuple #.Tuple (List Code)]
[parse-text #.Text Text]
)
(do-template [<name> <tag> <desc>]
[(def: #export (<name> anns)
{#.doc <desc>}
(-> Code (List Text))
(maybe.default (list)
(do maybe.Monad<Maybe>
[_args (get-ann (ident-for <tag>) anns)
args (parse-tuple _args)]
(monad.map @ parse-text args))))]
[func-args #.func-args "Looks up the arguments of a function."]
[type-args #.type-args "Looks up the arguments of a parameterized type."]
[declared-tags #.tags "Looks up the tags of a tagged (variant or record) type."]
)
(def: (find-macro' modules this-module module name)
(-> (List [Text Module]) Text Text Text
(Maybe Macro))
(do maybe.Monad<Maybe>
[$module (get module modules)
[def-type def-anns def-value] (: (Maybe Definition) (|> (: Module $module) (get@ #.definitions) (get name)))]
(if (and (macro? def-anns)
(or (export? def-anns) (text/= module this-module)))
(#.Some (:coerce Macro def-value))
(case (get-symbol-ann (ident-for #.alias) def-anns)
(#.Some [r-module r-name])
(find-macro' modules this-module r-module r-name)
_
#.None))))
(def: #export (normalize ident)
{#.doc "If given an identifier without a module prefix, gives it the current module's name as prefix.
Otherwise, returns the identifier as-is."}
(-> Ident (Meta Ident))
(case ident
["" name]
(do Monad<Meta>
[module-name current-module-name]
(wrap [module-name name]))
_
(:: Monad<Meta> wrap ident)))
(def: #export (find-macro ident)
(-> Ident (Meta (Maybe Macro)))
(do Monad<Meta>
[ident (normalize ident)
this-module current-module-name]
(let [[module name] ident]
(: (Meta (Maybe Macro))
(function (_ compiler)
(#e.Success [compiler (find-macro' (get@ #.modules compiler) this-module module name)]))))))
(def: #export (expand-once syntax)
{#.doc "Given code that requires applying a macro, does it once and returns the result.
Otherwise, returns the code as-is."}
(-> Code (Meta (List Code)))
(case syntax
[_ (#.Form (#.Cons [[_ (#.Symbol name)] args]))]
(do Monad<Meta>
[?macro (find-macro name)]
(case ?macro
(#.Some macro)
(macro args)
#.None
(:: Monad<Meta> wrap (list syntax))))
_
(:: Monad<Meta> wrap (list syntax))))
(def: #export (expand syntax)
{#.doc "Given code that requires applying a macro, expands repeatedly until no more direct macro-calls are left.
Otherwise, returns the code as-is."}
(-> Code (Meta (List Code)))
(case syntax
[_ (#.Form (#.Cons [[_ (#.Symbol name)] args]))]
(do Monad<Meta>
[?macro (find-macro name)]
(case ?macro
(#.Some macro)
(do Monad<Meta>
[expansion (macro args)
expansion' (monad.map Monad<Meta> expand expansion)]
(wrap (list/join expansion')))
#.None
(:: Monad<Meta> wrap (list syntax))))
_
(:: Monad<Meta> wrap (list syntax))))
(def: #export (expand-all syntax)
{#.doc "Expands all macro-calls everywhere recursively, until only primitive/base code remains."}
(-> Code (Meta (List Code)))
(case syntax
[_ (#.Form (#.Cons [[_ (#.Symbol name)] args]))]
(do Monad<Meta>
[?macro (find-macro name)]
(case ?macro
(#.Some macro)
(do Monad<Meta>
[expansion (macro args)
expansion' (monad.map Monad<Meta> expand-all expansion)]
(wrap (list/join expansion')))
#.None
(do Monad<Meta>
[parts' (monad.map Monad<Meta> expand-all (list& (code.symbol name) args))]
(wrap (list (code.form (list/join parts')))))))
[_ (#.Form (#.Cons [harg targs]))]
(do Monad<Meta>
[harg+ (expand-all harg)
targs+ (monad.map Monad<Meta> expand-all targs)]
(wrap (list (code.form (list/compose harg+ (list/join (: (List (List Code)) targs+)))))))
[_ (#.Tuple members)]
(do Monad<Meta>
[members' (monad.map Monad<Meta> expand-all members)]
(wrap (list (code.tuple (list/join members')))))
_
(:: Monad<Meta> wrap (list syntax))))
(def: #export (gensym prefix)
{#.doc "Generates a unique identifier as an Code node (ready to be used in code templates).
A prefix can be given (or just be empty text \"\") to better identify the code for debugging purposes."}
(-> Text (Meta Code))
(function (_ compiler)
(#e.Success [(update@ #.seed inc compiler)
(|> compiler
(get@ #.seed)
(:: number.Codec<Text,Nat> encode)
($_ text/compose "__gensym__" prefix)
[""] code.symbol)])))
(def: (get-local-symbol ast)
(-> Code (Meta Text))
(case ast
[_ (#.Symbol [_ name])]
(:: Monad<Meta> wrap name)
_
(fail (text/compose "Code is not a local symbol: " (code.to-text ast)))))
(macro: #export (with-gensyms tokens)
{#.doc (doc "Creates new symbols and offers them to the body expression."
(syntax: #export (synchronized lock body)
(with-gensyms [g!lock g!body g!_]
(wrap (list (` (let [(~ g!lock) (~ lock)
(~ g!_) ("jvm monitorenter" (~ g!lock))
(~ g!body) (~ body)
(~ g!_) ("jvm monitorexit" (~ g!lock))]
(~ g!body)))))
)))}
(case tokens
(^ (list [_ (#.Tuple symbols)] body))
(do Monad<Meta>
[symbol-names (monad.map @ get-local-symbol symbols)
#let [symbol-defs (list/join (list/map (: (-> Text (List Code))
(function (_ name) (list (code.symbol ["" name]) (` (gensym (~ (code.text name)))))))
symbol-names))]]
(wrap (list (` ((~! do) (~! Monad<Meta>)
[(~+ symbol-defs)]
(~ body))))))
_
(fail "Wrong syntax for with-gensyms")))
(def: #export (expand-1 token)
{#.doc "Works just like expand, except that it ensures that the output is a single Code token."}
(-> Code (Meta Code))
(do Monad<Meta>
[token+ (expand token)]
(case token+
(^ (list token'))
(wrap token')
_
(fail "Macro expanded to more than 1 element."))))
(def: #export (module-exists? module)
(-> Text (Meta Bit))
(function (_ compiler)
(#e.Success [compiler (case (get module (get@ #.modules compiler))
(#.Some _)
#1
#.None
#0)])))
(def: (try-both f x1 x2)
(All [a b]
(-> (-> a (Maybe b)) a a (Maybe b)))
(case (f x1)
#.None (f x2)
(#.Some y) (#.Some y)))
(def: (find-type-var idx bindings)
(-> Nat (List [Nat (Maybe Type)]) (Maybe Type))
(case bindings
#.Nil
#.None
(#.Cons [var bound] bindings')
(if (n/= idx var)
bound
(find-type-var idx bindings'))))
(def: (clean-type type)
(-> Type (Meta Type))
(case type
(#.Var var)
(function (_ compiler)
(case (|> compiler
(get@ [#.type-context #.var-bindings])
(find-type-var var))
(^or #.None (#.Some (#.Var _)))
(#e.Success [compiler type])
(#.Some type')
(#e.Success [compiler type'])))
_
(:: Monad<Meta> wrap type)))
(def: #export (find-var-type name)
{#.doc "Looks-up the type of a local variable somewhere in the environment."}
(-> Text (Meta Type))
(function (_ compiler)
(let [test (: (-> [Text [Type Any]] Bit)
(|>> product.left (text/= name)))]
(case (do maybe.Monad<Maybe>
[scope (list.find (function (_ env)
(or (list.any? test (: (List [Text [Type Any]])
(get@ [#.locals #.mappings] env)))
(list.any? test (: (List [Text [Type Any]])
(get@ [#.captured #.mappings] env)))))
(get@ #.scopes compiler))
[_ [type _]] (try-both (list.find test)
(: (List [Text [Type Any]])
(get@ [#.locals #.mappings] scope))
(: (List [Text [Type Any]])
(get@ [#.captured #.mappings] scope)))]
(wrap type))
(#.Some var-type)
((clean-type var-type) compiler)
#.None
(#e.Error ($_ text/compose "Unknown variable: " name))))))
(def: #export (find-def name)
{#.doc "Looks-up a definition's whole data in the available modules (including the current one)."}
(-> Ident (Meta Definition))
(do Monad<Meta>
[name (normalize name)]
(function (_ compiler)
(case (: (Maybe Definition)
(do maybe.Monad<Maybe>
[#let [[v-prefix v-name] name]
(^slots [#.definitions]) (get v-prefix (get@ #.modules compiler))]
(get v-name definitions)))
(#.Some definition)
(#e.Success [compiler definition])
_
(let [current-module (|> compiler (get@ #.current-module) (maybe.default "???"))]
(#e.Error ($_ text/compose
"Unknown definition: " (ident/encode name) "\n"
" Current module: " current-module "\n"
(case (get current-module (get@ #.modules compiler))
(#.Some this-module)
($_ text/compose
" Imports: " (|> this-module (get@ #.imports) (text.join-with ", ")) "\n"
" Aliases: " (|> this-module (get@ #.module-aliases) (list/map (function (_ [alias real]) ($_ text/compose alias " => " real))) (text.join-with ", ")) "\n")
_
"")
" All Known modules: " (|> compiler (get@ #.modules) (list/map product.left) (text.join-with ", ")) "\n")))))))
(def: #export (find-def-type name)
{#.doc "Looks-up a definition's type in the available modules (including the current one)."}
(-> Ident (Meta Type))
(do Monad<Meta>
[[def-type def-data def-value] (find-def name)]
(clean-type def-type)))
(def: #export (find-type name)
{#.doc "Looks-up the type of either a local variable or a definition."}
(-> Ident (Meta Type))
(do Monad<Meta>
[#let [[_ _name] name]]
(case name
["" _name]
(either (find-var-type _name)
(find-def-type name))
_
(find-def-type name))))
(def: #export (find-type-def name)
{#.doc "Finds the value of a type definition (such as Int, Any or Lux)."}
(-> Ident (Meta Type))
(do Monad<Meta>
[[def-type def-data def-value] (find-def name)]
(wrap (:coerce Type def-value))))
(def: #export (definitions module-name)
{#.doc "The entire list of definitions in a module (including the non-exported/private ones)."}
(-> Text (Meta (List [Text Definition])))
(function (_ compiler)
(case (get module-name (get@ #.modules compiler))
#.None (#e.Error ($_ text/compose "Unknown module: " module-name))
(#.Some module) (#e.Success [compiler (get@ #.definitions module)])
)))
(def: #export (exports module-name)
{#.doc "All the exported definitions in a module."}
(-> Text (Meta (List [Text Definition])))
(do Monad<Meta>
[definitions (definitions module-name)]
(wrap (list.filter (function (_ [name [def-type def-anns def-value]])
(export? def-anns))
definitions))))
(def: #export modules
{#.doc "All the available modules (including the current one)."}
(Meta (List [Text Module]))
(function (_ compiler)
(|> compiler
(get@ #.modules)
[compiler]
#e.Success)))
(def: #export (tags-of type-name)
{#.doc "All the tags associated with a type definition."}
(-> Ident (Meta (Maybe (List Ident))))
(do Monad<Meta>
[#let [[module name] type-name]
module (find-module module)]
(case (get name (get@ #.types module))
(#.Some [tags _])
(wrap (#.Some tags))
_
(wrap #.None))))
(def: #export cursor
{#.doc "The cursor of the current expression being analyzed."}
(Meta Cursor)
(function (_ compiler)
(#e.Success [compiler (get@ #.cursor compiler)])))
(def: #export expected-type
{#.doc "The expected type of the current expression being analyzed."}
(Meta Type)
(function (_ compiler)
(case (get@ #.expected compiler)
(#.Some type)
(#e.Success [compiler type])
#.None
(#e.Error "Not expecting any type."))))
(def: #export (imported-modules module-name)
{#.doc "All the modules imported by a specified module."}
(-> Text (Meta (List Text)))
(do Monad<Meta>
[(^slots [#.imports]) (find-module module-name)]
(wrap imports)))
(def: #export (imported-by? import module)
(-> Text Text (Meta Bit))
(do Monad<Meta>
[(^slots [#.imports]) (find-module module)]
(wrap (list.any? (text/= import) imports))))
(def: #export (imported? import)
(-> Text (Meta Bit))
(let [(^open) Monad<Meta>]
(|> current-module-name
(map find-module) join
(map (|>> (get@ #.imports) (list.any? (text/= import)))))))
(def: #export (resolve-tag tag)
{#.doc "Given a tag, finds out what is its index, its related tag-list and it's associated type."}
(-> Ident (Meta [Nat (List Ident) Type]))
(do Monad<Meta>
[#let [[module name] tag]
=module (find-module module)
this-module-name current-module-name
imported! (..imported? module)]
(case (get name (get@ #.tags =module))
(#.Some [idx tag-list exported? type])
(if (or (text/= this-module-name module)
(and imported! exported?))
(wrap [idx tag-list type])
(fail ($_ text/compose "Cannot access tag: " (ident/encode tag) " from module " this-module-name)))
_
(fail ($_ text/compose "Unknown tag: " (ident/encode tag))))))
(def: #export (tag-lists module)
{#.doc "All the tag-lists defined in a module, with their associated types."}
(-> Text (Meta (List [(List Ident) Type])))
(do Monad<Meta>
[=module (find-module module)
this-module-name current-module-name]
(wrap (|> (get@ #.types =module)
(list.filter (function (_ [type-name [tag-list exported? type]])
(or exported?
(text/= this-module-name module))))
(list/map (function (_ [type-name [tag-list exported? type]])
[tag-list type]))))))
(def: #export locals
{#.doc "All the local variables currently in scope, separated in different scopes."}
(Meta (List (List [Text Type])))
(function (_ compiler)
(case (list.inits (get@ #.scopes compiler))
#.None
(#e.Error "No local environment")
(#.Some scopes)
(#e.Success [compiler
(list/map (|>> (get@ [#.locals #.mappings])
(list/map (function (_ [name [type _]])
[name type])))
scopes)]))))
(def: #export (un-alias def-name)
{#.doc "Given an aliased definition's name, returns the original definition being referenced."}
(-> Ident (Meta Ident))
(do Monad<Meta>
[[_ def-anns _] (find-def def-name)]
(case (get-symbol-ann (ident-for #.alias) def-anns)
(#.Some real-def-name)
(wrap real-def-name)
_
(wrap def-name))))
(def: #export get-compiler
{#.doc "Obtains the current state of the compiler."}
(Meta Lux)
(function (_ compiler)
(#e.Success [compiler compiler])))
(def: #export type-context
(Meta Type-Context)
(function (_ compiler)
(#e.Success [compiler (get@ #.type-context compiler)])))
(do-template [<macro> <func> <desc>]
[(macro: #export (<macro> tokens)
{#.doc (doc "Performs a macro-expansion and logs the resulting code."
"You can either use the resulting code, or omit them."
"By omitting them, this macro produces nothing (just like the lux.comment macro)."
(<macro> #omit
(def: (foo bar baz)
(-> Int Int Int)
(i/+ bar baz))))}
(case (: (Maybe [Bit Code])
(case tokens
(^ (list [_ (#.Tag ["" "omit"])]
token))
(#.Some [#1 token])
(^ (list token))
(#.Some [#0 token])
_
#.None))
(#.Some [omit? token])
(do Monad<Meta>
[cursor ..cursor
output (<func> token)
#let [_ (log! ($_ text/compose <desc> " @ " (.cursor-description cursor)))
_ (list/map (|>> code.to-text log!)
output)
_ (log! "")]]
(wrap (if omit?
(list)
output)))
#.None
(fail ($_ text/compose "Wrong syntax for " <desc> "."))))]
[log-expand! expand "log-expand!"]
[log-expand-all! expand-all "log-expand-all!"]
[log-expand-once! expand-once "log-expand-once!"]
)
|