-
Notifications
You must be signed in to change notification settings - Fork 17
/
better-monad-parse.el
718 lines (624 loc) · 20.9 KB
/
better-monad-parse.el
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
(require 'monads)
(require 'utils)
(require 'cl)
(require 'defn)
(require 'functional)
(require 'multi-methods)
;;; Uniform Input Represention:
(defstruct buffer-input (buffer :read-only) (index :read-only))
(defun create-buffer-input (buf)
"Create an initialized buffer-input struct for the buffer BUF."
(make-buffer-input :buffer (get-buffer buf) :index 1))
(defun set-buffer-input-index (b i)
"Functionally modify the buffer-input B's index to I. Original structure
remains unmodified. If B is a regular buffer, it is promoted to a
buffer-input."
(cond
((bufferp b) (make-buffer-input :buffer (get-buffer b) :index i))
((buffer-input-p b)
(make-buffer-input
:buffer
(buffer-input-buffer b)
:index i))))
(defun incr-buffer-input-index (b)
"Functionally increment a buffer input index."
(cond
((bufferp b) (incr-buffer-input-index (create-buffer-input b)))
((buffer-input-p b)
(let ((i (buffer-input-index b)))
(set-buffer-input-index b (+ i 1))))))
(defstruct stateful-input (input :read-only) (state :read-only))
(defun make-input-stateful (input &optional initial-state)
(make-stateful-input :input input :state initial-state))
(defun stateful-input-store/alist (s k v)
(make-stateful-input :input
(stateful-input-input s)
:state
(alist>> (stateful-input-state s) k v)))
(defun stateful-input-fetch/alist (s k &optional or-value)
(alist-or (stateful-input-state s) k or-value))
(defun input-dispatcher (&rest args)
(let ((thing (car args)))
"Dispatch function for generic parser input methods."
(cond
((stringp thing) :string)
((listp thing) :list)
((buffer-input-p thing) :buffer-input)
((bufferp thing) :buffer)
((stateful-input-p thing) :stateful-input))))
;;; Define predicate methods for detecting empty inputs.
(defmulti input-empty? #'input-dispatcher "Returns t if an input is empty.")
(defunmethod input-empty? :string (s) (= (length s) 0))
(defunmethod input-empty? :list (l) (not l))
(defun point-max-of (buffer)
"Retrieve (point-max) for a BUFFER."
(with-current-buffer buffer
(point-max)))
(defunmethod input-empty? :buffer-input (b)
(>= (buffer-input-index b) (point-max-of (buffer-input-buffer b))))
(defunmethod input-empty? :buffer (b)
(if (= 1 (point-max-of b)) t nil))
(defunmethod input-empty? :stateful-input (s)
(input-empty? (stateful-input-input s)))
(defalias 'input-emptyp #'input-empty?)
(defmulti input-first #'input-dispatcher "Get the first element of an input.")
(defunmethod input-first :string (s)
(if (> (length s) 0) (substring s 0 1)
(error "Can't take the first element of an empty string.")))
(defunmethod input-first :list (l)
(if l (car l) (error "Can't take the fist element of an empty list.")))
(defunmethod input-first :buffer (b)
(input-first (create-buffer-input b)))
(defunmethod input-first :buffer-input (bi)
(with-current-buffer (buffer-input-buffer bi)
(let ((i (buffer-input-index bi)))
(buffer-substring i (+ i 1)))))
(defunmethod input-first :stateful-input (s)
(input-first (stateful-input-input s)))
(defmulti input-rest #'input-dispatcher "Get an input representing subsequent elements of an input.")
(defunmethod input-rest :string (s)
(substring s 1))
(defunmethod input-rest :list (l)
(cdr l))
(defunmethod input-rest :buffer (b)
(input-rest (create-buffer-input b)))
(defunmethod input-rest :buffer-input (bi)
(incr-buffer-input-index bi))
(defunmethod input-rest :stateful-input (s)
(make-stateful-input :input
(input-rest (stateful-input-input s))
:state (stateful-input-state s)))
(defmulti store-uncurried #'input-dispatcher "Uncurried storage multimethod.")
(defunmethod store-uncurried :stateful-input (s k v)
(list (cons v (stateful-input-store/alist s k v))))
($ :list derives-from :non-stateful-input)
($ :buffer derives-from :non-stateful-input)
($ :string derives-from :non-stateful-input)
(defunmethod store-uncurried :non-stateful-input (s k v)
(store-uncurried (make-input-stateful s) k v))
(defun =>store (k v)
"Parser which stores the value V at K in the STATEFUL portion of the input."
(enclose
(k v)
(lambda (s) (store-uncurried s k v))))
(defmulti fetch-uncurried #'input-dispatcher "Uncurried fetch multimethod.")
(defunmethod fetch-uncurried :stateful-input (s k &optional or-value)
(list (cons (stateful-input-fetch/alist s k or-value) s)))
(defunmethod fetch-uncurried :non-stateful-input (s k &optional or-value)
(fetch-uncurried (make-input-stateful s) k or-value))
(defun =>fetch (k &optional or-value)
"Parser which fetches the value at K from the parse state.
Returns NIL if no such value is present, OR-VALUE if not, which
defaults to nil."
(enclose (k or-value)
(lambda (s)
(fetch-uncurried s k or-value))))
(defun push-dispatcher (item input)
(input-dispatcher input))
(defmulti input-push #'push-dispatcher "Add an item to the front of an input")
(defunmethod input-push :string (item input) (concat (if (stringp item) item (format "%S" item)) input))
(defunmethod input-push :list (item input) (cons item input))
(defunmethod input-push :buffer (item input) (input-push item (create-buffer-input input)))
(defunmethod input-push :buffer-input (item input)
(warn "Pushing an input onto a buffer is non-functional.")
(with-current-buffer (buffer-input-buffer input)
(save-excursion
(goto-char (buffer-input-index input))
(insert (if (stringp item) item (format "%S" item)))))
input)
;;; Monadic Functions:
;;; Parsers start with =
;;; Functions returning parsers start with =>
;;; It is convenient to treat parsers as both values and functions. This
;;; form defines them as both.
(defmacro defun/var (name args &rest body)
"Simultaneously define a function and set NAME's SYMBOL-VALUE to that function."
`(progn
(defun ,name ,args ,@body)
(defvar ,name nil ,@(if (stringp (car body)) (list (car body)) nil))
(setq ,name #',name)))
(defun/var =nil (input)
"The nil parser. The zero of the parser monad."
nil)
(defun/var =item (input)
"The one-item parser. Parse the first item from the input, regardless of what it is."
(unless (input-empty? input)
(list (cons (input-first input)
(input-rest input)))))
(defun/var =rest (input)
"Get the parser state itself. Useful for checking for the end of the input
within the monad."
(list (cons input input)))
(defun =>items (n)
"Produce the parser that gets the N first items from the parser
input or as many as possible when the input contains fewer
items."
(enclose
(n)
(lambda (input)
(recur-let
((acc '())
(input input)
(n n))
(cond
((or (= n 0)
(input-empty? input))
(list (cons (reverse acc) input)))
(t
(recur (cons (input-first input) acc)
(input-rest input)
(- n 1))))))))
(defun parser-bind (parser =>parser)
"Produce a new parser which represents the parser produced by =>PARSER on the
monadic return values of PARSER."
(enclose
(parser =>parser)
(lex-lambda
(input)
(recur-let
((acc '())
(rs (funcall parser input)))
(if (empty? rs) acc
(let ((pair (car rs))
(rest (cdr rs)))
(recur (append (funcall
(funcall =>parser (car pair))
(cdr pair)) acc)
rest)))))))
(defun parser-return (&rest things)
"Produce a parser which leaves its input unmodified and which
monadically returns THING."
(enclose
(things)
(lambda (input)
(mapcar (par #'cons input) things))))
(defun parser-plus (p1 p2)
"Parser monadic plus operation - returns the parser which
parses P1 and then P2, with the monadic return value of P2."
(parser-bind p1 (lambda (stub) p2)))
(defvar monad-parse
(tbl!
:m-return #'parser-return
:m-bind #'parser-bind
:m-zero =nil
:m-plus #'parser-plus)
"The (better) parser monad.")
(defun parse/first-result (parser input)
"Parse INPUT with PARSER and return the FIRST monadic return value."
(car (car (funcall parser input))))
;;; Now we can use monadic binding to build some parsers.
(defun =>items->string-unspecialized (n)
"Pull N items from the input (or fewer if fewer are in input)
and return the results concatenated into a string. Handles any
case with appropriate multimethod definitions."
(enclose
(n)
(monadic-do
monad-parse
(items-list <- (=>items n))
(m-return (reduce #'concat items-list)))))
(defun =>items->string (n)
"Pull N items from the input (or fewer if fewer are in input)
and return the results concatenated into a string. Efficiently
handles the string case."
(enclose
(n)
(lambda (input)
(if (stringp input)
(let* ((in-len (length input))
(actual-n (min in-len n))
(result (substring input 0 actual-n))
(new-input (substring input actual-n)))
(list (cons result new-input)))
(=>items->string-unspecialized n)))))
(defun =>satisfies (fun)
"Parse one item IF it FUN is true for that item."
(enclose
(fun)
(monadic-do
monad-parse
(item <- =item)
(if (funcall fun item)
(m-return item)
=nil))))
(defun =>list (parser)
"Wraps the monadic return value of PARSER into a LIST."
(enclose
(parser)
(monadic-do monad-parse
(item <- parser)
(m-return (list item)))))
(defun =>maybe (parser)
"Produces a parser that always succeeds. If parser succeeds,
the monadic return value comes from PARSER. Otherwise,
monadically returns NIL."
(enclose
(parser)
(lambda (input)
(let ((rs (funcall parser input)))
(if rs rs
(list (cons nil input)))))))
;;; The dreaded zero plus more combinator.
(defun zero-plus-more-step (substate parser)
"Apply PARSER to the CDR of substate. If it succeeds, cons the
result onto the list in the CAR of substate and indicate CONTINUE
for MAPCAR/DEAL. If PARSER on CDR of substate FAILS, then
reverse the CAR of SUBSTATE and return this value consed with the
last INPUT state."
(let* ((mrv (car substate))
(input (cdr substate))
(r (funcall parser input)))
(if r (list
:continue
(mapcar (lambda (subr)
(let ((r (car subr))
(rest (cdr subr)))
(cons (cons r mrv) rest)))
r))
(list :terminate
(cons (reverse mrv) input)))))
(defun =>zero-plus-more (p)
"Produce a parser which parses P zero or more times and monadically
returns the results in a list."
(enclose
(p)
(lex-lambda
(input)
(recur-let
((terminals nil)
(continuers (funcall (=>list p) input)))
(if (empty? continuers)
(if (empty? terminals)
(list (cons nil input))
terminals)
(let* ((split-tbl
(mapcar/deal (par #'zero-plus-more-step p) continuers))
(new-continuers (alist split-tbl :continue))
(new-terminals (alist split-tbl :terminate)))
(recur (append terminals new-terminals)
(reduce #'append new-continuers))))))))
(defun =>zero-plus-more->string (p)
"Like =>ZERO-PLUS-MORE, but the monadic return is concatenated
into a string."
(=>reduce-concat (=>zero-plus-more p)))
(defun =>zero-or-more (p)
"Alias for =>ZERO-PLUS-MORE."
(=>zero-plus-more p))
(defun =>one-plus-more (p)
"Parse P at least once and then accumlate as many P as possible."
(enclose
(p)
(monadic-do monad-parse
(first <- p)
(rest <- (=>zero-plus-more p))
(m-return (cons first rest)))))
(defun =>one-or-more (p)
"Alias for =>ZERO-PLUS-MORE."
(=>one-plus-more p))
(defun =>or2 (p1 p2)
"Produce a PARSER which succeeds on P1 or P2. Returns the
successful parser's value."
(enclose
(p1 p2)
(lambda (input)
(let ((rs (funcall p1 input)))
(if rs rs
(funcall p2 input))))))
(defun =>or (&rest ps)
"Produce a parser which succeeds if one of PS is true."
(reduce #'=>or2 ps))
(defun =>and2 (p1 p2)
"Produce a parser which succeeds if P1 and P2 both succeed."
(monadic-do
monad-parse
p1
p2))
(defun =>and (&rest ps)
"Produces a parser if all PS succeed. Result is last parser's result."
(reduce #'=>and2 ps))
(defun =>not (p)
"Succeeds only if P fails. Returns one item."
(enclose
(p)
(lambda (input)
(let ((rs (funcall p input)))
(if rs =nil
=item)))))
(defun =>reduce-concat (p)
"Return a new parser that reduces the result of P with concat."
(monadic-do
monad-parse
(r <- p)
(m-return (reduce #'concat r))))
;;; We need to start writing
(defmacro defvar/fun (name lambda &optional doc)
`(progn
(defvar ,name nil ,@(if doc (list doc) (list)))
(setq ,name ,lambda)
(defalias ',name ,name)))
(defun to-char (s)
"Convert s to the character code representing its first
character."
(car (coerce s 'list)))
(lexical-let*
((low-chars "abcdefghijklmnopqrstuvwxyz")
(low-chars-list (coerce low-chars 'list))
(high-chars-list (coerce (upcase low-chars) 'list))
(both-list (append low-chars-list high-chars-list)))
(defvar/fun =alpha
(=>satisfies
(lambda (x) (in (to-char x) both-list)))
"Parse an alphabetical character.")
(defvar/fun =alpha-upper
(=>satisfies
(lambda (x) (in (to-char x) high-chars-list)))
"Parse an uppercast alphabetical character.")
(defvar/fun =alpha-lower
(=>satisfies
(lambda (x) (in (to-char x) low-chars-list)))
"Parse a lowercase alphabetical character"))
(lexical-let
((digits (coerce "1234567890" 'list)))
(defvar/fun =digit
(=>satisfies
(lambda (x) (in (to-char x) digits)))))
(defun/var =input-type (input)
"Monadically return the type of the input being parsed."
(list (cons (input-dispatcher input) input)))
(defun =>string (&rest s)
"Produces a parser which, if the input is a string or buffer,
matches N characters matching the string S. If the input is a list, then it
succeeds only when the item is a string which matches S."
(if (= 1 (length s))
(lexical-let* ((s (car s))
(n (length s)))
(monadic-do
monad-parse
(type <- =input-type)
(if (eq :list type)
(monadic-do
monad-parse
(item <- =item)
(if (and (stringp item) (string= item s))
(m-return item)
=nil))
(monadic-do
monad-parse
(items <- (=>items->string n))
(if (string= items s) (m-return items)
=nil)))))
(apply #'=>or (mapcar #'=>string s))))
(defun =>stringi (&rest s)
"Produces a parser which, if the input is a string or buffer,
matches N characters matching the string S. If the input is a list, then it
succeeds only when the item is a string which matches S."
(if (= 1 (length s))
(lexical-let* ((s (car s))
(n (length s)))
(monadic-do
monad-parse
(type <- =input-type)
(if (eq :list type)
(monadic-do
monad-parse
(item <- =item)
(if (and (stringp item) (stringi= item s))
(m-return item)
=nil))
(monadic-do
monad-parse
(items <- (=>items->string n))
(if (stringi= items s) (m-return items)
=nil)))))
(apply #'=>or (mapcar #'=>stringi s))))
(defvar/fun =number-from-list
(monadic-do
monad-parse
(item <- =item)
(if (numberp item) (m-return item) =nil))
"Parse a number from a list. This parser will always fail on
character based inputs.")
(defvar/fun =sign
(=>or (=>string "+") (=>string "-")))
(defvar/fun =string-of-digits
(=>one-plus-more =digit))
(defvar/fun =string-of-digits->string
(monadic-do
monad-parse
(items <- =string-of-digits)
(m-return
(if (empty? items) "" (reduce #'concat items)))))
(defvar/fun =dot (=>string "."))
;; (defvar/fun =number-char
;; (monadic-do
;; monad-parse
;; (sign <- (=>maybe =sign))
;; (pre <- =string-of-digits->string)
;; (dot <- (=>maybe =dot))
;; (rest <- =string-of-digits->string)
;; (m-return
;; (string-to-number
;; (let ((sign (if sign sign "")))
;; (if dot (concat sign pre dot rest)
;; (concat sign pre)))))))
(defvar/fun =number-char
(monadic-do
monad-parse
(sign <- (=>maybe =sign))
(pre-decimal <- (=>maybe =string-of-digits->string))
(maybe-dot <- (=>maybe =dot))
(cond
((and (not maybe-dot)
(not pre-decimal))
=nil)
((and maybe-dot
pre-decimal)
(monadic-do
monad-parse
(rest <- (=>maybe =string-of-digits->string))
(m-return
(if rest (string-to-number (concat pre-decimal "." rest))
(string-to-number pre-decimal)))))
((and pre-decimal (not maybe-dot))
(m-return (string-to-number pre-decimal)))
((and (not pre-decimal)
maybe-dot)
(monadic-do
monad-parse
(post-decimal <- =string-of-digits->string)
(m-return (string-to-number (concat "." post-decimal)))))
(t =nil))))
(defvar/fun =number
(monadic-do
monad-parse
(input-type <- =input-type)
(if (eq input-type :list)
=number-from-list
=number-char)))
(defmacro parser (&rest body)
"Create a parser by using the parser monad to sequence the
monadic values represented by the forms in BODY. Each form must
either be a monadic value or a binding form of the type (SYMBOL
<- EXPR), where the expression is a monadic value. SYMBOL is
bound to the monadic return value thereof in subsequent
expressions."
`(monadic-do monad-parse
,@body))
(defmacro defparser-fun (name args maybe-doc &rest body)
"Create a parser-producing function by evaluating the BODY
expressions as in a MONADIC-DO in the body of a function named
NAME with lexically bound arguments ARGS. If MAYBE-DOC is a string,
it is counted as the doc-string for the function."
`(lex-defun ,name ,args
,@(if (stringp maybe-doc) (list maybe-doc) nil)
(parser
,@(if (not (stringp maybe-doc)) (list maybe-doc) nil)
,@body)))
(defmacro defparser-val (name maybe-doc &rest body)
"Creates a parser value/function binding by evaluating the BODY
as if in a monadic-do form in the parser monad. If MAYBE-DOC is
a string, this is treated as the doc-string."
`(defvar/fun ,name
(parser ,@(if (not (stringp maybe-doc)) (list maybe-doc) nil)
,@body)
,@(if (stringp maybe-doc) (list maybe-doc) nil)))
(defmacro defparser (name/args maybe-doc &rest body)
"Combines DEFPARSER-VAL and DEFPARSER-FUN in one easy to use,
Scheme-like defining form. If NAME/ARGS is a symbol, this
expression defines a parser as in DEFPARSER-VAL. If it is a list,
then the car of the list is taken to be the function name and the
CDR the arguments in a DEFPARSER-FUN expression."
(if (symbolp name/args) `(defparser-val ,name/args ,maybe-doc ,@body)
(let ((name (car name/args))
(args (cdr name/args)))
`(defparser-fun ,name ,args ,maybe-doc ,@body))))
(defparser (=>this-symbol s)
"Return a parser matching S only. Such a parser always fails
for string and buffer input."
(item <- =item)
(if (and (symbolp item) (eq item s))
(m-return item)
=nil))
(lexical-let
((punctuation
(coerce "~`!@#$%^&*()_-+={[}]|\\/?.,<>;:'\"" 'list)))
(defparser =punctuation
"Matches any punctuation mark."
(item <- =item)
(if (in (to-char item) punctuation)
(m-return item)
=nil)))
(defparser (=>equal what)
"Returns a parser which succeeds when an ITEM is EQUAL to WHAT."
(item <- =item)
(if (equal item what) (m-return item) =nil))
(defparser (=>eq what)
"Returns a parser which succeeds when an ITEM is EQ to WHAT."
(item <- =item)
(if (eq item what) (m-return item) =nil))
(defparser (=>n-equal n to)
"Returns a parser which succeeds when N ITEMS are equal to the list TO."
(items <- (=>items n))
(if (equal items to)
(m-return items)
=nil))
(defun =>unparse (what)
"An unparser: put WHAT onto the input."
(enclose
(what)
(lambda (input)
(list (cons what
(input-push what input))))))
(defun/var =peek (input)
"Return the next ITEM without removing it from the input."
(list (cons (input-first input) input)))
(defparser (=>items-upto predicate)
"Collect items until PREDICATE is true for one, which is left on the input."
(peek <- =peek)
(if (funcall predicate peek) (m-return nil)
(parser
(item <- =item)
(rest <- (=>items-upto predicate))
(m-return (cons item
rest)))))
(defparser (=>items-upto->string predicate)
"As =>ITEMS-UPTO but concatenates list of results."
(=>reduce-concat (=>items-upto predicate)))
(defun/var =input (input)
"Get the input state as it is."
(list (cons input input)))
(defun =>set-input (to)
"Set the input state to the value TO. Monadically return T."
(enclose (to)
(lambda (input)
(list (cons t to)))))
(defparser (=>do-to-input fun)
"Apply a transformation FUN directly to the parser INPUT state, replace the result."
(input <- =input)
(lexical-let ((new-input (funcall fun input)))
(parser
(=>set-input new-input)
(m-return new-input))))
(defparser (=>number equal-to)
"Parse an expression equal to the specific number EQUAL-TO. Fail otherwise."
(n <- =number)
(if (= n equal-to)
(m-return n)
=nil))
;; (defmacro defparser-w/delim (nameish delim-parser &rest expressions)
;; "Defines a parser as in DEFPARSER where each term is separated by the DELIM-PARSER."
;; (with-gensyms
;; (d_)
;; `(lexical-let ((,d_ ,delim-parser))
;; (defparser ,nameish ,@(intersperse d_ expressions)))))
(defun =>alist>> (&rest args)
"Returns the parser which returns the ALIST created by passing ARGS to ALIST>>."
(parser-return (apply #'alist>> args)))
(defun =>. (f &rest args)
"Return F on ARGS."
(parser-return (apply f args)))
(defalias '=> #'parser-return)
(defun parser-return. (f &rest args)
"Return F on ARGS."
(parser-return (apply f args)))
(provide 'better-monad-parse)