simplified parser
This commit is contained in:
parent
bc6ea7c39c
commit
2ba75d2caf
11 changed files with 917 additions and 1104 deletions
3
.vimrc
3
.vimrc
|
|
@ -1 +1,2 @@
|
|||
noremap <silent> <F5> :!./make && ./make runtest \| less<CR>
|
||||
noremap <silent> <F10> :!./make && echo OK && ./make tests<CR>
|
||||
noremap <silent> <F11> :!./make tests \| less<CR>
|
||||
|
|
|
|||
243
dist/xrfragment.js
vendored
243
dist/xrfragment.js
vendored
|
|
@ -20,6 +20,13 @@ EReg.prototype = {
|
|||
}
|
||||
};
|
||||
var HxOverrides = function() { };
|
||||
HxOverrides.cca = function(s,index) {
|
||||
var x = s.charCodeAt(index);
|
||||
if(x != x) {
|
||||
return undefined;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
HxOverrides.substr = function(s,pos,len) {
|
||||
if(len == null) {
|
||||
len = s.length;
|
||||
|
|
@ -76,6 +83,41 @@ Std.parseInt = function(x) {
|
|||
}
|
||||
return null;
|
||||
};
|
||||
var StringTools = function() { };
|
||||
StringTools.isSpace = function(s,pos) {
|
||||
var c = HxOverrides.cca(s,pos);
|
||||
if(!(c > 8 && c < 14)) {
|
||||
return c == 32;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
StringTools.ltrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,r)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,r,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.rtrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,0,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.trim = function(s) {
|
||||
return StringTools.ltrim(StringTools.rtrim(s));
|
||||
};
|
||||
StringTools.replace = function(s,sub,by) {
|
||||
return s.split(sub).join(by);
|
||||
};
|
||||
var haxe_iterators_ArrayIterator = function(array) {
|
||||
this.current = 0;
|
||||
this.array = array;
|
||||
|
|
@ -89,195 +131,130 @@ haxe_iterators_ArrayIterator.prototype = {
|
|||
}
|
||||
};
|
||||
var xrfragment_Query = function(str) {
|
||||
this.preset = "";
|
||||
this.accept = false;
|
||||
this.exclude = [];
|
||||
this.include = [];
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
if(str != null) {
|
||||
this.parse(str);
|
||||
}
|
||||
};
|
||||
xrfragment_Query.prototype = {
|
||||
selected: function(nodename) {
|
||||
if(this.q.copy_all) {
|
||||
this.accept = true;
|
||||
expandAliases: function(token) {
|
||||
var classAlias = new EReg("^(-)?\\.","");
|
||||
if(classAlias.match(token)) {
|
||||
return StringTools.replace(token,".","class:");
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
if(this.include.indexOf(nodename) != -1) {
|
||||
this.accept = true;
|
||||
}
|
||||
if(this.exclude.indexOf(nodename) != -1) {
|
||||
this.accept = false;
|
||||
}
|
||||
return this.accept;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
var _gthis = this;
|
||||
var copyAll = recurse ? this.q.copy_all : HxOverrides.substr(str,0,1) == "-" || HxOverrides.substr(str,0,1) == "?" || str == "";
|
||||
var isOr = new EReg("^or$","");
|
||||
var isProp = new EReg(".*:[><=!]?","");
|
||||
var isName = new EReg("[^:/]","");
|
||||
var isExclude = new EReg("^-","");
|
||||
var isInclude = new EReg("^\\+","");
|
||||
var isPreset = new EReg("^\\?","");
|
||||
var token = str.split(" ");
|
||||
var ors = [];
|
||||
var q = { };
|
||||
var composeQuery = function() {
|
||||
q = { };
|
||||
var value = [];
|
||||
q["object"] = value;
|
||||
var value = [];
|
||||
q["-object"] = value;
|
||||
ors.push(q);
|
||||
return q;
|
||||
};
|
||||
composeQuery();
|
||||
var match = null;
|
||||
match = function(str,prefix) {
|
||||
var process = function(str,prefix) {
|
||||
if(prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
if(isPreset.match(str) && !recurse) {
|
||||
_gthis.preset = str;
|
||||
return;
|
||||
}
|
||||
if(isExclude.match(str) || isInclude.match(str)) {
|
||||
var t = HxOverrides.substr(str,1,null);
|
||||
match(t,HxOverrides.substr(str,0,1));
|
||||
return;
|
||||
}
|
||||
if(isProp.match(str)) {
|
||||
var skip = 0;
|
||||
var type = "=";
|
||||
str = StringTools.trim(str);
|
||||
var value = { };
|
||||
if(_gthis.isProp.match(str)) {
|
||||
var oper = "";
|
||||
if(str.indexOf("*") != -1) {
|
||||
type = "*";
|
||||
oper = "*";
|
||||
}
|
||||
if(str.indexOf(">") != -1) {
|
||||
type = ">";
|
||||
oper = ">";
|
||||
}
|
||||
if(str.indexOf("<") != -1) {
|
||||
type = "<";
|
||||
oper = "<";
|
||||
}
|
||||
if(str.indexOf("!=") != -1) {
|
||||
type = "!=";
|
||||
oper = "!=";
|
||||
}
|
||||
if(str.indexOf(">=") != -1) {
|
||||
type = ">=";
|
||||
oper = ">=";
|
||||
}
|
||||
if(str.indexOf("<=") != -1) {
|
||||
type = "<=";
|
||||
oper = "<=";
|
||||
}
|
||||
if(type != "=") {
|
||||
skip += type.length;
|
||||
var k = str.split(":")[0];
|
||||
var v = str.split(":")[1];
|
||||
if(q[prefix + k]) {
|
||||
value = q[prefix + k];
|
||||
}
|
||||
var property = str.split(":")[0];
|
||||
var value;
|
||||
if(q[prefix + property]) {
|
||||
value = q[prefix + property];
|
||||
if(oper.length > 0) {
|
||||
value[oper] = parseFloat(HxOverrides.substr(v,oper.length,null));
|
||||
q[k] = value;
|
||||
} else {
|
||||
value = { };
|
||||
}
|
||||
value[type] = HxOverrides.substr(str.split(":")[1],skip,null);
|
||||
q[prefix + property] = value;
|
||||
return;
|
||||
}
|
||||
if(isName.match(str)) {
|
||||
if(prefix == "-") {
|
||||
q["-object"].push(str);
|
||||
while(q["object"].contains(str) == true) q["object"].remove(str);
|
||||
} else {
|
||||
q["object"].push(str);
|
||||
while(q["-object"].contains(str) == true) q["-object"].remove(str);
|
||||
value[prefix + (_gthis.isExclude.match(k) ? HxOverrides.substr(k,1,null) : k)] = _gthis.isExclude.match(k) == false;
|
||||
q[v] = value;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
value["id"] = _gthis.isExclude.match(str) ? false : true;
|
||||
var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str;
|
||||
q[key] = value;
|
||||
}
|
||||
};
|
||||
var _g = 0;
|
||||
var _g1 = token.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
if(isOr.match(token[i])) {
|
||||
composeQuery();
|
||||
} else {
|
||||
match(token[i]);
|
||||
process(this.expandAliases(token[i]));
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = ors.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var or = ors[i];
|
||||
if(Reflect.field(or,"object") != null) {
|
||||
this.include = this.include.concat(Reflect.field(or,"object"));
|
||||
}
|
||||
if(Reflect.field(or,"-object") != null) {
|
||||
this.exclude = this.exclude.concat(Reflect.field(or,"-object"));
|
||||
}
|
||||
}
|
||||
this.q = { or : ors, copy_all : copyAll};
|
||||
this.q = q;
|
||||
return this.q;
|
||||
}
|
||||
,test: function(property,value) {
|
||||
if(this.preset == property) {
|
||||
this.parse(value,true);
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = this.q.or.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var or = this.q.or[i];
|
||||
var conds = [0];
|
||||
var fails = [0];
|
||||
var pass = 0;
|
||||
var when = (function(fails,conds) {
|
||||
return function(expr) {
|
||||
conds[0] += 1;
|
||||
fails[0] += expr ? 0 : 1;
|
||||
var conds = 0;
|
||||
var fails = 0;
|
||||
var qualify = 0;
|
||||
var testprop = function(expr) {
|
||||
conds += 1;
|
||||
fails += expr ? 0 : 1;
|
||||
return expr;
|
||||
};
|
||||
})(fails,conds);
|
||||
var _g2 = 0;
|
||||
var _g3 = Reflect.fields(or);
|
||||
while(_g2 < _g3.length) {
|
||||
var k = _g3[_g2];
|
||||
++_g2;
|
||||
var orval = Reflect.field(or,k);
|
||||
if(k != property) {
|
||||
if(this.q[value] != null) {
|
||||
var v = this.q[value];
|
||||
if(v[property] != null) {
|
||||
return v[property];
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(this.q);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var qval = Reflect.field(this.q,k);
|
||||
if(typeof(value) == "string") {
|
||||
continue;
|
||||
}
|
||||
if(Reflect.field(orval,"=") != null && when(value == Reflect.field(orval,"="))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"=") != null && testprop(value == Reflect.field(qval,"="))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"*") != null && when(value != null)) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"*") != null && testprop(value != null)) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,">") != null && when(value > Std.parseInt(Reflect.field(orval,">")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,">") != null && testprop(value > parseFloat(Reflect.field(qval,">")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"<") != null && when(value < Std.parseInt(Reflect.field(orval,"<")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"<") != null && testprop(value < parseFloat(Reflect.field(qval,"<")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,">=") != null && when(value >= Std.parseInt(Reflect.field(orval,">=")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,">=") != null && testprop(value >= parseFloat(Reflect.field(qval,">=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"<=") != null && when(value >= Std.parseInt(Reflect.field(orval,"<=")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"<=") != null && testprop(value >= parseFloat(Reflect.field(qval,"<=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"!=") != null && when(value != Std.parseInt(Reflect.field(orval,"!=")))) {
|
||||
++pass;
|
||||
}
|
||||
}
|
||||
if(this.accept && conds[0] > 0 && fails[0] > 0) {
|
||||
this.accept = false;
|
||||
}
|
||||
if(conds[0] > 0 && pass > 0 && fails[0] == 0) {
|
||||
this.accept = true;
|
||||
if(Reflect.field(qval,"!=") != null && testprop(value != parseFloat(Reflect.field(qval,"!=")))) {
|
||||
++qualify;
|
||||
}
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
};
|
||||
var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() {
|
||||
|
|
|
|||
516
dist/xrfragment.lua
vendored
516
dist/xrfragment.lua
vendored
|
|
@ -204,6 +204,7 @@ local Math = _hx_e()
|
|||
local Reflect = _hx_e()
|
||||
local String = _hx_e()
|
||||
local Std = _hx_e()
|
||||
local StringTools = _hx_e()
|
||||
__haxe_Exception = _hx_e()
|
||||
__haxe_NativeStackTrace = _hx_e()
|
||||
__haxe_ValueException = _hx_e()
|
||||
|
|
@ -832,55 +833,156 @@ Std.int = function(x)
|
|||
do return _hx_bit_clamp(x) end;
|
||||
end;
|
||||
end
|
||||
Std.parseInt = function(x)
|
||||
if (x == nil) then
|
||||
do return nil end;
|
||||
Std.parseFloat = function(x)
|
||||
if ((x == nil) or (x == "")) then
|
||||
do return (0/0) end;
|
||||
end;
|
||||
local hexMatch = _G.string.match(x, "^[ \t\r\n]*([%-+]*0[xX][%da-fA-F]*)");
|
||||
if (hexMatch ~= nil) then
|
||||
local sign;
|
||||
local _g = __lua_lib_luautf8_Utf8.byte(hexMatch, 1);
|
||||
if (_g) == 43 then
|
||||
sign = 1;
|
||||
elseif (_g) == 45 then
|
||||
sign = -1;else
|
||||
sign = 0; end;
|
||||
local pos = (function()
|
||||
local _hx_1
|
||||
if (sign == 0) then
|
||||
_hx_1 = 2; else
|
||||
_hx_1 = 3; end
|
||||
return _hx_1
|
||||
end )();
|
||||
local digitMatch = _G.string.match(x, "^ *[%.%-+]?[0-9]%d*");
|
||||
if (digitMatch == nil) then
|
||||
do return (0/0) end;
|
||||
end;
|
||||
local pos = __lua_lib_luautf8_Utf8.len(digitMatch);
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(hexMatch)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(hexMatch);
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(x)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(x);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(hexMatch) + len;
|
||||
len = __lua_lib_luautf8_Utf8.len(x) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(hexMatch) + pos;
|
||||
pos = __lua_lib_luautf8_Utf8.len(x) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
do return (function()
|
||||
local _hx_2
|
||||
if (sign == -1) then
|
||||
_hx_2 = -1; else
|
||||
_hx_2 = 1; end
|
||||
return _hx_2
|
||||
end )() * _G.tonumber(__lua_lib_luautf8_Utf8.sub(hexMatch, pos + 1, pos + len), 16) end;
|
||||
x = __lua_lib_luautf8_Utf8.sub(x, pos + 1, pos + len);
|
||||
local decimalMatch = _G.string.match(x, "^%.%d*");
|
||||
if (decimalMatch == nil) then
|
||||
decimalMatch = "";
|
||||
end;
|
||||
local pos = __lua_lib_luautf8_Utf8.len(decimalMatch);
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(x)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(x);
|
||||
else
|
||||
local intMatch = _G.string.match(x, "^ *[%-+]?%d*");
|
||||
if (intMatch ~= nil) then
|
||||
do return _G.tonumber(intMatch) end;
|
||||
else
|
||||
do return nil end;
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(x) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(x) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
x = __lua_lib_luautf8_Utf8.sub(x, pos + 1, pos + len);
|
||||
local eMatch = _G.string.match(x, "^[eE][+%-]?%d+");
|
||||
if (eMatch == nil) then
|
||||
eMatch = "";
|
||||
end;
|
||||
local result = _G.tonumber(Std.string(Std.string(digitMatch) .. Std.string(decimalMatch)) .. Std.string(eMatch));
|
||||
if (result ~= nil) then
|
||||
do return result end;
|
||||
else
|
||||
do return (0/0) end;
|
||||
end;
|
||||
end
|
||||
|
||||
StringTools.new = {}
|
||||
StringTools.__name__ = true
|
||||
StringTools.isSpace = function(s,pos)
|
||||
if (((__lua_lib_luautf8_Utf8.len(s) == 0) or (pos < 0)) or (pos >= __lua_lib_luautf8_Utf8.len(s))) then
|
||||
do return false end;
|
||||
end;
|
||||
local c = __lua_lib_luautf8_Utf8.byte(s, pos + 1);
|
||||
if (not ((c > 8) and (c < 14))) then
|
||||
do return c == 32 end;
|
||||
else
|
||||
do return true end;
|
||||
end;
|
||||
end
|
||||
StringTools.ltrim = function(s)
|
||||
local l = __lua_lib_luautf8_Utf8.len(s);
|
||||
local r = 0;
|
||||
while ((r < l) and StringTools.isSpace(s, r)) do
|
||||
r = r + 1;
|
||||
end;
|
||||
if (r > 0) then
|
||||
local pos = r;
|
||||
local len = l - r;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(s)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(s);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(s) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(s) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
do return __lua_lib_luautf8_Utf8.sub(s, pos + 1, pos + len) end;
|
||||
else
|
||||
do return s end;
|
||||
end;
|
||||
end
|
||||
StringTools.rtrim = function(s)
|
||||
local l = __lua_lib_luautf8_Utf8.len(s);
|
||||
local r = 0;
|
||||
while ((r < l) and StringTools.isSpace(s, (l - r) - 1)) do
|
||||
r = r + 1;
|
||||
end;
|
||||
if (r > 0) then
|
||||
local pos = 0;
|
||||
local len = l - r;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(s)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(s);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(s) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(s) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
do return __lua_lib_luautf8_Utf8.sub(s, pos + 1, pos + len) end;
|
||||
else
|
||||
do return s end;
|
||||
end;
|
||||
end
|
||||
StringTools.trim = function(s)
|
||||
do return StringTools.ltrim(StringTools.rtrim(s)) end;
|
||||
end
|
||||
StringTools.replace = function(s,sub,by)
|
||||
local idx = 1;
|
||||
local ret = _hx_tab_array({}, 0);
|
||||
while (idx ~= nil) do
|
||||
local newidx = 0;
|
||||
if (__lua_lib_luautf8_Utf8.len(sub) > 0) then
|
||||
newidx = __lua_lib_luautf8_Utf8.find(s, sub, idx, true);
|
||||
else
|
||||
if (idx >= __lua_lib_luautf8_Utf8.len(s)) then
|
||||
newidx = nil;
|
||||
else
|
||||
newidx = idx + 1;
|
||||
end;
|
||||
end;
|
||||
if (newidx ~= nil) then
|
||||
local match = __lua_lib_luautf8_Utf8.sub(s, idx, newidx - 1);
|
||||
ret:push(match);
|
||||
idx = newidx + __lua_lib_luautf8_Utf8.len(sub);
|
||||
else
|
||||
ret:push(__lua_lib_luautf8_Utf8.sub(s, idx, __lua_lib_luautf8_Utf8.len(s)));
|
||||
idx = nil;
|
||||
end;
|
||||
end;
|
||||
do return ret:join(by) end;
|
||||
end
|
||||
|
||||
__haxe_Exception.new = function(message,previous,native)
|
||||
|
|
@ -1132,10 +1234,8 @@ __xrfragment_Query.new = function(str)
|
|||
return self
|
||||
end
|
||||
__xrfragment_Query.super = function(self,str)
|
||||
self.preset = "";
|
||||
self.accept = false;
|
||||
self.exclude = Array.new();
|
||||
self.include = Array.new();
|
||||
self.isExclude = EReg.new("^-", "");
|
||||
self.isProp = EReg.new("^.*:[><=!]?", "");
|
||||
self.q = _hx_e();
|
||||
self.str = "";
|
||||
if (str ~= nil) then
|
||||
|
|
@ -1148,71 +1248,19 @@ __xrfragment_Query.prototype = _hx_e();
|
|||
__xrfragment_Query.prototype.toObject = function(self)
|
||||
do return self.q end
|
||||
end
|
||||
__xrfragment_Query.prototype.selected = function(self,nodename)
|
||||
if (self.q.copy_all) then
|
||||
self.accept = true;
|
||||
__xrfragment_Query.prototype.expandAliases = function(self,token)
|
||||
local classAlias = EReg.new("^(-)?\\.", "");
|
||||
if (classAlias:match(token)) then
|
||||
do return StringTools.replace(token, ".", "class:") end;
|
||||
else
|
||||
do return token end;
|
||||
end;
|
||||
if (self.include:contains(nodename)) then
|
||||
self.accept = true;
|
||||
end;
|
||||
if (self.exclude:contains(nodename)) then
|
||||
self.accept = false;
|
||||
end;
|
||||
do return self.accept end
|
||||
end
|
||||
__xrfragment_Query.prototype.parse = function(self,str,recurse)
|
||||
if (recurse == nil) then
|
||||
recurse = false;
|
||||
end;
|
||||
local _gthis = self;
|
||||
local copyAll;
|
||||
if (recurse) then
|
||||
copyAll = self.q.copy_all;
|
||||
else
|
||||
local copyAll1;
|
||||
local pos = 0;
|
||||
local len = 1;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(str)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(str) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
if (__lua_lib_luautf8_Utf8.sub(str, pos + 1, pos + len) ~= "-") then
|
||||
local pos = 0;
|
||||
local len = 1;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(str)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(str) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
copyAll1 = __lua_lib_luautf8_Utf8.sub(str, pos + 1, pos + len) == "?";
|
||||
else
|
||||
copyAll1 = true;
|
||||
end;
|
||||
copyAll = copyAll1 or (str == "");
|
||||
end;
|
||||
local isOr = EReg.new("^or$", "");
|
||||
local isProp = EReg.new(".*:[><=!]?", "");
|
||||
local isName = EReg.new("[^:/]", "");
|
||||
local isExclude = EReg.new("^-", "");
|
||||
local isInclude = EReg.new("^\\+", "");
|
||||
local isPreset = EReg.new("^\\?", "");
|
||||
local idx = 1;
|
||||
local ret = _hx_tab_array({}, 0);
|
||||
while (idx ~= nil) do
|
||||
|
|
@ -1236,65 +1284,15 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
end;
|
||||
end;
|
||||
local token = ret;
|
||||
local ors = Array.new();
|
||||
local q = _hx_e();
|
||||
local composeQuery = function()
|
||||
q = _hx_e();
|
||||
local value = Array.new();
|
||||
q.object = value;
|
||||
local value = Array.new();
|
||||
q["-object"] = value;
|
||||
ors:push(q);
|
||||
do return q end;
|
||||
end;
|
||||
composeQuery();
|
||||
local match = nil;
|
||||
match = function(str,prefix)
|
||||
local process = function(str,prefix)
|
||||
if (prefix == nil) then
|
||||
prefix = "";
|
||||
end;
|
||||
if (isPreset:match(str) and not recurse) then
|
||||
_gthis.preset = str;
|
||||
do return end;
|
||||
end;
|
||||
if (isExclude:match(str) or isInclude:match(str)) then
|
||||
local pos = 1;
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(str)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(str) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
local t = __lua_lib_luautf8_Utf8.sub(str, pos + 1, pos + len);
|
||||
local pos = 0;
|
||||
local len = 1;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(str)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(str) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
match(t, __lua_lib_luautf8_Utf8.sub(str, pos + 1, pos + len));
|
||||
do return end;
|
||||
end;
|
||||
if (isProp:match(str)) then
|
||||
local skip = 0;
|
||||
local type = "=";
|
||||
str = StringTools.trim(str);
|
||||
local value = _hx_e();
|
||||
if (_gthis.isProp:match(str)) then
|
||||
local oper = "";
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
startIndex = 1;
|
||||
|
|
@ -1309,7 +1307,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_1 = -1; end
|
||||
return _hx_1
|
||||
end )() ~= -1) then
|
||||
type = "*";
|
||||
oper = "*";
|
||||
end;
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
|
|
@ -1325,7 +1323,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_2 = -1; end
|
||||
return _hx_2
|
||||
end )() ~= -1) then
|
||||
type = ">";
|
||||
oper = ">";
|
||||
end;
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
|
|
@ -1341,7 +1339,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_3 = -1; end
|
||||
return _hx_3
|
||||
end )() ~= -1) then
|
||||
type = "<";
|
||||
oper = "<";
|
||||
end;
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
|
|
@ -1357,7 +1355,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_4 = -1; end
|
||||
return _hx_4
|
||||
end )() ~= -1) then
|
||||
type = "!=";
|
||||
oper = "!=";
|
||||
end;
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
|
|
@ -1373,7 +1371,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_5 = -1; end
|
||||
return _hx_5
|
||||
end )() ~= -1) then
|
||||
type = ">=";
|
||||
oper = ">=";
|
||||
end;
|
||||
local startIndex = nil;
|
||||
if (startIndex == nil) then
|
||||
|
|
@ -1389,10 +1387,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
_hx_6 = -1; end
|
||||
return _hx_6
|
||||
end )() ~= -1) then
|
||||
type = "<=";
|
||||
end;
|
||||
if (type ~= "=") then
|
||||
skip = skip + __lua_lib_luautf8_Utf8.len(type);
|
||||
oper = "<=";
|
||||
end;
|
||||
local idx = 1;
|
||||
local ret = _hx_tab_array({}, 0);
|
||||
|
|
@ -1416,13 +1411,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
idx = nil;
|
||||
end;
|
||||
end;
|
||||
local property = ret[0];
|
||||
local value;
|
||||
if (Reflect.field(q, Std.string(prefix) .. Std.string(property))) then
|
||||
value = Reflect.field(q, Std.string(prefix) .. Std.string(property));
|
||||
else
|
||||
value = _hx_e();
|
||||
end;
|
||||
local k = ret[0];
|
||||
local idx = 1;
|
||||
local ret = _hx_tab_array({}, 0);
|
||||
while (idx ~= nil) do
|
||||
|
|
@ -1445,40 +1434,87 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
idx = nil;
|
||||
end;
|
||||
end;
|
||||
local _this = ret[1];
|
||||
local pos = skip;
|
||||
local v = ret[1];
|
||||
if (Reflect.field(q, Std.string(prefix) .. Std.string(k))) then
|
||||
value = Reflect.field(q, Std.string(prefix) .. Std.string(k));
|
||||
end;
|
||||
if (__lua_lib_luautf8_Utf8.len(oper) > 0) then
|
||||
local pos = __lua_lib_luautf8_Utf8.len(oper);
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(_this)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(_this);
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(v)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(v);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(_this) + len;
|
||||
len = __lua_lib_luautf8_Utf8.len(v) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(_this) + pos;
|
||||
pos = __lua_lib_luautf8_Utf8.len(v) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
local value1 = __lua_lib_luautf8_Utf8.sub(_this, pos + 1, pos + len);
|
||||
value[type] = value1;
|
||||
q[Std.string(prefix) .. Std.string(property)] = value;
|
||||
do return end;
|
||||
end;
|
||||
if (isName:match(str)) then
|
||||
if (prefix == "-") then
|
||||
Reflect.field(q, "-object"):push(str);
|
||||
while (Reflect.field(q, "object"):contains(str) == true) do
|
||||
Reflect.field(q, "object"):remove(str);
|
||||
end;
|
||||
local value1 = Std.parseFloat(__lua_lib_luautf8_Utf8.sub(v, pos + 1, pos + len));
|
||||
value[oper] = value1;
|
||||
q[k] = value;
|
||||
else
|
||||
Reflect.field(q, "object"):push(str);
|
||||
while (Reflect.field(q, "-object"):contains(str) == true) do
|
||||
Reflect.field(q, "-object"):remove(str);
|
||||
local key;
|
||||
if (_gthis.isExclude:match(k)) then
|
||||
local pos = 1;
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(k)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(k);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(k) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(k) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
key = __lua_lib_luautf8_Utf8.sub(k, pos + 1, pos + len);
|
||||
else
|
||||
key = k;
|
||||
end;
|
||||
local value1 = _gthis.isExclude:match(k) == false;
|
||||
value[Std.string(prefix) .. Std.string(key)] = value1;
|
||||
q[v] = value;
|
||||
end;
|
||||
do return end;
|
||||
else
|
||||
local value1 = (function()
|
||||
local _hx_7
|
||||
if (_gthis.isExclude:match(str)) then
|
||||
_hx_7 = false; else
|
||||
_hx_7 = true; end
|
||||
return _hx_7
|
||||
end )();
|
||||
value.id = value1;
|
||||
local key;
|
||||
if (_gthis.isExclude:match(str)) then
|
||||
local pos = 1;
|
||||
local len = nil;
|
||||
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(str)))) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str);
|
||||
else
|
||||
if (len < 0) then
|
||||
len = __lua_lib_luautf8_Utf8.len(str) + len;
|
||||
end;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = __lua_lib_luautf8_Utf8.len(str) + pos;
|
||||
end;
|
||||
if (pos < 0) then
|
||||
pos = 0;
|
||||
end;
|
||||
key = __lua_lib_luautf8_Utf8.sub(str, pos + 1, pos + len);
|
||||
else
|
||||
key = str;
|
||||
end;
|
||||
q[key] = value;
|
||||
end;
|
||||
end;
|
||||
local _g = 0;
|
||||
|
|
@ -1486,49 +1522,18 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
|
|||
while (_g < _g1) do
|
||||
_g = _g + 1;
|
||||
local i = _g - 1;
|
||||
if (isOr:match(token[i])) then
|
||||
composeQuery();
|
||||
else
|
||||
match(token[i]);
|
||||
process(self:expandAliases(token[i]));
|
||||
end;
|
||||
end;
|
||||
local _g = 0;
|
||||
local _g1 = ors.length;
|
||||
while (_g < _g1) do
|
||||
_g = _g + 1;
|
||||
local i = _g - 1;
|
||||
local _or = ors[i];
|
||||
if (Reflect.field(_or, "object") ~= nil) then
|
||||
self.include = self.include:concat(Reflect.field(_or, "object"));
|
||||
end;
|
||||
if (Reflect.field(_or, "-object") ~= nil) then
|
||||
self.exclude = self.exclude:concat(Reflect.field(_or, "-object"));
|
||||
end;
|
||||
end;
|
||||
self.q = _hx_o({__fields__={['or']=true,copy_all=true},['or']=ors,copy_all=copyAll});
|
||||
self.q = q;
|
||||
do return self.q end
|
||||
end
|
||||
__xrfragment_Query.prototype.test = function(self,property,value)
|
||||
if (self.preset == property) then
|
||||
self:parse(value, true);
|
||||
end;
|
||||
local _g = 0;
|
||||
local _g1 = _hx_wrap_if_string_field(self.q["or"],'length');
|
||||
while (_g < _g1) do
|
||||
_g = _g + 1;
|
||||
local i = _g - 1;
|
||||
local _or = self.q["or"][i];
|
||||
local conds = _hx_tab_array({[0]=0}, 1);
|
||||
local fails = _hx_tab_array({[0]=0}, 1);
|
||||
local pass = 0;
|
||||
local when = (function(fails,conds)
|
||||
do return function(expr)
|
||||
local conds = conds;
|
||||
local when = 0;
|
||||
conds[when] = conds[when] + 1;
|
||||
local fails = fails;
|
||||
local when = 0;
|
||||
fails[when] = fails[when] + (function()
|
||||
local conds = 0;
|
||||
local fails = 0;
|
||||
local qualify = 0;
|
||||
local testprop = function(expr)
|
||||
conds = conds + 1;
|
||||
fails = fails + (function()
|
||||
local _hx_1
|
||||
if (expr) then
|
||||
_hx_1 = 0; else
|
||||
|
|
@ -1536,52 +1541,51 @@ __xrfragment_Query.prototype.test = function(self,property,value)
|
|||
return _hx_1
|
||||
end )();
|
||||
do return expr end;
|
||||
end end;
|
||||
end)(fails, conds);
|
||||
end;
|
||||
if (Reflect.field(self.q, value) ~= nil) then
|
||||
local v = Reflect.field(self.q, value);
|
||||
if (Reflect.field(v, property) ~= nil) then
|
||||
do return Reflect.field(v, property) end;
|
||||
end;
|
||||
end;
|
||||
local _g = 0;
|
||||
local _g1 = Reflect.fields(_or);
|
||||
local _hx_continue_2 = false;
|
||||
local _g1 = Reflect.fields(self.q);
|
||||
local _hx_continue_1 = false;
|
||||
while (_g < _g1.length) do repeat
|
||||
local k = _g1[_g];
|
||||
_g = _g + 1;
|
||||
local orval = Reflect.field(_or, k);
|
||||
if (k ~= property) then
|
||||
local qval = Reflect.field(self.q, k);
|
||||
if (__lua_Boot.__instanceof(value, String)) then
|
||||
break;
|
||||
end;
|
||||
if ((Reflect.field(orval, "=") ~= nil) and when(value == Reflect.field(orval, "="))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, "=") ~= nil) and testprop(value == Reflect.field(qval, "="))) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, "*") ~= nil) and when(value ~= nil)) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, "*") ~= nil) and testprop(value ~= nil)) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, ">") ~= nil) and when(value > Std.parseInt(Reflect.field(orval, ">")))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, ">") ~= nil) and testprop(value > Std.parseFloat(Reflect.field(qval, ">")))) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, "<") ~= nil) and when(value < Std.parseInt(Reflect.field(orval, "<")))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, "<") ~= nil) and testprop(value < Std.parseFloat(Reflect.field(qval, "<")))) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, ">=") ~= nil) and when(value >= Std.parseInt(Reflect.field(orval, ">=")))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, ">=") ~= nil) and testprop(value >= Std.parseFloat(Reflect.field(qval, ">=")))) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, "<=") ~= nil) and when(value >= Std.parseInt(Reflect.field(orval, "<=")))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, "<=") ~= nil) and testprop(value >= Std.parseFloat(Reflect.field(qval, "<=")))) then
|
||||
qualify = qualify + 1;
|
||||
end;
|
||||
if ((Reflect.field(orval, "!=") ~= nil) and when(value ~= Std.parseInt(Reflect.field(orval, "!=")))) then
|
||||
pass = pass + 1;
|
||||
if ((Reflect.field(qval, "!=") ~= nil) and testprop(value ~= Std.parseFloat(Reflect.field(qval, "!=")))) then
|
||||
qualify = qualify + 1;
|
||||
end;until true
|
||||
if _hx_continue_2 then
|
||||
_hx_continue_2 = false;
|
||||
if _hx_continue_1 then
|
||||
_hx_continue_1 = false;
|
||||
break;
|
||||
end;
|
||||
|
||||
end;
|
||||
if ((self.accept and (conds[0] > 0)) and (fails[0] > 0)) then
|
||||
self.accept = false;
|
||||
end;
|
||||
if (((conds[0] > 0) and (pass > 0)) and (fails[0] == 0)) then
|
||||
self.accept = true;
|
||||
end;
|
||||
end;
|
||||
do return qualify > 0 end
|
||||
end
|
||||
|
||||
__xrfragment_Query.prototype.__class__ = __xrfragment_Query
|
||||
|
|
|
|||
407
dist/xrfragment.py
vendored
407
dist/xrfragment.py
vendored
|
|
@ -100,7 +100,7 @@ class Reflect:
|
|||
class Std:
|
||||
_hx_class_name = "Std"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["isOfType", "string", "parseInt"]
|
||||
_hx_statics = ["isOfType", "string", "shortenPossibleNumber", "parseFloat"]
|
||||
|
||||
@staticmethod
|
||||
def isOfType(v,t):
|
||||
|
|
@ -193,70 +193,36 @@ class Std:
|
|||
return python_Boot.toString1(s,"")
|
||||
|
||||
@staticmethod
|
||||
def parseInt(x):
|
||||
if (x is None):
|
||||
return None
|
||||
try:
|
||||
return int(x)
|
||||
except BaseException as _g:
|
||||
None
|
||||
base = 10
|
||||
_hx_len = len(x)
|
||||
foundCount = 0
|
||||
sign = 0
|
||||
firstDigitIndex = 0
|
||||
lastDigitIndex = -1
|
||||
previous = 0
|
||||
def shortenPossibleNumber(x):
|
||||
r = ""
|
||||
_g = 0
|
||||
_g1 = _hx_len
|
||||
_g1 = len(x)
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
c = (-1 if ((i >= len(x))) else ord(x[i]))
|
||||
if (((c > 8) and ((c < 14))) or ((c == 32))):
|
||||
if (foundCount > 0):
|
||||
return None
|
||||
continue
|
||||
c = ("" if (((i < 0) or ((i >= len(x))))) else x[i])
|
||||
_g2 = HxString.charCodeAt(c,0)
|
||||
if (_g2 is None):
|
||||
break
|
||||
else:
|
||||
_g3 = _g2
|
||||
if (((((((((((_g3 == 57) or ((_g3 == 56))) or ((_g3 == 55))) or ((_g3 == 54))) or ((_g3 == 53))) or ((_g3 == 52))) or ((_g3 == 51))) or ((_g3 == 50))) or ((_g3 == 49))) or ((_g3 == 48))) or ((_g3 == 46))):
|
||||
r = (("null" if r is None else r) + ("null" if c is None else c))
|
||||
else:
|
||||
c1 = c
|
||||
if (c1 == 43):
|
||||
if (foundCount == 0):
|
||||
sign = 1
|
||||
elif (not (((48 <= c) and ((c <= 57))))):
|
||||
if (not (((base == 16) and ((((97 <= c) and ((c <= 122))) or (((65 <= c) and ((c <= 90))))))))):
|
||||
break
|
||||
elif (c1 == 45):
|
||||
if (foundCount == 0):
|
||||
sign = -1
|
||||
elif (not (((48 <= c) and ((c <= 57))))):
|
||||
if (not (((base == 16) and ((((97 <= c) and ((c <= 122))) or (((65 <= c) and ((c <= 90))))))))):
|
||||
break
|
||||
elif (c1 == 48):
|
||||
if (not (((foundCount == 0) or (((foundCount == 1) and ((sign != 0))))))):
|
||||
if (not (((48 <= c) and ((c <= 57))))):
|
||||
if (not (((base == 16) and ((((97 <= c) and ((c <= 122))) or (((65 <= c) and ((c <= 90))))))))):
|
||||
break
|
||||
elif ((c1 == 120) or ((c1 == 88))):
|
||||
if ((previous == 48) and ((((foundCount == 1) and ((sign == 0))) or (((foundCount == 2) and ((sign != 0))))))):
|
||||
base = 16
|
||||
elif (not (((48 <= c) and ((c <= 57))))):
|
||||
if (not (((base == 16) and ((((97 <= c) and ((c <= 122))) or (((65 <= c) and ((c <= 90))))))))):
|
||||
break
|
||||
elif (not (((48 <= c) and ((c <= 57))))):
|
||||
if (not (((base == 16) and ((((97 <= c) and ((c <= 122))) or (((65 <= c) and ((c <= 90))))))))):
|
||||
break
|
||||
if (((foundCount == 0) and ((sign == 0))) or (((foundCount == 1) and ((sign != 0))))):
|
||||
firstDigitIndex = i
|
||||
foundCount = (foundCount + 1)
|
||||
lastDigitIndex = i
|
||||
previous = c
|
||||
if (firstDigitIndex <= lastDigitIndex):
|
||||
digits = HxString.substring(x,firstDigitIndex,(lastDigitIndex + 1))
|
||||
return r
|
||||
|
||||
@staticmethod
|
||||
def parseFloat(x):
|
||||
try:
|
||||
return (((-1 if ((sign == -1)) else 1)) * int(digits,base))
|
||||
return float(x)
|
||||
except BaseException as _g:
|
||||
return None
|
||||
return None
|
||||
None
|
||||
if (x is not None):
|
||||
r1 = Std.shortenPossibleNumber(x)
|
||||
if (r1 != x):
|
||||
return Std.parseFloat(r1)
|
||||
return Math.NaN
|
||||
|
||||
|
||||
class Float: pass
|
||||
|
|
@ -271,6 +237,53 @@ class Bool: pass
|
|||
class Dynamic: pass
|
||||
|
||||
|
||||
class StringTools:
|
||||
_hx_class_name = "StringTools"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["isSpace", "ltrim", "rtrim", "trim", "replace"]
|
||||
|
||||
@staticmethod
|
||||
def isSpace(s,pos):
|
||||
if (((len(s) == 0) or ((pos < 0))) or ((pos >= len(s)))):
|
||||
return False
|
||||
c = HxString.charCodeAt(s,pos)
|
||||
if (not (((c > 8) and ((c < 14))))):
|
||||
return (c == 32)
|
||||
else:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def ltrim(s):
|
||||
l = len(s)
|
||||
r = 0
|
||||
while ((r < l) and StringTools.isSpace(s,r)):
|
||||
r = (r + 1)
|
||||
if (r > 0):
|
||||
return HxString.substr(s,r,(l - r))
|
||||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def rtrim(s):
|
||||
l = len(s)
|
||||
r = 0
|
||||
while ((r < l) and StringTools.isSpace(s,((l - r) - 1))):
|
||||
r = (r + 1)
|
||||
if (r > 0):
|
||||
return HxString.substr(s,0,(l - r))
|
||||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def trim(s):
|
||||
return StringTools.ltrim(StringTools.rtrim(s))
|
||||
|
||||
@staticmethod
|
||||
def replace(s,sub,by):
|
||||
_this = (list(s) if ((sub == "")) else s.split(sub))
|
||||
return by.join([python_Boot.toString1(x1,'') for x1 in _this])
|
||||
|
||||
|
||||
class haxe_Exception(Exception):
|
||||
_hx_class_name = "haxe.Exception"
|
||||
__slots__ = ("_hx___nativeStack", "_hx___nativeException", "_hx___previousException")
|
||||
|
|
@ -855,11 +868,7 @@ class python_HaxeIterator:
|
|||
class python_internal_ArrayImpl:
|
||||
_hx_class_name = "python.internal.ArrayImpl"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["get_length", "concat", "copy", "iterator", "keyValueIterator", "indexOf", "lastIndexOf", "join", "toString", "pop", "push", "unshift", "remove", "contains", "shift", "slice", "sort", "splice", "map", "filter", "insert", "reverse", "_get", "_set"]
|
||||
|
||||
@staticmethod
|
||||
def get_length(x):
|
||||
return len(x)
|
||||
_hx_statics = ["concat", "copy", "iterator", "keyValueIterator", "indexOf", "lastIndexOf", "join", "toString", "pop", "push", "unshift", "remove", "contains", "shift", "slice", "sort", "splice", "map", "filter", "insert", "reverse", "_get"]
|
||||
|
||||
@staticmethod
|
||||
def concat(a1,a2):
|
||||
|
|
@ -991,23 +1000,11 @@ class python_internal_ArrayImpl:
|
|||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _set(x,idx,v):
|
||||
l = len(x)
|
||||
while (l < idx):
|
||||
x.append(None)
|
||||
l = (l + 1)
|
||||
if (l == idx):
|
||||
x.append(v)
|
||||
else:
|
||||
x[idx] = v
|
||||
return v
|
||||
|
||||
|
||||
class HxOverrides:
|
||||
_hx_class_name = "HxOverrides"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["eq", "stringOrNull", "push", "length", "arrayGet"]
|
||||
_hx_statics = ["eq", "stringOrNull", "arrayGet"]
|
||||
|
||||
@staticmethod
|
||||
def eq(a,b):
|
||||
|
|
@ -1022,22 +1019,6 @@ class HxOverrides:
|
|||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def push(x,e):
|
||||
if isinstance(x,list):
|
||||
_this = x
|
||||
_this.append(e)
|
||||
return len(_this)
|
||||
return x.push(e)
|
||||
|
||||
@staticmethod
|
||||
def length(x):
|
||||
if isinstance(x,str):
|
||||
return len(x)
|
||||
elif isinstance(x,list):
|
||||
return len(x)
|
||||
return x.length
|
||||
|
||||
@staticmethod
|
||||
def arrayGet(a,i):
|
||||
if isinstance(a,list):
|
||||
|
|
@ -1068,7 +1049,7 @@ class python_internal_MethodClosure:
|
|||
class HxString:
|
||||
_hx_class_name = "HxString"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["split", "charCodeAt", "charAt", "lastIndexOf", "toUpperCase", "toLowerCase", "indexOf", "indexOfImpl", "toString", "get_length", "substring", "substr"]
|
||||
_hx_statics = ["split", "charCodeAt", "charAt", "lastIndexOf", "toUpperCase", "toLowerCase", "indexOf", "indexOfImpl", "toString", "substring", "substr"]
|
||||
|
||||
@staticmethod
|
||||
def split(s,d):
|
||||
|
|
@ -1147,10 +1128,6 @@ class HxString:
|
|||
def toString(s):
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def get_length(s):
|
||||
return len(s)
|
||||
|
||||
@staticmethod
|
||||
def substring(s,startIndex,endIndex = None):
|
||||
if (startIndex < 0):
|
||||
|
|
@ -1181,15 +1158,13 @@ class HxString:
|
|||
|
||||
class xrfragment_Query:
|
||||
_hx_class_name = "xrfragment.Query"
|
||||
__slots__ = ("str", "q", "include", "exclude", "accept", "preset")
|
||||
_hx_fields = ["str", "q", "include", "exclude", "accept", "preset"]
|
||||
_hx_methods = ["toObject", "selected", "parse", "test"]
|
||||
__slots__ = ("str", "q", "isProp", "isExclude")
|
||||
_hx_fields = ["str", "q", "isProp", "isExclude"]
|
||||
_hx_methods = ["toObject", "expandAliases", "parse", "test"]
|
||||
|
||||
def __init__(self,_hx_str):
|
||||
self.preset = ""
|
||||
self.accept = False
|
||||
self.exclude = list()
|
||||
self.include = list()
|
||||
self.isExclude = EReg("^-","")
|
||||
self.isProp = EReg("^.*:[><=!]?","")
|
||||
self.q = _hx_AnonObject({})
|
||||
self.str = ""
|
||||
if (_hx_str is not None):
|
||||
|
|
@ -1198,182 +1173,122 @@ class xrfragment_Query:
|
|||
def toObject(self):
|
||||
return self.q
|
||||
|
||||
def selected(self,nodename):
|
||||
if Reflect.field(self.q,"copy_all"):
|
||||
self.accept = True
|
||||
if (nodename in self.include):
|
||||
self.accept = True
|
||||
if (nodename in self.exclude):
|
||||
self.accept = False
|
||||
return self.accept
|
||||
def expandAliases(self,token):
|
||||
classAlias = EReg("^(-)?\\.","")
|
||||
classAlias.matchObj = python_lib_Re.search(classAlias.pattern,token)
|
||||
if (classAlias.matchObj is not None):
|
||||
return StringTools.replace(token,".","class:")
|
||||
else:
|
||||
return token
|
||||
|
||||
def parse(self,_hx_str,recurse = None):
|
||||
if (recurse is None):
|
||||
recurse = False
|
||||
_gthis = self
|
||||
copyAll = (Reflect.field(self.q,"copy_all") if recurse else (((HxString.substr(_hx_str,0,1) == "-") or ((HxString.substr(_hx_str,0,1) == "?"))) or ((_hx_str == ""))))
|
||||
isOr = EReg("^or$","")
|
||||
isProp = EReg(".*:[><=!]?","")
|
||||
isName = EReg("[^:/]","")
|
||||
isExclude = EReg("^-","")
|
||||
isInclude = EReg("^\\+","")
|
||||
isPreset = EReg("^\\?","")
|
||||
token = _hx_str.split(" ")
|
||||
ors = list()
|
||||
q = _hx_AnonObject({})
|
||||
def _hx_local_0():
|
||||
nonlocal q
|
||||
q = _hx_AnonObject({})
|
||||
value = list()
|
||||
setattr(q,(("_hx_" + "object") if (("object" in python_Boot.keywords)) else (("_hx_" + "object") if (((((len("object") > 2) and ((ord("object"[0]) == 95))) and ((ord("object"[1]) == 95))) and ((ord("object"[(len("object") - 1)]) != 95)))) else "object")),value)
|
||||
value = list()
|
||||
setattr(q,(("_hx_" + "-object") if (("-object" in python_Boot.keywords)) else (("_hx_" + "-object") if (((((len("-object") > 2) and ((ord("-object"[0]) == 95))) and ((ord("-object"[1]) == 95))) and ((ord("-object"[(len("-object") - 1)]) != 95)))) else "-object")),value)
|
||||
ors.append(q)
|
||||
return q
|
||||
composeQuery = _hx_local_0
|
||||
composeQuery()
|
||||
match = None
|
||||
def _hx_local_2(_hx_str,prefix = None):
|
||||
def _hx_local_0(_hx_str,prefix = None):
|
||||
if (prefix is None):
|
||||
prefix = ""
|
||||
isPreset.matchObj = python_lib_Re.search(isPreset.pattern,_hx_str)
|
||||
if ((isPreset.matchObj is not None) and (not recurse)):
|
||||
_gthis.preset = _hx_str
|
||||
return
|
||||
match1 = None
|
||||
isExclude.matchObj = python_lib_Re.search(isExclude.pattern,_hx_str)
|
||||
if (isExclude.matchObj is None):
|
||||
isInclude.matchObj = python_lib_Re.search(isInclude.pattern,_hx_str)
|
||||
match1 = (isInclude.matchObj is not None)
|
||||
else:
|
||||
match1 = True
|
||||
if match1:
|
||||
t = HxString.substr(_hx_str,1,None)
|
||||
match(t,HxString.substr(_hx_str,0,1))
|
||||
return
|
||||
isProp.matchObj = python_lib_Re.search(isProp.pattern,_hx_str)
|
||||
if (isProp.matchObj is not None):
|
||||
skip = 0
|
||||
_hx_type = "="
|
||||
_hx_str = StringTools.trim(_hx_str)
|
||||
value = _hx_AnonObject({})
|
||||
_this = _gthis.isProp
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
if (_this.matchObj is not None):
|
||||
oper = ""
|
||||
startIndex = None
|
||||
if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1):
|
||||
_hx_type = "*"
|
||||
oper = "*"
|
||||
startIndex = None
|
||||
if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1):
|
||||
_hx_type = ">"
|
||||
oper = ">"
|
||||
startIndex = None
|
||||
if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1):
|
||||
_hx_type = "<"
|
||||
oper = "<"
|
||||
startIndex = None
|
||||
if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1):
|
||||
_hx_type = "!="
|
||||
oper = "!="
|
||||
startIndex = None
|
||||
if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1):
|
||||
_hx_type = ">="
|
||||
oper = ">="
|
||||
startIndex = None
|
||||
if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1):
|
||||
_hx_type = "<="
|
||||
if (_hx_type != "="):
|
||||
skip = (skip + len(_hx_type))
|
||||
property = HxOverrides.arrayGet(_hx_str.split(":"), 0)
|
||||
value = None
|
||||
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))):
|
||||
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property)))
|
||||
oper = "<="
|
||||
k = HxOverrides.arrayGet(_hx_str.split(":"), 0)
|
||||
v = HxOverrides.arrayGet(_hx_str.split(":"), 1)
|
||||
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k))):
|
||||
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k)))
|
||||
if (len(oper) > 0):
|
||||
value1 = Std.parseFloat(HxString.substr(v,len(oper),None))
|
||||
setattr(value,(("_hx_" + oper) if ((oper in python_Boot.keywords)) else (("_hx_" + oper) if (((((len(oper) > 2) and ((ord(oper[0]) == 95))) and ((ord(oper[1]) == 95))) and ((ord(oper[(len(oper) - 1)]) != 95)))) else oper)),value1)
|
||||
setattr(q,(("_hx_" + k) if ((k in python_Boot.keywords)) else (("_hx_" + k) if (((((len(k) > 2) and ((ord(k[0]) == 95))) and ((ord(k[1]) == 95))) and ((ord(k[(len(k) - 1)]) != 95)))) else k)),value)
|
||||
else:
|
||||
value = _hx_AnonObject({})
|
||||
value1 = HxString.substr(HxOverrides.arrayGet(_hx_str.split(":"), 1),skip,None)
|
||||
setattr(value,(("_hx_" + _hx_type) if ((_hx_type in python_Boot.keywords)) else (("_hx_" + _hx_type) if (((((len(_hx_type) > 2) and ((ord(_hx_type[0]) == 95))) and ((ord(_hx_type[1]) == 95))) and ((ord(_hx_type[(len(_hx_type) - 1)]) != 95)))) else _hx_type)),value1)
|
||||
key = (("null" if prefix is None else prefix) + ("null" if property is None else property))
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,k)
|
||||
key = (("null" if prefix is None else prefix) + HxOverrides.stringOrNull(((HxString.substr(k,1,None) if ((_this.matchObj is not None)) else k))))
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,k)
|
||||
value1 = ((_this.matchObj is not None) == False)
|
||||
setattr(value,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
setattr(q,(("_hx_" + v) if ((v in python_Boot.keywords)) else (("_hx_" + v) if (((((len(v) > 2) and ((ord(v[0]) == 95))) and ((ord(v[1]) == 95))) and ((ord(v[(len(v) - 1)]) != 95)))) else v)),value)
|
||||
return
|
||||
else:
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
value1 = (False if ((_this.matchObj is not None)) else True)
|
||||
setattr(value,(("_hx_" + "id") if (("id" in python_Boot.keywords)) else (("_hx_" + "id") if (((((len("id") > 2) and ((ord("id"[0]) == 95))) and ((ord("id"[1]) == 95))) and ((ord("id"[(len("id") - 1)]) != 95)))) else "id")),value1)
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
key = (HxString.substr(_hx_str,1,None) if ((_this.matchObj is not None)) else _hx_str)
|
||||
setattr(q,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value)
|
||||
return
|
||||
isName.matchObj = python_lib_Re.search(isName.pattern,_hx_str)
|
||||
if (isName.matchObj is not None):
|
||||
if (prefix == "-"):
|
||||
Reflect.field(Reflect.field(q,"-object"),"push")(_hx_str)
|
||||
while (Reflect.field(Reflect.field(q,"object"),"contains")(_hx_str) == True):
|
||||
Reflect.field(Reflect.field(q,"object"),"remove")(_hx_str)
|
||||
else:
|
||||
Reflect.field(Reflect.field(q,"object"),"push")(_hx_str)
|
||||
while (Reflect.field(Reflect.field(q,"-object"),"contains")(_hx_str) == True):
|
||||
Reflect.field(Reflect.field(q,"-object"),"remove")(_hx_str)
|
||||
return
|
||||
match = _hx_local_2
|
||||
process = _hx_local_0
|
||||
_g = 0
|
||||
_g1 = len(token)
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
isOr.matchObj = python_lib_Re.search(isOr.pattern,(token[i] if i >= 0 and i < len(token) else None))
|
||||
if (isOr.matchObj is not None):
|
||||
composeQuery()
|
||||
else:
|
||||
match((token[i] if i >= 0 and i < len(token) else None))
|
||||
_g = 0
|
||||
_g1 = len(ors)
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
_hx_or = (ors[i] if i >= 0 and i < len(ors) else None)
|
||||
if (Reflect.field(_hx_or,"object") is not None):
|
||||
self.include = (self.include + Reflect.field(_hx_or,"object"))
|
||||
if (Reflect.field(_hx_or,"-object") is not None):
|
||||
self.exclude = (self.exclude + Reflect.field(_hx_or,"-object"))
|
||||
self.q = _hx_AnonObject({'_hx_or': ors, 'copy_all': copyAll})
|
||||
process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None)))
|
||||
self.q = q
|
||||
return self.q
|
||||
|
||||
def test(self,property,value = None):
|
||||
if (self.preset == property):
|
||||
self.parse(value,True)
|
||||
_g = 0
|
||||
_g1 = Reflect.field(Reflect.field(self.q,"or"),"length")
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
_hx_or = HxOverrides.arrayGet(Reflect.field(self.q,"or"), i)
|
||||
conds = [0]
|
||||
fails = [0]
|
||||
_hx_pass = 0
|
||||
def _hx_local_7(fails,conds):
|
||||
def _hx_local_0(expr):
|
||||
_hx_local_1 = conds
|
||||
_hx_local_2 = 0
|
||||
_hx_local_3 = (_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None)
|
||||
python_internal_ArrayImpl._set(_hx_local_1, _hx_local_2, (_hx_local_3 + 1))
|
||||
(_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None)
|
||||
_hx_local_4 = fails
|
||||
_hx_local_5 = 0
|
||||
_hx_local_6 = (_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None)
|
||||
python_internal_ArrayImpl._set(_hx_local_4, _hx_local_5, (_hx_local_6 + (0 if expr else 1)))
|
||||
(_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None)
|
||||
conds = 0
|
||||
fails = 0
|
||||
qualify = 0
|
||||
def _hx_local_2(expr):
|
||||
nonlocal conds
|
||||
nonlocal fails
|
||||
conds = (conds + 1)
|
||||
fails = (fails + (0 if expr else 1))
|
||||
return expr
|
||||
return _hx_local_0
|
||||
when = _hx_local_7(fails,conds)
|
||||
_g2 = 0
|
||||
_g3 = python_Boot.fields(_hx_or)
|
||||
while (_g2 < len(_g3)):
|
||||
k = (_g3[_g2] if _g2 >= 0 and _g2 < len(_g3) else None)
|
||||
_g2 = (_g2 + 1)
|
||||
orval = Reflect.field(_hx_or,k)
|
||||
if (k != property):
|
||||
testprop = _hx_local_2
|
||||
if (Reflect.field(self.q,value) is not None):
|
||||
v = Reflect.field(self.q,value)
|
||||
if (Reflect.field(v,property) is not None):
|
||||
return Reflect.field(v,property)
|
||||
_g = 0
|
||||
_g1 = python_Boot.fields(self.q)
|
||||
while (_g < len(_g1)):
|
||||
k = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
|
||||
_g = (_g + 1)
|
||||
qval = Reflect.field(self.q,k)
|
||||
if Std.isOfType(value,str):
|
||||
continue
|
||||
if ((Reflect.field(orval,"=") is not None) and when(HxOverrides.eq(value,Reflect.field(orval,"=")))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"*") is not None) and when((value is not None))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,">") is not None) and when((value > Std.parseInt(Reflect.field(orval,">"))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"<") is not None) and when((value < Std.parseInt(Reflect.field(orval,"<"))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,">=") is not None) and when((value >= Std.parseInt(Reflect.field(orval,">="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"<=") is not None) and when((value >= Std.parseInt(Reflect.field(orval,"<="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"!=") is not None) and when((value != Std.parseInt(Reflect.field(orval,"!="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((self.accept and (((conds[0] if 0 < len(conds) else None) > 0))) and (((fails[0] if 0 < len(fails) else None) > 0))):
|
||||
self.accept = False
|
||||
if ((((conds[0] if 0 < len(conds) else None) > 0) and ((_hx_pass > 0))) and (((fails[0] if 0 < len(fails) else None) == 0))):
|
||||
self.accept = True
|
||||
if ((Reflect.field(qval,"=") is not None) and testprop(HxOverrides.eq(value,Reflect.field(qval,"=")))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"*") is not None) and testprop((value is not None))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,">") is not None) and testprop((value > Std.parseFloat(Reflect.field(qval,">"))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"<") is not None) and testprop((value < Std.parseFloat(Reflect.field(qval,"<"))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,">=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,">="))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"<=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,"<="))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"!=") is not None) and testprop((value != Std.parseFloat(Reflect.field(qval,"!="))))):
|
||||
qualify = (qualify + 1)
|
||||
return (qualify > 0)
|
||||
|
||||
|
||||
Math.NEGATIVE_INFINITY = float("-inf")
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ class Spec {
|
|||
class Test {
|
||||
|
||||
static public function main():Void {
|
||||
test( Spec.load("src/spec/query.or.json") );
|
||||
test( Spec.load("src/spec/url.json") );
|
||||
test( Spec.load("src/spec/query.class.json") );
|
||||
test( Spec.load("src/spec/query.conditional.json") );
|
||||
//test( Spec.load("src/spec/tmp.json") );
|
||||
}
|
||||
|
||||
static public function test(spec:Array<Dynamic>):Void {
|
||||
|
|
@ -26,7 +28,7 @@ class Test {
|
|||
var item:Dynamic = spec[i];
|
||||
if( item.fn == "query" ) q = new Query(item.data);
|
||||
if( item.fn == "url" ) res = Url.parse(item.data);
|
||||
if( item.expect.fn == "selected" ) valid = item.expect.out == q.selected( item.expect.input );
|
||||
if( item.expect.fn == "test" ) valid = item.expect.out == q.test( item.expect.input[0], item.expect.input[1] );
|
||||
if( item.expect.fn == "equal.string" ) valid = item.expect.out == res.get(item.expect.input).string;
|
||||
if( item.expect.fn == "equal.xy" ) valid = item.expect.out == (Std.string(res.get(item.expect.input).x) + Std.string(res.get(item.expect.input).y) );
|
||||
if( item.expect.fn == "equal.multi" ) valid = equalMulti(res, item);
|
||||
|
|
|
|||
14
src/spec/query.class.json
Normal file
14
src/spec/query.class.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[
|
||||
{"fn":"query","data":"class:bar", "expect":{ "fn":"test","input":["class","bar"],"out":true}},
|
||||
{"fn":"query","data":".bar", "expect":{ "fn":"test","input":["class","bar"],"out":true}, "label":".bar shorthand"},
|
||||
{"fn":"query","data":".bar -.foo", "expect":{ "fn":"test","input":["class","foo"],"out":false}},
|
||||
{"fn":"query","data":".bar -.foo .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true}},
|
||||
{"fn":"query","data":".bar -.bar .bar", "expect":{ "fn":"test","input":["class","bar"],"out":true}},
|
||||
{"fn":"query","data":"foo -foo foo", "expect":{ "fn":"test","input":["id","foo"],"out":true},"label":"id:foo?"},
|
||||
{"fn":"query","data":".foo -.foo .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true},"label":"class:foo"},
|
||||
{"fn":"query","data":".foo -.foo bar:5 .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true},"label":"class:foo"},
|
||||
{"fn":"query","data":".foo -.foo bar:>5 .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true},"label":"class:foo"},
|
||||
{"fn":"query","data":".foo -.foo bar:>5 .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true},"label":"class:foo"},
|
||||
{"fn":"query","data":".foo -.foo .foo", "expect":{ "fn":"test","input":["class","foo"],"out":true},"label":"class:foo"},
|
||||
{"fn":"query","data":".foo -.foo .foo", "expect":{ "fn":"test","input":["id","foo"],"out":false},"label":"!id:foo"}
|
||||
]
|
||||
6
src/spec/query.conditional.json
Normal file
6
src/spec/query.conditional.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
{"fn":"query","data":"price:>=5", "expect":{ "fn":"test","input":["price","10"],"out":true}},
|
||||
{"fn":"query","data":"price:>=15", "expect":{ "fn":"test","input":["price","10"],"out":false}},
|
||||
{"fn":"query","data":"price:>=5", "expect":{ "fn":"test","input":["price","4"],"out":false}},
|
||||
{"fn":"query","data":"price:>=5", "expect":{ "fn":"test","input":["price","0"],"out":false}}
|
||||
]
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[
|
||||
{"fn":"query","data":"foo or bar", "expect":{ "fn":"selected","input":"foo","out":true}},
|
||||
{"fn":"query","data":"foo or bar", "expect":{ "fn":"selected","input":"xxx","out":false}, "label":"nonselected entity"}
|
||||
]
|
||||
|
|
@ -39,11 +39,9 @@ package xrfragment;
|
|||
class Query {
|
||||
|
||||
private var str:String = "";
|
||||
private var q:Dynamic = {};
|
||||
private var include:Array<String> = new Array();
|
||||
private var exclude:Array<String> = new Array();
|
||||
private var accept:Bool = false;
|
||||
private var preset:String = "";
|
||||
private var q:haxe.DynamicAccess<Dynamic> = {};
|
||||
private var isProp:EReg = ~/^.*:[><=!]?/;
|
||||
private var isExclude:EReg = ~/^-/;
|
||||
|
||||
public function new(str:String){
|
||||
if( str != null ) this.parse(str);
|
||||
|
|
@ -53,125 +51,80 @@ class Query {
|
|||
return this.q;
|
||||
}
|
||||
|
||||
@:keep
|
||||
public function selected( nodename:String ): Bool {
|
||||
if( this.q.copy_all ) this.accept = true;
|
||||
if( this.include.contains(nodename) ) this.accept = true;
|
||||
if( this.exclude.contains(nodename) ) this.accept = false;
|
||||
return this.accept;
|
||||
public function expandAliases(token:String) : String {
|
||||
// expand '.foo' to 'class:foo'
|
||||
var classAlias = ~/^(-)?\./;
|
||||
return classAlias.match(token) ? StringTools.replace(token,".","class:") : token;
|
||||
}
|
||||
|
||||
@:keep
|
||||
public function parse(str:String,recurse:Bool = false) : Dynamic {
|
||||
|
||||
var copyAll:Bool = recurse ? this.q.copy_all : str.substr(0,1) == "-" || str.substr(0,1) == "?" || str == "";
|
||||
var isOr:EReg = ~/^or$/;
|
||||
var isProp:EReg = ~/.*:[><=!]?/;
|
||||
var isName:EReg = ~/[^:\/]/;
|
||||
var isExclude:EReg = ~/^-/;
|
||||
var isInclude:EReg = ~/^\+/;
|
||||
var isPreset:EReg = ~/^\?/;
|
||||
|
||||
var token = str.split(" ");
|
||||
var ors = new Array();
|
||||
var q:haxe.DynamicAccess<Dynamic> = {};
|
||||
|
||||
function composeQuery() : Dynamic {
|
||||
q = {};
|
||||
q.set("object", new Array() );
|
||||
q.set("-object", new Array() );
|
||||
ors.push(q);
|
||||
return q;
|
||||
}
|
||||
composeQuery();
|
||||
|
||||
function match(str,prefix = ""){
|
||||
if( isPreset.match(str) && !recurse ){
|
||||
this.preset = str;
|
||||
return;
|
||||
}
|
||||
if( isExclude.match(str) || isInclude.match(str) ){
|
||||
var t = str.substr(1);
|
||||
match(t, str.substr(0,1) );
|
||||
return;
|
||||
}
|
||||
function process(str,prefix = ""){
|
||||
str = StringTools.trim(str);
|
||||
var value:haxe.DynamicAccess<Dynamic> = {};
|
||||
if( isProp.match(str) ){
|
||||
var skip = 0;
|
||||
var type = "=";
|
||||
if( str.indexOf("*") != -1 ) type = "*";
|
||||
if( str.indexOf(">") != -1 ) type = ">";
|
||||
if( str.indexOf("<") != -1 ) type = "<";
|
||||
if( str.indexOf("!=") != -1 ) type = "!=";
|
||||
if( str.indexOf(">=") != -1 ) type = ">=";
|
||||
if( str.indexOf("<=") != -1 ) type = "<=";
|
||||
if( type != "=" ) skip += type.length;
|
||||
var property = str.split(":")[0];
|
||||
var value:haxe.DynamicAccess<Dynamic>;
|
||||
if( q.get(prefix+property) ) value = q.get(prefix+property);
|
||||
else value = {};
|
||||
value[ type ] = str.split(":")[1].substr(skip);
|
||||
q.set(prefix+property,value);
|
||||
return;
|
||||
}
|
||||
if( isName.match(str) ){
|
||||
if( prefix == '-' ){
|
||||
q["-object"].push(str);
|
||||
while( q["object"].contains(str) == true) {
|
||||
q["object"].remove(str);
|
||||
}
|
||||
var oper:String = "";
|
||||
if( str.indexOf("*") != -1 ) oper = "*";
|
||||
if( str.indexOf(">") != -1 ) oper = ">";
|
||||
if( str.indexOf("<") != -1 ) oper = "<";
|
||||
if( str.indexOf("!=") != -1 ) oper = "!=";
|
||||
if( str.indexOf(">=") != -1 ) oper = ">=";
|
||||
if( str.indexOf("<=") != -1 ) oper = "<=";
|
||||
var k:String = str.split(":")[0];
|
||||
var v:String = str.split(":")[1];
|
||||
if( q.get(prefix+k) ) value = q.get(prefix+k);
|
||||
if( oper.length > 0 ){
|
||||
value[ oper ] = Std.parseFloat( v.substr(oper.length) );
|
||||
q.set( k, value );
|
||||
}else{
|
||||
q["object"].push(str);
|
||||
while( q["-object"].contains(str) == true ){
|
||||
q["-object"].remove(str);
|
||||
}
|
||||
value[ prefix+ (isExclude.match(k) ? k.substr(1) : k) ] = isExclude.match(k) == false;
|
||||
q.set(v,value);
|
||||
}
|
||||
return;
|
||||
}else{ // id
|
||||
value[ "id" ] = isExclude.match(str) ? false: true;
|
||||
q.set( (isExclude.match(str) ? str.substr(1) : str ) ,value );
|
||||
}
|
||||
}
|
||||
|
||||
for( i in 0...token.length ) {
|
||||
if( isOr.match(token[i]) ){
|
||||
composeQuery();
|
||||
}else match(token[i]);
|
||||
}
|
||||
for ( i in 0...ors.length ) {
|
||||
var or:Dynamic = ors[i];
|
||||
if( Reflect.field(or,'object') != null ) this.include = this.include.concat( Reflect.field(or,'object') );
|
||||
if( Reflect.field(or,'-object') != null ) this.exclude = this.exclude.concat( Reflect.field(or,'-object') );
|
||||
}
|
||||
this.q = { or: ors, copy_all: copyAll };
|
||||
for( i in 0...token.length ) process( expandAliases(token[i]) );
|
||||
this.q = q;
|
||||
return this.q;
|
||||
}
|
||||
|
||||
@:keep
|
||||
public function test( property:String, ?value:Dynamic ):Void{
|
||||
if( this.preset == property ){
|
||||
this.parse( value, true );
|
||||
}
|
||||
for ( i in 0...this.q.or.length ) {
|
||||
var or:Dynamic = this.q.or[i];
|
||||
public function test( property:String, ?value:Dynamic ):Bool{
|
||||
var conds:Int = 0;
|
||||
var fails:Int = 0;
|
||||
var pass:Int = 0;
|
||||
var qualify:Int = 0;
|
||||
|
||||
var when = function(expr:Bool) : Bool {
|
||||
var testprop = function(expr:Bool) : Bool {
|
||||
conds+=1;
|
||||
fails+= expr ? 0 : 1;
|
||||
return expr;
|
||||
}
|
||||
|
||||
for ( k in Reflect.fields(or) ){
|
||||
var orval:Dynamic = Reflect.field(or,k);
|
||||
if( k != property ) continue;
|
||||
if( Reflect.field(orval,'=') != null && when( value == Reflect.field(orval,'=') ) ) pass += 1;
|
||||
if( Reflect.field(orval,'*') != null && when( value != null ) ) pass += 1;
|
||||
if( Reflect.field(orval,'>') != null && when( value > Std.parseInt(Reflect.field(orval,'>' )) ) ) pass += 1;
|
||||
if( Reflect.field(orval,'<') != null && when( value < Std.parseInt(Reflect.field(orval,'<' )) ) ) pass += 1;
|
||||
if( Reflect.field(orval,'>=') != null && when( value >= Std.parseInt(Reflect.field(orval,'>=')) ) ) pass += 1;
|
||||
if( Reflect.field(orval,'<=') != null && when( value >= Std.parseInt(Reflect.field(orval,'<=')) ) ) pass += 1;
|
||||
if( Reflect.field(orval,'!=') != null && when( value != Std.parseInt(Reflect.field(orval,'!=')) ) ) pass += 1;
|
||||
}
|
||||
if( this.accept && conds > 0 && fails > 0 ) this.accept = false;
|
||||
if( conds > 0 && pass > 0 && fails == 0 ) this.accept = true;
|
||||
// class or id
|
||||
if( q[value] != null ){
|
||||
var v:haxe.DynamicAccess<Dynamic> = q[value];
|
||||
if( v.get(property) != null ) return v.get(property);
|
||||
}
|
||||
|
||||
// conditional props
|
||||
for ( k in Reflect.fields(q) ){
|
||||
var qval:Dynamic = Reflect.field(q,k);
|
||||
if( Std.isOfType(value, String) ) continue;
|
||||
if( Reflect.field(qval,'=') != null && testprop( value == Reflect.field(qval,'=') ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'*') != null && testprop( value != null ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'>') != null && testprop( value > Std.parseFloat(Reflect.field(qval,'>' )) ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'<') != null && testprop( value < Std.parseFloat(Reflect.field(qval,'<' )) ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'>=') != null && testprop( value >= Std.parseFloat(Reflect.field(qval,'>=')) ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'<=') != null && testprop( value >= Std.parseFloat(Reflect.field(qval,'<=')) ) ) qualify += 1;
|
||||
if( Reflect.field(qval,'!=') != null && testprop( value != Std.parseFloat(Reflect.field(qval,'!=')) ) ) qualify += 1;
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ EReg.prototype = {
|
|||
};
|
||||
var HxOverrides = function() { };
|
||||
HxOverrides.__name__ = true;
|
||||
HxOverrides.cca = function(s,index) {
|
||||
var x = s.charCodeAt(index);
|
||||
if(x != x) {
|
||||
return undefined;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
HxOverrides.substr = function(s,pos,len) {
|
||||
if(len == null) {
|
||||
len = s.length;
|
||||
|
|
@ -84,11 +91,48 @@ Std.parseInt = function(x) {
|
|||
}
|
||||
return null;
|
||||
};
|
||||
var StringTools = function() { };
|
||||
StringTools.__name__ = true;
|
||||
StringTools.isSpace = function(s,pos) {
|
||||
var c = HxOverrides.cca(s,pos);
|
||||
if(!(c > 8 && c < 14)) {
|
||||
return c == 32;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
StringTools.ltrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,r)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,r,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.rtrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,0,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.trim = function(s) {
|
||||
return StringTools.ltrim(StringTools.rtrim(s));
|
||||
};
|
||||
StringTools.replace = function(s,sub,by) {
|
||||
return s.split(sub).join(by);
|
||||
};
|
||||
var Test = function() { };
|
||||
Test.__name__ = true;
|
||||
Test.main = function() {
|
||||
Test.test([{ fn : "query", expect : { fn : "selected", input : "foo", out : true}, data : "foo or bar"},{ fn : "query", expect : { fn : "selected", input : "xxx", out : false}, label : "nonselected entity", data : "foo or bar"}]);
|
||||
Test.test([{ fn : "url", expect : { fn : "equal.string", input : "bar", out : "flop"}, data : "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3"},{ fn : "url", expect : { fn : "equal.xy", input : "a", out : "1.22.2"}, label : "a equal.xy", data : "http://foo.com?foo=1#bar=flop&a=1.2,2.2&b=c|d|1,2,3"},{ fn : "url", expect : { fn : "equal.multi", input : "b", out : "c|d|1,2,3"}, label : "b equal.multi", data : "http://foo.com?foo=1#b=c|d|1,2,3"}]);
|
||||
Test.test([{ fn : "query", expect : { fn : "test", input : ["class","bar"], out : true}, data : "class:bar"},{ fn : "query", expect : { fn : "test", input : ["class","bar"], out : true}, label : ".bar shorthand", data : ".bar"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : false}, data : ".bar -.foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, data : ".bar -.foo .foo"},{ fn : "query", expect : { fn : "test", input : ["class","bar"], out : true}, data : ".bar -.bar .bar"},{ fn : "query", expect : { fn : "test", input : ["id","foo"], out : true}, label : "id:foo?", data : "foo -foo foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:5 .foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "test", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "test", input : ["id","foo"], out : false}, label : "!id:foo", data : ".foo -.foo .foo"}]);
|
||||
Test.test([{ fn : "query", expect : { fn : "test", input : ["price","10"], out : true}, data : "price:>=5"},{ fn : "query", expect : { fn : "test", input : ["price","10"], out : false}, data : "price:>=15"},{ fn : "query", expect : { fn : "test", input : ["price","4"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "test", input : ["price","0"], out : false}, data : "price:>=5"}]);
|
||||
};
|
||||
Test.test = function(spec) {
|
||||
var Query = xrfragment_Query;
|
||||
|
|
@ -107,8 +151,8 @@ Test.test = function(spec) {
|
|||
if(item.fn == "url") {
|
||||
res = xrfragment_Url.parse(item.data);
|
||||
}
|
||||
if(item.expect.fn == "selected") {
|
||||
valid = item.expect.out == q.selected(item.expect.input);
|
||||
if(item.expect.fn == "test") {
|
||||
valid = item.expect.out == q.test(item.expect.input[0],item.expect.input[1]);
|
||||
}
|
||||
if(item.expect.fn == "equal.string") {
|
||||
valid = item.expect.out == res[item.expect.input].string;
|
||||
|
|
@ -120,13 +164,13 @@ Test.test = function(spec) {
|
|||
valid = Test.equalMulti(res,item);
|
||||
}
|
||||
var ok = valid ? "[ ✔ ] " : "[ ❌] ";
|
||||
console.log("src/Test.hx:34:",ok + Std.string(item.fn) + ": '" + Std.string(item.data) + "'" + (item.label ? " <= " + (item.label ? item.label : item.expect.fn) : ""));
|
||||
console.log("src/Test.hx:36:",ok + Std.string(item.fn) + ": '" + Std.string(item.data) + "'" + (item.label ? " <= " + (item.label ? item.label : item.expect.fn) : ""));
|
||||
if(!valid) {
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
if(errors > 1) {
|
||||
console.log("src/Test.hx:37:","\n-----\n[ ❌] " + errors + " errors :/");
|
||||
console.log("src/Test.hx:39:","\n-----\n[ ❌] " + errors + " errors :/");
|
||||
}
|
||||
};
|
||||
Test.equalMulti = function(res,item) {
|
||||
|
|
@ -221,10 +265,8 @@ js_Boot.__string_rec = function(o,s) {
|
|||
}
|
||||
};
|
||||
var xrfragment_Query = function(str) {
|
||||
this.preset = "";
|
||||
this.accept = false;
|
||||
this.exclude = [];
|
||||
this.include = [];
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
if(str != null) {
|
||||
this.parse(str);
|
||||
|
|
@ -232,185 +274,122 @@ var xrfragment_Query = function(str) {
|
|||
};
|
||||
xrfragment_Query.__name__ = true;
|
||||
xrfragment_Query.prototype = {
|
||||
selected: function(nodename) {
|
||||
if(this.q.copy_all) {
|
||||
this.accept = true;
|
||||
expandAliases: function(token) {
|
||||
var classAlias = new EReg("^(-)?\\.","");
|
||||
if(classAlias.match(token)) {
|
||||
return StringTools.replace(token,".","class:");
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
if(this.include.indexOf(nodename) != -1) {
|
||||
this.accept = true;
|
||||
}
|
||||
if(this.exclude.indexOf(nodename) != -1) {
|
||||
this.accept = false;
|
||||
}
|
||||
return this.accept;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
var _gthis = this;
|
||||
var copyAll = recurse ? this.q.copy_all : HxOverrides.substr(str,0,1) == "-" || HxOverrides.substr(str,0,1) == "?" || str == "";
|
||||
var isOr = new EReg("^or$","");
|
||||
var isProp = new EReg(".*:[><=!]?","");
|
||||
var isName = new EReg("[^:/]","");
|
||||
var isExclude = new EReg("^-","");
|
||||
var isInclude = new EReg("^\\+","");
|
||||
var isPreset = new EReg("^\\?","");
|
||||
var token = str.split(" ");
|
||||
var ors = [];
|
||||
var q = { };
|
||||
var composeQuery = function() {
|
||||
q = { };
|
||||
var value = [];
|
||||
q["object"] = value;
|
||||
var value = [];
|
||||
q["-object"] = value;
|
||||
ors.push(q);
|
||||
return q;
|
||||
};
|
||||
composeQuery();
|
||||
var match = null;
|
||||
match = function(str,prefix) {
|
||||
var process = function(str,prefix) {
|
||||
if(prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
if(isPreset.match(str) && !recurse) {
|
||||
_gthis.preset = str;
|
||||
return;
|
||||
}
|
||||
if(isExclude.match(str) || isInclude.match(str)) {
|
||||
var t = HxOverrides.substr(str,1,null);
|
||||
match(t,HxOverrides.substr(str,0,1));
|
||||
return;
|
||||
}
|
||||
if(isProp.match(str)) {
|
||||
var skip = 0;
|
||||
var type = "=";
|
||||
str = StringTools.trim(str);
|
||||
var value = { };
|
||||
if(_gthis.isProp.match(str)) {
|
||||
var oper = "";
|
||||
if(str.indexOf("*") != -1) {
|
||||
type = "*";
|
||||
oper = "*";
|
||||
}
|
||||
if(str.indexOf(">") != -1) {
|
||||
type = ">";
|
||||
oper = ">";
|
||||
}
|
||||
if(str.indexOf("<") != -1) {
|
||||
type = "<";
|
||||
oper = "<";
|
||||
}
|
||||
if(str.indexOf("!=") != -1) {
|
||||
type = "!=";
|
||||
oper = "!=";
|
||||
}
|
||||
if(str.indexOf(">=") != -1) {
|
||||
type = ">=";
|
||||
oper = ">=";
|
||||
}
|
||||
if(str.indexOf("<=") != -1) {
|
||||
type = "<=";
|
||||
oper = "<=";
|
||||
}
|
||||
if(type != "=") {
|
||||
skip += type.length;
|
||||
var k = str.split(":")[0];
|
||||
var v = str.split(":")[1];
|
||||
if(q[prefix + k]) {
|
||||
value = q[prefix + k];
|
||||
}
|
||||
var property = str.split(":")[0];
|
||||
var value;
|
||||
if(q[prefix + property]) {
|
||||
value = q[prefix + property];
|
||||
if(oper.length > 0) {
|
||||
value[oper] = parseFloat(HxOverrides.substr(v,oper.length,null));
|
||||
q[k] = value;
|
||||
} else {
|
||||
value = { };
|
||||
}
|
||||
value[type] = HxOverrides.substr(str.split(":")[1],skip,null);
|
||||
q[prefix + property] = value;
|
||||
return;
|
||||
}
|
||||
if(isName.match(str)) {
|
||||
if(prefix == "-") {
|
||||
q["-object"].push(str);
|
||||
while(q["object"].contains(str) == true) q["object"].remove(str);
|
||||
} else {
|
||||
q["object"].push(str);
|
||||
while(q["-object"].contains(str) == true) q["-object"].remove(str);
|
||||
value[prefix + (_gthis.isExclude.match(k) ? HxOverrides.substr(k,1,null) : k)] = _gthis.isExclude.match(k) == false;
|
||||
q[v] = value;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
value["id"] = _gthis.isExclude.match(str) ? false : true;
|
||||
var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str;
|
||||
q[key] = value;
|
||||
}
|
||||
};
|
||||
var _g = 0;
|
||||
var _g1 = token.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
if(isOr.match(token[i])) {
|
||||
composeQuery();
|
||||
} else {
|
||||
match(token[i]);
|
||||
process(this.expandAliases(token[i]));
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = ors.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var or = ors[i];
|
||||
if(Reflect.field(or,"object") != null) {
|
||||
this.include = this.include.concat(Reflect.field(or,"object"));
|
||||
}
|
||||
if(Reflect.field(or,"-object") != null) {
|
||||
this.exclude = this.exclude.concat(Reflect.field(or,"-object"));
|
||||
}
|
||||
}
|
||||
this.q = { or : ors, copy_all : copyAll};
|
||||
this.q = q;
|
||||
return this.q;
|
||||
}
|
||||
,test: function(property,value) {
|
||||
if(this.preset == property) {
|
||||
this.parse(value,true);
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = this.q.or.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var or = this.q.or[i];
|
||||
var conds = [0];
|
||||
var fails = [0];
|
||||
var pass = 0;
|
||||
var when = (function(fails,conds) {
|
||||
return function(expr) {
|
||||
conds[0] += 1;
|
||||
fails[0] += expr ? 0 : 1;
|
||||
var conds = 0;
|
||||
var fails = 0;
|
||||
var qualify = 0;
|
||||
var testprop = function(expr) {
|
||||
conds += 1;
|
||||
fails += expr ? 0 : 1;
|
||||
return expr;
|
||||
};
|
||||
})(fails,conds);
|
||||
var _g2 = 0;
|
||||
var _g3 = Reflect.fields(or);
|
||||
while(_g2 < _g3.length) {
|
||||
var k = _g3[_g2];
|
||||
++_g2;
|
||||
var orval = Reflect.field(or,k);
|
||||
if(k != property) {
|
||||
if(this.q[value] != null) {
|
||||
var v = this.q[value];
|
||||
if(v[property] != null) {
|
||||
return v[property];
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(this.q);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var qval = Reflect.field(this.q,k);
|
||||
if(typeof(value) == "string") {
|
||||
continue;
|
||||
}
|
||||
if(Reflect.field(orval,"=") != null && when(value == Reflect.field(orval,"="))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"=") != null && testprop(value == Reflect.field(qval,"="))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"*") != null && when(value != null)) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"*") != null && testprop(value != null)) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,">") != null && when(value > Std.parseInt(Reflect.field(orval,">")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,">") != null && testprop(value > parseFloat(Reflect.field(qval,">")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"<") != null && when(value < Std.parseInt(Reflect.field(orval,"<")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"<") != null && testprop(value < parseFloat(Reflect.field(qval,"<")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,">=") != null && when(value >= Std.parseInt(Reflect.field(orval,">=")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,">=") != null && testprop(value >= parseFloat(Reflect.field(qval,">=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"<=") != null && when(value >= Std.parseInt(Reflect.field(orval,"<=")))) {
|
||||
++pass;
|
||||
if(Reflect.field(qval,"<=") != null && testprop(value >= parseFloat(Reflect.field(qval,"<=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(orval,"!=") != null && when(value != Std.parseInt(Reflect.field(orval,"!=")))) {
|
||||
++pass;
|
||||
}
|
||||
}
|
||||
if(this.accept && conds[0] > 0 && fails[0] > 0) {
|
||||
this.accept = false;
|
||||
}
|
||||
if(conds[0] > 0 && pass > 0 && fails[0] == 0) {
|
||||
this.accept = true;
|
||||
if(Reflect.field(qval,"!=") != null && testprop(value != parseFloat(Reflect.field(qval,"!=")))) {
|
||||
++qualify;
|
||||
}
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
};
|
||||
var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() {
|
||||
|
|
|
|||
|
|
@ -325,6 +325,53 @@ class Bool: pass
|
|||
class Dynamic: pass
|
||||
|
||||
|
||||
class StringTools:
|
||||
_hx_class_name = "StringTools"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["isSpace", "ltrim", "rtrim", "trim", "replace"]
|
||||
|
||||
@staticmethod
|
||||
def isSpace(s,pos):
|
||||
if (((len(s) == 0) or ((pos < 0))) or ((pos >= len(s)))):
|
||||
return False
|
||||
c = HxString.charCodeAt(s,pos)
|
||||
if (not (((c > 8) and ((c < 14))))):
|
||||
return (c == 32)
|
||||
else:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def ltrim(s):
|
||||
l = len(s)
|
||||
r = 0
|
||||
while ((r < l) and StringTools.isSpace(s,r)):
|
||||
r = (r + 1)
|
||||
if (r > 0):
|
||||
return HxString.substr(s,r,(l - r))
|
||||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def rtrim(s):
|
||||
l = len(s)
|
||||
r = 0
|
||||
while ((r < l) and StringTools.isSpace(s,((l - r) - 1))):
|
||||
r = (r + 1)
|
||||
if (r > 0):
|
||||
return HxString.substr(s,0,(l - r))
|
||||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def trim(s):
|
||||
return StringTools.ltrim(StringTools.rtrim(s))
|
||||
|
||||
@staticmethod
|
||||
def replace(s,sub,by):
|
||||
_this = (list(s) if ((sub == "")) else s.split(sub))
|
||||
return by.join([python_Boot.toString1(x1,'') for x1 in _this])
|
||||
|
||||
|
||||
class Test:
|
||||
_hx_class_name = "Test"
|
||||
__slots__ = ()
|
||||
|
|
@ -332,8 +379,9 @@ class Test:
|
|||
|
||||
@staticmethod
|
||||
def main():
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "selected", 'input': "foo", 'out': True}), 'data': "foo or bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "selected", 'input': "xxx", 'out': False}), 'label': "nonselected entity", 'data': "foo or bar"})])
|
||||
Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.string", 'input': "bar", 'out': "flop"}), 'data': "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "a", 'out': "1.22.2"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#bar=flop&a=1.2,2.2&b=c|d|1,2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.multi", 'input': "b", 'out': "c|d|1,2,3"}), 'label': "b equal.multi", 'data': "http://foo.com?foo=1#b=c|d|1,2,3"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "bar"], 'out': True}), 'data': "class:bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "bar"], 'out': True}), 'label': ".bar shorthand", 'data': ".bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': False}), 'data': ".bar -.foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'data': ".bar -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "bar"], 'out': True}), 'data': ".bar -.bar .bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["id", "foo"], 'out': True}), 'label': "id:foo?", 'data': "foo -foo foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["id", "foo"], 'out': False}), 'label': "!id:foo", 'data': ".foo -.foo .foo"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["price", "10"], 'out': True}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["price", "10"], 'out': False}), 'data': "price:>=15"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["price", "4"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': ["price", "0"], 'out': False}), 'data': "price:>=5"})])
|
||||
|
||||
@staticmethod
|
||||
def test(spec):
|
||||
|
|
@ -352,8 +400,8 @@ class Test:
|
|||
q = xrfragment_Query(Reflect.field(item,"data"))
|
||||
if (Reflect.field(item,"fn") == "url"):
|
||||
res = xrfragment_Url.parse(Reflect.field(item,"data"))
|
||||
if (Reflect.field(Reflect.field(item,"expect"),"fn") == "selected"):
|
||||
valid = (Reflect.field(Reflect.field(item,"expect"),"out") == q.selected(Reflect.field(Reflect.field(item,"expect"),"input")))
|
||||
if (Reflect.field(Reflect.field(item,"expect"),"fn") == "test"):
|
||||
valid = (Reflect.field(Reflect.field(item,"expect"),"out") == q.test(HxOverrides.arrayGet(Reflect.field(Reflect.field(item,"expect"),"input"), 0),HxOverrides.arrayGet(Reflect.field(Reflect.field(item,"expect"),"input"), 1)))
|
||||
if (Reflect.field(Reflect.field(item,"expect"),"fn") == "equal.string"):
|
||||
valid = HxOverrides.eq(Reflect.field(Reflect.field(item,"expect"),"out"),Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"string"))
|
||||
if (Reflect.field(Reflect.field(item,"expect"),"fn") == "equal.xy"):
|
||||
|
|
@ -965,7 +1013,7 @@ class python_HaxeIterator:
|
|||
class python_internal_ArrayImpl:
|
||||
_hx_class_name = "python.internal.ArrayImpl"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["get_length", "concat", "copy", "iterator", "keyValueIterator", "indexOf", "lastIndexOf", "join", "toString", "pop", "push", "unshift", "remove", "contains", "shift", "slice", "sort", "splice", "map", "filter", "insert", "reverse", "_get", "_set"]
|
||||
_hx_statics = ["get_length", "concat", "copy", "iterator", "keyValueIterator", "indexOf", "lastIndexOf", "join", "toString", "pop", "push", "unshift", "remove", "contains", "shift", "slice", "sort", "splice", "map", "filter", "insert", "reverse", "_get"]
|
||||
|
||||
@staticmethod
|
||||
def get_length(x):
|
||||
|
|
@ -1101,23 +1149,11 @@ class python_internal_ArrayImpl:
|
|||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _set(x,idx,v):
|
||||
l = len(x)
|
||||
while (l < idx):
|
||||
x.append(None)
|
||||
l = (l + 1)
|
||||
if (l == idx):
|
||||
x.append(v)
|
||||
else:
|
||||
x[idx] = v
|
||||
return v
|
||||
|
||||
|
||||
class HxOverrides:
|
||||
_hx_class_name = "HxOverrides"
|
||||
__slots__ = ()
|
||||
_hx_statics = ["eq", "stringOrNull", "push", "length", "arrayGet"]
|
||||
_hx_statics = ["eq", "stringOrNull", "length", "arrayGet"]
|
||||
|
||||
@staticmethod
|
||||
def eq(a,b):
|
||||
|
|
@ -1132,14 +1168,6 @@ class HxOverrides:
|
|||
else:
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def push(x,e):
|
||||
if isinstance(x,list):
|
||||
_this = x
|
||||
_this.append(e)
|
||||
return len(_this)
|
||||
return x.push(e)
|
||||
|
||||
@staticmethod
|
||||
def length(x):
|
||||
if isinstance(x,str):
|
||||
|
|
@ -1291,15 +1319,13 @@ class HxString:
|
|||
|
||||
class xrfragment_Query:
|
||||
_hx_class_name = "xrfragment.Query"
|
||||
__slots__ = ("str", "q", "include", "exclude", "accept", "preset")
|
||||
_hx_fields = ["str", "q", "include", "exclude", "accept", "preset"]
|
||||
_hx_methods = ["toObject", "selected", "parse", "test"]
|
||||
__slots__ = ("str", "q", "isProp", "isExclude")
|
||||
_hx_fields = ["str", "q", "isProp", "isExclude"]
|
||||
_hx_methods = ["toObject", "expandAliases", "parse", "test"]
|
||||
|
||||
def __init__(self,_hx_str):
|
||||
self.preset = ""
|
||||
self.accept = False
|
||||
self.exclude = list()
|
||||
self.include = list()
|
||||
self.isExclude = EReg("^-","")
|
||||
self.isProp = EReg("^.*:[><=!]?","")
|
||||
self.q = _hx_AnonObject({})
|
||||
self.str = ""
|
||||
if (_hx_str is not None):
|
||||
|
|
@ -1308,182 +1334,122 @@ class xrfragment_Query:
|
|||
def toObject(self):
|
||||
return self.q
|
||||
|
||||
def selected(self,nodename):
|
||||
if Reflect.field(self.q,"copy_all"):
|
||||
self.accept = True
|
||||
if (nodename in self.include):
|
||||
self.accept = True
|
||||
if (nodename in self.exclude):
|
||||
self.accept = False
|
||||
return self.accept
|
||||
def expandAliases(self,token):
|
||||
classAlias = EReg("^(-)?\\.","")
|
||||
classAlias.matchObj = python_lib_Re.search(classAlias.pattern,token)
|
||||
if (classAlias.matchObj is not None):
|
||||
return StringTools.replace(token,".","class:")
|
||||
else:
|
||||
return token
|
||||
|
||||
def parse(self,_hx_str,recurse = None):
|
||||
if (recurse is None):
|
||||
recurse = False
|
||||
_gthis = self
|
||||
copyAll = (Reflect.field(self.q,"copy_all") if recurse else (((HxString.substr(_hx_str,0,1) == "-") or ((HxString.substr(_hx_str,0,1) == "?"))) or ((_hx_str == ""))))
|
||||
isOr = EReg("^or$","")
|
||||
isProp = EReg(".*:[><=!]?","")
|
||||
isName = EReg("[^:/]","")
|
||||
isExclude = EReg("^-","")
|
||||
isInclude = EReg("^\\+","")
|
||||
isPreset = EReg("^\\?","")
|
||||
token = _hx_str.split(" ")
|
||||
ors = list()
|
||||
q = _hx_AnonObject({})
|
||||
def _hx_local_0():
|
||||
nonlocal q
|
||||
q = _hx_AnonObject({})
|
||||
value = list()
|
||||
setattr(q,(("_hx_" + "object") if (("object" in python_Boot.keywords)) else (("_hx_" + "object") if (((((len("object") > 2) and ((ord("object"[0]) == 95))) and ((ord("object"[1]) == 95))) and ((ord("object"[(len("object") - 1)]) != 95)))) else "object")),value)
|
||||
value = list()
|
||||
setattr(q,(("_hx_" + "-object") if (("-object" in python_Boot.keywords)) else (("_hx_" + "-object") if (((((len("-object") > 2) and ((ord("-object"[0]) == 95))) and ((ord("-object"[1]) == 95))) and ((ord("-object"[(len("-object") - 1)]) != 95)))) else "-object")),value)
|
||||
ors.append(q)
|
||||
return q
|
||||
composeQuery = _hx_local_0
|
||||
composeQuery()
|
||||
match = None
|
||||
def _hx_local_2(_hx_str,prefix = None):
|
||||
def _hx_local_0(_hx_str,prefix = None):
|
||||
if (prefix is None):
|
||||
prefix = ""
|
||||
isPreset.matchObj = python_lib_Re.search(isPreset.pattern,_hx_str)
|
||||
if ((isPreset.matchObj is not None) and (not recurse)):
|
||||
_gthis.preset = _hx_str
|
||||
return
|
||||
match1 = None
|
||||
isExclude.matchObj = python_lib_Re.search(isExclude.pattern,_hx_str)
|
||||
if (isExclude.matchObj is None):
|
||||
isInclude.matchObj = python_lib_Re.search(isInclude.pattern,_hx_str)
|
||||
match1 = (isInclude.matchObj is not None)
|
||||
else:
|
||||
match1 = True
|
||||
if match1:
|
||||
t = HxString.substr(_hx_str,1,None)
|
||||
match(t,HxString.substr(_hx_str,0,1))
|
||||
return
|
||||
isProp.matchObj = python_lib_Re.search(isProp.pattern,_hx_str)
|
||||
if (isProp.matchObj is not None):
|
||||
skip = 0
|
||||
_hx_type = "="
|
||||
_hx_str = StringTools.trim(_hx_str)
|
||||
value = _hx_AnonObject({})
|
||||
_this = _gthis.isProp
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
if (_this.matchObj is not None):
|
||||
oper = ""
|
||||
startIndex = None
|
||||
if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1):
|
||||
_hx_type = "*"
|
||||
oper = "*"
|
||||
startIndex = None
|
||||
if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1):
|
||||
_hx_type = ">"
|
||||
oper = ">"
|
||||
startIndex = None
|
||||
if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1):
|
||||
_hx_type = "<"
|
||||
oper = "<"
|
||||
startIndex = None
|
||||
if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1):
|
||||
_hx_type = "!="
|
||||
oper = "!="
|
||||
startIndex = None
|
||||
if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1):
|
||||
_hx_type = ">="
|
||||
oper = ">="
|
||||
startIndex = None
|
||||
if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1):
|
||||
_hx_type = "<="
|
||||
if (_hx_type != "="):
|
||||
skip = (skip + len(_hx_type))
|
||||
property = HxOverrides.arrayGet(_hx_str.split(":"), 0)
|
||||
value = None
|
||||
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))):
|
||||
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property)))
|
||||
oper = "<="
|
||||
k = HxOverrides.arrayGet(_hx_str.split(":"), 0)
|
||||
v = HxOverrides.arrayGet(_hx_str.split(":"), 1)
|
||||
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k))):
|
||||
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k)))
|
||||
if (len(oper) > 0):
|
||||
value1 = Std.parseFloat(HxString.substr(v,len(oper),None))
|
||||
setattr(value,(("_hx_" + oper) if ((oper in python_Boot.keywords)) else (("_hx_" + oper) if (((((len(oper) > 2) and ((ord(oper[0]) == 95))) and ((ord(oper[1]) == 95))) and ((ord(oper[(len(oper) - 1)]) != 95)))) else oper)),value1)
|
||||
setattr(q,(("_hx_" + k) if ((k in python_Boot.keywords)) else (("_hx_" + k) if (((((len(k) > 2) and ((ord(k[0]) == 95))) and ((ord(k[1]) == 95))) and ((ord(k[(len(k) - 1)]) != 95)))) else k)),value)
|
||||
else:
|
||||
value = _hx_AnonObject({})
|
||||
value1 = HxString.substr(HxOverrides.arrayGet(_hx_str.split(":"), 1),skip,None)
|
||||
setattr(value,(("_hx_" + _hx_type) if ((_hx_type in python_Boot.keywords)) else (("_hx_" + _hx_type) if (((((len(_hx_type) > 2) and ((ord(_hx_type[0]) == 95))) and ((ord(_hx_type[1]) == 95))) and ((ord(_hx_type[(len(_hx_type) - 1)]) != 95)))) else _hx_type)),value1)
|
||||
key = (("null" if prefix is None else prefix) + ("null" if property is None else property))
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,k)
|
||||
key = (("null" if prefix is None else prefix) + HxOverrides.stringOrNull(((HxString.substr(k,1,None) if ((_this.matchObj is not None)) else k))))
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,k)
|
||||
value1 = ((_this.matchObj is not None) == False)
|
||||
setattr(value,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
setattr(q,(("_hx_" + v) if ((v in python_Boot.keywords)) else (("_hx_" + v) if (((((len(v) > 2) and ((ord(v[0]) == 95))) and ((ord(v[1]) == 95))) and ((ord(v[(len(v) - 1)]) != 95)))) else v)),value)
|
||||
return
|
||||
else:
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
value1 = (False if ((_this.matchObj is not None)) else True)
|
||||
setattr(value,(("_hx_" + "id") if (("id" in python_Boot.keywords)) else (("_hx_" + "id") if (((((len("id") > 2) and ((ord("id"[0]) == 95))) and ((ord("id"[1]) == 95))) and ((ord("id"[(len("id") - 1)]) != 95)))) else "id")),value1)
|
||||
_this = _gthis.isExclude
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
|
||||
key = (HxString.substr(_hx_str,1,None) if ((_this.matchObj is not None)) else _hx_str)
|
||||
setattr(q,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value)
|
||||
return
|
||||
isName.matchObj = python_lib_Re.search(isName.pattern,_hx_str)
|
||||
if (isName.matchObj is not None):
|
||||
if (prefix == "-"):
|
||||
Reflect.field(Reflect.field(q,"-object"),"push")(_hx_str)
|
||||
while (Reflect.field(Reflect.field(q,"object"),"contains")(_hx_str) == True):
|
||||
Reflect.field(Reflect.field(q,"object"),"remove")(_hx_str)
|
||||
else:
|
||||
Reflect.field(Reflect.field(q,"object"),"push")(_hx_str)
|
||||
while (Reflect.field(Reflect.field(q,"-object"),"contains")(_hx_str) == True):
|
||||
Reflect.field(Reflect.field(q,"-object"),"remove")(_hx_str)
|
||||
return
|
||||
match = _hx_local_2
|
||||
process = _hx_local_0
|
||||
_g = 0
|
||||
_g1 = len(token)
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
isOr.matchObj = python_lib_Re.search(isOr.pattern,(token[i] if i >= 0 and i < len(token) else None))
|
||||
if (isOr.matchObj is not None):
|
||||
composeQuery()
|
||||
else:
|
||||
match((token[i] if i >= 0 and i < len(token) else None))
|
||||
_g = 0
|
||||
_g1 = len(ors)
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
_hx_or = (ors[i] if i >= 0 and i < len(ors) else None)
|
||||
if (Reflect.field(_hx_or,"object") is not None):
|
||||
self.include = (self.include + Reflect.field(_hx_or,"object"))
|
||||
if (Reflect.field(_hx_or,"-object") is not None):
|
||||
self.exclude = (self.exclude + Reflect.field(_hx_or,"-object"))
|
||||
self.q = _hx_AnonObject({'_hx_or': ors, 'copy_all': copyAll})
|
||||
process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None)))
|
||||
self.q = q
|
||||
return self.q
|
||||
|
||||
def test(self,property,value = None):
|
||||
if (self.preset == property):
|
||||
self.parse(value,True)
|
||||
_g = 0
|
||||
_g1 = Reflect.field(Reflect.field(self.q,"or"),"length")
|
||||
while (_g < _g1):
|
||||
i = _g
|
||||
_g = (_g + 1)
|
||||
_hx_or = HxOverrides.arrayGet(Reflect.field(self.q,"or"), i)
|
||||
conds = [0]
|
||||
fails = [0]
|
||||
_hx_pass = 0
|
||||
def _hx_local_7(fails,conds):
|
||||
def _hx_local_0(expr):
|
||||
_hx_local_1 = conds
|
||||
_hx_local_2 = 0
|
||||
_hx_local_3 = (_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None)
|
||||
python_internal_ArrayImpl._set(_hx_local_1, _hx_local_2, (_hx_local_3 + 1))
|
||||
(_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None)
|
||||
_hx_local_4 = fails
|
||||
_hx_local_5 = 0
|
||||
_hx_local_6 = (_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None)
|
||||
python_internal_ArrayImpl._set(_hx_local_4, _hx_local_5, (_hx_local_6 + (0 if expr else 1)))
|
||||
(_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None)
|
||||
conds = 0
|
||||
fails = 0
|
||||
qualify = 0
|
||||
def _hx_local_2(expr):
|
||||
nonlocal fails
|
||||
nonlocal conds
|
||||
conds = (conds + 1)
|
||||
fails = (fails + (0 if expr else 1))
|
||||
return expr
|
||||
return _hx_local_0
|
||||
when = _hx_local_7(fails,conds)
|
||||
_g2 = 0
|
||||
_g3 = python_Boot.fields(_hx_or)
|
||||
while (_g2 < len(_g3)):
|
||||
k = (_g3[_g2] if _g2 >= 0 and _g2 < len(_g3) else None)
|
||||
_g2 = (_g2 + 1)
|
||||
orval = Reflect.field(_hx_or,k)
|
||||
if (k != property):
|
||||
testprop = _hx_local_2
|
||||
if (Reflect.field(self.q,value) is not None):
|
||||
v = Reflect.field(self.q,value)
|
||||
if (Reflect.field(v,property) is not None):
|
||||
return Reflect.field(v,property)
|
||||
_g = 0
|
||||
_g1 = python_Boot.fields(self.q)
|
||||
while (_g < len(_g1)):
|
||||
k = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
|
||||
_g = (_g + 1)
|
||||
qval = Reflect.field(self.q,k)
|
||||
if Std.isOfType(value,str):
|
||||
continue
|
||||
if ((Reflect.field(orval,"=") is not None) and when(HxOverrides.eq(value,Reflect.field(orval,"=")))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"*") is not None) and when((value is not None))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,">") is not None) and when((value > Std.parseInt(Reflect.field(orval,">"))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"<") is not None) and when((value < Std.parseInt(Reflect.field(orval,"<"))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,">=") is not None) and when((value >= Std.parseInt(Reflect.field(orval,">="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"<=") is not None) and when((value >= Std.parseInt(Reflect.field(orval,"<="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((Reflect.field(orval,"!=") is not None) and when((value != Std.parseInt(Reflect.field(orval,"!="))))):
|
||||
_hx_pass = (_hx_pass + 1)
|
||||
if ((self.accept and (((conds[0] if 0 < len(conds) else None) > 0))) and (((fails[0] if 0 < len(fails) else None) > 0))):
|
||||
self.accept = False
|
||||
if ((((conds[0] if 0 < len(conds) else None) > 0) and ((_hx_pass > 0))) and (((fails[0] if 0 < len(fails) else None) == 0))):
|
||||
self.accept = True
|
||||
if ((Reflect.field(qval,"=") is not None) and testprop(HxOverrides.eq(value,Reflect.field(qval,"=")))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"*") is not None) and testprop((value is not None))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,">") is not None) and testprop((value > Std.parseFloat(Reflect.field(qval,">"))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"<") is not None) and testprop((value < Std.parseFloat(Reflect.field(qval,"<"))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,">=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,">="))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"<=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,"<="))))):
|
||||
qualify = (qualify + 1)
|
||||
if ((Reflect.field(qval,"!=") is not None) and testprop((value != Std.parseFloat(Reflect.field(qval,"!="))))):
|
||||
qualify = (qualify + 1)
|
||||
return (qualify > 0)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue