score:4

Accepted answer

You need to specify how to handle whitespace, for example the following fails

import fastparse._
import fastparse.NoWhitespace._

def ab[_:P] = P("a" ~ "b")
assert(parse("a      b", ab(_)).isSuccess)

because "a b" contains spaces, whilst the following passes

import fastparse._
import fastparse.SingleLineWhitespace._

def ab[_:P] = P("a" ~ "b")
assert(parse("a      b", ab(_)).isSuccess)

becase import fastparse.SingleLineWhitespace._ provides whitespace consumer. If we look at the definition of ~

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]

we see implicit whitespace: P[Any] => P[Unit] requirement which explains No implicit view available error. The whitespace imports provide this capability, for example

object NoWhitespace {
  implicit object noWhitespaceImplicit extends (ParsingRun[_] => ParsingRun[Unit]){
    def apply(ctx: ParsingRun[_]) = ctx.freshSuccessUnit()
  }
}

where we see ParsingRun[_] => ParsingRun[Unit] implicit function.

score:2

You missed one more import

import NoWhitespace._

https://scastie.scala-lang.org/qCKZEnRHS7eOhjpVjtWNIQ


Related Query

More Query from same tag