-
Notifications
You must be signed in to change notification settings - Fork 100
Adding a language
Create two folders with the following paths (relative to the jsrepl directory):
-
extern/{language_name}
: Holds the language interpreter's code (could be a git submodule). -
langs/{language_name}
: Holds the language engine interface.
A CoffeeScript class that is located in langs/{language_name}
preferably with the
name jsrepl_{language_name}.coffee
functions as an interface for the language engine.
The name of the class must be self.JSREPLEngine
and must implement the following methods:
-
constructor: (input, output, result, error, sandbox, ready) ->
:
This is the engine constructor. Its called when the language is first loaded and should be
responsible for instantiating the interpreter. Called with the following parameters:- (Function)
input
: A function that should be called each time a program being executed
asks for user input. When called it must be passed a continuation function that would
recieve the user input and continues execution. - (Function)
output
: Called with the output from the language. - (Function)
result
: Called with the return value fromeval
. - (Function)
error
: Called with the error output from the engine. - (Object)
sandbox
: Is the sandbox containing the language, could be an iframe window
or a Web Worker. - (Function)
ready
: Called when the language is ready to receive input
- (Function)
-
Eval: (command) ->
:
Called with the a string to be evaled by the language. Any return value must be passed to
the above-mentionedresult
function. -
GetNextLineIndent: (command) ->
:
This function is called just before passing the command to theEval
method to decide
wether the command is ready for evaluation or more lines is intended. Returns:-
false
: Meaning this command should continue its way toEval
. -
(Integer)
: The interpreter should wait for more lines of code before passing them
toEval
. The value of the integer specifies the number of indentation for the next line.
-
See the JavaScript interface.
languages.coffee is a set of language engine configurations used by jsREPL. Every engine must
create an object that encapsulates all its configuration parameters:
@JSREPL::Languages::JavaScript =
name: 'JavaScript'
extension: 'js'
matchings: [
['(', ')']
['[', ']']
['{', '}']
]
scripts: [
'util/inspect.js'
]
includes: []
engine: 'langs/javascript/jsrepl_js.coffee'
worker_friendly: true
minifier: 'closure'
-
name
: The display name of the language. -
extension
: The file extension of the language. -
matchings
: An array of tuples containing a set of characters that could be matched. -
scripts
: An array of scripts paths that is relative to the root jsrepl directory. Could
also be an array of objects which specifies if certain browsers should load different scripts:- key: Browser string identifier.
- value: Script path.
-
includes
: An array of folder paths relative to the root jsrepl directory that specifies
the locations of language library files. -
engine
: The path to the language engine interface. -
worker_friendly
: Boolean specifies whether the language could be loaded in a worker or not. -
minifier
: A string specifying the minifier that should be used when building the project:-
none
: No minifier should be used. -
yui
: Use the YUI compressor. -
uglify
: Use uglifyJS. -
closure
: Use the standard closure compiler. -
closure_es5
: Use the closure compiler with support for ES5. -
closure_advanced
: Use the closure compiler in advanced mode.
-