@@ -1297,12 +1297,17 @@ defsyntax core :
1297
1297
1298
1298
;Represents the entire defn header.
1299
1299
defproduction defnheader:DefnHeader
1300
- defrule defnheader = ((?args:#fnargbinding! ...) ?a2:#return-type?) :
1300
+ defrule defnheader = ((#do? ?args:#fnargbinding! ...) ?a2:#return-type?) :
1301
1301
DefnHeader(closest-info(), to-tuple(args), a2)
1302
1302
1303
+ ;Represents an optional @do so that users can optionally
1304
+ ;omit the space.
1305
+ defproduction do?: False
1306
+ defrule do? = (@do) : false
1307
+ defrule do? = () : false
1308
+
1303
1309
;Error production
1304
1310
defproduction defnheader!:DefnHeader
1305
- fail-if defnheader! = ((@do _ ...)) : CSE(closest-info(), BAD-ARGLIST-MSG)
1306
1311
defrule defnheader! = (?x:#defnheader)
1307
1312
fail-if defnheader! = () : CSE(closest-info(), "Invalid syntax for function arguments.")
1308
1313
@@ -1332,12 +1337,11 @@ defsyntax core :
1332
1337
1333
1338
;Represents the entire defn header.
1334
1339
defproduction lsdefnheader:DefnHeader
1335
- defrule lsdefnheader = ((?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
1340
+ defrule lsdefnheader = ((#do? ?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
1336
1341
DefnHeader(closest-info(), to-tuple(args), One(a2))
1337
1342
1338
1343
;Error production
1339
1344
defproduction lsdefnheader!:DefnHeader
1340
- fail-if lsdefnheader! = ((@do _ ...)) : CSE(closest-info(), BAD-ARGLIST-MSG)
1341
1345
defrule lsdefnheader! = (?x:#lsdefnheader)
1342
1346
fail-if lsdefnheader! = () : CSE(closest-info(), "Invalid syntax for function arguments.")
1343
1347
@@ -1363,13 +1367,11 @@ defsyntax core :
1363
1367
defrule arglist = ((?xs:#argbinding ...)) : [map(key, xs), map(value, xs)]
1364
1368
1365
1369
defproduction fnheader! : [List List ?]
1366
- fail-if fnheader! = ((@do _ ...)) :
1367
- CSE(closest-info(), BAD-ARGLIST-MSG)
1368
- defrule fnheader! = (?args:#arglist -> ?a2:#type!) :
1369
- val [xs, a1] = args
1370
+ defrule fnheader! = ((#do? ?args:#argbinding ...) -> ?a2:#type!) :
1371
+ val [xs, a1] = [map(key, args), map(value, args)]
1370
1372
[xs, a1, a2]
1371
- defrule fnheader! = (? args:#arglist ) :
1372
- val [xs, a1] = args
1373
+ defrule fnheader! = ((#do? ? args:#argbinding ...) ) :
1374
+ val [xs, a1] = [map(key, args), map(value, args)]
1373
1375
[xs, a1, `($none)]
1374
1376
fail-if fnheader! = () :
1375
1377
CSE(closest-info(), "Expected argument list here.")
@@ -1759,10 +1761,12 @@ defsyntax core :
1759
1761
defproduction in-bindings! : List<KeyValue>
1760
1762
defrule in-bindings! = ((?b0:#in-binding ?bn:#in-binding! ...)) : cons(b0, bn)
1761
1763
defrule in-bindings! = (?b:#in-binding!) : List(b)
1764
+
1765
+ defproduction operator-exp!
1766
+ defrule operator-exp! = (:) : `core/do
1767
+ defrule operator-exp! = (?f:#exp! #:!) : f
1762
1768
1763
- fail-if exp4 = (for #in-binding :) :
1764
- CSE(closest-info(), BAD-FOR-MSG)
1765
- defrule exp4 = (for ?bs:#in-bindings! ?f:#exp! #:! ?body:#exp!) :
1769
+ defrule exp4 = (for ?bs:#in-bindings! ?f:#operator-exp! ?body:#exp!) :
1766
1770
val template = `(f(fn xs : body, ys))
1767
1771
parse-syntax[core / #exp](
1768
1772
fill-template(template, [
@@ -2936,6 +2940,4 @@ defsyntax core :
2936
2940
2937
2941
2938
2942
;============== Error Messages ============================
2939
- val BAD-ARGLIST-MSG = "Incorrect syntax for argument list. Did you forget to put a space between the function name and the argument list?"
2940
2943
val BAD-MATCH-MSG = "Incorrect syntax for match expression. Is there an extra space between match and the argument list?"
2941
- val BAD-FOR-MSG = "Missing operating function in for expression. Did you forget to put a do after the bindings?"
0 commit comments