|
@@ -7,10 +7,10 @@ import lua.lib.lpeg.Pattern.PatternMetatable as M;
|
|
|
|
|
|
@:luaRequire("lpeg")
|
|
|
extern class PatternMetatable {
|
|
|
- static public function __add(p1:Pattern, p2:AbstractPattern) : AbstractPattern;
|
|
|
- static public function __mul(p1:Pattern, n:Int) : AbstractPattern;
|
|
|
- static public function __pow(p1:Pattern, n:Int) : AbstractPattern;
|
|
|
- static public function __div(p1:Pattern, n:Dynamic) : AbstractPattern;
|
|
|
+ static public function __add(v1:Dynamic, v2:Dynamic) : AbstractPattern;
|
|
|
+ static public function __mul(v1:Dynamic, v2:Dynamic) : AbstractPattern;
|
|
|
+ static public function __pow(v1:Dynamic, v2:Dynamic) : AbstractPattern;
|
|
|
+ static public function __div(v1:Dynamic, v2:Dynamic) : AbstractPattern;
|
|
|
static inline function __init__() : Void {
|
|
|
untyped PatternMetatable = __lua__("getmetatable(require('lpeg').P(1))");
|
|
|
}
|
|
@@ -20,13 +20,22 @@ extern class PatternMetatable {
|
|
|
@:forward(match)
|
|
|
abstract AbstractPattern(Pattern){
|
|
|
@:op(A + B)
|
|
|
- public inline function add(p:AbstractPattern) : AbstractPattern return M.__add(this, p);
|
|
|
+ public static inline function add(p1:AbstractPattern, p2 : AbstractPattern) : AbstractPattern return M.__mul(p1, p2);
|
|
|
+
|
|
|
+ @:op(A + B)
|
|
|
+ public static inline function addString(p : AbstractPattern, str:String) : AbstractPattern return M.__mul(p, str);
|
|
|
+
|
|
|
+ @:op(A + B)
|
|
|
+ public static inline function addStringPre(str : String, p : AbstractPattern) : AbstractPattern return M.__mul(str, p);
|
|
|
+
|
|
|
+ // @:op(A | B)
|
|
|
+ // public inline function or(p:AbstractPattern) : AbstractPattern return M.__add(this, p);
|
|
|
|
|
|
@:op(A * B)
|
|
|
- public inline function mul(n:Int) : AbstractPattern return M.__pow(this, n);
|
|
|
+ public static inline function mul(p: AbstractPattern, n:Int) : AbstractPattern return M.__pow(p, n);
|
|
|
|
|
|
- @:op(A / B)
|
|
|
- public inline function divf(f:Function) : AbstractPattern return M.__div(this, f);
|
|
|
+ @:op(A >> B)
|
|
|
+ public static inline function divf(p : AbstractPattern, f:Function) : AbstractPattern return M.__div(p, f);
|
|
|
|
|
|
public inline function len() : AbstractPattern { return untyped __lua_length__(this);}
|
|
|
}
|
|
@@ -53,6 +62,7 @@ extern class Pattern {
|
|
|
Unlike typical pattern-matching functions, match works only in anchored mode; that is, it tries to match the pattern with a prefix of the given subject string (at position init), not with an arbitrary substring of the subject. So, if we want to find a pattern anywhere in a string, we must either write a loop in Lua or write a pattern that matches anywhere. This second approach is easy and quite efficient;
|
|
|
**/
|
|
|
public static function R(args:Rest<String>) : AbstractPattern;
|
|
|
+ public static function Cf(p:AbstractPattern, f : Function) : AbstractPattern;
|
|
|
public function match(subject:String, ?init:Int) : Int;
|
|
|
public function __add(p2:AbstractPattern) : AbstractPattern;
|
|
|
public function __mul(n:Int) : AbstractPattern;
|