aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-26 22:52:25 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-26 22:52:59 -0600
commit15e5a0179c05861011ea79f6139f2038d0cf1f0a (patch)
tree269167d411f33a7431faf65bf0f55fe1b7c04948
parentf5bc8b2ba9e2eb8ea53d49d67dbd8e00d4702d68 (diff)
downloadscala-test-more-15e5a0179c05861011ea79f6139f2038d0cf1f0a.tar.gz
scala-test-more-15e5a0179c05861011ea79f6139f2038d0cf1f0a.zip
use a recursive call rather than a var
a bit more complicated than i'd like, due to path-dependent types, but oh well
-rw-r--r--src/main/scala/org/perl8/test/tap/Parser.scala41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/main/scala/org/perl8/test/tap/Parser.scala b/src/main/scala/org/perl8/test/tap/Parser.scala
index f422b4e..5f06385 100644
--- a/src/main/scala/org/perl8/test/tap/Parser.scala
+++ b/src/main/scala/org/perl8/test/tap/Parser.scala
@@ -9,11 +9,17 @@ import scala.util.parsing.input.{Position,Reader}
import org.perl8.test.Plan
import org.perl8.test.tap.Consumer._
-class Parser (cb: TAPEvent => Unit) extends Parsers {
+class Parser (
+ cb: TAPEvent => Unit,
+ indent: String
+) extends Parsers {
type Elem = Line
- def this () =
- this(e => ())
+ def this (cb: TAPEvent => Unit = e => ()) =
+ this(cb, "")
+
+ def this (indent: String) =
+ this(e => (), indent)
def parse (input: InputStream): TAPResult =
tap(new LineReader(input)) match {
@@ -60,22 +66,23 @@ class Parser (cb: TAPEvent => Unit) extends Parsers {
)
}
- private def subtest: Parser[TAPResult] = LineParser("subtest") { in =>
- val oldIndent = expectedIndent
- val newIndent = in.first.indent
-
- try {
- expectedIndent = newIndent
- tap(in)
- }
- finally {
- expectedIndent = oldIndent
+ private def subtest: Parser[TAPResult] =
+ LineParser("subtest") { in =>
+ // can't just return the result directly, because it's of a different
+ // type (the path dependent type associated with the new Parser instance
+ // we create here, rather than the path dependent type associated with
+ // this)
+ val subParser = new org.perl8.test.tap.Parser(cb, in.first.indent)
+ subParser.tap(in) match {
+ case subParser.Success(p, rest) => Success(p, rest)
+ case subParser.Failure(m, rest) => Failure(m, rest)
+ case subParser.Error(m, rest) => Error(m, rest)
+ }
}
- }
private def planLine: Parser[PlanLine] = LineParser("plan") { in =>
val line = in.first
- if (line.indent == expectedIndent) {
+ if (line.indent == indent) {
line match {
case p: PlanLine =>
Success(p, in.rest)
@@ -94,7 +101,7 @@ class Parser (cb: TAPEvent => Unit) extends Parsers {
private def resultLine: Parser[ResultLine] = LineParser("result") { in =>
val line = in.first
- if (line.indent == expectedIndent) {
+ if (line.indent == indent) {
line match {
case p: ResultLine =>
Success(p, in.rest)
@@ -175,8 +182,6 @@ class Parser (cb: TAPEvent => Unit) extends Parsers {
) extends Position {
def column: Int = 1
}
-
- private var expectedIndent = ""
}
sealed trait TAPEvent