首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scala快速解析类型检查

scala快速解析类型检查
EN

Stack Overflow用户
提问于 2017-06-07 08:38:28
回答 0查看 82关注 0票数 1

我对以下使用scala fastparse 0.4.3的代码无法进行类型检查感到困惑。

代码语言:javascript
复制
val White = WhitespaceApi.Wrapper{
  import fastparse.all._
  NoTrace(CharIn(" \t\n").rep)
}
import fastparse.noApi._
import White._

case class Term(tokens: Seq[String])
case class Terms(terms: Seq[Term])

val token = P[String] ( CharIn('a' to 'z', 'A' to 'Z', '0' to '9').rep(min=1).!)
val term: P[Term] = P("[" ~ token.!.rep(sep=" ", min=1) ~ "]").map(x => Term(x))
val terms = P("(" ~ term.!.rep(sep=" ", min=1) ~ ")").map{x => Terms(x)}
val parse = terms.parse("([ab bd ef] [xy wa dd] [jk mn op])")

错误消息:

代码语言:javascript
复制
[error] .../MyParser.scala: type mismatch;
[error]  found   : Seq[String]
[error]  required: Seq[Term]
[error]     val terms = P("(" ~ term.!.rep(sep=" ", min=1) ~")").map{x => Terms(x)}
[error]                                                                         ^

我可以想象,由于termTerm类型,并且terms模式使用term.!.rep(...,因此它应该获得一个Seq[Term]

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44401746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档