diff options
author | Martin Odersky <odersky@gmail.com> | 2003-03-03 17:41:08 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-03-03 17:41:08 +0000 |
commit | fe9d7cc9ec4e55d42a09b149d60d6cf2f8be09af (patch) | |
tree | b75e907e87f3448b01ca3ec2f7af7cd62d574e0e /sources/examples/parsers1.scala | |
parent | 1d2a33a1c2692407698dd7c4dd7b46703eef2d24 (diff) | |
download | scala-fe9d7cc9ec4e55d42a09b149d60d6cf2f8be09af.tar.gz scala-fe9d7cc9ec4e55d42a09b149d60d6cf2f8be09af.tar.bz2 scala-fe9d7cc9ec4e55d42a09b149d60d6cf2f8be09af.zip |
*** empty log message ***
Diffstat (limited to 'sources/examples/parsers1.scala')
-rw-r--r-- | sources/examples/parsers1.scala | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sources/examples/parsers1.scala b/sources/examples/parsers1.scala index cf2d02d076..bbd0a0dbe0 100644 --- a/sources/examples/parsers1.scala +++ b/sources/examples/parsers1.scala @@ -7,35 +7,35 @@ case class Binop(op: Char, l: Tree, r: Tree): Tree extends Tree {} module Parse { - type Result[b] = Option[Pair[b, List[Char]]]; + trait Parser[p] { - trait Parser[p] extends Function1[List[Char], Result[p]] { + type Result = Option[Pair[p, List[Char]]]; - def apply(in: List[Char]): Result[p]; + def apply(in: List[Char]): Result; def filter(p: p => Boolean) = new Parser[p] { - def apply(in: List[Char]): Result[p] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => if (p(x)) Some(Pair(x, in1)) else None() case n => n } } def map[b](f: p => b) = new Parser[b] { - def apply(in: List[Char]): Result[b] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => Some(Pair(f(x), in1)) case None() => None() } } def flatMap[b](f: p => Parser[b]) = new Parser[b] { - def apply(in: List[Char]): Result[b] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => f(x)(in1) case None() => None() } } def ||| (def p: Parser[p]) = new Parser[p] { - def apply(in: List[Char]): Result[p] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case None() => p(in) case s => s } @@ -64,7 +64,7 @@ module ExprParser { import Parse._; def chrWith(p: Char => Boolean) = new Parser[Char] { - def apply(in: List[Char]): Result[Char] = in match { + def apply(in: List[Char]): Result = in match { case List() => None() case (c :: in1) => if (p(c)) Some(Pair(c, in1)) else None() } |