玩Scala和Anorm:无法创建简单的解析器

时间:2013-04-11 18:39:12

标签: scala playframework-2.0 anorm

这里应该有一些简单的东西,虽然我完全错过了它,因为我是Scala和Play中的菜鸟。这是代码:

case class ExceptionInfo(ExceptionType: String, Message: String, StackTrace: Seq[String])

object ExceptionInfo
    {
      val excInfoParser = {
        get[String]("ExceptionInfo.ExceptionType") ~ 
        get[String]("Message") ~ 
        get[String]("ExceptionInfo.StackTrace") map {
          case ExceptionType ~ Message ~ StackTrace => ExceptionInfo(ExceptionType, Message, StackTrace.split("\r\n"))
        }
      }
    }

这不能编译,输出如下:

Description Resource            Path                Location                        Type
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value Message        Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value StackTrace     Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem

提前致谢!

1 个答案:

答案 0 :(得分:2)

当您使用小写命名变量时应该有效:

case exceptionType ~ message ~ stackTrace => ExceptionInfo(exceptionType, message, stackTrace.split("\r\n"))

小写是区分要绑定的变量(您要查找的)与要匹配的常量的区别。有关详情,请参阅herehere