simplified parser

This commit is contained in:
Leon van Kammen 2023-03-21 17:57:54 +01:00
parent bc6ea7c39c
commit 2ba75d2caf
11 changed files with 917 additions and 1104 deletions

3
.vimrc
View file

@ -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>

255
dist/xrfragment.js vendored
View file

@ -20,6 +20,13 @@ EReg.prototype = {
} }
}; };
var HxOverrides = function() { }; 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) { HxOverrides.substr = function(s,pos,len) {
if(len == null) { if(len == null) {
len = s.length; len = s.length;
@ -76,6 +83,41 @@ Std.parseInt = function(x) {
} }
return null; 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) { var haxe_iterators_ArrayIterator = function(array) {
this.current = 0; this.current = 0;
this.array = array; this.array = array;
@ -89,195 +131,130 @@ haxe_iterators_ArrayIterator.prototype = {
} }
}; };
var xrfragment_Query = function(str) { var xrfragment_Query = function(str) {
this.preset = ""; this.isExclude = new EReg("^-","");
this.accept = false; this.isProp = new EReg("^.*:[><=!]?","");
this.exclude = [];
this.include = [];
this.q = { }; this.q = { };
if(str != null) { if(str != null) {
this.parse(str); this.parse(str);
} }
}; };
xrfragment_Query.prototype = { xrfragment_Query.prototype = {
selected: function(nodename) { expandAliases: function(token) {
if(this.q.copy_all) { var classAlias = new EReg("^(-)?\\.","");
this.accept = true; 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) { ,parse: function(str,recurse) {
if(recurse == null) { if(recurse == null) {
recurse = false; recurse = false;
} }
var _gthis = this; 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 token = str.split(" ");
var ors = [];
var q = { }; var q = { };
var composeQuery = function() { var process = function(str,prefix) {
q = { };
var value = [];
q["object"] = value;
var value = [];
q["-object"] = value;
ors.push(q);
return q;
};
composeQuery();
var match = null;
match = function(str,prefix) {
if(prefix == null) { if(prefix == null) {
prefix = ""; prefix = "";
} }
if(isPreset.match(str) && !recurse) { str = StringTools.trim(str);
_gthis.preset = str; var value = { };
return; if(_gthis.isProp.match(str)) {
} var oper = "";
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 = "=";
if(str.indexOf("*") != -1) { if(str.indexOf("*") != -1) {
type = "*"; oper = "*";
} }
if(str.indexOf(">") != -1) { if(str.indexOf(">") != -1) {
type = ">"; oper = ">";
} }
if(str.indexOf("<") != -1) { if(str.indexOf("<") != -1) {
type = "<"; oper = "<";
} }
if(str.indexOf("!=") != -1) { if(str.indexOf("!=") != -1) {
type = "!="; oper = "!=";
} }
if(str.indexOf(">=") != -1) { if(str.indexOf(">=") != -1) {
type = ">="; oper = ">=";
} }
if(str.indexOf("<=") != -1) { if(str.indexOf("<=") != -1) {
type = "<="; oper = "<=";
} }
if(type != "=") { var k = str.split(":")[0];
skip += type.length; var v = str.split(":")[1];
if(q[prefix + k]) {
value = q[prefix + k];
} }
var property = str.split(":")[0]; if(oper.length > 0) {
var value; value[oper] = parseFloat(HxOverrides.substr(v,oper.length,null));
if(q[prefix + property]) { q[k] = value;
value = q[prefix + property];
} else { } else {
value = { }; value[prefix + (_gthis.isExclude.match(k) ? HxOverrides.substr(k,1,null) : k)] = _gthis.isExclude.match(k) == false;
} q[v] = 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);
} }
return; 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 _g = 0;
var _g1 = token.length; var _g1 = token.length;
while(_g < _g1) { while(_g < _g1) {
var i = _g++; var i = _g++;
if(isOr.match(token[i])) { process(this.expandAliases(token[i]));
composeQuery();
} else {
match(token[i]);
}
} }
var _g = 0; this.q = q;
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};
return this.q; return this.q;
} }
,test: function(property,value) { ,test: function(property,value) {
if(this.preset == property) { var conds = 0;
this.parse(value,true); var fails = 0;
var qualify = 0;
var testprop = function(expr) {
conds += 1;
fails += expr ? 0 : 1;
return expr;
};
if(this.q[value] != null) {
var v = this.q[value];
if(v[property] != null) {
return v[property];
}
} }
var _g = 0; var _g = 0;
var _g1 = this.q.or.length; var _g1 = Reflect.fields(this.q);
while(_g < _g1) { while(_g < _g1.length) {
var i = _g++; var k = _g1[_g];
var or = this.q.or[i]; ++_g;
var conds = [0]; var qval = Reflect.field(this.q,k);
var fails = [0]; if(typeof(value) == "string") {
var pass = 0; continue;
var when = (function(fails,conds) {
return function(expr) {
conds[0] += 1;
fails[0] += 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) {
continue;
}
if(Reflect.field(orval,"=") != null && when(value == Reflect.field(orval,"="))) {
++pass;
}
if(Reflect.field(orval,"*") != null && when(value != null)) {
++pass;
}
if(Reflect.field(orval,">") != null && when(value > Std.parseInt(Reflect.field(orval,">")))) {
++pass;
}
if(Reflect.field(orval,"<") != null && when(value < Std.parseInt(Reflect.field(orval,"<")))) {
++pass;
}
if(Reflect.field(orval,">=") != null && when(value >= Std.parseInt(Reflect.field(orval,">=")))) {
++pass;
}
if(Reflect.field(orval,"<=") != null && when(value >= Std.parseInt(Reflect.field(orval,"<=")))) {
++pass;
}
if(Reflect.field(orval,"!=") != null && when(value != Std.parseInt(Reflect.field(orval,"!=")))) {
++pass;
}
} }
if(this.accept && conds[0] > 0 && fails[0] > 0) { if(Reflect.field(qval,"=") != null && testprop(value == Reflect.field(qval,"="))) {
this.accept = false; ++qualify;
} }
if(conds[0] > 0 && pass > 0 && fails[0] == 0) { if(Reflect.field(qval,"*") != null && testprop(value != null)) {
this.accept = true; ++qualify;
}
if(Reflect.field(qval,">") != null && testprop(value > parseFloat(Reflect.field(qval,">")))) {
++qualify;
}
if(Reflect.field(qval,"<") != null && testprop(value < parseFloat(Reflect.field(qval,"<")))) {
++qualify;
}
if(Reflect.field(qval,">=") != null && testprop(value >= parseFloat(Reflect.field(qval,">=")))) {
++qualify;
}
if(Reflect.field(qval,"<=") != null && testprop(value >= parseFloat(Reflect.field(qval,"<=")))) {
++qualify;
}
if(Reflect.field(qval,"!=") != null && testprop(value != parseFloat(Reflect.field(qval,"!=")))) {
++qualify;
} }
} }
return qualify > 0;
} }
}; };
var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() { var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() {

568
dist/xrfragment.lua vendored
View file

@ -204,6 +204,7 @@ local Math = _hx_e()
local Reflect = _hx_e() local Reflect = _hx_e()
local String = _hx_e() local String = _hx_e()
local Std = _hx_e() local Std = _hx_e()
local StringTools = _hx_e()
__haxe_Exception = _hx_e() __haxe_Exception = _hx_e()
__haxe_NativeStackTrace = _hx_e() __haxe_NativeStackTrace = _hx_e()
__haxe_ValueException = _hx_e() __haxe_ValueException = _hx_e()
@ -832,55 +833,156 @@ Std.int = function(x)
do return _hx_bit_clamp(x) end; do return _hx_bit_clamp(x) end;
end; end;
end end
Std.parseInt = function(x) Std.parseFloat = function(x)
if (x == nil) then if ((x == nil) or (x == "")) then
do return nil end; do return (0/0) end;
end; end;
local hexMatch = _G.string.match(x, "^[ \t\r\n]*([%-+]*0[xX][%da-fA-F]*)"); local digitMatch = _G.string.match(x, "^ *[%.%-+]?[0-9]%d*");
if (hexMatch ~= nil) then if (digitMatch == nil) then
local sign; do return (0/0) end;
local _g = __lua_lib_luautf8_Utf8.byte(hexMatch, 1); end;
if (_g) == 43 then local pos = __lua_lib_luautf8_Utf8.len(digitMatch);
sign = 1; local len = nil;
elseif (_g) == 45 then if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(x)))) then
sign = -1;else len = __lua_lib_luautf8_Utf8.len(x);
sign = 0; end; else
local pos = (function() if (len < 0) then
local _hx_1 len = __lua_lib_luautf8_Utf8.len(x) + len;
if (sign == 0) then end;
_hx_1 = 2; else end;
_hx_1 = 3; end if (pos < 0) then
return _hx_1 pos = __lua_lib_luautf8_Utf8.len(x) + pos;
end )(); end;
local len = nil; if (pos < 0) then
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(hexMatch)))) then pos = 0;
len = __lua_lib_luautf8_Utf8.len(hexMatch); 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
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 else
if (len < 0) then if (len < 0) then
len = __lua_lib_luautf8_Utf8.len(hexMatch) + len; len = __lua_lib_luautf8_Utf8.len(s) + len;
end; end;
end; end;
if (pos < 0) then if (pos < 0) then
pos = __lua_lib_luautf8_Utf8.len(hexMatch) + pos; pos = __lua_lib_luautf8_Utf8.len(s) + pos;
end; end;
if (pos < 0) then if (pos < 0) then
pos = 0; pos = 0;
end; end;
do return (function() do return __lua_lib_luautf8_Utf8.sub(s, pos + 1, pos + len) end;
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;
else else
local intMatch = _G.string.match(x, "^ *[%-+]?%d*"); do return s end;
if (intMatch ~= nil) then end;
do return _G.tonumber(intMatch) 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 else
do return nil end; 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;
end; end;
do return ret:join(by) end;
end end
__haxe_Exception.new = function(message,previous,native) __haxe_Exception.new = function(message,previous,native)
@ -1132,10 +1234,8 @@ __xrfragment_Query.new = function(str)
return self return self
end end
__xrfragment_Query.super = function(self,str) __xrfragment_Query.super = function(self,str)
self.preset = ""; self.isExclude = EReg.new("^-", "");
self.accept = false; self.isProp = EReg.new("^.*:[><=!]?", "");
self.exclude = Array.new();
self.include = Array.new();
self.q = _hx_e(); self.q = _hx_e();
self.str = ""; self.str = "";
if (str ~= nil) then if (str ~= nil) then
@ -1148,71 +1248,19 @@ __xrfragment_Query.prototype = _hx_e();
__xrfragment_Query.prototype.toObject = function(self) __xrfragment_Query.prototype.toObject = function(self)
do return self.q end do return self.q end
end end
__xrfragment_Query.prototype.selected = function(self,nodename) __xrfragment_Query.prototype.expandAliases = function(self,token)
if (self.q.copy_all) then local classAlias = EReg.new("^(-)?\\.", "");
self.accept = true; if (classAlias:match(token)) then
do return StringTools.replace(token, ".", "class:") end;
else
do return token end;
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 end
__xrfragment_Query.prototype.parse = function(self,str,recurse) __xrfragment_Query.prototype.parse = function(self,str,recurse)
if (recurse == nil) then if (recurse == nil) then
recurse = false; recurse = false;
end; end;
local _gthis = self; 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 idx = 1;
local ret = _hx_tab_array({}, 0); local ret = _hx_tab_array({}, 0);
while (idx ~= nil) do while (idx ~= nil) do
@ -1236,65 +1284,15 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
end; end;
end; end;
local token = ret; local token = ret;
local ors = Array.new();
local q = _hx_e(); local q = _hx_e();
local composeQuery = function() local process = function(str,prefix)
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)
if (prefix == nil) then if (prefix == nil) then
prefix = ""; prefix = "";
end; end;
if (isPreset:match(str) and not recurse) then str = StringTools.trim(str);
_gthis.preset = str; local value = _hx_e();
do return end; if (_gthis.isProp:match(str)) then
end; local oper = "";
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 = "=";
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
startIndex = 1; startIndex = 1;
@ -1309,7 +1307,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_1 = -1; end _hx_1 = -1; end
return _hx_1 return _hx_1
end )() ~= -1) then end )() ~= -1) then
type = "*"; oper = "*";
end; end;
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
@ -1325,7 +1323,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_2 = -1; end _hx_2 = -1; end
return _hx_2 return _hx_2
end )() ~= -1) then end )() ~= -1) then
type = ">"; oper = ">";
end; end;
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
@ -1341,7 +1339,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_3 = -1; end _hx_3 = -1; end
return _hx_3 return _hx_3
end )() ~= -1) then end )() ~= -1) then
type = "<"; oper = "<";
end; end;
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
@ -1357,7 +1355,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_4 = -1; end _hx_4 = -1; end
return _hx_4 return _hx_4
end )() ~= -1) then end )() ~= -1) then
type = "!="; oper = "!=";
end; end;
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
@ -1373,7 +1371,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_5 = -1; end _hx_5 = -1; end
return _hx_5 return _hx_5
end )() ~= -1) then end )() ~= -1) then
type = ">="; oper = ">=";
end; end;
local startIndex = nil; local startIndex = nil;
if (startIndex == nil) then if (startIndex == nil) then
@ -1389,10 +1387,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
_hx_6 = -1; end _hx_6 = -1; end
return _hx_6 return _hx_6
end )() ~= -1) then end )() ~= -1) then
type = "<="; oper = "<=";
end;
if (type ~= "=") then
skip = skip + __lua_lib_luautf8_Utf8.len(type);
end; end;
local idx = 1; local idx = 1;
local ret = _hx_tab_array({}, 0); local ret = _hx_tab_array({}, 0);
@ -1416,13 +1411,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
idx = nil; idx = nil;
end; end;
end; end;
local property = ret[0]; local k = 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 idx = 1; local idx = 1;
local ret = _hx_tab_array({}, 0); local ret = _hx_tab_array({}, 0);
while (idx ~= nil) do while (idx ~= nil) do
@ -1445,40 +1434,87 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
idx = nil; idx = nil;
end; end;
end; end;
local _this = ret[1]; local v = ret[1];
local pos = skip; if (Reflect.field(q, Std.string(prefix) .. Std.string(k))) then
local len = nil; value = Reflect.field(q, Std.string(prefix) .. Std.string(k));
if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(_this)))) then end;
len = __lua_lib_luautf8_Utf8.len(_this); 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(v)))) then
len = __lua_lib_luautf8_Utf8.len(v);
else
if (len < 0) then
len = __lua_lib_luautf8_Utf8.len(v) + len;
end;
end;
if (pos < 0) then
pos = __lua_lib_luautf8_Utf8.len(v) + pos;
end;
if (pos < 0) then
pos = 0;
end;
local value1 = Std.parseFloat(__lua_lib_luautf8_Utf8.sub(v, pos + 1, pos + len));
value[oper] = value1;
q[k] = value;
else else
if (len < 0) then local key;
len = __lua_lib_luautf8_Utf8.len(_this) + len; if (_gthis.isExclude:match(k)) then
end; local pos = 1;
end; local len = nil;
if (pos < 0) then if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(k)))) then
pos = __lua_lib_luautf8_Utf8.len(_this) + pos; len = __lua_lib_luautf8_Utf8.len(k);
end; else
if (pos < 0) then if (len < 0) then
pos = 0; len = __lua_lib_luautf8_Utf8.len(k) + len;
end; end;
local value1 = __lua_lib_luautf8_Utf8.sub(_this, pos + 1, pos + len); end;
value[type] = value1; if (pos < 0) then
q[Std.string(prefix) .. Std.string(property)] = value; pos = __lua_lib_luautf8_Utf8.len(k) + pos;
do return end; end;
end; if (pos < 0) then
if (isName:match(str)) then pos = 0;
if (prefix == "-") then end;
Reflect.field(q, "-object"):push(str); key = __lua_lib_luautf8_Utf8.sub(k, pos + 1, pos + len);
while (Reflect.field(q, "object"):contains(str) == true) do else
Reflect.field(q, "object"):remove(str); key = k;
end;
else
Reflect.field(q, "object"):push(str);
while (Reflect.field(q, "-object"):contains(str) == true) do
Reflect.field(q, "-object"):remove(str);
end; end;
local value1 = _gthis.isExclude:match(k) == false;
value[Std.string(prefix) .. Std.string(key)] = value1;
q[v] = value;
end; end;
do return 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;
end; end;
local _g = 0; local _g = 0;
@ -1486,102 +1522,70 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse)
while (_g < _g1) do while (_g < _g1) do
_g = _g + 1; _g = _g + 1;
local i = _g - 1; local i = _g - 1;
if (isOr:match(token[i])) then process(self:expandAliases(token[i]));
composeQuery();
else
match(token[i]);
end;
end; end;
local _g = 0; self.q = q;
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});
do return self.q end do return self.q end
end end
__xrfragment_Query.prototype.test = function(self,property,value) __xrfragment_Query.prototype.test = function(self,property,value)
if (self.preset == property) then local conds = 0;
self:parse(value, true); 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
_hx_1 = 1; end
return _hx_1
end )();
do return expr end;
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; end;
local _g = 0; local _g = 0;
local _g1 = _hx_wrap_if_string_field(self.q["or"],'length'); local _g1 = Reflect.fields(self.q);
while (_g < _g1) do local _hx_continue_1 = false;
while (_g < _g1.length) do repeat
local k = _g1[_g];
_g = _g + 1; _g = _g + 1;
local i = _g - 1; local qval = Reflect.field(self.q, k);
local _or = self.q["or"][i]; if (__lua_Boot.__instanceof(value, String)) then
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 _hx_1
if (expr) then
_hx_1 = 0; else
_hx_1 = 1; end
return _hx_1
end )();
do return expr end;
end end;
end)(fails, conds);
local _g = 0;
local _g1 = Reflect.fields(_or);
local _hx_continue_2 = false;
while (_g < _g1.length) do repeat
local k = _g1[_g];
_g = _g + 1;
local orval = Reflect.field(_or, k);
if (k ~= property) then
break;
end;
if ((Reflect.field(orval, "=") ~= nil) and when(value == Reflect.field(orval, "="))) then
pass = pass + 1;
end;
if ((Reflect.field(orval, "*") ~= nil) and when(value ~= nil)) then
pass = pass + 1;
end;
if ((Reflect.field(orval, ">") ~= nil) and when(value > Std.parseInt(Reflect.field(orval, ">")))) then
pass = pass + 1;
end;
if ((Reflect.field(orval, "<") ~= nil) and when(value < Std.parseInt(Reflect.field(orval, "<")))) then
pass = pass + 1;
end;
if ((Reflect.field(orval, ">=") ~= nil) and when(value >= Std.parseInt(Reflect.field(orval, ">=")))) then
pass = pass + 1;
end;
if ((Reflect.field(orval, "<=") ~= nil) and when(value >= Std.parseInt(Reflect.field(orval, "<=")))) then
pass = pass + 1;
end;
if ((Reflect.field(orval, "!=") ~= nil) and when(value ~= Std.parseInt(Reflect.field(orval, "!=")))) then
pass = pass + 1;
end;until true
if _hx_continue_2 then
_hx_continue_2 = false;
break; break;
end;
end; end;
if ((self.accept and (conds[0] > 0)) and (fails[0] > 0)) then if ((Reflect.field(qval, "=") ~= nil) and testprop(value == Reflect.field(qval, "="))) then
self.accept = false; qualify = qualify + 1;
end; end;
if (((conds[0] > 0) and (pass > 0)) and (fails[0] == 0)) then if ((Reflect.field(qval, "*") ~= nil) and testprop(value ~= nil)) then
self.accept = true; qualify = qualify + 1;
end; end;
if ((Reflect.field(qval, ">") ~= nil) and testprop(value > Std.parseFloat(Reflect.field(qval, ">")))) then
qualify = qualify + 1;
end;
if ((Reflect.field(qval, "<") ~= nil) and testprop(value < Std.parseFloat(Reflect.field(qval, "<")))) then
qualify = qualify + 1;
end;
if ((Reflect.field(qval, ">=") ~= nil) and testprop(value >= Std.parseFloat(Reflect.field(qval, ">=")))) then
qualify = qualify + 1;
end;
if ((Reflect.field(qval, "<=") ~= nil) and testprop(value >= Std.parseFloat(Reflect.field(qval, "<=")))) then
qualify = qualify + 1;
end;
if ((Reflect.field(qval, "!=") ~= nil) and testprop(value ~= Std.parseFloat(Reflect.field(qval, "!=")))) then
qualify = qualify + 1;
end;until true
if _hx_continue_1 then
_hx_continue_1 = false;
break;
end;
end; end;
do return qualify > 0 end
end end
__xrfragment_Query.prototype.__class__ = __xrfragment_Query __xrfragment_Query.prototype.__class__ = __xrfragment_Query

