author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 15 Jun 2013 09:23:18 -0400 | |
changeset 93 | 4794759139ea |
parent 92 | scala/app7.scala@e85600529ca5 |
child 169 | 57df3d7b4a25 |
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) |
70
e6868bd2942b
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
66
diff
changeset
|
12 |
def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = |
e6868bd2942b
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
66
diff
changeset
|
13 |
new SeqParser(this, right) |
66
9215b9fb8852
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
7
diff
changeset
|
14 |
} |
7 | 15 |
|
16 |