我正在通过快速解析教程/解释工作,并得到错误消息
error: No implicit view available from fastparse.P[Any] => fastparse.P[Unit]对于序列示例。
我使用的是SBT1.3.8和Scala2.13.1。快速解析的定义版本为2.2.2。
scala> import fastparse._
import fastparse._
scala> def ab[_:P] = P("a" ~ "b")
^
error: No implicit view available from fastparse.P[Any] => fastparse.P[Unit].
scala> def a[_:P] = P("a")
a: [_](implicit evidence$1: fastparse.P[Any])fastparse.package.P[Unit]
scala> def b[_:P] = P("b")
b: [_](implicit evidence$1: fastparse.P[Any])fastparse.package.P[Unit]
scala> def ab[_:P] = P(a ~ b)
^
error: No implicit view available from fastparse.package.P[Any] => fastparse.package.P[Unit].
scala> def ab[_:P] = P("a" | "b")
ab: [_](implicit evidence$1: fastparse.P[Any])fastparse.package.P[Unit]
scala> fastparse.parse("a", ab(_))
res2: fastparse.Parsed[Unit] = Parsed.Success((), 1)这个错误意味着什么?我做错了什么/如何在没有错误的情况下结束本教程步骤?
发布于 2020-08-05 17:55:31
您需要指定如何处理白空间,例如,下列操作失败
import fastparse._
import fastparse.NoWhitespace._
def ab[_:P] = P("a" ~ "b")
assert(parse("a b", ab(_)).isSuccess)因为"a b"包含空格,而下面的传递
import fastparse._
import fastparse.SingleLineWhitespace._
def ab[_:P] = P("a" ~ "b")
assert(parse("a b", ab(_)).isSuccess)因为import fastparse.SingleLineWhitespace._提供空白用户。如果我们看一下~的定义
def ~[V, R](other: P[V])
(implicit s: Implicits.Sequencer[T, V, R],
whitespace: P[Any] => P[Unit],
ctx: P[_]): P[R] = macro MacroImpls.parsedSequence[T, V, R]我们看到了implicit whitespace: P[Any] => P[Unit]需求,它解释了No implicit view available错误。例如,空格导入提供了此功能。
object NoWhitespace {
implicit object noWhitespaceImplicit extends (ParsingRun[_] => ParsingRun[Unit]){
def apply(ctx: ParsingRun[_]) = ctx.freshSuccessUnit()
}
}在这里我们看到ParsingRun[_] => ParsingRun[Unit]隐函数。
发布于 2020-08-05 17:33:36
https://stackoverflow.com/questions/63270429
复制相似问题