Re: libseed-list AlgoScript and custom module importer
- From: Jonatan Liljedahl <lijon kymatica com>
- To: Seed - Gnome Javascript <libseed-list gnome org>
- Subject: Re: libseed-list AlgoScript and custom module importer
- Date: Fri, 11 Jun 2010 00:09:53 +0200
Robert Carr wrote:
On Thu, Jun 10, 2010 at 11:35 AM, Jonatan Liljedahl <lijon kymatica com> wrote:
I'm working on a parser for "AlgoScript", which compiles to javascript and
has some nice syntactic sugar and hides some of javascripts uglyness.
Example:
[0..10].do {x -> print x}
=>
(Array.range(0,10)).forEach(function(x){return(print(x));})
I have an algoscript.parse() function that parses algoscript and returns a
string of javascript.
This sounds cool! I sort of wanted to do this with coffeescript and Seed once.
I used the JS/CC with some minor modifications to support Seed, since
jison (used by coffeescript) had a lot of other js dependencies.
Now I have an imports.algoscript.Context class that works the same as
the sandbox, and uses the sandbox to run algoscripts in contained area.
It was very useful, since I can load my algoscript runtime library (some
prototype extensions) in this context instead of polluting the global
namespace.
I will put everything up on the net as soon as it's finished, would be
great to get some feedback!
One thing I'm thinking about is how I should solve module imports.. Surely I
could have an import(name) function, but it would be a bit ugly to have this
AND imports.gi.name for the gobject stuff.
The best thing would be if imports.name could check the file extension and
run it through my parser if it ends with '.as' or something like that. Any
ideas how this could be achieved? Maybe the seed importer could have hooks
that is called for files not ending with '.js'?
algoscript_importer = function(filename,str) {
return eval(algoscript.parse(str));
}
imports.unknownFileCallback = algoscript_importer;
Or it could just pass the filename and not the contents, or it could have a
table of callbacks for each suffix:
imports.customImporterCallback['as'] = algoscript_importer;
What do you think? I imagine that this could be very useful for other stuff
as well..
I would be happy to try and add support for this if you want.
/Jonatan
I'm a little hesitant with the file extension, but maybe some sort of
line to parse in the shebang? I can actually probably give a pass at
this in a few days, I'm getting ready to do a biggggg rework of Seed.
Actually, I don't really see the reason to ignore the file extension.
Strange things happen if you have foo.js, foo.txt, foo.html etc in the
module search path at the same time, this has bit me a couple of times.
Why would you name a javascript module to anything else than .js?
I would argue that parsing shebang would be more hackish (in a negative
sense ;) than to look at the filename extension.
What rework are you planning? Sounds interesting!
/Jonatan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]