Skip to content

Commit 37e7522

Browse files
committed
HxParser params update
1 parent 2c54dd7 commit 37e7522

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ RuleScript supports [String Interpolation](https://haxe.org/manual/lf-string-int
5050
var a = 'Hello';
5151
return 'RuleScript: $a World'; // RuleScript: Hello World
5252
```
53+
```haxe
54+
var a = {
55+
a:'RuleScript',
56+
b: () -> 'Hello',
57+
c:'World'
58+
};
59+
60+
return '${a.a}: ${a.b() + " " + a.c}'; // RuleScript: Hello World
61+
```
5362

5463
More templates in `test/src/Main.hx`.
5564
# Limitations
5665

57-
- String interpolations don't support many functions.
66+
- [String interpolations](https://haxe.org/manual/lf-string-interpolation.html) don't support many functions
5867
- Script `using` callback supports max number of arguments is 8.
5968
- [Wildcard imports](https://haxe.org/manual/type-system-import.html#wildcard-import) don't support.
6069

rulescript/HxParser.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class HxParser extends Parser
1515
super();
1616
}
1717

18+
inline public function allowAll():Void
19+
setParams(true, true, true);
20+
21+
public function setParams(?allowJSON:Bool, ?allowMetadata:Bool, ?allowTypes:Bool)
22+
{
23+
parser.allowJSON = allowJSON;
24+
parser.allowMetadata = allowMetadata;
25+
parser.allowTypes = allowTypes;
26+
}
27+
1828
override public function parse(code:String):Expr
1929
{
2030
return parser.parseString(code, 'rulescript:HxParser', 0);

rulescript/RuleScript.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract StringOrExpr(Dynamic) from String to String from Expr to Expr {}
1717
* script = new RuleScript(null,new HxParser());
1818
*
1919
* // Get parser as HxParser
20-
* script.getParser(HxParser).allowJSON = true;
20+
* script.getParser(HxParser).allowAll();
2121
*
2222
* // Run execute inside try-catch
2323
* script.tryExecute('trace("Hello World");'); // Hello World

test/src/Main.hx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class Main
1212
{
1313
script = new RuleScript(null, new HxParser());
1414

15-
var parser = script.getParser(HxParser).parser;
16-
17-
parser.allowJSON = parser.allowMetadata = parser.allowTypes = true;
15+
script.getParser(HxParser).allowAll();
1816

1917
trace('Testing Commands:');
2018

0 commit comments

Comments
 (0)