Language::Expr::Compiler::JS
version 0.06
Compiles Language::Expr expression to JS code. Some notes:
JavaScript version
This compiler emits JavaScript 1.8.1 code (it uses several Array methods like map() and filter() [supported since JavaScript 1.6], 'let' lexical variables [supported since JavaScript 1.7 / Firefox 2] and native JSON [supported since JavaScript 1.8.1 / Firefox 3.5]).
Currently to test emitted JavaScript code, we use Spidermonkey 1.9.1+ JavaScript interpreter (typically located in /usr/bin/js) as the JavaScript and JE modules are still not up to par.
JavaScript-ness
The emitted JS code will follow JavaScript's weak typing and coercion rules, e.g. Expr '1+"2"' will simply be translated to JavaScript '1+"2"' and will result in "12".
Currently strings are rudimentary escaped.
Data dumping modules can't be used currently due to segfaults (at least in 5.10.1).
Variables by default simply use JavaScript variables.
E.g. $a becomes a, and so on. Be careful not to make variables which are invalid in JavaScript, e.g. $.. or ${foo/bar}.
You can subclass and override rule_var() if you want to provide your own variables.
Functions by default simply use Javascript functions.
foo() becomes foo(). Except those mentioned in func_mapping (e.g. rand() becomes Math.rand() if func_mapping->{rand} is 'Math.rand').
Or you can subclass and override rule_func() for more translation freedom.
Used to remember which subexpression need to be parsed later.
Mapping from Expr function to JavaScript functions/methods. Example:
{ ceil => 'Math.ceil', uc => '.toUpperCase', }
Convert Language::Expr expression into JavaScript code. Dies if there is syntax error in expression.
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2010 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Language::Expr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Language::Expr
CPAN shell
perl -MCPAN -e shell install Language::Expr
For more information on module installation, please visit the detailed CPAN module installation guide.