blob: 4f4f65f3a52a831d8cf9c737ece2267514020bdf (
plain) (
blame)
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
|
class StringConsumerEngine inherits System {
consumers: ConsumerList <- (new ConsumerList)
.push((new WhitespaceConsumer).init())
.push((new ExpressionConsumer).init())
.push((new IfConsumer).init())
;
str: String;
tl: TokenList <- new TokenList;
init(code: String) : Object {{
assert(not (code = ""), "init", "input code cannot be empty!");
assert(str = "", "init", "already initialised!");
str <- code;
}};
try_consume() : Bool {
let
consumer: Object <- consumers.find(str)
in
if isvoid consumer
then
false
else
case consumers.find(str) of
c: IStringConsumer => {
str <- str.substr(c.consumed_length(), str.length() - c.consumed_length());
tl.push(c.token());
true;
};
o: Object => false;
esac
fi
};
out() : Object {
out_string(str)
};
empty() : Bool {
str = ""
};
generated_tokens() : TokenList {
tl
};
};
|