1///|
2pub fn[A, B] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(x : Parser[A], z : Parser[B], f : Parser[(B, A) -> B]) -> Parser[B]
foldl(
3 Parser[A]
x : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A],
4 Parser[B]
z : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter B
B],
5 Parser[(B, A) -> B]
f : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[(type parameter B
B, type parameter A
A) -> type parameter B
B]
6) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter B
B] {
7 fn(Input
input) {
8 let (B
z, Input
zr) = Parser[B]
z(Input
input)
9 let mut Input
rest = Input
zr
10 let mut B
acc = B
z
11 while (try? Parser[(B, A) -> B]
f(Input
rest)) is (((B, A) -> B, Input)) -> Result[((B, A) -> B, Input), ParseError]
Ok(((B, A) -> B
f, Input
fr)) (Bool, Bool) -> Bool
&& (try? Parser[A]
x(Input
fr)) is ((A, Input)) -> Result[(A, Input), ParseError]
Ok((A
x, Input
xr)) {
12 B
acc = (B, A) -> B
f(B
acc, A
x)
13 Input
rest = Input
xr
14 }
15 (B
acc, Input
rest)
16 }
17}
18
19///|
20pub fn[A, B] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(x : Parser[A], z : Parser[B], f : Parser[(B, A) -> B]) -> Parser[B]
foldr(
21 Parser[A]
x : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A],
22 Parser[B]
z : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter B
B],
23 Parser[(B, A) -> B]
f : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[(type parameter B
B, type parameter A
A) -> type parameter B
B]
24) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter B
B] {
25 fn(Input
input) {
26 let Array[(A, (B, A) -> B)]
buffer = []
27 let mut Input
rest = Input
input
28 while (try? Parser[A]
x(Input
rest)) is ((A, Input)) -> Result[(A, Input), ParseError]
Ok((A
x, Input
xr)) (Bool, Bool) -> Bool
&& (try? Parser[(B, A) -> B]
f(Input
xr)) is (((B, A) -> B, Input)) -> Result[((B, A) -> B, Input), ParseError]
Ok(((B, A) -> B
f, Input
fr)) {
29 Array[(A, (B, A) -> B)]
buffer.(self : Array[(A, (B, A) -> B)], value : (A, (B, A) -> B)) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push((A
x, (B, A) -> B
f))
30 Input
rest = Input
fr
31 }
32 let (B
z, Input
rest) = Parser[B]
z(Input
rest)
33 let mut B
acc = B
z
34 for (A, (B, A) -> B)
e in Array[(A, (B, A) -> B)]
buffer.(self : Array[(A, (B, A) -> B)]) -> Iter[(A, (B, A) -> B)]
Returns an iterator that yields elements from the array in reverse order,
from the last element to the first.
Parameters:
array : The array to iterate over in reverse order.
Returns an iterator that yields each element of the array, starting from the
last element and moving towards the first.
Example:
let arr = [1, 2, 3]
let result = []
arr.rev_iter().each(fn(x) { result.push(x) })
inspect(result, content="[3, 2, 1]")
rev_iter() {
35 let (A
x, (B, A) -> B
f) = (A, (B, A) -> B)
e
36 B
acc = (B, A) -> B
f(B
acc, A
x)
37 }
38 (B
acc, Input
rest)
39 }
40}
41
42///|
43pub fn[A] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(x : Parser[A], f : Parser[(A, A) -> A]) -> Parser[A]
foldr1(Parser[A]
x : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A], Parser[(A, A) -> A]
f : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[(type parameter A
A, type parameter A
A) -> type parameter A
A]) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A] {
44 (x : Parser[A], z : Parser[A], f : Parser[(A, A) -> A]) -> Parser[A]
foldr(Parser[A]
x, Parser[A]
x, Parser[(A, A) -> A]
f)
45}
46
47///|
48pub fn[A] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(x : Parser[A], f : Parser[(A, A) -> A]) -> Parser[A]
foldl1(Parser[A]
x : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A], Parser[(A, A) -> A]
f : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[(type parameter A
A, type parameter A
A) -> type parameter A
A]) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A] {
49 (x : Parser[A], z : Parser[A], f : Parser[(A, A) -> A]) -> Parser[A]
foldl(Parser[A]
x, Parser[A]
x, Parser[(A, A) -> A]
f)
50}
51
52///|
53pub fn[A] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(x : Parser[A], f : (A) -> Unit) -> Parser[Unit]
many_each(Parser[A]
x : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A], (A) -> Unit
f : (type parameter A
A) -> Unit
Unit) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[Unit
Unit] {
54 fn(Input
input) {
55 let (A, Input)
r = Parser[A]
x(Input
input)
56 (A) -> Unit
f((A, Input)
r.A
0)
57 let mut Input
rest = (A, Input)
r.Input
1
58 while (try? Parser[A]
x(Input
rest)) is ((A, Input)) -> Result[(A, Input), ParseError]
Ok((A
v, Input
vr)) {
59 (A) -> Unit
f(A
v)
60 Input
rest = Input
vr
61 }
62 ((), Input
rest)
63 }
64}
65
66///|
67pub fn[A] type Parser[A] (Input) -> (A, Input) raise ParseError
Parser::(self : Parser[A]) -> Parser[Array[A]]
many(Parser[A]
self : type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type parameter A
A]) -> type Parser[A] (Input) -> (A, Input) raise ParseError
Parser[type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[type parameter A
A]] {
68 Parser[A]
self.(x : Parser[A], z : Parser[Array[A]], f : Parser[(Array[A], A) -> Array[A]]) -> Parser[Array[A]]
foldl(
69 (x : Array[A]) -> Parser[Array[A]]
pure([]),
70 (x : (Array[A], A) -> Array[A]) -> Parser[(Array[A], A) -> Array[A]]
pure(fn(Array[A]
acc : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[type parameter A
A], A
x) {
71 Array[A]
acc.(self : Array[A], value : A) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(A
x)
72 Array[A]
acc
73 }),
74 )
75}
76