【发布时间】:2018-02-13 05:34:51
【问题描述】:
假设我在一个更大的解析类中有一个解析器定义,如下所示:
def thing: Parser[Thing] = stringTerm ^^ { tLabel => repo.getThing(tLabel).get }
repo.getThing 返回一个 Option[Thing]。好的,假设没有找到 tLabel。我宁愿不要把我的饼干扔到一个例外中。有没有更可控的方法可以让我在解析过程中冒泡?
理想情况下,它会触发这种顶级调用:
parse(freq, "johnny 121") match {
case Success(matched,_) => println(matched)
case Failure(msg,_) => println("FAILURE: " + msg)
case Error(msg,_) => println("ERROR: " + msg)
}
我可以将其冒泡为失败或错误吗?
【问题讨论】: