fastparse icon indicating copy to clipboard operation
fastparse copied to clipboard

Simple example no longer runs on scala 3.5.1

Open TimPigden opened this issue 1 year ago • 4 comments

import fastparse._ object TestFastParse { def parseA[$: P] = P("a")

val Parsed.Success(value, successIndex) = parse("a", parseA(_))

assert(value == (), successIndex == 1) }

. /home/tim/repos/untitled/src/main/scala/TestFastParse.scala:5:56 Context bounds will map to context parameters. A using clause is needed to pass explicit arguments to them. This code can be rewritten automatically under -rewrite -source 3.4-migration. val Parsed.Success(value, successIndex) = parse("a", parseA(_))

TimPigden avatar Sep 24 '24 12:09 TimPigden

This can be manually worked around by replacing parse("a", parseA(_)) with parse("a", c => parseA(using c)) since a using keyword now appears to be required.

vladimir-lu avatar Sep 25 '24 22:09 vladimir-lu

also applies to 3.6. Tho the error message is now No given instance of type fastparse.ParsingRun[$]

The change I applied is:

parse("a", parseA(using _))

which is easier than creating the lambda explicitly. Also: TIL about using _.

coreyoconnor avatar Dec 20 '24 16:12 coreyoconnor

Ow man I was so frustrated to make it work. Thx for this. I can confirm that examples do not work on Scala 3.6.3. But what is the solution I have to write using all the time? Will there be a fix for this?

dejvid avatar Feb 15 '25 19:02 dejvid

Ok I have kinda create a wrapper function so I don't need to write those using keywords all the time. If any of you have suggestions but this worked for me:

def parseAlternative[T](input: ParserInputSource,
                          parser: P[?] ?=> P[T],
                          verboseFailures: Boolean = false,
                          startIndex: Int = 0,
                          instrument: Instrument = null): Parsed[T] = {

    parse[T](
      input,
      parser = v => parser(using v),
      verboseFailures,
      startIndex,
      instrument
    )
  }

Example code:

def parseA[$: P] = P("a")
val Parsed.Success(value, successIndex) =
    parseAlternative("a", parseA)

dejvid avatar Feb 15 '25 19:02 dejvid