Files
hscript-improved/README.md
T
2013-06-07 22:39:10 +02:00

33 lines
1.1 KiB
Markdown

hscript
=======
Parse and evalutate Haxe expressions.
Usage :
<pre>
var expr = "var x = 4; 1 + 2 * x";
var parser = new hscript.Parser();
var ast = parser.parseString(expr);
var interp = new hscript.Interp();
trace(interp.execute(ast));
</pre>
In case of parse error an `hscript.Expr.Error` is throwed. You can use `parser.line` to know the line number.
You can set some globaly accessible identifiers by using `interp.variables.set("name",value)`
Advanced Usage
--------------
When compiled with `-D hscriptPos` you will get fine error reporting at parsing time.
You can subclass `hscript.Interp` to override behaviors for `get`, `set`, `call`, `fcall` and `cnew` behaviors.
You can add more binary and unary operations to the parser by setting `opPriority`, `opRightAssoc` and `unops` content.
You can use `parser.allowJSON` to allow JSON data.
You can use `parser.allowTypes` to parse types for local vars, exceptions, function args and return types. Types are ignored by the interpreter.
You can use `new hscript.Macro(pos).convert(ast)` to convert an hscript AST to a Haxe macros one.