1///|
2pub(all) struct SourcePos {
3 Int
row : Int
Int
4 Int
col : Int
Int
5} derive(trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Trait for types that can be converted to String
Show, trait Eq {
op_equal(Self, Self) -> Bool
}
Trait for types whose elements can test for equality
Eq, trait Compare {
compare(Self, Self) -> Int
}
Trait for types whose elements are ordered
The return value of [compare] is:
- zero, if the two arguments are equal
- negative, if the first argument is smaller
- positive, if the first argument is greater
Compare)
6
7///|
8pub(all) struct Input {
9 @string.StringView
chars : type @string.StringView
A @string.View represents a view of a String that maintains proper Unicode
character boundaries. It allows safe access to a substring while handling
multi-byte characters correctly.
@string.View
10 Int
row : Int
Int
11 Int
col : Int
Int
12} derive(trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Trait for types that can be converted to String
Show)
13
14///|
15pub typealias enum @list.T[A] {
Empty
More(A, tail~ : @list.T[A])
}
@list.T as List
16
17///|
18pub(all) suberror ParseError {
19 (SourcePos, @list.T[String]) -> ParseError
ParseError(struct SourcePos {
row: Int
col: Int
}
SourcePos, enum @list.T[A] {
Empty
More(A, tail~ : @list.T[A])
}
List[String
String])
20}
21
22///|
23pub(all) type Parser[A] (struct Input {
chars: @string.StringView
row: Int
col: Int
}
Input) -> (type parameter A
A, struct Input {
chars: @string.StringView
row: Int
col: Int
}
Input) raise type! ParseError {
ParseError(SourcePos, @list.T[String])
}
ParseError
24
25///|
26pub impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Trait for types that can be converted to String
Show for type! ParseError {
ParseError(SourcePos, @list.T[String])
}
ParseError with (self : ParseError, logger : &Logger) -> Unit
output(ParseError
self, &Logger
logger) {
27 let (SourcePos, @list.T[String]) -> ParseError
ParseError({ Int
row, Int
col }, @list.T[String]
xs) = ParseError
self
28 &Logger
logger.(&Logger, String) -> Unit
write_string(
29 $|
30 $|Parse Error:\{Int
row}:\{Int
col}:
31 $|
32 ,
33 )
34 for String
msg in @list.T[String]
xs {
35 &Logger
logger.(&Logger, String) -> Unit
write_string(
36 $| \{String
msg} is expected
37 $|
38 ,
39 )
40 }
41}
42