blob: 1f7a54a1af4f0d5f2644244c4c277397c3e5f5a1 (
plain)
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
|
(.module:
[library
[lux #*
[abstract
[monad (#+ do)]]
[control
["." try (#+ Try)]
["." exception (#+ exception:)]]
[data
[collection
[tree (#+ Tree)
["." zipper (#+ Zipper)]]]]]]
["." //])
(type: .public (Parser t a)
(//.Parser (Zipper t) a))
(def: .public (result' parser zipper)
(All [t a] (-> (Parser t a) (Zipper t) (Try a)))
(do try.monad
[[zipper output] (//.result parser zipper)]
(in output)))
(def: .public (result parser tree)
(All [t a] (-> (Parser t a) (Tree t) (Try a)))
(result' parser (zipper.zipper tree)))
(def: .public value
(All [t] (Parser t t))
(function (_ zipper)
(#try.Success [zipper (zipper.value zipper)])))
(exception: .public cannot_move_further)
(template [<name> <direction> <doc>]
[(def: .public <name>
{#.doc (example <doc>)}
(All [t] (Parser t []))
(function (_ zipper)
(case (<direction> zipper)
#.None
(exception.except ..cannot_move_further [])
(#.Some next)
(#try.Success [next []]))))]
[down zipper.down
"Move down."]
[up zipper.up
"Move up."]
[right zipper.right
"Move to the right."]
[rightmost zipper.rightmost
"Move to the rightmost node."]
[left zipper.left
"Move to the left."]
[leftmost zipper.leftmost
"Move to the leftmost node."]
[next zipper.next
"Move to the next node."]
[end zipper.end
"Move to the last node."]
[previous zipper.previous
"Move to the previous node."]
[start zipper.start
"Move to the root node."]
)
|