diff --git a/.vimrc b/.vimrc index 754ed65..4cddf77 100644 --- a/.vimrc +++ b/.vimrc @@ -1,3 +1,4 @@ +noremap :!haxe --no-output % noremap :!./make doc noremap :!./make && echo OK && ./make tests noremap :!./make tests \| less diff --git a/README.md b/README.md index 08f25fb..85d74df 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,11 @@ # available implementations -* [javascript](dist/xrfragment.js) [(+example)](test/test.js) -* [python](dist/xrfragment.py) [(+example)](test/test.py) -* [lua](dist/xrfragment.lua) [(+example)](test/test.lua) +* [lua (handwritten)](dist/xrfragment.lua) [(+example)](src/xrfragment/Parser.lua) * [haXe](src/xrfragment) - -# docs - -* [RFC](doc/RFC.md) + * [javascript](dist/xrfragment.js) [(+example)](test/test.js) + * [python](dist/xrfragment.py) [(+example)](test/test.py) + * [lua](dist/xrfragment.lua) [(+example)](test/test.lua) # development diff --git a/build.hxml b/build.hxml index 1397590..ede3035 100644 --- a/build.hxml +++ b/build.hxml @@ -1,38 +1,36 @@ -dce full -cp src - xrfragment -D shallow-expose -js dist/xrfragment.js --next - -dce full -cp src - Test -D shallow-expose -m Test -js test/generated/test.js --next - -dce full -cp src - -xrfragment.Query +xrfragment -lua dist/xrfragment.lua --next - -dce full -cp src - -xrfragment.Query +xrfragment -python dist/xrfragment.py ---next +#--next +#-dce full +#-cp src +#xrfragment +#-cpp dist/xrfragment.cpp +--next -dce full -cp src @@ -53,8 +51,6 @@ Test #-dce full #-cp src # -#xrfragment.Query -#-cpp dist/xrfragment.cpp # #--next # diff --git a/dist/xrfragment.js b/dist/xrfragment.js index ff11a21..5581c58 100644 --- a/dist/xrfragment.js +++ b/dist/xrfragment.js @@ -65,6 +65,13 @@ Reflect.fields = function(o) { } return a; }; +Reflect.deleteField = function(o,field) { + if(!Object.prototype.hasOwnProperty.call(o,field)) { + return false; + } + delete(o[field]); + return true; +}; var Std = function() { }; Std.__name__ = true; Std.string = function(s) { @@ -209,66 +216,46 @@ var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { }; xrfragment_Parser.__name__ = true; xrfragment_Parser.parse = function(key,value,resultMap) { var Frag_h = Object.create(null); - Frag_h["prio"] = xrfragment_Type.isInt; - Frag_h["pos"] = xrfragment_Type.isVector; - Frag_h["q"] = xrfragment_Type.isString; - var vec = "1,2,3"; + Frag_h["prio"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_INT; + Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW; + Frag_h["class"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_STRING; + Frag_h["src"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_audio"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_shader"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_env"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL; + Frag_h["src_env_audio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL; + Frag_h["pos"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.T_STRING_OBJ; + Frag_h["href"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL | xrfragment_XRF.T_PREDEFINED_VIEW; + Frag_h["q"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING; + Frag_h["scale"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT; + Frag_h["rot"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3; + Frag_h["translate"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3; + Frag_h["visible"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT; + Frag_h["t"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["gravity"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3; + Frag_h["physics"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3; + Frag_h["scroll"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING; + Frag_h["fov"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_INT | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["clip"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["fog"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["namespace"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["SPFX"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["unit"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["src_session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.BROWSER_OVERRIDE | xrfragment_XRF.PROMPT; if(Object.prototype.hasOwnProperty.call(Frag_h,key)) { - if(Frag_h[key].match(value)) { - var v = new xrfragment_Value(); - xrfragment_Parser.guessType(v,value); - if(value.split("|").length > 1) { - v.args = []; - var args = value.split("|"); - var _g = 0; - var _g1 = args.length; - while(_g < _g1) { - var i = _g++; - var x = new xrfragment_Value(); - xrfragment_Parser.guessType(x,args[i]); - v.args.push(x); - } - } - resultMap[key] = v; - } else { - console.log("src/xrfragment/Parser.hx:47:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")"); + var v = new xrfragment_XRF(key,Frag_h[key]); + if(!v.validate(value)) { + console.log("src/xrfragment/Parser.hx:66:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")"); return false; } + resultMap[key] = v; } else { - console.log("src/xrfragment/Parser.hx:48:","[ i ] fragment '" + key + "' does not exist or has no type defined (yet)"); + console.log("src/xrfragment/Parser.hx:70:","[ i ] fragment '" + key + "' does not exist or has no type typed (yet)"); return false; } return true; }; -xrfragment_Parser.guessType = function(v,str) { - v.string = str; - if(str.split(",").length > 1) { - var xyz = str.split(","); - if(xyz.length > 0) { - v.x = parseFloat(xyz[0]); - } - if(xyz.length > 1) { - v.y = parseFloat(xyz[1]); - } - if(xyz.length > 2) { - v.y = parseFloat(xyz[2]); - } - } - if(xrfragment_Type.isColor.match(str)) { - v.color = str; - } - if(xrfragment_Type.isFloat.match(str)) { - v.float = parseFloat(str); - } - if(xrfragment_Type.isInt.match(str)) { - v.int = Std.parseInt(str); - } -}; -var xrfragment_Value = function() { -}; -xrfragment_Value.__name__ = true; -var xrfragment_Type = function() { }; -xrfragment_Type.__name__ = true; var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) { this.isNumber = new EReg("^[0-9\\.]+$",""); this.isClass = new EReg("^[-]?class$",""); @@ -293,6 +280,9 @@ xrfragment_Query.prototype = { return token; } } + ,get: function() { + return this.q; + } ,parse: function(str,recurse) { if(recurse == null) { recurse = false; @@ -364,8 +354,7 @@ xrfragment_Query.prototype = { var i = _g++; process(this.expandAliases(token[i])); } - this.q = q; - return this.q; + return this.q = q; } ,test: function(obj) { var qualify = false; @@ -451,7 +440,7 @@ xrfragment_Query.prototype = { }; var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; -xrfragment_URI.parse = function(qs) { +xrfragment_URI.parse = function(qs,browser_override) { var fragment = qs.split("#"); var splitArray = fragment[1].split("&"); var resultMap = { }; @@ -468,8 +457,92 @@ xrfragment_URI.parse = function(qs) { var ok = xrfragment_Parser.parse(key,value,resultMap); } } + if(browser_override) { + var _g = 0; + var _g1 = Reflect.fields(resultMap); + while(_g < _g1.length) { + var key = _g1[_g]; + ++_g; + var xrf = resultMap[key]; + if(!xrf.is(xrfragment_XRF.BROWSER_OVERRIDE)) { + Reflect.deleteField(resultMap,key); + } + } + } return resultMap; }; +var xrfragment_XRF = function(_fragment,_flags) { + this.fragment = _fragment; + this.flags = _flags; +}; +xrfragment_XRF.__name__ = true; +xrfragment_XRF.prototype = { + is: function(flag) { + return (this.flags & flag) != 0; + } + ,validate: function(value) { + this.guessType(this,value); + if(value.split("|").length > 1) { + this.args = []; + var args = value.split("|"); + var _g = 0; + var _g1 = args.length; + while(_g < _g1) { + var i = _g++; + var x = new xrfragment_XRF(this.fragment,this.flags); + this.guessType(x,args[i]); + this.args.push(x); + } + } + if(this.fragment == "q") { + this.query = new xrfragment_Query(value).get(); + } + var ok = true; + if(!((this.args) instanceof Array)) { + if(this.is(xrfragment_XRF.T_VECTOR3) && !(typeof(this.x) == "number" && typeof(this.y) == "number" && typeof(this.z) == "number")) { + ok = false; + } + if(this.is(xrfragment_XRF.T_VECTOR2) && !(typeof(this.x) == "number" && typeof(this.y) == "number")) { + ok = false; + } + var tmp; + if(this.is(xrfragment_XRF.T_INT)) { + var v = this.int; + tmp = !(typeof(v) == "number" && ((v | 0) === v)); + } else { + tmp = false; + } + if(tmp) { + ok = false; + } + } + return ok; + } + ,guessType: function(v,str) { + v.string = str; + if(str.split(",").length > 1) { + var xyz = str.split(","); + if(xyz.length > 0) { + v.x = parseFloat(xyz[0]); + } + if(xyz.length > 1) { + v.y = parseFloat(xyz[1]); + } + if(xyz.length > 2) { + v.z = parseFloat(xyz[2]); + } + } + if(xrfragment_XRF.isColor.match(str)) { + v.color = str; + } + if(xrfragment_XRF.isFloat.match(str)) { + v.float = parseFloat(str); + } + if(xrfragment_XRF.isInt.match(str)) { + v.int = Std.parseInt(str); + } + } +}; if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) { HxOverrides.now = performance.now.bind(performance); } @@ -477,10 +550,22 @@ String.__name__ = true; Array.__name__ = true; js_Boot.__toStr = ({ }).toString; xrfragment_Parser.error = ""; -xrfragment_Type.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); -xrfragment_Type.isInt = new EReg("^[0-9]+$",""); -xrfragment_Type.isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); -xrfragment_Type.isVector = new EReg("([,]+|\\w)",""); -xrfragment_Type.isString = new EReg(".*",""); +xrfragment_XRF.ASSET = 1; +xrfragment_XRF.ASSET_OBJ = 2; +xrfragment_XRF.PV_OVERRIDE = 4; +xrfragment_XRF.QUERY_OPERATOR = 8; +xrfragment_XRF.PROMPT = 16; +xrfragment_XRF.ROUNDROBIN = 32; +xrfragment_XRF.BROWSER_OVERRIDE = 64; +xrfragment_XRF.T_INT = 256; +xrfragment_XRF.T_VECTOR2 = 1024; +xrfragment_XRF.T_VECTOR3 = 2048; +xrfragment_XRF.T_URL = 4096; +xrfragment_XRF.T_PREDEFINED_VIEW = 8192; +xrfragment_XRF.T_STRING = 16384; +xrfragment_XRF.T_STRING_OBJ = 32768; +xrfragment_XRF.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); +xrfragment_XRF.isInt = new EReg("^[0-9]+$",""); +xrfragment_XRF.isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); })({}); var xrfragment = $hx_exports["xrfragment"]; diff --git a/dist/xrfragment.lua b/dist/xrfragment.lua index f4a3411..5c08600 100644 --- a/dist/xrfragment.lua +++ b/dist/xrfragment.lua @@ -205,15 +205,22 @@ local Reflect = _hx_e() local String = _hx_e() local Std = _hx_e() local StringTools = _hx_e() +__haxe_IMap = _hx_e() __haxe_Exception = _hx_e() +__haxe_Log = _hx_e() __haxe_NativeStackTrace = _hx_e() __haxe_ValueException = _hx_e() +__haxe_ds_StringMap = _hx_e() __haxe_iterators_ArrayIterator = _hx_e() __haxe_iterators_ArrayKeyValueIterator = _hx_e() __lua_Boot = _hx_e() __lua_UserData = _hx_e() +__lua_Lib = _hx_e() __lua_Thread = _hx_e() +__xrfragment_Parser = _hx_e() __xrfragment_Query = _hx_e() +__xrfragment_URI = _hx_e() +__xrfragment_XRF = _hx_e() local _hx_bind, _hx_bit, _hx_staticToInstance, _hx_funcToField, _hx_maxn, _hx_print, _hx_apply_self, _hx_box_mr, _hx_bit_clamp, _hx_table, _hx_bit_raw local _hx_pcall_default = {}; @@ -585,6 +592,55 @@ EReg.prototype.match = function(self,s) do return self.m[1] ~= nil end; end; end +EReg.prototype.split = function(self,s) + if (self.global) then + do return __lua_Lib.fillArray(_hx_wrap_if_string_field(__lua_lib_lrexlib_Rex,'split')(s, self.r)) end; + else + local d = "#__delim__#"; + do return __lua_Lib.fillArray(_hx_wrap_if_string_field(__lua_lib_lrexlib_Rex,'split')(self:replace(s, d), d)) end; + end; +end +EReg.prototype.replace = function(self,s,by) + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("$$") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(by, "$$", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(by)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(by, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("$$"); + else + ret:push(__lua_lib_luautf8_Utf8.sub(by, idx, __lua_lib_luautf8_Utf8.len(by))); + idx = nil; + end; + end; + local chunks = ret; + local _g = _hx_tab_array({}, 0); + local _g1 = 0; + while (_g1 < chunks.length) do + local chunk = chunks[_g1]; + _g1 = _g1 + 1; + _g:push(__lua_lib_lrexlib_Rex.gsub(chunk, "\\$(\\d)", "%%%1", 1)); + end; + chunks = _g; + by = chunks:join("$"); + do return __lua_lib_lrexlib_Rex.gsub(s, self.r, by, (function() + local _hx_1 + if (self.global) then + _hx_1 = nil; else + _hx_1 = 1; end + return _hx_1 + end )()) end +end EReg.prototype.__class__ = EReg @@ -639,6 +695,21 @@ Reflect.fields = function(o) do return _hx_field_arr(o) end; end; end +Reflect.deleteField = function(o,field) + if (not ((function() + local _hx_1 + if ((_G.type(o) == "string") and ((String.prototype[field] ~= nil) or (field == "length"))) then + _hx_1 = true; elseif (o.__fields__ ~= nil) then + _hx_1 = o.__fields__[field] ~= nil; else + _hx_1 = o[field] ~= nil; end + return _hx_1 + end )())) then + do return false end; + end; + o[field] = nil; + o.__fields__[field] = nil; + do return true end; +end String.new = function(string) local self = _hx_new(String.prototype) @@ -833,6 +904,56 @@ Std.int = function(x) do return _hx_bit_clamp(x) end; end; end +Std.parseInt = function(x) + if (x == nil) then + do return nil end; + end; + local hexMatch = _G.string.match(x, "^[ \t\r\n]*([%-+]*0[xX][%da-fA-F]*)"); + if (hexMatch ~= nil) then + local sign; + local _g = __lua_lib_luautf8_Utf8.byte(hexMatch, 1); + if (_g) == 43 then + sign = 1; + elseif (_g) == 45 then + sign = -1;else + sign = 0; end; + local pos = (function() + local _hx_1 + if (sign == 0) then + _hx_1 = 2; else + _hx_1 = 3; end + return _hx_1 + end )(); + local len = nil; + if ((len == nil) or (len > (pos + __lua_lib_luautf8_Utf8.len(hexMatch)))) then + len = __lua_lib_luautf8_Utf8.len(hexMatch); + else + if (len < 0) then + len = __lua_lib_luautf8_Utf8.len(hexMatch) + len; + end; + end; + if (pos < 0) then + pos = __lua_lib_luautf8_Utf8.len(hexMatch) + pos; + end; + if (pos < 0) then + pos = 0; + end; + do return (function() + local _hx_2 + if (sign == -1) then + _hx_2 = -1; else + _hx_2 = 1; end + return _hx_2 + end )() * _G.tonumber(__lua_lib_luautf8_Utf8.sub(hexMatch, pos + 1, pos + len), 16) end; + else + local intMatch = _G.string.match(x, "^ *[%-+]?%d*"); + if (intMatch ~= nil) then + do return _G.tonumber(intMatch) end; + else + do return nil end; + end; + end; +end Std.parseFloat = function(x) if ((x == nil) or (x == "")) then do return (0/0) end; @@ -891,6 +1012,14 @@ end StringTools.new = {} StringTools.__name__ = true +StringTools.urlDecode = function(s) + s = _G.string.gsub(s, "+", " "); + s = _G.string.gsub(s, "%%(%x%x)", function(h) + do return _G.string.char(_G.tonumber(h, 16)) end; + end); + s = _G.string.gsub(s, "\r\n", "\n"); + do return s end; +end 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; @@ -985,6 +1114,9 @@ StringTools.replace = function(s,sub,by) do return ret:join(by) end; end +__haxe_IMap.new = {} +__haxe_IMap.__name__ = true + __haxe_Exception.new = function(message,previous,native) local self = _hx_new(__haxe_Exception.prototype) __haxe_Exception.super(self,message,previous,native) @@ -1020,6 +1152,30 @@ end __haxe_Exception.prototype.__class__ = __haxe_Exception +__haxe_Log.new = {} +__haxe_Log.__name__ = true +__haxe_Log.formatOutput = function(v,infos) + local str = Std.string(v); + if (infos == nil) then + do return str end; + end; + local pstr = Std.string(Std.string(infos.fileName) .. Std.string(":")) .. Std.string(infos.lineNumber); + if (infos.customParams ~= nil) then + local _g = 0; + local _g1 = infos.customParams; + while (_g < _g1.length) do + local v = _g1[_g]; + _g = _g + 1; + str = Std.string(str) .. Std.string((Std.string(", ") .. Std.string(Std.string(v)))); + end; + end; + do return Std.string(Std.string(pstr) .. Std.string(": ")) .. Std.string(str) end; +end +__haxe_Log.trace = function(v,infos) + local str = __haxe_Log.formatOutput(v, infos); + _hx_print(str); +end + __haxe_NativeStackTrace.new = {} __haxe_NativeStackTrace.__name__ = true __haxe_NativeStackTrace.saveStack = function(exception) @@ -1075,6 +1231,10 @@ __haxe_ValueException.prototype.__class__ = __haxe_ValueException __haxe_ValueException.__super__ = __haxe_Exception setmetatable(__haxe_ValueException.prototype,{__index=__haxe_Exception.prototype}) +__haxe_ds_StringMap.new = {} +__haxe_ds_StringMap.__name__ = true +__haxe_ds_StringMap.__interfaces__ = {__haxe_IMap} + __haxe_iterators_ArrayIterator.new = function(array) local self = _hx_new(__haxe_iterators_ArrayIterator.prototype) __haxe_iterators_ArrayIterator.super(self,array) @@ -1225,9 +1385,209 @@ end __lua_UserData.new = {} __lua_UserData.__name__ = true +__lua_Lib.new = {} +__lua_Lib.__name__ = true +__lua_Lib.fillArray = function(itr) + local i = nil; + local ret = _hx_tab_array({}, 0); + while (true) do + i = itr(); + if (not (i ~= nil)) then + break; + end; + ret:push(i); + end; + do return ret end; +end + __lua_Thread.new = {} __lua_Thread.__name__ = true +__xrfragment_Parser.new = {} +_hx_exports["xrfragment"]["Parser"] = __xrfragment_Parser +__xrfragment_Parser.__name__ = true +__xrfragment_Parser.parse = function(key,value,resultMap) + local Frag_h = ({}); + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_INT); + if (value1 == nil) then + Frag_h.prio = __haxe_ds_StringMap.tnull; + else + Frag_h.prio = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_PREDEFINED_VIEW); + if (value1 == nil) then + Frag_h["#"] = __haxe_ds_StringMap.tnull; + else + Frag_h["#"] = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.class = __haxe_ds_StringMap.tnull; + else + Frag_h.class = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_URL); + if (value1 == nil) then + Frag_h.src = __haxe_ds_StringMap.tnull; + else + Frag_h.src = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_URL); + if (value1 == nil) then + Frag_h.src_audio = __haxe_ds_StringMap.tnull; + else + Frag_h.src_audio = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_URL); + if (value1 == nil) then + Frag_h.src_shader = __haxe_ds_StringMap.tnull; + else + Frag_h.src_shader = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_URL); + if (value1 == nil) then + Frag_h.src_env = __haxe_ds_StringMap.tnull; + else + Frag_h.src_env = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_URL); + if (value1 == nil) then + Frag_h.src_env_audio = __haxe_ds_StringMap.tnull; + else + Frag_h.src_env_audio = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.PV_OVERRIDE,__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_VECTOR3),__xrfragment_XRF.T_STRING_OBJ); + if (value1 == nil) then + Frag_h.pos = __haxe_ds_StringMap.tnull; + else + Frag_h.pos = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET_OBJ,__xrfragment_XRF.T_URL),__xrfragment_XRF.T_PREDEFINED_VIEW); + if (value1 == nil) then + Frag_h.href = __haxe_ds_StringMap.tnull; + else + Frag_h.href = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.PV_OVERRIDE,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.q = __haxe_ds_StringMap.tnull; + else + Frag_h.q = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.QUERY_OPERATOR,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_INT); + if (value1 == nil) then + Frag_h.scale = __haxe_ds_StringMap.tnull; + else + Frag_h.scale = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.QUERY_OPERATOR,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_VECTOR3); + if (value1 == nil) then + Frag_h.rot = __haxe_ds_StringMap.tnull; + else + Frag_h.rot = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.QUERY_OPERATOR,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_VECTOR3); + if (value1 == nil) then + Frag_h.translate = __haxe_ds_StringMap.tnull; + else + Frag_h.translate = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.QUERY_OPERATOR,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_INT); + if (value1 == nil) then + Frag_h.visible = __haxe_ds_StringMap.tnull; + else + Frag_h.visible = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.ROUNDROBIN),__xrfragment_XRF.T_VECTOR2),__xrfragment_XRF.BROWSER_OVERRIDE); + if (value1 == nil) then + Frag_h.t = __haxe_ds_StringMap.tnull; + else + Frag_h.t = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_VECTOR3); + if (value1 == nil) then + Frag_h.gravity = __haxe_ds_StringMap.tnull; + else + Frag_h.gravity = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_VECTOR3); + if (value1 == nil) then + Frag_h.physics = __haxe_ds_StringMap.tnull; + else + Frag_h.physics = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.scroll = __haxe_ds_StringMap.tnull; + else + Frag_h.scroll = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_INT),__xrfragment_XRF.BROWSER_OVERRIDE); + if (value1 == nil) then + Frag_h.fov = __haxe_ds_StringMap.tnull; + else + Frag_h.fov = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_VECTOR2),__xrfragment_XRF.BROWSER_OVERRIDE); + if (value1 == nil) then + Frag_h.clip = __haxe_ds_StringMap.tnull; + else + Frag_h.clip = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_STRING),__xrfragment_XRF.BROWSER_OVERRIDE); + if (value1 == nil) then + Frag_h.fog = __haxe_ds_StringMap.tnull; + else + Frag_h.fog = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.namespace = __haxe_ds_StringMap.tnull; + else + Frag_h.namespace = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.SPFX = __haxe_ds_StringMap.tnull; + else + Frag_h.SPFX = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.unit = __haxe_ds_StringMap.tnull; + else + Frag_h.unit = value1; + end; + local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_STRING); + if (value1 == nil) then + Frag_h.description = __haxe_ds_StringMap.tnull; + else + Frag_h.description = value1; + end; + local value1 = _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_URL),__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.BROWSER_OVERRIDE),__xrfragment_XRF.PROMPT); + if (value1 == nil) then + Frag_h.src_session = __haxe_ds_StringMap.tnull; + else + Frag_h.src_session = value1; + end; + if (Frag_h[key] ~= nil) then + local ret = Frag_h[key]; + if (ret == __haxe_ds_StringMap.tnull) then + ret = nil; + end; + local v = __xrfragment_XRF.new(key, ret); + if (not v:validate(value)) then + __haxe_Log.trace(Std.string(Std.string(Std.string(Std.string("[ i ] fragment '") .. Std.string(key)) .. Std.string("' has incompatible value (")) .. Std.string(value)) .. Std.string(")"), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=66,className="xrfragment.Parser",methodName="parse"})); + do return false end; + end; + resultMap[key] = v; + else + __haxe_Log.trace(Std.string(Std.string("[ i ] fragment '") .. Std.string(key)) .. Std.string("' does not exist or has no type typed (yet)"), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=70,className="xrfragment.Parser",methodName="parse"})); + do return false end; + end; + do return true end; +end + __xrfragment_Query.new = function(str) local self = _hx_new(__xrfragment_Query.prototype) __xrfragment_Query.super(self,str) @@ -1258,6 +1618,9 @@ __xrfragment_Query.prototype.expandAliases = function(self,token) do return token end; end; end +__xrfragment_Query.prototype.get = function(self) + do return self.q end +end __xrfragment_Query.prototype.parse = function(self,str,recurse) if (recurse == nil) then recurse = false; @@ -1527,8 +1890,7 @@ __xrfragment_Query.prototype.parse = function(self,str,recurse) local i = _g - 1; process(self:expandAliases(token[i])); end; - self.q = q; - do return self.q end + self.q = q do return self.q end end __xrfragment_Query.prototype.test = function(self,obj) local qualify = false; @@ -1625,6 +1987,270 @@ __xrfragment_Query.prototype.testProperty = function(self,property,value,exclude end __xrfragment_Query.prototype.__class__ = __xrfragment_Query + +__xrfragment_URI.new = {} +_hx_exports["xrfragment"]["URI"] = __xrfragment_URI +__xrfragment_URI.__name__ = true +__xrfragment_URI.parse = function(qs,browser_override) + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("#") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(qs, "#", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(qs)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(qs, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("#"); + else + ret:push(__lua_lib_luautf8_Utf8.sub(qs, idx, __lua_lib_luautf8_Utf8.len(qs))); + idx = nil; + end; + end; + local fragment = ret; + local _this = fragment[1]; + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("&") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(_this, "&", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(_this)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(_this, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("&"); + else + ret:push(__lua_lib_luautf8_Utf8.sub(_this, idx, __lua_lib_luautf8_Utf8.len(_this))); + idx = nil; + end; + end; + local splitArray = ret; + local resultMap = _hx_e(); + local _g = 0; + local _g1 = splitArray.length; + while (_g < _g1) do + _g = _g + 1; + local i = _g - 1; + local _this = splitArray[i]; + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("=") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(_this, "=", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(_this)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(_this, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("="); + else + ret:push(__lua_lib_luautf8_Utf8.sub(_this, idx, __lua_lib_luautf8_Utf8.len(_this))); + idx = nil; + end; + end; + local splitByEqual = ret; + local regexPlus = EReg.new("\\+", "g"); + local key = splitByEqual[0]; + if (splitByEqual.length > 1) then + local value = StringTools.urlDecode(regexPlus:split(splitByEqual[1]):join(" ")); + local ok = __xrfragment_Parser.parse(key, value, resultMap); + end; + end; + if (browser_override) then + local _g = 0; + local _g1 = Reflect.fields(resultMap); + while (_g < _g1.length) do + local key = _g1[_g]; + _g = _g + 1; + local xrf = Reflect.field(resultMap, key); + if (not xrf:is(__xrfragment_XRF.BROWSER_OVERRIDE)) then + Reflect.deleteField(resultMap, key); + end; + end; + end; + do return resultMap end; +end + +__xrfragment_XRF.new = function(_fragment,_flags) + local self = _hx_new(__xrfragment_XRF.prototype) + __xrfragment_XRF.super(self,_fragment,_flags) + return self +end +__xrfragment_XRF.super = function(self,_fragment,_flags) + self.fragment = _fragment; + self.flags = _flags; +end +__xrfragment_XRF.__name__ = true +__xrfragment_XRF.prototype = _hx_e(); +__xrfragment_XRF.prototype.is = function(self,flag) + do return (_hx_bit.band(self.flags,flag)) ~= 0 end +end +__xrfragment_XRF.prototype.validate = function(self,value) + self:guessType(self, value); + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("|") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(value, "|", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(value)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(value, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("|"); + else + ret:push(__lua_lib_luautf8_Utf8.sub(value, idx, __lua_lib_luautf8_Utf8.len(value))); + idx = nil; + end; + end; + if (ret.length > 1) then + self.args = Array.new(); + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len("|") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(value, "|", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(value)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(value, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len("|"); + else + ret:push(__lua_lib_luautf8_Utf8.sub(value, idx, __lua_lib_luautf8_Utf8.len(value))); + idx = nil; + end; + end; + local args = ret; + local _g = 0; + local _g1 = args.length; + while (_g < _g1) do + _g = _g + 1; + local i = _g - 1; + local x = __xrfragment_XRF.new(self.fragment, self.flags); + self:guessType(x, args[i]); + self.args:push(x); + end; + end; + if (self.fragment == "q") then + self.query = __xrfragment_Query.new(value):get(); + end; + local ok = true; + if (not __lua_Boot.__instanceof(self.args, Array)) then + if (self:is(__xrfragment_XRF.T_VECTOR3) and not ((__lua_Boot.__instanceof(self.x, Float) and __lua_Boot.__instanceof(self.y, Float)) and __lua_Boot.__instanceof(self.z, Float))) then + ok = false; + end; + if (self:is(__xrfragment_XRF.T_VECTOR2) and not (__lua_Boot.__instanceof(self.x, Float) and __lua_Boot.__instanceof(self.y, Float))) then + ok = false; + end; + if (self:is(__xrfragment_XRF.T_INT) and not __lua_Boot.__instanceof(self.int, Int)) then + ok = false; + end; + end; + do return ok end +end +__xrfragment_XRF.prototype.guessType = function(self,v,str) + v.string = str; + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len(",") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(str, ",", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(str)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(str, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len(","); + else + ret:push(__lua_lib_luautf8_Utf8.sub(str, idx, __lua_lib_luautf8_Utf8.len(str))); + idx = nil; + end; + end; + if (ret.length > 1) then + local idx = 1; + local ret = _hx_tab_array({}, 0); + while (idx ~= nil) do + local newidx = 0; + if (__lua_lib_luautf8_Utf8.len(",") > 0) then + newidx = __lua_lib_luautf8_Utf8.find(str, ",", idx, true); + else + if (idx >= __lua_lib_luautf8_Utf8.len(str)) then + newidx = nil; + else + newidx = idx + 1; + end; + end; + if (newidx ~= nil) then + local match = __lua_lib_luautf8_Utf8.sub(str, idx, newidx - 1); + ret:push(match); + idx = newidx + __lua_lib_luautf8_Utf8.len(","); + else + ret:push(__lua_lib_luautf8_Utf8.sub(str, idx, __lua_lib_luautf8_Utf8.len(str))); + idx = nil; + end; + end; + local xyz = ret; + if (xyz.length > 0) then + v.x = Std.parseFloat(xyz[0]); + end; + if (xyz.length > 1) then + v.y = Std.parseFloat(xyz[1]); + end; + if (xyz.length > 2) then + v.z = Std.parseFloat(xyz[2]); + end; + end; + if (__xrfragment_XRF.isColor:match(str)) then + v.color = str; + end; + if (__xrfragment_XRF.isFloat:match(str)) then + v.float = Std.parseFloat(str); + end; + if (__xrfragment_XRF.isInt:match(str)) then + v.int = Std.parseInt(str); + end; +end + +__xrfragment_XRF.prototype.__class__ = __xrfragment_XRF -- require this for lua 5.1 pcall(require, 'bit') if bit then @@ -1679,9 +2305,49 @@ local _hx_static_init = function() String.__name__ = true; Array.__name__ = true;EReg.FLAGS = __lua_lib_lrexlib_Rex.flags(); + __haxe_ds_StringMap.tnull = ({}); + + __xrfragment_Parser.error = ""; + + __xrfragment_XRF.ASSET = 1; + + __xrfragment_XRF.ASSET_OBJ = 2; + + __xrfragment_XRF.PV_OVERRIDE = 4; + + __xrfragment_XRF.QUERY_OPERATOR = 8; + + __xrfragment_XRF.PROMPT = 16; + + __xrfragment_XRF.ROUNDROBIN = 32; + + __xrfragment_XRF.BROWSER_OVERRIDE = 64; + + __xrfragment_XRF.T_INT = 256; + + __xrfragment_XRF.T_VECTOR2 = 1024; + + __xrfragment_XRF.T_VECTOR3 = 2048; + + __xrfragment_XRF.T_URL = 4096; + + __xrfragment_XRF.T_PREDEFINED_VIEW = 8192; + + __xrfragment_XRF.T_STRING = 16384; + + __xrfragment_XRF.T_STRING_OBJ = 32768; + + __xrfragment_XRF.isColor = EReg.new("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", ""); + + __xrfragment_XRF.isInt = EReg.new("^[0-9]+$", ""); + + __xrfragment_XRF.isFloat = EReg.new("^[0-9]+\\.[0-9]+$", ""); + end +_hx_print = print or (function() end) + _hx_table = {} _hx_table.pack = _G.table.pack or function(...) return {...} diff --git a/dist/xrfragment.py b/dist/xrfragment.py index 79641b3..351079c 100644 --- a/dist/xrfragment.py +++ b/dist/xrfragment.py @@ -7,6 +7,7 @@ import sys as python_lib_Sys import functools as python_lib_Functools import re as python_lib_Re import traceback as python_lib_Traceback +import urllib.parse as python_lib_urllib_Parse class _hx_AnonObject: @@ -62,6 +63,7 @@ class EReg: _hx_class_name = "EReg" __slots__ = ("pattern", "matchObj", "_hx_global") _hx_fields = ["pattern", "matchObj", "global"] + _hx_methods = ["split"] def __init__(self,r,opt): self.matchObj = None @@ -85,22 +87,53 @@ class EReg: self._hx_global = True self.pattern = python_lib_Re.compile(r,options) + def split(self,s): + if self._hx_global: + ret = [] + lastEnd = 0 + x = python_HaxeIterator(python_lib_Re.finditer(self.pattern,s)) + while x.hasNext(): + x1 = x.next() + x2 = HxString.substring(s,lastEnd,x1.start()) + ret.append(x2) + lastEnd = x1.end() + x = HxString.substr(s,lastEnd,None) + ret.append(x) + return ret + else: + self.matchObj = python_lib_Re.search(self.pattern,s) + if (self.matchObj is None): + return [s] + else: + return [HxString.substring(s,0,self.matchObj.start()), HxString.substr(s,self.matchObj.end(),None)] + class Reflect: _hx_class_name = "Reflect" __slots__ = () - _hx_statics = ["field"] + _hx_statics = ["field", "deleteField"] @staticmethod def field(o,field): return python_Boot.field(o,field) + @staticmethod + def deleteField(o,field): + if (field in python_Boot.keywords): + field = ("_hx_" + field) + elif ((((len(field) > 2) and ((ord(field[0]) == 95))) and ((ord(field[1]) == 95))) and ((ord(field[(len(field) - 1)]) != 95))): + field = ("_hx_" + field) + if (not python_Boot.hasField(o,field)): + return False + o.__delattr__(field) + return True + class Std: _hx_class_name = "Std" __slots__ = () - _hx_statics = ["isOfType", "string", "shortenPossibleNumber", "parseFloat"] + _hx_statics = ["isOfType", "string", "parseInt", "shortenPossibleNumber", "parseFloat"] @staticmethod def isOfType(v,t): @@ -192,6 +225,72 @@ class Std: def string(s): return python_Boot.toString1(s,"") + @staticmethod + def parseInt(x): + if (x is None): + return None + try: + return int(x) + except BaseException as _g: + None + base = 10 + _hx_len = len(x) + foundCount = 0 + sign = 0 + firstDigitIndex = 0 + lastDigitIndex = -1 + previous = 0 + _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 + @staticmethod def shortenPossibleNumber(x): r = "" @@ -284,6 +383,11 @@ class StringTools: return by.join([python_Boot.toString1(x1,'') for x1 in _this]) +class haxe_IMap: + _hx_class_name = "haxe.IMap" + __slots__ = () + + class haxe_Exception(Exception): _hx_class_name = "haxe.Exception" __slots__ = ("_hx___nativeStack", "_hx___nativeException", "_hx___previousException") @@ -365,6 +469,17 @@ class haxe_ValueException(haxe_Exception): +class haxe_ds_StringMap: + _hx_class_name = "haxe.ds.StringMap" + __slots__ = ("h",) + _hx_fields = ["h"] + _hx_interfaces = [haxe_IMap] + + def __init__(self): + self.h = dict() + + + class haxe_iterators_ArrayIterator: _hx_class_name = "haxe.iterators.ArrayIterator" __slots__ = ("array", "current") @@ -418,7 +533,7 @@ class haxe_iterators_ArrayKeyValueIterator: class python_Boot: _hx_class_name = "python.Boot" __slots__ = () - _hx_statics = ["keywords", "toString1", "fields", "simpleField", "field", "getInstanceFields", "getSuperClass", "getClassFields", "prefixLength", "unhandleKeywords"] + _hx_statics = ["keywords", "toString1", "fields", "simpleField", "hasField", "field", "getInstanceFields", "getSuperClass", "getClassFields", "prefixLength", "unhandleKeywords"] @staticmethod def toString1(o,s): @@ -582,6 +697,12 @@ class python_Boot: else: return None + @staticmethod + def hasField(o,field): + if isinstance(o,_hx_AnonObject): + return o._hx_hasattr(field) + return hasattr(o,(("_hx_" + field) if ((field in python_Boot.keywords)) else (("_hx_" + field) if (((((len(field) > 2) and ((ord(field[0]) == 95))) and ((ord(field[1]) == 95))) and ((ord(field[(len(field) - 1)]) != 95)))) else field))) + @staticmethod def field(o,field): if (field is None): @@ -1164,11 +1285,58 @@ class HxString: return s[startIndex:(startIndex + _hx_len)] +class xrfragment_Parser: + _hx_class_name = "xrfragment.Parser" + __slots__ = () + _hx_statics = ["error", "parse"] + + @staticmethod + def parse(key,value,resultMap): + Frag = haxe_ds_StringMap() + Frag.h["prio"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_INT) + Frag.h["#"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW) + Frag.h["class"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_STRING) + Frag.h["src"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_audio"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_shader"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_env"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) + Frag.h["src_env_audio"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) + Frag.h["pos"] = (((xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) | xrfragment_XRF.T_STRING_OBJ) + Frag.h["href"] = ((xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) | xrfragment_XRF.T_PREDEFINED_VIEW) + Frag.h["q"] = (xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING) + Frag.h["scale"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_INT) + Frag.h["rot"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) + Frag.h["translate"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) + Frag.h["visible"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_INT) + Frag.h["t"] = ((((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR2) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["gravity"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR3) + Frag.h["physics"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR3) + Frag.h["scroll"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) + Frag.h["fov"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_INT) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["clip"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR2) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["fog"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["namespace"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["SPFX"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["unit"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["description"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["src_session"] = ((((xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.BROWSER_OVERRIDE) | xrfragment_XRF.PROMPT) + if (key in Frag.h): + v = xrfragment_XRF(key,Frag.h.get(key,None)) + if (not v.validate(value)): + print(str((((("[ i ] fragment '" + ("null" if key is None else key)) + "' has incompatible value (") + ("null" if value is None else value)) + ")"))) + return False + setattr(resultMap,(("_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)),v) + else: + print(str((("[ i ] fragment '" + ("null" if key is None else key)) + "' does not exist or has no type typed (yet)"))) + return False + return True + + class xrfragment_Query: _hx_class_name = "xrfragment.Query" __slots__ = ("str", "q", "isProp", "isExclude", "isClass", "isNumber") _hx_fields = ["str", "q", "isProp", "isExclude", "isClass", "isNumber"] - _hx_methods = ["toObject", "expandAliases", "parse", "test", "testProperty"] + _hx_methods = ["toObject", "expandAliases", "get", "parse", "test", "testProperty"] def __init__(self,_hx_str): self.isNumber = EReg("^[0-9\\.]+$","") @@ -1191,6 +1359,9 @@ class xrfragment_Query: else: return token + def get(self): + return self.q + def parse(self,_hx_str,recurse = None): if (recurse is None): recurse = False @@ -1271,8 +1442,12 @@ class xrfragment_Query: i = _g _g = (_g + 1) process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None))) - self.q = q - return self.q + def _hx_local_2(): + def _hx_local_1(): + self.q = q + return self.q + return _hx_local_1() + return _hx_local_2() def test(self,obj = None): qualify = False @@ -1341,10 +1516,138 @@ class xrfragment_Query: return (qualify > 0) + +class xrfragment_URI: + _hx_class_name = "xrfragment.URI" + __slots__ = () + _hx_statics = ["parse"] + + @staticmethod + def parse(qs,browser_override): + fragment = qs.split("#") + _this = (fragment[1] if 1 < len(fragment) else None) + splitArray = _this.split("&") + resultMap = _hx_AnonObject({}) + _g = 0 + _g1 = len(splitArray) + while (_g < _g1): + i = _g + _g = (_g + 1) + _this = (splitArray[i] if i >= 0 and i < len(splitArray) else None) + splitByEqual = _this.split("=") + regexPlus = EReg("\\+","g") + key = (splitByEqual[0] if 0 < len(splitByEqual) else None) + if (len(splitByEqual) > 1): + _this1 = regexPlus.split((splitByEqual[1] if 1 < len(splitByEqual) else None)) + value = python_lib_urllib_Parse.unquote(" ".join([python_Boot.toString1(x1,'') for x1 in _this1])) + ok = xrfragment_Parser.parse(key,value,resultMap) + if browser_override: + _g = 0 + _g1 = python_Boot.fields(resultMap) + while (_g < len(_g1)): + key = (_g1[_g] if _g >= 0 and _g < len(_g1) else None) + _g = (_g + 1) + xrf = Reflect.field(resultMap,key) + if (not xrf._hx_is(xrfragment_XRF.BROWSER_OVERRIDE)): + Reflect.deleteField(resultMap,key) + return resultMap + + +class xrfragment_XRF: + _hx_class_name = "xrfragment.XRF" + __slots__ = ("fragment", "flags", "x", "y", "z", "color", "string", "int", "float", "args", "query") + _hx_fields = ["fragment", "flags", "x", "y", "z", "color", "string", "int", "float", "args", "query"] + _hx_methods = ["is", "validate", "guessType"] + _hx_statics = ["ASSET", "ASSET_OBJ", "PV_OVERRIDE", "QUERY_OPERATOR", "PROMPT", "ROUNDROBIN", "BROWSER_OVERRIDE", "T_INT", "T_VECTOR2", "T_VECTOR3", "T_URL", "T_PREDEFINED_VIEW", "T_STRING", "T_STRING_OBJ", "isColor", "isInt", "isFloat"] + + def __init__(self,_fragment,_flags): + self.query = None + self.args = None + self.float = None + self.int = None + self.string = None + self.color = None + self.z = None + self.y = None + self.x = None + self.fragment = _fragment + self.flags = _flags + + def _hx_is(self,flag): + return (((self.flags & flag)) != 0) + + def validate(self,value): + self.guessType(self,value) + if (len(value.split("|")) > 1): + self.args = list() + args = value.split("|") + _g = 0 + _g1 = len(args) + while (_g < _g1): + i = _g + _g = (_g + 1) + x = xrfragment_XRF(self.fragment,self.flags) + self.guessType(x,(args[i] if i >= 0 and i < len(args) else None)) + _this = self.args + _this.append(x) + if (self.fragment == "q"): + self.query = xrfragment_Query(value).get() + ok = True + if (not Std.isOfType(self.args,list)): + if (self._hx_is(xrfragment_XRF.T_VECTOR3) and (not (((Std.isOfType(self.x,Float) and Std.isOfType(self.y,Float)) and Std.isOfType(self.z,Float))))): + ok = False + if (self._hx_is(xrfragment_XRF.T_VECTOR2) and (not ((Std.isOfType(self.x,Float) and Std.isOfType(self.y,Float))))): + ok = False + if (self._hx_is(xrfragment_XRF.T_INT) and (not Std.isOfType(self.int,Int))): + ok = False + return ok + + def guessType(self,v,_hx_str): + v.string = _hx_str + if (len(_hx_str.split(",")) > 1): + xyz = _hx_str.split(",") + if (len(xyz) > 0): + v.x = Std.parseFloat((xyz[0] if 0 < len(xyz) else None)) + if (len(xyz) > 1): + v.y = Std.parseFloat((xyz[1] if 1 < len(xyz) else None)) + if (len(xyz) > 2): + v.z = Std.parseFloat((xyz[2] if 2 < len(xyz) else None)) + _this = xrfragment_XRF.isColor + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.color = _hx_str + _this = xrfragment_XRF.isFloat + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.float = Std.parseFloat(_hx_str) + _this = xrfragment_XRF.isInt + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.int = Std.parseInt(_hx_str) + + Math.NEGATIVE_INFINITY = float("-inf") Math.POSITIVE_INFINITY = float("inf") Math.NaN = float("nan") Math.PI = python_lib_Math.pi python_Boot.keywords = set(["and", "del", "from", "not", "with", "as", "elif", "global", "or", "yield", "assert", "else", "if", "pass", "None", "break", "except", "import", "raise", "True", "class", "exec", "in", "return", "False", "continue", "finally", "is", "try", "def", "for", "lambda", "while"]) -python_Boot.prefixLength = len("_hx_") \ No newline at end of file +python_Boot.prefixLength = len("_hx_") +xrfragment_Parser.error = "" +xrfragment_XRF.ASSET = 1 +xrfragment_XRF.ASSET_OBJ = 2 +xrfragment_XRF.PV_OVERRIDE = 4 +xrfragment_XRF.QUERY_OPERATOR = 8 +xrfragment_XRF.PROMPT = 16 +xrfragment_XRF.ROUNDROBIN = 32 +xrfragment_XRF.BROWSER_OVERRIDE = 64 +xrfragment_XRF.T_INT = 256 +xrfragment_XRF.T_VECTOR2 = 1024 +xrfragment_XRF.T_VECTOR3 = 2048 +xrfragment_XRF.T_URL = 4096 +xrfragment_XRF.T_PREDEFINED_VIEW = 8192 +xrfragment_XRF.T_STRING = 16384 +xrfragment_XRF.T_STRING_OBJ = 32768 +xrfragment_XRF.isColor = EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","") +xrfragment_XRF.isInt = EReg("^[0-9]+$","") +xrfragment_XRF.isFloat = EReg("^[0-9]+\\.[0-9]+$","") \ No newline at end of file diff --git a/src/Test.hx b/src/Test.hx index 8342e82..e04e358 100644 --- a/src/Test.hx +++ b/src/Test.hx @@ -29,13 +29,15 @@ class Test { var valid:Bool = false; var item:Dynamic = spec[i]; if( item.fn == "query" ) q = new Query(item.data); - if( item.fn == "url" ) res = URI.parse(item.data); + if( item.fn == "url" ) res = URI.parse(item.data,false); if( item.expect.fn == "test" ) valid = item.expect.out == q.test( item.expect.input[0] ); if( item.expect.fn == "testProperty" ) valid = item.expect.out == q.testProperty( item.expect.input[0], item.expect.input[1] ); if( item.expect.fn == "testPropertyExclude" ) valid = item.expect.out == q.testProperty( item.expect.input[0], item.expect.input[1], true ); if( item.expect.fn == "testParsed" ) valid = item.expect.out == res.exists(item.expect.input); - 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 == "testBrowserOverride" ) valid = item.expect.out == (URI.parse(item.data,true)).exists(item.expect.input); + if( item.expect.fn == "equal.string" ) valid = res.get(item.expect.input) && item.expect.out == res.get(item.expect.input).string; + if( item.expect.fn == "equal.xy" ) valid = equalXY(res,item); + if( item.expect.fn == "equal.xyz" ) valid = equalXYZ(res,item); if( item.expect.fn == "equal.multi" ) valid = equalMulti(res, item); var ok:String = valid ? "[ ✔ ] " : "[ ❌] "; trace( ok + item.fn + ": '" + item.data + "'" + (item.label ? " (" + (item.label?item.label:item.expect.fn) +")" : "")); @@ -43,6 +45,16 @@ class Test { } } + static public function equalXY(res:haxe.DynamicAccess, item:Dynamic):Bool { + if( !item.expect.out && !res.get(item.expect.input) ) return true; + else return res.get(item.expect.input) && item.expect.out == (Std.string(res.get(item.expect.input).x) +","+ Std.string(res.get(item.expect.input).y) ); + } + + static public function equalXYZ(res:haxe.DynamicAccess, item:Dynamic):Bool { + if( !item.expect.out && !res.get(item.expect.input) ) return true; + else return res.get(item.expect.input) && item.expect.out == (Std.string(res.get(item.expect.input).x) +","+ Std.string(res.get(item.expect.input).y)+","+ Std.string(res.get(item.expect.input).z)); + } + static public function equalMulti(res:haxe.DynamicAccess, item:Dynamic):Bool { var target:Dynamic = res.get(item.expect.input); var str:String = ""; @@ -58,7 +70,7 @@ class Test { var Uri = xrfragment.URI; var url:String = "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3"; trace(url); - trace( Uri.parse(url) ); + trace( Uri.parse(url,false) ); } static public function testQuery():Void { diff --git a/src/spec/url.json b/src/spec/url.json index 7a3aeac..5a0e1a6 100644 --- a/src/spec/url.json +++ b/src/spec/url.json @@ -1,6 +1,9 @@ [ - {"fn":"url","data":"http://foo.com?foo=1#pos=flop", "expect":{ "fn":"equal.string","input":"pos","out":"flop"}}, - {"fn":"url","data":"http://foo.com?foo=1#pos=1.2,2.2", "expect":{ "fn":"equal.xy", "input":"pos","out":"1.22.2"},"label":"a equal.xy"}, - {"fn":"url","data":"http://foo.com?foo=1#prio=foo", "expect":{ "fn":"testParsed", "input":"prio","out":false},"label":"drop incompatible type"}, - {"fn":"url","data":"http://foo.com?foo=1#pos=c|d|1,2,3", "expect":{ "fn":"equal.multi", "input":"pos","out":"c|d|1,2,3"},"label":"b equal.multi"} + {"fn":"url","data":"http://foo.com?foo=1#pos=1.2,2.2", "expect":{ "fn":"equal.xyz", "input":"pos","out":false},"label":"equal.xyz: should trigger incompatible type)"}, + {"fn":"url","data":"http://foo.com?foo=1#pos=1.2,2.2,3", "expect":{ "fn":"equal.xyz", "input":"pos","out":"1.2,2.2,3"},"label":"equal.xyz"}, + {"fn":"url","data":"http://foo.com?foo=1#t=1,100", "expect":{ "fn":"equal.xy", "input":"t","out":"1,100"},"label":"a equal.xy"}, + {"fn":"url","data":"http://foo.com?foo=1#prio=foo", "expect":{ "fn":"testParsed", "input":"prio","out":false},"label":"should trigger incompatible type"}, + {"fn":"url","data":"http://foo.com?foo=1#pos=c|d|1,2,3", "expect":{ "fn":"equal.multi", "input":"pos","out":"c|d|1,2,3"},"label":"b equal.multi"}, + {"fn":"url","data":"http://foo.com?foo=1#t=2,500", "expect":{ "fn":"testBrowserOverride", "input":"t","out":true},"label":"browser URI can override t (defined in asset)"}, + {"fn":"url","data":"http://foo.com?foo=1#q=-bar", "expect":{ "fn":"testBrowserOverride", "input":"q","out":false},"label":"browser URI cannot override q (defined in asset)"} ] diff --git a/src/xrfragment/XRF.hx b/src/xrfragment/XRF.hx index 7dfe7d6..78beb90 100644 --- a/src/xrfragment/XRF.hx +++ b/src/xrfragment/XRF.hx @@ -7,24 +7,26 @@ class XRF { */ // public static inline readonly ASSET - public static var ASSET:Int = 1; // fragment is immutable (typed in asset) globally - public static var ASSET_OBJ:Int = 2; // fragment is immutable (typed in object in asset) - public static var PV_OVERRIDE:Int = 4; // fragment can be overriden when specified in predefined view value - public static var QUERY_OPERATOR = 8; // fragment will be applied to result of queryselecto - public static var PROMPT:Int = 16; // ask user whether this fragment value can be changed - public static var ROUNDROBIN:Int = 32; // evaluation of this (multi) value can be roundrobined - public static var BROWSER_OVERRIDE:Int = 64; // fragment can be overriden by (manual) browser URI change - // highlevel types - public static var T_COLOR:Int = 128; - public static var T_INT:Int = 256; - public static var T_FLOAT:Int = 512; - public static var T_VECTOR2:Int = 1024; - public static var T_VECTOR3:Int = 2048; - public static var T_URL:Int = 4096; + // scope types (power of 2) + public static var ASSET:Int = 1; // fragment is immutable (typed in asset) globally + public static var ASSET_OBJ:Int = 2; // fragment is immutable (typed in object in asset) + public static var PV_OVERRIDE:Int = 4; // fragment can be overriden when specified in predefined view value + public static var QUERY_OPERATOR = 8; // fragment will be applied to result of queryselecto + public static var PROMPT:Int = 16; // ask user whether this fragment value can be changed + public static var ROUNDROBIN:Int = 32; // evaluation of this (multi) value can be roundrobined + public static var BROWSER_OVERRIDE:Int = 64; // fragment can be overriden by (manual) browser URI change + + // highlevel types (power of 2) + public static var T_COLOR:Int = 128; + public static var T_INT:Int = 256; + public static var T_FLOAT:Int = 512; + public static var T_VECTOR2:Int = 1024; + public static var T_VECTOR3:Int = 2048; + public static var T_URL:Int = 4096; public static var T_PREDEFINED_VIEW:Int = 8192; - public static var T_STRING:Int = 16384; - public static var T_STRING_OBJ:Int = 32768; + public static var T_STRING:Int = 16384; + public static var T_STRING_OBJ:Int = 32768; // regexes public static var isColor:EReg = ~/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/; // 1. hex colors are detected using regex `/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/` diff --git a/test/generated/test.js b/test/generated/test.js index b0ec805..a1b5ae2 100644 --- a/test/generated/test.js +++ b/test/generated/test.js @@ -65,6 +65,13 @@ Reflect.fields = function(o) { } return a; }; +Reflect.deleteField = function(o,field) { + if(!Object.prototype.hasOwnProperty.call(o,field)) { + return false; + } + delete(o[field]); + return true; +}; var Std = function() { }; Std.__name__ = true; Std.string = function(s) { @@ -129,7 +136,7 @@ StringTools.replace = function(s,sub,by) { var Test = function() { }; Test.__name__ = true; Test.main = function() { - Test.test([{ fn : "url", expect : { fn : "equal.string", input : "pos", out : "flop"}, data : "http://foo.com?foo=1#pos=flop"},{ fn : "url", expect : { fn : "equal.xy", input : "pos", out : "1.22.2"}, label : "a equal.xy", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "drop incompatible type", data : "http://foo.com?foo=1#prio=foo"},{ fn : "url", expect : { fn : "equal.multi", input : "pos", out : "c|d|1,2,3"}, label : "b equal.multi", data : "http://foo.com?foo=1#pos=c|d|1,2,3"}]); + Test.test([{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : false}, label : "equal.xyz: should trigger incompatible type)", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : "1.2,2.2,3"}, label : "equal.xyz", data : "http://foo.com?foo=1#pos=1.2,2.2,3"},{ fn : "url", expect : { fn : "equal.xy", input : "t", out : "1,100"}, label : "a equal.xy", data : "http://foo.com?foo=1#t=1,100"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "should trigger incompatible type", data : "http://foo.com?foo=1#prio=foo"},{ fn : "url", expect : { fn : "equal.multi", input : "pos", out : "c|d|1,2,3"}, label : "b equal.multi", data : "http://foo.com?foo=1#pos=c|d|1,2,3"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "t", out : true}, label : "browser URI can override t (defined in asset)", data : "http://foo.com?foo=1#t=2,500"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "q", out : false}, label : "browser URI cannot override q (defined in asset)", data : "http://foo.com?foo=1#q=-bar"}]); Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : "class:bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, label : ".bar shorthand", data : ".bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : false}, data : ".bar -.foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, data : ".bar -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : ".bar -.bar .bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : false}, label : "!id:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : true}, label : "id:foo?", data : "foo -foo foo"}]); Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : true}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : false}, data : "price:>=15"},{ fn : "query", expect : { fn : "testProperty", input : ["price","4"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","1"], out : false}, label : "price=1", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : true}, label : "price=0", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","6"], out : true}, label : "price=6", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : true}, data : "tag:foo"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : false}, data : "-tag:foo"},{ fn : "query", expect : { fn : "testPropertyExclude", input : ["tag","foo"], out : true}, label : "testExclude", data : "-tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ price : 5}], out : true}, data : ".foo price:5 -tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ tag : "foo", price : 5}], out : false}, data : ".foo price:5 -tag:foo"}]); if(Test.errors > 1) { @@ -150,7 +157,7 @@ Test.test = function(spec) { q = new xrfragment_Query(item.data); } if(item.fn == "url") { - res = xrfragment_URI.parse(item.data); + res = xrfragment_URI.parse(item.data,false); } if(item.expect.fn == "test") { valid = item.expect.out == q.test(item.expect.input[0]); @@ -164,22 +171,48 @@ Test.test = function(spec) { if(item.expect.fn == "testParsed") { valid = item.expect.out == Object.prototype.hasOwnProperty.call(res,item.expect.input); } + if(item.expect.fn == "testBrowserOverride") { + var item1 = item.expect.out; + var this1 = xrfragment_URI.parse(item.data,true); + valid = item1 == Object.prototype.hasOwnProperty.call(this1,item.expect.input); + } if(item.expect.fn == "equal.string") { - valid = item.expect.out == res[item.expect.input].string; + valid = res[item.expect.input] && item.expect.out == res[item.expect.input].string; } if(item.expect.fn == "equal.xy") { - valid = item.expect.out == Std.string(res[item.expect.input].x) + Std.string(res[item.expect.input].y); + valid = Test.equalXY(res,item); + } + if(item.expect.fn == "equal.xyz") { + valid = Test.equalXYZ(res,item); } if(item.expect.fn == "equal.multi") { valid = Test.equalMulti(res,item); } var ok = valid ? "[ ✔ ] " : "[ ❌] "; - console.log("src/Test.hx:41:",ok + Std.string(item.fn) + ": '" + Std.string(item.data) + "'" + (item.label ? " (" + (item.label ? item.label : item.expect.fn) + ")" : "")); + console.log("src/Test.hx:43:",ok + Std.string(item.fn) + ": '" + Std.string(item.data) + "'" + (item.label ? " (" + (item.label ? item.label : item.expect.fn) + ")" : "")); if(!valid) { Test.errors += 1; } } }; +Test.equalXY = function(res,item) { + if(!item.expect.out && !res[item.expect.input]) { + return true; + } else if(res[item.expect.input]) { + return item.expect.out == Std.string(res[item.expect.input].x) + "," + Std.string(res[item.expect.input].y); + } else { + return false; + } +}; +Test.equalXYZ = function(res,item) { + if(!item.expect.out && !res[item.expect.input]) { + return true; + } else if(res[item.expect.input]) { + return item.expect.out == Std.string(res[item.expect.input].x) + "," + Std.string(res[item.expect.input].y) + "," + Std.string(res[item.expect.input].z); + } else { + return false; + } +}; Test.equalMulti = function(res,item) { var target = res[item.expect.input]; var str = ""; @@ -282,66 +315,46 @@ var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { }; xrfragment_Parser.__name__ = true; xrfragment_Parser.parse = function(key,value,resultMap) { var Frag_h = Object.create(null); - Frag_h["prio"] = xrfragment_Type.isInt; - Frag_h["pos"] = xrfragment_Type.isVector; - Frag_h["q"] = xrfragment_Type.isString; - var vec = "1,2,3"; + Frag_h["prio"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_INT; + Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW; + Frag_h["class"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_STRING; + Frag_h["src"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_audio"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_shader"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL; + Frag_h["src_env"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL; + Frag_h["src_env_audio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL; + Frag_h["pos"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.T_STRING_OBJ; + Frag_h["href"] = xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL | xrfragment_XRF.T_PREDEFINED_VIEW; + Frag_h["q"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING; + Frag_h["scale"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT; + Frag_h["rot"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3; + Frag_h["translate"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3; + Frag_h["visible"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT; + Frag_h["t"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["gravity"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3; + Frag_h["physics"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3; + Frag_h["scroll"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING; + Frag_h["fov"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_INT | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["clip"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["fog"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.BROWSER_OVERRIDE; + Frag_h["namespace"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["SPFX"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["unit"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING; + Frag_h["src_session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.BROWSER_OVERRIDE | xrfragment_XRF.PROMPT; if(Object.prototype.hasOwnProperty.call(Frag_h,key)) { - if(Frag_h[key].match(value)) { - var v = new xrfragment_Value(); - xrfragment_Parser.guessType(v,value); - if(value.split("|").length > 1) { - v.args = []; - var args = value.split("|"); - var _g = 0; - var _g1 = args.length; - while(_g < _g1) { - var i = _g++; - var x = new xrfragment_Value(); - xrfragment_Parser.guessType(x,args[i]); - v.args.push(x); - } - } - resultMap[key] = v; - } else { - console.log("src/xrfragment/Parser.hx:47:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")"); + var v = new xrfragment_XRF(key,Frag_h[key]); + if(!v.validate(value)) { + console.log("src/xrfragment/Parser.hx:66:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")"); return false; } + resultMap[key] = v; } else { - console.log("src/xrfragment/Parser.hx:48:","[ i ] fragment '" + key + "' does not exist or has no type defined (yet)"); + console.log("src/xrfragment/Parser.hx:70:","[ i ] fragment '" + key + "' does not exist or has no type typed (yet)"); return false; } return true; }; -xrfragment_Parser.guessType = function(v,str) { - v.string = str; - if(str.split(",").length > 1) { - var xyz = str.split(","); - if(xyz.length > 0) { - v.x = parseFloat(xyz[0]); - } - if(xyz.length > 1) { - v.y = parseFloat(xyz[1]); - } - if(xyz.length > 2) { - v.y = parseFloat(xyz[2]); - } - } - if(xrfragment_Type.isColor.match(str)) { - v.color = str; - } - if(xrfragment_Type.isFloat.match(str)) { - v.float = parseFloat(str); - } - if(xrfragment_Type.isInt.match(str)) { - v.int = Std.parseInt(str); - } -}; -var xrfragment_Value = function() { -}; -xrfragment_Value.__name__ = true; -var xrfragment_Type = function() { }; -xrfragment_Type.__name__ = true; var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) { this.isNumber = new EReg("^[0-9\\.]+$",""); this.isClass = new EReg("^[-]?class$",""); @@ -366,6 +379,9 @@ xrfragment_Query.prototype = { return token; } } + ,get: function() { + return this.q; + } ,parse: function(str,recurse) { if(recurse == null) { recurse = false; @@ -437,8 +453,7 @@ xrfragment_Query.prototype = { var i = _g++; process(this.expandAliases(token[i])); } - this.q = q; - return this.q; + return this.q = q; } ,test: function(obj) { var qualify = false; @@ -524,7 +539,7 @@ xrfragment_Query.prototype = { }; var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; -xrfragment_URI.parse = function(qs) { +xrfragment_URI.parse = function(qs,browser_override) { var fragment = qs.split("#"); var splitArray = fragment[1].split("&"); var resultMap = { }; @@ -541,8 +556,92 @@ xrfragment_URI.parse = function(qs) { var ok = xrfragment_Parser.parse(key,value,resultMap); } } + if(browser_override) { + var _g = 0; + var _g1 = Reflect.fields(resultMap); + while(_g < _g1.length) { + var key = _g1[_g]; + ++_g; + var xrf = resultMap[key]; + if(!xrf.is(xrfragment_XRF.BROWSER_OVERRIDE)) { + Reflect.deleteField(resultMap,key); + } + } + } return resultMap; }; +var xrfragment_XRF = function(_fragment,_flags) { + this.fragment = _fragment; + this.flags = _flags; +}; +xrfragment_XRF.__name__ = true; +xrfragment_XRF.prototype = { + is: function(flag) { + return (this.flags & flag) != 0; + } + ,validate: function(value) { + this.guessType(this,value); + if(value.split("|").length > 1) { + this.args = []; + var args = value.split("|"); + var _g = 0; + var _g1 = args.length; + while(_g < _g1) { + var i = _g++; + var x = new xrfragment_XRF(this.fragment,this.flags); + this.guessType(x,args[i]); + this.args.push(x); + } + } + if(this.fragment == "q") { + this.query = new xrfragment_Query(value).get(); + } + var ok = true; + if(!((this.args) instanceof Array)) { + if(this.is(xrfragment_XRF.T_VECTOR3) && !(typeof(this.x) == "number" && typeof(this.y) == "number" && typeof(this.z) == "number")) { + ok = false; + } + if(this.is(xrfragment_XRF.T_VECTOR2) && !(typeof(this.x) == "number" && typeof(this.y) == "number")) { + ok = false; + } + var tmp; + if(this.is(xrfragment_XRF.T_INT)) { + var v = this.int; + tmp = !(typeof(v) == "number" && ((v | 0) === v)); + } else { + tmp = false; + } + if(tmp) { + ok = false; + } + } + return ok; + } + ,guessType: function(v,str) { + v.string = str; + if(str.split(",").length > 1) { + var xyz = str.split(","); + if(xyz.length > 0) { + v.x = parseFloat(xyz[0]); + } + if(xyz.length > 1) { + v.y = parseFloat(xyz[1]); + } + if(xyz.length > 2) { + v.z = parseFloat(xyz[2]); + } + } + if(xrfragment_XRF.isColor.match(str)) { + v.color = str; + } + if(xrfragment_XRF.isFloat.match(str)) { + v.float = parseFloat(str); + } + if(xrfragment_XRF.isInt.match(str)) { + v.int = Std.parseInt(str); + } + } +}; if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) { HxOverrides.now = performance.now.bind(performance); } @@ -551,11 +650,23 @@ Array.__name__ = true; js_Boot.__toStr = ({ }).toString; Test.errors = 0; xrfragment_Parser.error = ""; -xrfragment_Type.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); -xrfragment_Type.isInt = new EReg("^[0-9]+$",""); -xrfragment_Type.isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); -xrfragment_Type.isVector = new EReg("([,]+|\\w)",""); -xrfragment_Type.isString = new EReg(".*",""); +xrfragment_XRF.ASSET = 1; +xrfragment_XRF.ASSET_OBJ = 2; +xrfragment_XRF.PV_OVERRIDE = 4; +xrfragment_XRF.QUERY_OPERATOR = 8; +xrfragment_XRF.PROMPT = 16; +xrfragment_XRF.ROUNDROBIN = 32; +xrfragment_XRF.BROWSER_OVERRIDE = 64; +xrfragment_XRF.T_INT = 256; +xrfragment_XRF.T_VECTOR2 = 1024; +xrfragment_XRF.T_VECTOR3 = 2048; +xrfragment_XRF.T_URL = 4096; +xrfragment_XRF.T_PREDEFINED_VIEW = 8192; +xrfragment_XRF.T_STRING = 16384; +xrfragment_XRF.T_STRING_OBJ = 32768; +xrfragment_XRF.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); +xrfragment_XRF.isInt = new EReg("^[0-9]+$",""); +xrfragment_XRF.isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); Test.main(); })({}); var xrfragment = $hx_exports["xrfragment"]; diff --git a/test/generated/test.py b/test/generated/test.py index a6a83e8..3e5fb1d 100644 --- a/test/generated/test.py +++ b/test/generated/test.py @@ -112,12 +112,23 @@ class EReg: class Reflect: _hx_class_name = "Reflect" __slots__ = () - _hx_statics = ["field"] + _hx_statics = ["field", "deleteField"] @staticmethod def field(o,field): return python_Boot.field(o,field) + @staticmethod + def deleteField(o,field): + if (field in python_Boot.keywords): + field = ("_hx_" + field) + elif ((((len(field) > 2) and ((ord(field[0]) == 95))) and ((ord(field[1]) == 95))) and ((ord(field[(len(field) - 1)]) != 95))): + field = ("_hx_" + field) + if (not python_Boot.hasField(o,field)): + return False + o.__delattr__(field) + return True + class Std: _hx_class_name = "Std" @@ -375,11 +386,11 @@ class StringTools: class Test: _hx_class_name = "Test" __slots__ = () - _hx_statics = ["errors", "main", "test", "equalMulti"] + _hx_statics = ["errors", "main", "test", "equalXY", "equalXYZ", "equalMulti"] @staticmethod def main(): - Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.string", 'input': "pos", 'out': "flop"}), 'data': "http://foo.com?foo=1#pos=flop"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "pos", 'out': "1.22.2"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#pos=1.2,2.2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "prio", 'out': False}), 'label': "drop incompatible type", 'data': "http://foo.com?foo=1#prio=foo"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.multi", 'input': "pos", 'out': "c|d|1,2,3"}), 'label': "b equal.multi", 'data': "http://foo.com?foo=1#pos=c|d|1,2,3"})]) + Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': False}), 'label': "equal.xyz: should trigger incompatible type)", 'data': "http://foo.com?foo=1#pos=1.2,2.2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': "1.2,2.2,3"}), 'label': "equal.xyz", 'data': "http://foo.com?foo=1#pos=1.2,2.2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "t", 'out': "1,100"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#t=1,100"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "prio", 'out': False}), 'label': "should trigger incompatible type", 'data': "http://foo.com?foo=1#prio=foo"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.multi", 'input': "pos", 'out': "c|d|1,2,3"}), 'label': "b equal.multi", 'data': "http://foo.com?foo=1#pos=c|d|1,2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "t", 'out': True}), 'label': "browser URI can override t (defined in asset)", 'data': "http://foo.com?foo=1#t=2,500"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "q", 'out': False}), 'label': "browser URI cannot override q (defined in asset)", 'data': "http://foo.com?foo=1#q=-bar"})]) Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': "class:bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'label': ".bar shorthand", 'data': ".bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': False}), 'data': ".bar -.foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'data': ".bar -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': ".bar -.bar .bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': False}), 'label': "!id:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': True}), 'label': "id:foo?", 'data': "foo -foo foo"})]) Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': True}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': False}), 'data': "price:>=15"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "4"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "1"], 'out': False}), 'label': "price=1", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': True}), 'label': "price=0", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "6"], 'out': True}), 'label': "price=6", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': True}), 'data': "tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': False}), 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testPropertyExclude", 'input': ["tag", "foo"], 'out': True}), 'label': "testExclude", 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'price': 5})], 'out': True}), 'data': ".foo price:5 -tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'tag': "foo", 'price': 5})], 'out': False}), 'data': ".foo price:5 -tag:foo"})]) if (Test.errors > 1): @@ -400,7 +411,7 @@ class Test: if (Reflect.field(item,"fn") == "query"): q = xrfragment_Query(Reflect.field(item,"data")) if (Reflect.field(item,"fn") == "url"): - res = xrfragment_URI.parse(Reflect.field(item,"data")) + res = xrfragment_URI.parse(Reflect.field(item,"data"),False) if (Reflect.field(Reflect.field(item,"expect"),"fn") == "test"): valid = (Reflect.field(Reflect.field(item,"expect"),"out") == q.test(HxOverrides.arrayGet(Reflect.field(Reflect.field(item,"expect"),"input"), 0))) if (Reflect.field(Reflect.field(item,"expect"),"fn") == "testProperty"): @@ -409,10 +420,14 @@ class Test: valid = (Reflect.field(Reflect.field(item,"expect"),"out") == q.testProperty(HxOverrides.arrayGet(Reflect.field(Reflect.field(item,"expect"),"input"), 0),HxOverrides.arrayGet(Reflect.field(Reflect.field(item,"expect"),"input"), 1),True)) if (Reflect.field(Reflect.field(item,"expect"),"fn") == "testParsed"): valid = (Reflect.field(Reflect.field(item,"expect"),"out") == python_Boot.hasField(res,Reflect.field(Reflect.field(item,"expect"),"input"))) + if (Reflect.field(Reflect.field(item,"expect"),"fn") == "testBrowserOverride"): + valid = (Reflect.field(Reflect.field(item,"expect"),"out") == python_Boot.hasField(xrfragment_URI.parse(Reflect.field(item,"data"),True),Reflect.field(Reflect.field(item,"expect"),"input"))) 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 = (Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")) and (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"): - valid = (Reflect.field(Reflect.field(item,"expect"),"out") == ((Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"x")) + Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"y"))))) + valid = Test.equalXY(res,item) + if (Reflect.field(Reflect.field(item,"expect"),"fn") == "equal.xyz"): + valid = Test.equalXYZ(res,item) if (Reflect.field(Reflect.field(item,"expect"),"fn") == "equal.multi"): valid = Test.equalMulti(res,item) ok = ("[ ✔ ] " if valid else "[ ❌] ") @@ -423,6 +438,24 @@ class Test: _hx_local_0.errors = (_hx_local_1 + 1) _hx_local_0.errors + @staticmethod + def equalXY(res,item): + if ((not Reflect.field(Reflect.field(item,"expect"),"out")) and (not Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")))): + return True + elif Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")): + return (Reflect.field(Reflect.field(item,"expect"),"out") == (((Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"x")) + ",") + Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"y"))))) + else: + return False + + @staticmethod + def equalXYZ(res,item): + if ((not Reflect.field(Reflect.field(item,"expect"),"out")) and (not Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")))): + return True + elif Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")): + return (Reflect.field(Reflect.field(item,"expect"),"out") == (((((Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"x")) + ",") + Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"y"))) + ",") + Std.string(Reflect.field(Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")),"z"))))) + else: + return False + @staticmethod def equalMulti(res,item): target = Reflect.field(res,Reflect.field(Reflect.field(item,"expect"),"input")) @@ -1363,94 +1396,55 @@ class HxString: class xrfragment_Parser: _hx_class_name = "xrfragment.Parser" __slots__ = () - _hx_statics = ["error", "parse", "guessType"] + _hx_statics = ["error", "parse"] @staticmethod def parse(key,value,resultMap): Frag = haxe_ds_StringMap() - Frag.h["prio"] = xrfragment_Type.isInt - Frag.h["pos"] = xrfragment_Type.isVector - Frag.h["q"] = xrfragment_Type.isString - vec = "1,2,3" + Frag.h["prio"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_INT) + Frag.h["#"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW) + Frag.h["class"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_STRING) + Frag.h["src"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_audio"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_shader"] = (xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) + Frag.h["src_env"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) + Frag.h["src_env_audio"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) + Frag.h["pos"] = (((xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) | xrfragment_XRF.T_STRING_OBJ) + Frag.h["href"] = ((xrfragment_XRF.ASSET_OBJ | xrfragment_XRF.T_URL) | xrfragment_XRF.T_PREDEFINED_VIEW) + Frag.h["q"] = (xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING) + Frag.h["scale"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_INT) + Frag.h["rot"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) + Frag.h["translate"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR3) + Frag.h["visible"] = (((xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_INT) + Frag.h["t"] = ((((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.ROUNDROBIN) | xrfragment_XRF.T_VECTOR2) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["gravity"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR3) + Frag.h["physics"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR3) + Frag.h["scroll"] = ((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) + Frag.h["fov"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_INT) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["clip"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_VECTOR2) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["fog"] = (((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.BROWSER_OVERRIDE) + Frag.h["namespace"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["SPFX"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["unit"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["description"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING) + Frag.h["src_session"] = ((((xrfragment_XRF.ASSET | xrfragment_XRF.T_URL) | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.BROWSER_OVERRIDE) | xrfragment_XRF.PROMPT) if (key in Frag.h): - _this = Frag.h.get(key,None) - _this.matchObj = python_lib_Re.search(_this.pattern,value) - if (_this.matchObj is not None): - v = xrfragment_Value() - xrfragment_Parser.guessType(v,value) - if (len(value.split("|")) > 1): - v.args = list() - args = value.split("|") - _g = 0 - _g1 = len(args) - while (_g < _g1): - i = _g - _g = (_g + 1) - x = xrfragment_Value() - xrfragment_Parser.guessType(x,(args[i] if i >= 0 and i < len(args) else None)) - _this = v.args - _this.append(x) - setattr(resultMap,(("_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)),v) - else: + v = xrfragment_XRF(key,Frag.h.get(key,None)) + if (not v.validate(value)): print(str((((("[ i ] fragment '" + ("null" if key is None else key)) + "' has incompatible value (") + ("null" if value is None else value)) + ")"))) return False + setattr(resultMap,(("_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)),v) else: - print(str((("[ i ] fragment '" + ("null" if key is None else key)) + "' does not exist or has no type defined (yet)"))) + print(str((("[ i ] fragment '" + ("null" if key is None else key)) + "' does not exist or has no type typed (yet)"))) return False return True - @staticmethod - def guessType(v,_hx_str): - v.string = _hx_str - if (len(_hx_str.split(",")) > 1): - xyz = _hx_str.split(",") - if (len(xyz) > 0): - v.x = Std.parseFloat((xyz[0] if 0 < len(xyz) else None)) - if (len(xyz) > 1): - v.y = Std.parseFloat((xyz[1] if 1 < len(xyz) else None)) - if (len(xyz) > 2): - v.y = Std.parseFloat((xyz[2] if 2 < len(xyz) else None)) - _this = xrfragment_Type.isColor - _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) - if (_this.matchObj is not None): - v.color = _hx_str - _this = xrfragment_Type.isFloat - _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) - if (_this.matchObj is not None): - v.float = Std.parseFloat(_hx_str) - _this = xrfragment_Type.isInt - _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) - if (_this.matchObj is not None): - v.int = Std.parseInt(_hx_str) - - -class xrfragment_Value: - _hx_class_name = "xrfragment.Value" - __slots__ = ("x", "y", "color", "string", "int", "float", "args") - _hx_fields = ["x", "y", "color", "string", "int", "float", "args"] - - def __init__(self): - self.args = None - self.float = None - self.int = None - self.string = None - self.color = None - self.y = None - self.x = None - - - -class xrfragment_Type: - _hx_class_name = "xrfragment.Type" - __slots__ = () - _hx_statics = ["isColor", "isInt", "isFloat", "isVector", "isString"] - class xrfragment_Query: _hx_class_name = "xrfragment.Query" __slots__ = ("str", "q", "isProp", "isExclude", "isClass", "isNumber") _hx_fields = ["str", "q", "isProp", "isExclude", "isClass", "isNumber"] - _hx_methods = ["toObject", "expandAliases", "parse", "test", "testProperty"] + _hx_methods = ["toObject", "expandAliases", "get", "parse", "test", "testProperty"] def __init__(self,_hx_str): self.isNumber = EReg("^[0-9\\.]+$","") @@ -1473,6 +1467,9 @@ class xrfragment_Query: else: return token + def get(self): + return self.q + def parse(self,_hx_str,recurse = None): if (recurse is None): recurse = False @@ -1553,8 +1550,12 @@ class xrfragment_Query: i = _g _g = (_g + 1) process(self.expandAliases((token[i] if i >= 0 and i < len(token) else None))) - self.q = q - return self.q + def _hx_local_2(): + def _hx_local_1(): + self.q = q + return self.q + return _hx_local_1() + return _hx_local_2() def test(self,obj = None): qualify = False @@ -1581,8 +1582,8 @@ class xrfragment_Query: fails = 0 qualify = 0 def _hx_local_2(expr): - nonlocal fails nonlocal conds + nonlocal fails conds = (conds + 1) fails = (fails + (0 if expr else 1)) return expr @@ -1630,7 +1631,7 @@ class xrfragment_URI: _hx_statics = ["parse"] @staticmethod - def parse(qs): + def parse(qs,browser_override): fragment = qs.split("#") _this = (fragment[1] if 1 < len(fragment) else None) splitArray = _this.split("&") @@ -1648,8 +1649,91 @@ class xrfragment_URI: _this1 = regexPlus.split((splitByEqual[1] if 1 < len(splitByEqual) else None)) value = python_lib_urllib_Parse.unquote(" ".join([python_Boot.toString1(x1,'') for x1 in _this1])) ok = xrfragment_Parser.parse(key,value,resultMap) + if browser_override: + _g = 0 + _g1 = python_Boot.fields(resultMap) + while (_g < len(_g1)): + key = (_g1[_g] if _g >= 0 and _g < len(_g1) else None) + _g = (_g + 1) + xrf = Reflect.field(resultMap,key) + if (not xrf._hx_is(xrfragment_XRF.BROWSER_OVERRIDE)): + Reflect.deleteField(resultMap,key) return resultMap + +class xrfragment_XRF: + _hx_class_name = "xrfragment.XRF" + __slots__ = ("fragment", "flags", "x", "y", "z", "color", "string", "int", "float", "args", "query") + _hx_fields = ["fragment", "flags", "x", "y", "z", "color", "string", "int", "float", "args", "query"] + _hx_methods = ["is", "validate", "guessType"] + _hx_statics = ["ASSET", "ASSET_OBJ", "PV_OVERRIDE", "QUERY_OPERATOR", "PROMPT", "ROUNDROBIN", "BROWSER_OVERRIDE", "T_INT", "T_VECTOR2", "T_VECTOR3", "T_URL", "T_PREDEFINED_VIEW", "T_STRING", "T_STRING_OBJ", "isColor", "isInt", "isFloat"] + + def __init__(self,_fragment,_flags): + self.query = None + self.args = None + self.float = None + self.int = None + self.string = None + self.color = None + self.z = None + self.y = None + self.x = None + self.fragment = _fragment + self.flags = _flags + + def _hx_is(self,flag): + return (((self.flags & flag)) != 0) + + def validate(self,value): + self.guessType(self,value) + if (len(value.split("|")) > 1): + self.args = list() + args = value.split("|") + _g = 0 + _g1 = len(args) + while (_g < _g1): + i = _g + _g = (_g + 1) + x = xrfragment_XRF(self.fragment,self.flags) + self.guessType(x,(args[i] if i >= 0 and i < len(args) else None)) + _this = self.args + _this.append(x) + if (self.fragment == "q"): + self.query = xrfragment_Query(value).get() + ok = True + if (not Std.isOfType(self.args,list)): + if (self._hx_is(xrfragment_XRF.T_VECTOR3) and (not (((Std.isOfType(self.x,Float) and Std.isOfType(self.y,Float)) and Std.isOfType(self.z,Float))))): + ok = False + if (self._hx_is(xrfragment_XRF.T_VECTOR2) and (not ((Std.isOfType(self.x,Float) and Std.isOfType(self.y,Float))))): + ok = False + if (self._hx_is(xrfragment_XRF.T_INT) and (not Std.isOfType(self.int,Int))): + ok = False + return ok + + def guessType(self,v,_hx_str): + v.string = _hx_str + if (len(_hx_str.split(",")) > 1): + xyz = _hx_str.split(",") + if (len(xyz) > 0): + v.x = Std.parseFloat((xyz[0] if 0 < len(xyz) else None)) + if (len(xyz) > 1): + v.y = Std.parseFloat((xyz[1] if 1 < len(xyz) else None)) + if (len(xyz) > 2): + v.z = Std.parseFloat((xyz[2] if 2 < len(xyz) else None)) + _this = xrfragment_XRF.isColor + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.color = _hx_str + _this = xrfragment_XRF.isFloat + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.float = Std.parseFloat(_hx_str) + _this = xrfragment_XRF.isInt + _this.matchObj = python_lib_Re.search(_this.pattern,_hx_str) + if (_this.matchObj is not None): + v.int = Std.parseInt(_hx_str) + + Math.NEGATIVE_INFINITY = float("-inf") Math.POSITIVE_INFINITY = float("inf") Math.NaN = float("nan") @@ -1659,10 +1743,22 @@ Test.errors = 0 python_Boot.keywords = set(["and", "del", "from", "not", "with", "as", "elif", "global", "or", "yield", "assert", "else", "if", "pass", "None", "break", "except", "import", "raise", "True", "class", "exec", "in", "return", "False", "continue", "finally", "is", "try", "def", "for", "lambda", "while"]) python_Boot.prefixLength = len("_hx_") xrfragment_Parser.error = "" -xrfragment_Type.isColor = EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","") -xrfragment_Type.isInt = EReg("^[0-9]+$","") -xrfragment_Type.isFloat = EReg("^[0-9]+\\.[0-9]+$","") -xrfragment_Type.isVector = EReg("([,]+|\\w)","") -xrfragment_Type.isString = EReg(".*","") +xrfragment_XRF.ASSET = 1 +xrfragment_XRF.ASSET_OBJ = 2 +xrfragment_XRF.PV_OVERRIDE = 4 +xrfragment_XRF.QUERY_OPERATOR = 8 +xrfragment_XRF.PROMPT = 16 +xrfragment_XRF.ROUNDROBIN = 32 +xrfragment_XRF.BROWSER_OVERRIDE = 64 +xrfragment_XRF.T_INT = 256 +xrfragment_XRF.T_VECTOR2 = 1024 +xrfragment_XRF.T_VECTOR3 = 2048 +xrfragment_XRF.T_URL = 4096 +xrfragment_XRF.T_PREDEFINED_VIEW = 8192 +xrfragment_XRF.T_STRING = 16384 +xrfragment_XRF.T_STRING_OBJ = 32768 +xrfragment_XRF.isColor = EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","") +xrfragment_XRF.isInt = EReg("^[0-9]+$","") +xrfragment_XRF.isFloat = EReg("^[0-9]+\\.[0-9]+$","") Test.main() diff --git a/test/test.js b/test/test.js index 016c6cf..e80c92f 100644 --- a/test/test.js +++ b/test/test.js @@ -10,7 +10,7 @@ var XF = require('../dist/xrfragment').xrfragment let print = (e) => console.log( JSON.stringify(e, null, 1) + "\n" ) -print( XF.URI.parse('://foo.com/1.gltf#pos=1,2,3&q=-.foo') ); +print( XF.URI.parse('://foo.com/1.gltf#pos=1.0,2.0,3.0&q=-.foo&t=1,100',true) ); // query let q = new XF.Query();