Calling Atto from java/JRuby adds required mystery 3rd parameter to Combinators
kianwilcox opened this issue · comments
I'm trying to do something a little funky with Atto by using it from JRuby, and I'm running into a strange issue.
Trying to run the readme example of parsing a list of integers separated by whitespace, but when calling
Parser.parse(Atto.sepBy(Atto.int, Atto.spaceChar), "123 45 6"), it tells me I'm missing an argument (2 for 3) in sepBy, whose signature in the scala code appears to only require 2 arguments. When I try providing different kinds of arguments to the third slot, it suggests i get something coercible to atto.compat.NonEmptyListy.
When i try providing NonEmptyList like inputs into the 3rd argument,
Atto.sepBy(Atto.int, Atto.spaceChar, NonEmptyList(1)), it tells me that I'm missing a method 'cons'. It suggests something about overloading to atto.compat.NonEmptyListy, or scala.Function0, but I'm stuck unable to figure out what the 3rd argument should be. When I look in the code for Atto, I notice there is an implicit Functor in ParseResultInstances. Is there some sort of Functor i should be passing as the third argument to let it accumulate on? or some kind of 'empty parser', like the Ok parser?
I understand that this is not the usual use of this library, but I would very much appreciate any help you can give.
You're going to have a rough time calling atto from anything other than Scala, but the way you can figure this out is to try it from the REPL and use reify
to see the implicit arguments.
scala> import atto._, Atto._, compat.scalaz._
import atto._
import Atto._
import compat.scalaz._
scala> reflect.runtime.universe.reify { Parser.parse(Atto.sepBy(Atto.int, Atto.spaceChar), "123 45 6") }
res0: reflect.runtime.universe.Expr[atto.ParseResult[List[Int]]] = Expr[atto.ParseResult[scala.List[Int]]](Parser.parse(Atto.sepBy(Atto.int, Atto.spaceChar)(scalaz.ScalazNelMode), "123 45 6"))
So the third argument is the value atto.compat.scalaz.ScalazNelMode
.
That's a bug by the way; there is no non-empty list in the signature so it doesn't actually need to you provide that instance. I'll fix that.