Guidelines for building eval for another language?

瀏覽次數:714 次
跳到第一則未讀訊息

Marco Munizaga

未讀,
2014年1月16日 凌晨12:17:312014/1/16
收件者:light-table...@googlegroups.com
I'm currently looking at what was done for Python eval, but does anyone have any pointers on what I need to do to get eval working for arbitrary languages?

I'm going to start working on a Matlab/Octave eval, so any tips would be appreciated

Thanks,
Marco

Rafe Rosen

未讀,
2014年1月16日 下午2:37:282014/1/16
收件者:light-table...@googlegroups.com
I've been meaning to do a brain dump of what I learned implementing a ruby evaluator.  Thanks fro giving me an excuse!

Here's a broad overview of the connection and evaluation lifecycle.

1.  Register the connection with the LightTable Runtime (see eval/get-client!)

2.  On startup, your connection should spawn a client process that connects to the local lighttable server, listens for commands, and responds with the results of evaluation results.  Pass it the port to connect to and the client ID so LT knows which of its "connection" objects to match it up to.

3.  When your client starts up and connects, send the server it's client info as a JSON object:

{"name": "process-name", "client-id": 123, "dir":"/path/to/pwd", "commands":["editor.eval.mylanguage"], "type": "mylanguage"}

(make sure client-id is sent as an integer and not a string.  That one cost me a few hours sleep ;)
 
4.  The process that you used to spawn your client also should let lighttable know that it has connected.  The Python plugin does this by printing "Connected" to standard out, and then using a ::connecting-notifier object that listens for that string and marks the connection as connected.

The commands that lighttable will send your client are in json format:

[some-identifier, "command-type", {arguments}]

and the response is similarly formatted:
[some-identifier, "response-type", {arguments}]

Here's an example command and response:

Command From LT:
[68,"editor.eval.ruby",{"line-ending":null,"name":"scratch.rb","type-name":"Ruby",      "path":"/Users/rrosen/projects/usgbc-gbig/tmp/scratch.rb","mime":"text/x-ruby","tags":["editor.ruby"],"code":"foo += 2","meta":{"start":  13,"end":13}}]

Response from Client:
[68,"editor.eval.ruby.result",{"meta":{"end":13,"start":13},"result":3}]

The arguments of interest are "code" on the command side and "result" on the response.  Also "meta" indicates line numbers that LightTable will use to place the result inline in the editor.

Other possible commands include "client.close" for disconnect.  Other responses include "editor.eval.mylang.success" to indicate successful evals with a null result and "editor.eval.mylang.exception" for exceptions.

In your client, you can also redirect stdout and stderr to send the server the "editor.eval.mylang.print" command.  Then register a behavior in lighttable to receive these commands and print them to the console.

Hope this is helpful!  I'll try and get it into a more readable format and post it to the wiki.

~Rafe

Marco Munizaga

未讀,
2014年1月16日 下午4:31:512014/1/16
收件者:light-table...@googlegroups.com
Tons of good stuff, thank you!
回覆所有人
回覆作者
轉寄
0 則新訊息