Think of extending javascript with some little language extensions?
Writing a new / extending an existing compiler gives you a headache?
With OMeta/JS you can do it right in your javascript code:
Extend the Ometa Javascript parser (JSParser implemented in javascript) with a lets say say statement: Here it just does an alert();
Then switch the translator an execute the your new Javascript language right there:
eval(readFile('Compiled_JavaScript_Compiler'))
ometa EJSParser <: JSParser {
isKeyword :x = ?(x == 'say') | super(`isKeyword, x),
stmt = "say" expr:x sc -> ["call", ["get", "alert"], x]
| super("stmt")
}
EJSParser.matchAll("if (true) say 1+1", "stmt")
oldTranslateCode = translateCode
translateCode = function(s) {
var tree = EJSParser.matchAll(s, "topLevel")
var code = JSTranslator.match(tree, "trans")
return code
}
// evaluate the next statement in a different "do-it" than the above
say "hello world"
translateCode = oldTranslateCode
Some said Lively Kernel uses it. Well svg is nice. But why not stay with DOM nodes and be portable...
No comments:
Post a Comment