Skip to content

Commit

Permalink
Fixed examples for new Stream-based results
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Mar 31, 2010
1 parent 2418779 commit 0cd76da
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/src/Example.scala
Expand Up @@ -15,7 +15,7 @@ trait Example[A] extends Parsers {
if (results exists { _.isInstanceOf[Success[A]] }) {
handleSuccesses(for (Success(tree, _) <- results) yield tree)
} else {
val sorted = results sort { _.tail.length < _.tail.length }
val sorted = results.toList sort { _.tail.length < _.tail.length }
val length = sorted.head.tail.length

for (Failure(msg, tail) <- sorted takeWhile { _.tail.length == length }) {
Expand All @@ -30,5 +30,5 @@ trait Example[A] extends Parsers {

def parser: Parser[A]

def handleSuccesses(forest: List[A])
def handleSuccesses(forest: Stream[A])
}
2 changes: 1 addition & 1 deletion examples/src/arithmetic/ArithmeticParser.scala
Expand Up @@ -29,7 +29,7 @@ object ArithmeticParser extends common.Example[Expr] with RegexParsers {

def parser = expr

def handleSuccesses(forest: List[Expr]) {
def handleSuccesses(forest: Stream[Expr]) {
forest foreach println
}
}
4 changes: 2 additions & 2 deletions examples/src/config/ConfigParser.scala
Expand Up @@ -33,7 +33,7 @@ object ConfigParser extends common.Example[Map[String, String]] with RegexParser

back
} else {
val sorted = results sort { _.tail.length < _.tail.length }
val sorted = results.toList sort { _.tail.length < _.tail.length }
val length = sorted.head.tail.length

throw new ConfigException(sorted takeWhile { _.tail.length == length } flatMap {
Expand All @@ -43,7 +43,7 @@ object ConfigParser extends common.Example[Map[String, String]] with RegexParser
}
}

def handleSuccesses(forest: List[Map[String, String]]) {
def handleSuccesses(forest: Stream[Map[String, String]]) {
for ((key, value) <- forest.foldLeft(Map[String, String]()) { _ ++ _ }) {
println(" " + key + " -> " + value)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lambdacalc/LambdaCalcParser.scala
Expand Up @@ -35,7 +35,7 @@ object LambdaCalcParser extends common.Example[(List[Alias], Expr)] with RegexPa

def parser = aliases

def handleSuccesses(forest: List[(List[Alias], Expr)]) {
def handleSuccesses(forest: Stream[(List[Alias], Expr)]) {
val errors = mutable.Set[String]()

val status = for ((tree, expr) <- forest) yield {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/miniml/MiniMLParser.scala
Expand Up @@ -77,7 +77,7 @@ object MiniMLParser extends common.Example[Any] with RegexParsers {

def parser = decs

def handleSuccesses(v: List[Any]) {
def handleSuccesses(v: Stream[Any]) {
if (!v.isEmpty)
println(" Successfully recognized!")
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/paren/ParenParser.scala
Expand Up @@ -13,7 +13,7 @@ object ParenParser extends common.Example[Int] {

def parser = expr

def handleSuccesses(forest: List[Int]) {
def handleSuccesses(forest: Stream[Int]) {
for (depth <- forest) {
println(" " + depth)
}
Expand Down

0 comments on commit 0cd76da

Please sign in to comment.