417
dist/xrfragment.py vendored
View file

@ -100,7 +100,7 @@ class Reflect:
class Std: class Std:
_hx_class_name = "Std" _hx_class_name = "Std"
__slots__ = () __slots__ = ()
_hx_statics = ["isOfType", "string", "parseInt"] _hx_statics = ["isOfType", "string", "shortenPossibleNumber", "parseFloat"]
@staticmethod @staticmethod
def isOfType(v,t): def isOfType(v,t):
@ -193,70 +193,36 @@ class Std:
return python_Boot.toString1(s,"") return python_Boot.toString1(s,"")
@staticmethod @staticmethod
def parseInt(x): def shortenPossibleNumber(x):
if (x is None): r = ""
return None _g = 0
_g1 = len(x)
while (_g < _g1):
i = _g
_g = (_g + 1)
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:
break
return r
@staticmethod
def parseFloat(x):
try: try:
return int(x) return float(x)
except BaseException as _g: except BaseException as _g:
None None
base = 10 if (x is not None):
_hx_len = len(x) r1 = Std.shortenPossibleNumber(x)
foundCount = 0 if (r1 != x):
sign = 0 return Std.parseFloat(r1)
firstDigitIndex = 0 return Math.NaN
lastDigitIndex = -1
previous = 0
_g = 0
_g1 = _hx_len
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
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))
try:
return (((-1 if ((sign == -1)) else 1)) * int(digits,base))
except BaseException as _g:
return None
return None
class Float: pass class Float: pass
@ -271,6 +237,53 @@ class Bool: pass
class Dynamic: 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): class haxe_Exception(Exception):
_hx_class_name = "haxe.Exception" _hx_class_name = "haxe.Exception"
__slots__ = ("_hx___nativeStack", "_hx___nativeException", "_hx___previousException") __slots__ = ("_hx___nativeStack", "_hx___nativeException", "_hx___previousException")
@ -855,11 +868,7 @@ class python_HaxeIterator:
class python_internal_ArrayImpl: class python_internal_ArrayImpl:
_hx_class_name = "python.internal.ArrayImpl" _hx_class_name = "python.internal.ArrayImpl"
__slots__ = () __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 = ["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):
return len(x)
@staticmethod @staticmethod
def concat(a1,a2): def concat(a1,a2):
@ -991,23 +1000,11 @@ class python_internal_ArrayImpl:
else: else:
return None 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: class HxOverrides:
_hx_class_name = "HxOverrides" _hx_class_name = "HxOverrides"
__slots__ = () __slots__ = ()
_hx_statics = ["eq", "stringOrNull", "push", "length", "arrayGet"] _hx_statics = ["eq", "stringOrNull", "arrayGet"]
@staticmethod @staticmethod
def eq(a,b): def eq(a,b):
@ -1022,22 +1019,6 @@ class HxOverrides:
else: else:
return s 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 @staticmethod
def arrayGet(a,i): def arrayGet(a,i):
if isinstance(a,list): if isinstance(a,list):
@ -1068,7 +1049,7 @@ class python_internal_MethodClosure:
class HxString: class HxString:
_hx_class_name = "HxString" _hx_class_name = "HxString"
__slots__ = () __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 @staticmethod
def split(s,d): def split(s,d):
@ -1147,10 +1128,6 @@ class HxString:
def toString(s): def toString(s):
return s return s
@staticmethod
def get_length(s):
return len(s)
@staticmethod @staticmethod
def substring(s,startIndex,endIndex = None): def substring(s,startIndex,endIndex = None):
if (startIndex < 0): if (startIndex < 0):
@ -1181,15 +1158,13 @@ class HxString:
class xrfragment_Query: class xrfragment_Query:
_hx_class_name = "xrfragment.Query" _hx_class_name = "xrfragment.Query"
__slots__ = ("str", "q", "include", "exclude", "accept", "preset") __slots__ = ("str", "q", "isProp", "isExclude")
_hx_fields = ["str", "q", "include", "exclude", "accept", "preset"] _hx_fields = ["str", "q", "isProp", "isExclude"]
_hx_methods = ["toObject", "selected", "parse", "test"] _hx_methods = ["toObject", "expandAliases", "parse", "test"]
def __init__(self,_hx_str): def __init__(self,_hx_str):
self.preset = "" self.isExclude = EReg("^-","")
self.accept = False self.isProp = EReg("^.*:[><=!]?","")
self.exclude = list()
self.include = list()
self.q = _hx_AnonObject({}) self.q = _hx_AnonObject({})
self.str = "" self.str = ""
if (_hx_str is not None): if (_hx_str is not None):
@ -1198,182 +1173,122 @@ class xrfragment_Query:
def toObject(self): def toObject(self):
return self.q return self.q
def selected(self,nodename): def expandAliases(self,token):
if Reflect.field(self.q,"copy_all"): classAlias = EReg("^(-)?\\.","")
self.accept = True classAlias.matchObj = python_lib_Re.search(classAlias.pattern,token)
if (nodename in self.include): if (classAlias.matchObj is not None):
self.accept = True return StringTools.replace(token,".","class:")
if (nodename in self.exclude): else:
self.accept = False return token
return self.accept
def parse(self,_hx_str,recurse = None): def parse(self,_hx_str,recurse = None):
if (recurse is None): if (recurse is None):
recurse = False recurse = False
_gthis = self _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(" ") token = _hx_str.split(" ")
ors = list()
q = _hx_AnonObject({}) q = _hx_AnonObject({})
def _hx_local_0(): def _hx_local_0(_hx_str,prefix = None):
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):
if (prefix is None): if (prefix is None):
prefix = "" prefix = ""
isPreset.matchObj = python_lib_Re.search(isPreset.pattern,_hx_str) _hx_str = StringTools.trim(_hx_str)
if ((isPreset.matchObj is not None) and (not recurse)): value = _hx_AnonObject({})
_gthis.preset = _hx_str _this = _gthis.isProp
return _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
match1 = None if (_this.matchObj is not None):
isExclude.matchObj = python_lib_Re.search(isExclude.pattern,_hx_str) oper = ""
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 = "="
startIndex = None startIndex = None
if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1): if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1):
_hx_type = "*" oper = "*"
startIndex = None startIndex = None
if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1): if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1):
_hx_type = ">" oper = ">"
startIndex = None startIndex = None
if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1): if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1):
_hx_type = "<" oper = "<"
startIndex = None startIndex = None
if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1): if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1):
_hx_type = "!=" oper = "!="
startIndex = None startIndex = None
if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1): if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1):
_hx_type = ">=" oper = ">="
startIndex = None startIndex = None
if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1): if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1):
_hx_type = "<=" oper = "<="
if (_hx_type != "="): k = HxOverrides.arrayGet(_hx_str.split(":"), 0)
skip = (skip + len(_hx_type)) v = HxOverrides.arrayGet(_hx_str.split(":"), 1)
property = HxOverrides.arrayGet(_hx_str.split(":"), 0) if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k))):
value = None value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k)))
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))): if (len(oper) > 0):
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))) 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: else:
value = _hx_AnonObject({}) _this = _gthis.isExclude
value1 = HxString.substr(HxOverrides.arrayGet(_hx_str.split(":"), 1),skip,None) _this.matchObj = python_lib_Re.search(_this.pattern,k)
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) + HxOverrides.stringOrNull(((HxString.substr(k,1,None) if ((_this.matchObj is not None)) else k))))
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)
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) 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 process = _hx_local_0
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
_g = 0 _g = 0
_g1 = len(token) _g1 = len(token)
while (_g < _g1): while (_g < _g1):
i = _g i = _g
_g = (_g + 1) _g = (_g + 1)
isOr.matchObj = python_lib_Re.search(isOr.pattern,(token[i] if i >= 0 and i < len(token) else None)) process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None)))
if (isOr.matchObj is not None): self.q = q
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})
return self.q return self.q
def test(self,property,value = None): def test(self,property,value = None):
if (self.preset == property): conds = 0
self.parse(value,True) 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
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 _g = 0
_g1 = Reflect.field(Reflect.field(self.q,"or"),"length") _g1 = python_Boot.fields(self.q)
while (_g < _g1): while (_g < len(_g1)):
i = _g k = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
_g = (_g + 1) _g = (_g + 1)
_hx_or = HxOverrides.arrayGet(Reflect.field(self.q,"or"), i) qval = Reflect.field(self.q,k)
conds = [0] if Std.isOfType(value,str):
fails = [0] continue
_hx_pass = 0 if ((Reflect.field(qval,"=") is not None) and testprop(HxOverrides.eq(value,Reflect.field(qval,"=")))):
def _hx_local_7(fails,conds): qualify = (qualify + 1)
def _hx_local_0(expr): if ((Reflect.field(qval,"*") is not None) and testprop((value is not None))):
_hx_local_1 = conds qualify = (qualify + 1)
_hx_local_2 = 0 if ((Reflect.field(qval,">") is not None) and testprop((value > Std.parseFloat(Reflect.field(qval,">"))))):
_hx_local_3 = (_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None) qualify = (qualify + 1)
python_internal_ArrayImpl._set(_hx_local_1, _hx_local_2, (_hx_local_3 + 1)) if ((Reflect.field(qval,"<") is not None) and testprop((value < Std.parseFloat(Reflect.field(qval,"<"))))):
(_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None) qualify = (qualify + 1)
_hx_local_4 = fails if ((Reflect.field(qval,">=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,">="))))):
_hx_local_5 = 0 qualify = (qualify + 1)
_hx_local_6 = (_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None) if ((Reflect.field(qval,"<=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,"<="))))):
python_internal_ArrayImpl._set(_hx_local_4, _hx_local_5, (_hx_local_6 + (0 if expr else 1))) qualify = (qualify + 1)
(_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None) if ((Reflect.field(qval,"!=") is not None) and testprop((value != Std.parseFloat(Reflect.field(qval,"!="))))):
return expr qualify = (qualify + 1)
return _hx_local_0 return (qualify > 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):
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
Math.NEGATIVE_INFINITY = float("-inf") Math.NEGATIVE_INFINITY = float("-inf")

View file

@ -12,8 +12,10 @@ class Spec {
class Test { class Test {
static public function main():Void { 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/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 { static public function test(spec:Array<Dynamic>):Void {
@ -26,7 +28,7 @@ class Test {
var item:Dynamic = spec[i]; var item:Dynamic = spec[i];
if( item.fn == "query" ) q = new Query(item.data); if( item.fn == "query" ) q = new Query(item.data);
if( item.fn == "url" ) res = Url.parse(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.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.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); if( item.expect.fn == "equal.multi" ) valid = equalMulti(res, item);

14
src/spec/query.class.json Normal file
View 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"}
]

View 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}}
]

View file

@ -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"}
]

View file

@ -39,11 +39,9 @@ package xrfragment;
class Query { class Query {
private var str:String = ""; private var str:String = "";
private var q:Dynamic = {}; private var q:haxe.DynamicAccess<Dynamic> = {};
private var include:Array<String> = new Array(); private var isProp:EReg = ~/^.*:[><=!]?/;
private var exclude:Array<String> = new Array(); private var isExclude:EReg = ~/^-/;
private var accept:Bool = false;
private var preset:String = "";
public function new(str:String){ public function new(str:String){
if( str != null ) this.parse(str); if( str != null ) this.parse(str);
@ -53,125 +51,80 @@ class Query {
return this.q; return this.q;
} }
@:keep public function expandAliases(token:String) : String {
public function selected( nodename:String ): Bool { // expand '.foo' to 'class:foo'
if( this.q.copy_all ) this.accept = true; var classAlias = ~/^(-)?\./;
if( this.include.contains(nodename) ) this.accept = true; return classAlias.match(token) ? StringTools.replace(token,".","class:") : token;
if( this.exclude.contains(nodename) ) this.accept = false;
return this.accept;
} }
@:keep
public function parse(str:String,recurse:Bool = false) : Dynamic { 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 token = str.split(" ");
var ors = new Array();
var q:haxe.DynamicAccess<Dynamic> = {}; var q:haxe.DynamicAccess<Dynamic> = {};
function composeQuery() : Dynamic { function process(str,prefix = ""){
q = {}; str = StringTools.trim(str);
q.set("object", new Array() ); var value:haxe.DynamicAccess<Dynamic> = {};
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;
}
if( isProp.match(str) ){ if( isProp.match(str) ){
var skip = 0; var oper:String = "";
var type = "="; if( str.indexOf("*") != -1 ) oper = "*";
if( str.indexOf("*") != -1 ) type = "*"; if( str.indexOf(">") != -1 ) oper = ">";
if( str.indexOf(">") != -1 ) type = ">"; if( str.indexOf("<") != -1 ) oper = "<";
if( str.indexOf("<") != -1 ) type = "<"; if( str.indexOf("!=") != -1 ) oper = "!=";
if( str.indexOf("!=") != -1 ) type = "!="; if( str.indexOf(">=") != -1 ) oper = ">=";
if( str.indexOf(">=") != -1 ) type = ">="; if( str.indexOf("<=") != -1 ) oper = "<=";
if( str.indexOf("<=") != -1 ) type = "<="; var k:String = str.split(":")[0];
if( type != "=" ) skip += type.length; var v:String = str.split(":")[1];
var property = str.split(":")[0]; if( q.get(prefix+k) ) value = q.get(prefix+k);
var value:haxe.DynamicAccess<Dynamic>; if( oper.length > 0 ){
if( q.get(prefix+property) ) value = q.get(prefix+property); value[ oper ] = Std.parseFloat( v.substr(oper.length) );
else value = {}; q.set( k, 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);
}
}else{ }else{
q["object"].push(str); value[ prefix+ (isExclude.match(k) ? k.substr(1) : k) ] = isExclude.match(k) == false;
while( q["-object"].contains(str) == true ){ q.set(v,value);
q["-object"].remove(str);
}
} }
return; 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 ) process( expandAliases(token[i]) );
for( i in 0...token.length ) { this.q = q;
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 };
return this.q; return this.q;
} }
@:keep @:keep
public function test( property:String, ?value:Dynamic ):Void{ public function test( property:String, ?value:Dynamic ):Bool{
if( this.preset == property ){ var conds:Int = 0;
this.parse( value, true ); var fails:Int = 0;
} var qualify:Int = 0;
for ( i in 0...this.q.or.length ) {
var or:Dynamic = this.q.or[i];
var conds:Int = 0;
var fails:Int = 0;
var pass:Int = 0;
var when = function(expr:Bool) : Bool { var testprop = function(expr:Bool) : Bool {
conds+=1; conds+=1;
fails+= expr ? 0 : 1; fails+= expr ? 0 : 1;
return expr; 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;
} }
} }

View file

@ -22,6 +22,13 @@ EReg.prototype = {
}; };
var HxOverrides = function() { }; var HxOverrides = function() { };
HxOverrides.__name__ = true; 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) { HxOverrides.substr = function(s,pos,len) {
if(len == null) { if(len == null) {
len = s.length; len = s.length;
@ -84,11 +91,48 @@ Std.parseInt = function(x) {
} }
return null; 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() { }; var Test = function() { };
Test.__name__ = true; Test.__name__ = true;
Test.main = function() { 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 : "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) { Test.test = function(spec) {
var Query = xrfragment_Query; var Query = xrfragment_Query;
@ -107,8 +151,8 @@ Test.test = function(spec) {
if(item.fn == "url") { if(item.fn == "url") {
res = xrfragment_Url.parse(item.data); res = xrfragment_Url.parse(item.data);
} }
if(item.expect.fn == "selected") { if(item.expect.fn == "test") {
valid = item.expect.out == q.selected(item.expect.input); valid = item.expect.out == q.test(item.expect.input[0],item.expect.input[1]);
} }
if(item.expect.fn == "equal.string") { if(item.expect.fn == "equal.string") {
valid = item.expect.out == res[item.expect.input].string; valid = item.expect.out == res[item.expect.input].string;
@ -120,13 +164,13 @@ Test.test = function(spec) {
valid = Test.equalMulti(res,item); valid = Test.equalMulti(res,item);
} }
var ok = valid ? "[ ✔ ] " : "[ ❌] "; 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) { if(!valid) {
++errors; ++errors;
} }
} }
if(errors > 1) { 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) { Test.equalMulti = function(res,item) {
@ -221,10 +265,8 @@ js_Boot.__string_rec = function(o,s) {
} }
}; };
var xrfragment_Query = function(str) { var xrfragment_Query = function(str) {
this.preset = ""; this.isExclude = new EReg("^-","");
this.accept = false; this.isProp = new EReg("^.*:[><=!]?","");
this.exclude = [];
this.include = [];
this.q = { }; this.q = { };
if(str != null) { if(str != null) {
this.parse(str); this.parse(str);
@ -232,185 +274,122 @@ var xrfragment_Query = function(str) {
}; };
xrfragment_Query.__name__ = true; xrfragment_Query.__name__ = true;
xrfragment_Query.prototype = { xrfragment_Query.prototype = {
selected: function(nodename) { expandAliases: function(token) {
if(this.q.copy_all) { var classAlias = new EReg("^(-)?\\.","");
this.accept = true; 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) { ,parse: function(str,recurse) {
if(recurse == null) { if(recurse == null) {
recurse = false; recurse = false;
} }
var _gthis = this; 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 token = str.split(" ");
var ors = [];
var q = { }; var q = { };
var composeQuery = function() { var process = function(str,prefix) {
q = { };
var value = [];
q["object"] = value;
var value = [];
q["-object"] = value;
ors.push(q);
return q;
};
composeQuery();
var match = null;
match = function(str,prefix) {
if(prefix == null) { if(prefix == null) {
prefix = ""; prefix = "";
} }
if(isPreset.match(str) && !recurse) { str = StringTools.trim(str);
_gthis.preset = str; var value = { };
return; if(_gthis.isProp.match(str)) {
} var oper = "";
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 = "=";
if(str.indexOf("*") != -1) { if(str.indexOf("*") != -1) {
type = "*"; oper = "*";
} }
if(str.indexOf(">") != -1) { if(str.indexOf(">") != -1) {
type = ">"; oper = ">";
} }
if(str.indexOf("<") != -1) { if(str.indexOf("<") != -1) {
type = "<"; oper = "<";
} }
if(str.indexOf("!=") != -1) { if(str.indexOf("!=") != -1) {
type = "!="; oper = "!=";
} }
if(str.indexOf(">=") != -1) { if(str.indexOf(">=") != -1) {
type = ">="; oper = ">=";
} }
if(str.indexOf("<=") != -1) { if(str.indexOf("<=") != -1) {
type = "<="; oper = "<=";
} }
if(type != "=") { var k = str.split(":")[0];
skip += type.length; var v = str.split(":")[1];
if(q[prefix + k]) {
value = q[prefix + k];
} }
var property = str.split(":")[0]; if(oper.length > 0) {
var value; value[oper] = parseFloat(HxOverrides.substr(v,oper.length,null));
if(q[prefix + property]) { q[k] = value;
value = q[prefix + property];
} else { } else {
value = { }; value[prefix + (_gthis.isExclude.match(k) ? HxOverrides.substr(k,1,null) : k)] = _gthis.isExclude.match(k) == false;
} q[v] = 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);
} }
return; 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 _g = 0;
var _g1 = token.length; var _g1 = token.length;
while(_g < _g1) { while(_g < _g1) {
var i = _g++; var i = _g++;
if(isOr.match(token[i])) { process(this.expandAliases(token[i]));
composeQuery();
} else {
match(token[i]);
}
} }
var _g = 0; this.q = q;
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};
return this.q; return this.q;
} }
,test: function(property,value) { ,test: function(property,value) {
if(this.preset == property) { var conds = 0;
this.parse(value,true); var fails = 0;
var qualify = 0;
var testprop = function(expr) {
conds += 1;
fails += expr ? 0 : 1;
return expr;
};
if(this.q[value] != null) {
var v = this.q[value];
if(v[property] != null) {
return v[property];
}
} }
var _g = 0; var _g = 0;
var _g1 = this.q.or.length; var _g1 = Reflect.fields(this.q);
while(_g < _g1) { while(_g < _g1.length) {
var i = _g++; var k = _g1[_g];
var or = this.q.or[i]; ++_g;
var conds = [0]; var qval = Reflect.field(this.q,k);
var fails = [0]; if(typeof(value) == "string") {
var pass = 0; continue;
var when = (function(fails,conds) {
return function(expr) {
conds[0] += 1;
fails[0] += 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) {
continue;
}
if(Reflect.field(orval,"=") != null && when(value == Reflect.field(orval,"="))) {
++pass;
}
if(Reflect.field(orval,"*") != null && when(value != null)) {
++pass;
}
if(Reflect.field(orval,">") != null && when(value > Std.parseInt(Reflect.field(orval,">")))) {
++pass;
}
if(Reflect.field(orval,"<") != null && when(value < Std.parseInt(Reflect.field(orval,"<")))) {
++pass;
}
if(Reflect.field(orval,">=") != null && when(value >= Std.parseInt(Reflect.field(orval,">=")))) {
++pass;
}
if(Reflect.field(orval,"<=") != null && when(value >= Std.parseInt(Reflect.field(orval,"<=")))) {
++pass;
}
if(Reflect.field(orval,"!=") != null && when(value != Std.parseInt(Reflect.field(orval,"!=")))) {
++pass;
}
} }
if(this.accept && conds[0] > 0 && fails[0] > 0) { if(Reflect.field(qval,"=") != null && testprop(value == Reflect.field(qval,"="))) {
this.accept = false; ++qualify;
} }
if(conds[0] > 0 && pass > 0 && fails[0] == 0) { if(Reflect.field(qval,"*") != null && testprop(value != null)) {
this.accept = true; ++qualify;
}
if(Reflect.field(qval,">") != null && testprop(value > parseFloat(Reflect.field(qval,">")))) {
++qualify;
}
if(Reflect.field(qval,"<") != null && testprop(value < parseFloat(Reflect.field(qval,"<")))) {
++qualify;
}
if(Reflect.field(qval,">=") != null && testprop(value >= parseFloat(Reflect.field(qval,">=")))) {
++qualify;
}
if(Reflect.field(qval,"<=") != null && testprop(value >= parseFloat(Reflect.field(qval,"<=")))) {
++qualify;
}
if(Reflect.field(qval,"!=") != null && testprop(value != parseFloat(Reflect.field(qval,"!=")))) {
++qualify;
} }
} }
return qualify > 0;
} }
}; };
var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() { var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() {

View file

@ -325,6 +325,53 @@ class Bool: pass
class Dynamic: 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: class Test:
_hx_class_name = "Test" _hx_class_name = "Test"
__slots__ = () __slots__ = ()
@ -332,8 +379,9 @@ class Test:
@staticmethod @staticmethod
def main(): 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': "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 @staticmethod
def test(spec): def test(spec):
@ -352,8 +400,8 @@ class Test:
q = xrfragment_Query(Reflect.field(item,"data")) q = xrfragment_Query(Reflect.field(item,"data"))
if (Reflect.field(item,"fn") == "url"): if (Reflect.field(item,"fn") == "url"):
res = xrfragment_Url.parse(Reflect.field(item,"data")) res = xrfragment_Url.parse(Reflect.field(item,"data"))
if (Reflect.field(Reflect.field(item,"expect"),"fn") == "selected"): if (Reflect.field(Reflect.field(item,"expect"),"fn") == "test"):
valid = (Reflect.field(Reflect.field(item,"expect"),"out") == q.selected(Reflect.field(Reflect.field(item,"expect"),"input"))) 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"): 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")) 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"): if (Reflect.field(Reflect.field(item,"expect"),"fn") == "equal.xy"):
@ -965,7 +1013,7 @@ class python_HaxeIterator:
class python_internal_ArrayImpl: class python_internal_ArrayImpl:
_hx_class_name = "python.internal.ArrayImpl" _hx_class_name = "python.internal.ArrayImpl"
__slots__ = () __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 @staticmethod
def get_length(x): def get_length(x):
@ -1101,23 +1149,11 @@ class python_internal_ArrayImpl:
else: else:
return None 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: class HxOverrides:
_hx_class_name = "HxOverrides" _hx_class_name = "HxOverrides"
__slots__ = () __slots__ = ()
_hx_statics = ["eq", "stringOrNull", "push", "length", "arrayGet"] _hx_statics = ["eq", "stringOrNull", "length", "arrayGet"]
@staticmethod @staticmethod
def eq(a,b): def eq(a,b):
@ -1132,14 +1168,6 @@ class HxOverrides:
else: else:
return s return s
@staticmethod
def push(x,e):
if isinstance(x,list):
_this = x
_this.append(e)
return len(_this)
return x.push(e)
@staticmethod @staticmethod
def length(x): def length(x):
if isinstance(x,str): if isinstance(x,str):
@ -1291,15 +1319,13 @@ class HxString:
class xrfragment_Query: class xrfragment_Query:
_hx_class_name = "xrfragment.Query" _hx_class_name = "xrfragment.Query"
__slots__ = ("str", "q", "include", "exclude", "accept", "preset") __slots__ = ("str", "q", "isProp", "isExclude")
_hx_fields = ["str", "q", "include", "exclude", "accept", "preset"] _hx_fields = ["str", "q", "isProp", "isExclude"]
_hx_methods = ["toObject", "selected", "parse", "test"] _hx_methods = ["toObject", "expandAliases", "parse", "test"]
def __init__(self,_hx_str): def __init__(self,_hx_str):
self.preset = "" self.isExclude = EReg("^-","")
self.accept = False self.isProp = EReg("^.*:[><=!]?","")
self.exclude = list()
self.include = list()
self.q = _hx_AnonObject({}) self.q = _hx_AnonObject({})
self.str = "" self.str = ""
if (_hx_str is not None): if (_hx_str is not None):
@ -1308,182 +1334,122 @@ class xrfragment_Query:
def toObject(self): def toObject(self):
return self.q return self.q
def selected(self,nodename): def expandAliases(self,token):
if Reflect.field(self.q,"copy_all"): classAlias = EReg("^(-)?\\.","")
self.accept = True classAlias.matchObj = python_lib_Re.search(classAlias.pattern,token)
if (nodename in self.include): if (classAlias.matchObj is not None):
self.accept = True return StringTools.replace(token,".","class:")
if (nodename in self.exclude): else:
self.accept = False return token
return self.accept
def parse(self,_hx_str,recurse = None): def parse(self,_hx_str,recurse = None):
if (recurse is None): if (recurse is None):
recurse = False recurse = False
_gthis = self _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(" ") token = _hx_str.split(" ")
ors = list()
q = _hx_AnonObject({}) q = _hx_AnonObject({})
def _hx_local_0(): def _hx_local_0(_hx_str,prefix = None):
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):
if (prefix is None): if (prefix is None):
prefix = "" prefix = ""
isPreset.matchObj = python_lib_Re.search(isPreset.pattern,_hx_str) _hx_str = StringTools.trim(_hx_str)
if ((isPreset.matchObj is not None) and (not recurse)): value = _hx_AnonObject({})
_gthis.preset = _hx_str _this = _gthis.isProp
return _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str)
match1 = None if (_this.matchObj is not None):
isExclude.matchObj = python_lib_Re.search(isExclude.pattern,_hx_str) oper = ""
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 = "="
startIndex = None startIndex = None
if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1): if (((_hx_str.find("*") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"*",startIndex))) != -1):
_hx_type = "*" oper = "*"
startIndex = None startIndex = None
if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1): if (((_hx_str.find(">") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">",startIndex))) != -1):
_hx_type = ">" oper = ">"
startIndex = None startIndex = None
if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1): if (((_hx_str.find("<") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<",startIndex))) != -1):
_hx_type = "<" oper = "<"
startIndex = None startIndex = None
if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1): if (((_hx_str.find("!=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"!=",startIndex))) != -1):
_hx_type = "!=" oper = "!="
startIndex = None startIndex = None
if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1): if (((_hx_str.find(">=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,">=",startIndex))) != -1):
_hx_type = ">=" oper = ">="
startIndex = None startIndex = None
if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1): if (((_hx_str.find("<=") if ((startIndex is None)) else HxString.indexOfImpl(_hx_str,"<=",startIndex))) != -1):
_hx_type = "<=" oper = "<="
if (_hx_type != "="): k = HxOverrides.arrayGet(_hx_str.split(":"), 0)
skip = (skip + len(_hx_type)) v = HxOverrides.arrayGet(_hx_str.split(":"), 1)
property = HxOverrides.arrayGet(_hx_str.split(":"), 0) if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k))):
value = None value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if k is None else k)))
if Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))): if (len(oper) > 0):
value = Reflect.field(q,(("null" if prefix is None else prefix) + ("null" if property is None else property))) 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: else:
value = _hx_AnonObject({}) _this = _gthis.isExclude
value1 = HxString.substr(HxOverrides.arrayGet(_hx_str.split(":"), 1),skip,None) _this.matchObj = python_lib_Re.search(_this.pattern,k)
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) + HxOverrides.stringOrNull(((HxString.substr(k,1,None) if ((_this.matchObj is not None)) else k))))
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)
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) 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 process = _hx_local_0
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
_g = 0 _g = 0
_g1 = len(token) _g1 = len(token)
while (_g < _g1): while (_g < _g1):
i = _g i = _g
_g = (_g + 1) _g = (_g + 1)
isOr.matchObj = python_lib_Re.search(isOr.pattern,(token[i] if i >= 0 and i < len(token) else None)) process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None)))
if (isOr.matchObj is not None): self.q = q
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})
return self.q return self.q
def test(self,property,value = None): def test(self,property,value = None):
if (self.preset == property): conds = 0
self.parse(value,True) 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
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 _g = 0
_g1 = Reflect.field(Reflect.field(self.q,"or"),"length") _g1 = python_Boot.fields(self.q)
while (_g < _g1): while (_g < len(_g1)):
i = _g k = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
_g = (_g + 1) _g = (_g + 1)
_hx_or = HxOverrides.arrayGet(Reflect.field(self.q,"or"), i) qval = Reflect.field(self.q,k)
conds = [0] if Std.isOfType(value,str):
fails = [0] continue
_hx_pass = 0 if ((Reflect.field(qval,"=") is not None) and testprop(HxOverrides.eq(value,Reflect.field(qval,"=")))):
def _hx_local_7(fails,conds): qualify = (qualify + 1)
def _hx_local_0(expr): if ((Reflect.field(qval,"*") is not None) and testprop((value is not None))):
_hx_local_1 = conds qualify = (qualify + 1)
_hx_local_2 = 0 if ((Reflect.field(qval,">") is not None) and testprop((value > Std.parseFloat(Reflect.field(qval,">"))))):
_hx_local_3 = (_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None) qualify = (qualify + 1)
python_internal_ArrayImpl._set(_hx_local_1, _hx_local_2, (_hx_local_3 + 1)) if ((Reflect.field(qval,"<") is not None) and testprop((value < Std.parseFloat(Reflect.field(qval,"<"))))):
(_hx_local_1[_hx_local_2] if _hx_local_2 >= 0 and _hx_local_2 < len(_hx_local_1) else None) qualify = (qualify + 1)
_hx_local_4 = fails if ((Reflect.field(qval,">=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,">="))))):
_hx_local_5 = 0 qualify = (qualify + 1)
_hx_local_6 = (_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None) if ((Reflect.field(qval,"<=") is not None) and testprop((value >= Std.parseFloat(Reflect.field(qval,"<="))))):
python_internal_ArrayImpl._set(_hx_local_4, _hx_local_5, (_hx_local_6 + (0 if expr else 1))) qualify = (qualify + 1)
(_hx_local_4[_hx_local_5] if _hx_local_5 >= 0 and _hx_local_5 < len(_hx_local_4) else None) if ((Reflect.field(qval,"!=") is not None) and testprop((value != Std.parseFloat(Reflect.field(qval,"!="))))):
return expr qualify = (qualify + 1)
return _hx_local_0 return (qualify > 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):
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