author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Wed, 21 Nov 2012 02:20:16 +0000 | |
changeset 66 | 9215b9fb8852 |
parent 7 | 73cf4406b773 |
child 70 | e6868bd2942b |
permissions | -rw-r--r-- |
66
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
1 |
abstract class Parser[I, T] { |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
2 |
def parse(ts: I): Set[(T, I)] |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
3 |
|
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
4 |
def parse_all(ts: I) : Set[T] = |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
5 |
for ((head, tail) <- parse(ts); if (tail.isEmpty)) |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
6 |
yield head |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
7 |
|
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
8 |
def || (right : => Parser[I, T]) : Parser[I, T] = |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
9 |
new AltParser(this, right) |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
10 |
def ==>[S] (f: => T => S) : Parser [I, S] = |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
11 |
new FunParser(this, f) |
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
12 |
} |
7 | 13 |
|
14 |