bmjames / scala-optparse-applicative

Scala port of Paolo Capriotti's optparse-applicative library. This repository is no longer maintained; newer versions exist in this fork: https://github.com/xuwei-k/optparse-applicative
BSD 3-Clause "New" or "Revised" License
72 stars 9 forks source link

Change pretty printing to linear bounded #16

Closed coltfred closed 7 years ago

coltfred commented 7 years ago

A port of https://www.cs.kent.ac.uk/pubs/2009/2847/content.pdf section 3.3 to scala using trampolining to make it the most hideous thing to read (oh, and to make it work in Scala).

It fixes #15, which I have locally, but I wasn't sure if we should check it into the tests? I'd be happy to add scalatest or specs and add the large parser to ensure it doesn't take longer than a certain amount of time to execute.

I'll be taking this idea and expanding it out for a pretty printing library, if I do I'll contribute back changes or link to the lib directly if that makes sense.

bmjames commented 7 years ago

Thanks!

I am seeing errors when trying to compile this to Scala 2.10, any ideas?

[info] Compiling 35 Scala sources to /home/ben/scala-optparse-applicative/target/scala-2.10/classes...
[error] /home/ben/scala-optparse-applicative/src/main/scala/net/bmjames/opts/types/Doc.scala:65: value dequeueOption is not a member of net.bmjames.opts.types.Doc.Dq
[error]           dq.dequeueOption match {
[error]              ^
[error] /home/ben/scala-optparse-applicative/src/main/scala/net/bmjames/opts/types/Doc.scala:67: type mismatch;
[error]  found   : net.bmjames.opts.types.Doc.Remaining
[error]     (which expands to)  Int
[error]  required: String
[error]               if (p > s + r) {
[error]                           ^
[error] /home/ben/scala-optparse-applicative/src/main/scala/net/bmjames/opts/types/Doc.scala:70: type mismatch;
[error]  found   : Any
[error]  required: net.bmjames.opts.types.Doc.Dq
[error]     (which expands to)  scala.collection.immutable.Queue[(Int, Boolean => ((Int => scalaz.Free[Function0,String]) => scalaz.Free[Function0,Int => scalaz.Free[Function0,String]]))]
[error]                     cont2 <- prune(cont1)(p, tail)
[error]                                              ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 3 s, completed 06-Apr-2017 08:51:23
coltfred commented 7 years ago

@bmjames I didn't realize this was still being built for 2.10. The fix was simple enough.

bmjames commented 7 years ago

Thanks. It looks good to me; @tpolecat, any comments?

tpolecat commented 7 years ago

@coltfred is there any way to write a test for this change?

coltfred commented 7 years ago

@tpolecat I could write a suite of tests for the doc layout in general, but unless we commit the really big parser and use some kind of timing, I'm not sure how to test that it's efficient enough to handle it.

The reason there are only spec tests is that only scalacheck exists in this repo (no scalatest or specs2) so I just wrote the laws I could and moved on.

tpolecat commented 7 years ago

Ok, if you're confident that this addresses the issue then I'm 👍