diff options
author | michelou <michelou@epfl.ch> | 2004-05-04 13:26:25 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2004-05-04 13:26:25 +0000 |
commit | 687c2be6d7ad7430bc511ec152c0cff9365e334f (patch) | |
tree | cb96e14662a70fb81cf8d41fb18da2132ab72ec4 /sources/examples/parsers1.scala | |
parent | 26f8a264be69d50983d3e326a8f5d8487213387d (diff) | |
download | scala-687c2be6d7ad7430bc511ec152c0cff9365e334f.tar.gz scala-687c2be6d7ad7430bc511ec152c0cff9365e334f.tar.bz2 scala-687c2be6d7ad7430bc511ec152c0cff9365e334f.zip |
- moved abstract class 'Parsers' in a separate ...
- moved abstract class 'Parsers' in a separate file (used also by
- typeinf.scala). changed 'System.out.' to 'Console.'.
Diffstat (limited to 'sources/examples/parsers1.scala')
-rw-r--r-- | sources/examples/parsers1.scala | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/sources/examples/parsers1.scala b/sources/examples/parsers1.scala index 4fb035020a..613789e495 100644 --- a/sources/examples/parsers1.scala +++ b/sources/examples/parsers1.scala @@ -1,5 +1,7 @@ package examples; +object parsers1 { +/* abstract class Parsers { type intype; @@ -20,14 +22,14 @@ abstract class Parsers { def map[b](f: a => b) = new Parser[b] { def apply(in: intype): Result = Parser.this.apply(in) match { case None => None - case Some(Pair(x, in1)) => Some(Pair(f(x), in1)) + case Some(Pair(x, in1)) => Some(Pair(f(x), in1)) } } def flatMap[b](f: a => Parser[b]) = new Parser[b] { def apply(in: intype): Result = Parser.this.apply(in) match { case None => None - case Some(Pair(x, in1)) => f(x).apply(in1) + case Some(Pair(x, in1)) => f(x).apply(in1) } } @@ -63,7 +65,7 @@ abstract class CharParsers extends Parsers { def chr(p: char => boolean) = for (val c <- any; p(c)) yield c; } - +*/ abstract class Tree{} case class Id (s: String) extends Tree {} case class Num(n: int) extends Tree {} @@ -101,24 +103,23 @@ abstract class ListParsers extends CharParsers { } -class ParseString(s: String) extends Parsers { - type intype = int; - val input = 0; - def any = new Parser[char] { - def apply(in: int): Parser[char]#Result = - if (in < s.length()) Some(Pair(s charAt in, in + 1)) else None; + class ParseString(s: String) extends Parsers { + type intype = int; + val input = 0; + def any = new Parser[char] { + def apply(in: int): Parser[char]#Result = + if (in < s.length()) Some(Pair(s charAt in, in + 1)) else None; + } } -} -object Test { def main(args: Array[String]): unit = - System.out.println( + Console.println( if (args.length == 1) { - val ps = new ListParsers with ParseString(args(0)); - ps.expr(ps.input) match { - case Some(Pair(list, _)) => System.out.println("parsed: " + list); - case None => "nothing parsed" - } + val ps = new ListParsers with ParseString(args(0)); + ps.expr(ps.input) match { + case Some(Pair(list, _)) => Console.println("parsed: " + list); + case None => "nothing parsed" + } } else "usage: java examples.Test <expr-string>" ); } |