libseed-list AlgoScript and custom module importer



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.

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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]