Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Atto from java/JRuby adds required mystery 3rd parameter to Combinators #29

Open
kianwilcox opened this issue Jun 9, 2016 · 2 comments

Comments

@kianwilcox
Copy link

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.

@tpolecat
Copy link
Owner

tpolecat commented Jun 9, 2016

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.

@tpolecat
Copy link
Owner

tpolecat commented Jun 9, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants