This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Scripster - interactive scala REPL using telnet, http or swing

4 replies
Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.

some just-in-time thinking...as I typed i realized I should try the entire
package. sure enough, thise sequence works:

val c = new nsc.interpreter.Completion(p)

val scr = "java.lang.Syste"

c.jline.complete (scr, scr.length-1, l)
c.jline.complete (scr, scr.length-1, l)
println ("options for: \'"+scr+"\' are: " +l)

----------

however, this again prints an empty thing:

val c = new nsc.interpreter.Completion(p)

val scr = "java.lang.Syste"

// c.jline.complete (scr, scr.length-1, l)
c.jline.complete (scr, scr.length-1, l)
println ("options for: \'"+scr+"\' are: " +l)

---------

puzzly puzzle - unless the first one initializes something the second one
likes...

Razvan Cojocaru wrote:
>
> java.util.System should be in the default classpath...
>
> Either way, it should use the current classloader...it's meant to interact
> with the current process, but i can't figure out how to convince it to...
>
>
> Johannes Rudolph-2 wrote:
>>
>> You probably have to initialize the Interpreter with a decent classpath.
>>
>> On Thu, Mar 4, 2010 at 9:27 PM, Razvan Cojocaru wrote:
>>>
>>> I'm kind of stuck with the options...please help!!!
>>>
>>> I got this far by inspecting code - but i keep getting an empty list of
>>> options...
>>>
>>>
>>> package razie.scripster.test
>>> import scala.tools.{nsc => nsc}
>>>
>>> object CompletionTest {
>>>  def main(args : Array[String]) : Unit = {
>>>
>>>    val env = new nsc.Settings
>>>    val p = new nsc.Interpreter (env)
>>>    val l = new java.util.ArrayList[String]()
>>>    val c = new nsc.interpreter.Completion(p)
>>>
>>>    val scr = "System."
>>>
>>>    c.topLevelFor (nsc.interpreter.Parsed(scr))
>>>
>>>    println ("options for: \'"+scr+"\' are: " +l)
>>>  }
>>> }
>>>
>>>
>>>
>>> -----
>>> Razvan Cojocaru,
>>> Work: http://www.sigma-systems.com
>>> Playground: http://wiki.homecloud.ca
>>> Follow me:  http://feeds.razie.com/RazvanTech RSS Feed ,
>>> http://twitter.com/razie Twitter ,  http://github.com/razie GitHub ..
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Scripster---interactive-scala-REPL-using-telnet%2C...
>>> Sent from the Scala - Tools mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>

Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Scripster - interactive scala REPL using telnet, http or s

I settled on this sequence:

class ScalaScriptContext (parent:ScriptContext = null) extends
ScriptContext.Impl (parent) {
var lastError : String = null
val env = new nsc.Settings (err)
val p = new nsc.Interpreter (env)
lazy val c = new nsc.interpreter.Completion(p)

/** content assist options */
override def options (scr:String) : java.util.List[String] = {
val l = new java.util.ArrayList[String]()

c.jline.complete (scr, scr.length-1, l)
l
}

def err (s:String) : Unit = { lastError = s }
}

This produces the options...but is there any way to get just what to append?

java.lang.Syste
--> Selection:
1) System
2) SystemClassLoaderAction
0) - quit selection
java.lang.SysteSystem

Basically it rightly appends "System" after "...Syste".

Do I have to parse the expression myself again, to determine the remainder
to append or is there some method that does this? Either in jline or nsc?

thanks

