Reputation: 2600
Consider this source code that implements a parser for a term language in Scala. The main function, designed to test its functionality is defined as:
def main(args: Array[String]): Unit = {
val stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
val tokens = new lexical.Scanner(stdin.readLine())
phrase(term)(tokens) match {
case Success(trees, _) =>
for (t <- path(trees))
println(t)
try {
print("Big step: ")
println(eval(trees))
} catch {
case TermIsStuck(t) => println("Stuck term: " + t)
}
case e =>
println(e)
}
}
I wrote the following test:
package fos
import org.scalatest.FunSuite
class ArithmeticTest extends FunSuite {
test("testTerm") {
Arithmetic.term(new Arithmetic.lexical.Scanner("if iszero pred pred 2 then if iszero 0 then true else false else false")) match {
case Success(res,next) => assert(res == If(IsZero(Pred(Pred(Succ(Succ(Zero))))),If(IsZero(Zero),True,False),False))
case Failure(msg,next) => assert(false)
}
}
}
Unfortunately, the Success and Failure cases are not recognized even if I mix-in StandardTokenParsers
like in the link above. How can I get it working?
Upvotes: 0
Views: 18
Reputation: 170745
You need Arithmetic.Success
and Arithmetic.Failure
, just like you have Arithmetic.lexical.Scanner
. Alternatively, you could import Arithmetic._
.
Upvotes: 1