Razvan Cojocaru wrote:
>
> some just-in-time thinking...as I typed i realized I should try the entire
> package. sure enough, thise sequence works:
>
> val c = new nsc.interpreter.Completion(p)
>
> val scr = "java.lang.Syste"
>
> c.jline.complete (scr, scr.length-1, l)
> c.jline.complete (scr, scr.length-1, l)
> println ("options for: \'"+scr+"\' are: " +l)
>
> ----------
>
> however, this again prints an empty thing:
>
> val c = new nsc.interpreter.Completion(p)
>
> val scr = "java.lang.Syste"
>
> // c.jline.complete (scr, scr.length-1, l)
> c.jline.complete (scr, scr.length-1, l)
> println ("options for: \'"+scr+"\' are: " +l)
>
> ---------
>
> puzzly puzzle - unless the first one initializes something the second one
> likes...
>
>
> Razvan Cojocaru wrote:
>>
>> java.util.System should be in the default classpath...
>>
>> Either way, it should use the current classloader...it's meant to
>> interact with the current process, but i can't figure out how to convince
>> it to...
>>
>>
>> Johannes Rudolph-2 wrote:
>>>
>>> You probably have to initialize the Interpreter with a decent classpath.
>>>
>>> On Thu, Mar 4, 2010 at 9:27 PM, Razvan Cojocaru wrote:
>>>>
>>>> I'm kind of stuck with the options...please help!!!
>>>>
>>>> I got this far by inspecting code - but i keep getting an empty list of
>>>> options...
>>>>
>>>>
>>>> package razie.scripster.test
>>>> import scala.tools.{nsc => nsc}
>>>>
>>>> object CompletionTest {
>>>>  def main(args : Array[String]) : Unit = {
>>>>
>>>>    val env = new nsc.Settings
>>>>    val p = new nsc.Interpreter (env)
>>>>    val l = new java.util.ArrayList[String]()
>>>>    val c = new nsc.interpreter.Completion(p)
>>>>
>>>>    val scr = "System."
>>>>
>>>>    c.topLevelFor (nsc.interpreter.Parsed(scr))
>>>>
>>>>    println ("options for: \'"+scr+"\' are: " +l)
>>>>  }
>>>> }
>>>>
>>>>
>>>>
>>>> -----
>>>> Razvan Cojocaru,
>>>> Work: http://www.sigma-systems.com
>>>> Playground: http://wiki.homecloud.ca
>>>> Follow me:  http://feeds.razie.com/RazvanTech RSS Feed ,
>>>> http://twitter.com/razie Twitter ,  http://github.com/razie GitHub ..
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Scripster---interactive-scala-REPL-using-telnet%2C...
>>>> Sent from the Scala - Tools mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Johannes
>>>
>>> -----------------------------------------------
>>> Johannes Rudolph
>>> http://virtual-void.net
>>>
>>>
>>
>>
>
>

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub ..

Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Scripster - interactive scala REPL using telnet, http or s

Ok...since the kids were all over the piano, the one man orchestra kept
playing the ThinkPad.

After an intense hacking session picking the Interpreter apart, I have
pretty much all I need, for now. The hacked Interpreter is at
http://github.com/razie/scripster/blob/master/src/scala/tools/nsc/Interp...

Paul, I basically needed access to some things from the last Request...and
also, didn't know how to get the error messages, so I hacked the reporter to
collect them.

I dind't figure out how the CompletionAware stuff works, so I wrote a simple
one.

It all works fine now. You can play with the telnet version. TAB starts the
expansion. ^C aborts the current line. Multi-line defs should work fine.

The jar file is here: http://razpub.googlecode.com/files/scripster-dist.jar

the command line is
java -classpath
./dist/scripster-dist.jar:./lib/jline-0_9_5.jar:/host/bin/scala/lib/scala-library.jar:/host/bin/scala/lib/scala-compiler.jar:/host/bin/scala/lib/scala-swing.jar
razie.scripster.JScalapSwing

Here's an example:

~/w/scripster\> telnet localhost 4445
Trying ::1...
Connected to razubuntu.
Escape character is '^]'.
lava
:6: error: not found: value lava
lava
^
java.lang.Syste <--
TAB
--> Selection:
1) System
2) SystemClassLoaderAction
0) - quit selection
java.lang.Syste <-- 2
java.lang.SystemClassLoaderAction
:6: error: object SystemClassLoaderAction cannot be accessed in
package java.lang
java.lang.SystemClassLoaderAction
^

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub ..

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Scripster - interactive scala REPL using telnet, http or sw

Sorry I haven't been able to respond to any of your questions about it,
but I'm sure we'd all like to see 2.8 this lifetime. Still can't look
at it for a while but I'd like to applaud you for persevering.

Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Scripster - interactive scala REPL using telnet, http or sw

OK gents. content assist completed in all 3 versions (swing, html, telnet). I
hacked enough javascript to last me a decade...

See live demo at http://demo.razie.com:4445/scripster/session

Paul - let me know when you have time, I'll prepare a list of demands :)

cheers.

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub ..

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland