diff --git a/dist/xrfragment.js b/dist/xrfragment.js index 2506405..2f18623 100644 --- a/dist/xrfragment.js +++ b/dist/xrfragment.js @@ -283,9 +283,12 @@ xrfragment_Query.prototype = { } } }; -var xrfragment_Url = $hx_exports["xrfragment"]["Url"] = function() { }; -xrfragment_Url.parseQueryMap = function(qs) { - var splitArray = qs.split("&"); +var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() { +}; +var xrfragment_Url = function() { }; +xrfragment_Url.parse = function(qs) { + var fragment = qs.split("#"); + var splitArray = fragment[1].split("&"); var regexPlus = new EReg("\\+","g"); var resultMap = new haxe_ds_StringMap(); var _g = 0; @@ -294,22 +297,60 @@ xrfragment_Url.parseQueryMap = function(qs) { var i = _g++; var splitByEqual = splitArray[i].split("="); var key = splitByEqual[0]; - if(splitByEqual.length == 1) { - resultMap.h[key] = ""; - } else { + var v = new xrfragment_Value(); + if(splitByEqual.length > 1) { var s = regexPlus.split(splitByEqual[1]).join(" "); var value = decodeURIComponent(s.split("+").join(" ")); - resultMap.h[key] = value; + xrfragment_Url.guessType(v,value); + if(value.split("|").length > 1) { + v.args = []; + var args = value.split("|"); + var _g2 = 0; + var _g3 = args.length; + while(_g2 < _g3) { + var i1 = _g2++; + var x = new xrfragment_Value(); + xrfragment_Url.guessType(x,args[i1]); + v.args.push(x); + } + } + resultMap.h[key] = v; } } return resultMap; }; +xrfragment_Url.guessType = function(v,str) { + var isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); + var isInt = new EReg("^[0-9]+$",""); + var isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); + 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(isColor.match(str)) { + v.color = str; + } + if(isFloat.match(str)) { + v.float = parseFloat(str); + } + if(isInt.match(str)) { + v.int = Std.parseInt(str); + } +}; if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) { HxOverrides.now = performance.now.bind(performance); } var xrfragment_Query_ok = $hx_exports["xrfragment"]["Query"]["ok"] = // haxe workarounds - Array.prototype.contains = Array.prototype.includes if (typeof Array.prototype.remove !== "function") { diff --git a/src/Test.hx b/src/Test.hx index 5eef002..441d4f4 100644 --- a/src/Test.hx +++ b/src/Test.hx @@ -1,10 +1,22 @@ import xrfragment.Query; +import xrfragment.Url; class Test { static public function main():Void { trace("starting tests"); + testUrl(); + //testQuery(); + } + static public function testUrl():Void { + var Url = xrfragment.Url; + var uri:String = "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3"; + trace(uri); + trace( Url.parse(uri) ); + } + + static public function testQuery():Void { var Query = xrfragment.Query; trace( (new Query("foo or bar")).toObject() ); diff --git a/src/xrfragment/Query.hx b/src/xrfragment/Query.hx index 03277da..3a05611 100644 --- a/src/xrfragment/Query.hx +++ b/src/xrfragment/Query.hx @@ -7,7 +7,6 @@ package xrfragment; #if js var ok:Bool = js.Syntax.code(' // haxe workarounds - Array.prototype.contains = Array.prototype.includes if (typeof Array.prototype.remove !== "function") { diff --git a/src/xrfragment/Url.hx b/src/xrfragment/Url.hx index 61de6f0..d1de4f0 100644 --- a/src/xrfragment/Url.hx +++ b/src/xrfragment/Url.hx @@ -3,29 +3,66 @@ package xrfragment; @:expose // <- makes the class reachable from plain JavaScript @:keep // <- avoids accidental removal by dead code elimination +class Value { + public var x:Float; + public var y:Float; + public var z:Float; + public var color:String; + public var string:String; + public var int:Int; + public var float:Float; + public var args:Array; + public function new(){} +} + class Url { @:keep - private static var map:Map; - - @:keep - private static function parseQueryMap(qs:String):Map { - var splitArray:Array = qs.split('&'); + public static function parse(qs:String):Map { + var fragment:Array = qs.split("#"); + var splitArray:Array = fragment[1].split('&'); var regexPlus = ~/\+/g; // Regex for replacing addition symbol with a space - var resultMap = new Map(); + var resultMap = new Map(); for (i in 0...splitArray.length) { - var splitByEqual = splitArray[i].split('='); - var key:String = splitByEqual[0]; + var splitByEqual = splitArray[i].split('='); + var key:String = splitByEqual[0]; + var v:Value = new Value(); - if (splitByEqual.length == 1) { - // ..&a=&b.. (right side blank) - resultMap.set(key, ""); - } else { - var value:String = StringTools.urlDecode(regexPlus.split(splitByEqual[1]).join(" ")); - resultMap.set(key, value); + if (splitByEqual.length > 1) { + var value:String = StringTools.urlDecode(regexPlus.split(splitByEqual[1]).join(" ")); + guessType(v, value); + + // multiple/fallthrough values + if( value.split("|").length > 1 ){ + v.args = new Array(); + var args:Array = value.split("|"); + for( i in 0...args.length){ + var x:Value = new Value(); + guessType(x, args[i]); + v.args.push( x ); + } } + resultMap.set(key, v ); + } } return resultMap; } + @:keep + public static function guessType(v:Value, str:String):Void { + var isColor:EReg = ~/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/; + var isInt:EReg = ~/^[0-9]+$/; + var isFloat:EReg = ~/^[0-9]+\.[0-9]+$/; + v.string = str; + if( str.split(",").length > 1){ + var xyz:Array = str.split(","); + if( xyz.length > 0 ) v.x = Std.parseFloat(xyz[0]); + if( xyz.length > 1 ) v.y = Std.parseFloat(xyz[1]); + if( xyz.length > 2 ) v.z = Std.parseFloat(xyz[2]); + } + if( isColor.match(str) ) v.color = str; + if( isFloat.match(str) ) v.float = Std.parseFloat(str); + if( isInt.match(str) ) v.int = Std.parseInt(str); + } + } diff --git a/test/generated/test.js b/test/generated/test.js index 10fd200..aae8e52 100644 --- a/test/generated/test.js +++ b/test/generated/test.js @@ -2,15 +2,10 @@ var $hx_exports = typeof exports != "undefined" ? exports : typeof window != "un (function ($global) { "use strict"; $hx_exports["xrfragment"] = $hx_exports["xrfragment"] || {}; $hx_exports["xrfragment"]["Query"] = $hx_exports["xrfragment"]["Query"] || {}; -function $extend(from, fields) { - var proto = Object.create(from); - for (var name in fields) proto[name] = fields[name]; - if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString; - return proto; -} var EReg = function(r,opt) { this.r = new RegExp(r,opt.split("u").join("")); }; +EReg.__name__ = true; EReg.prototype = { match: function(s) { if(this.r.global) { @@ -20,8 +15,13 @@ EReg.prototype = { this.r.s = s; return this.r.m != null; } + ,split: function(s) { + var d = "#__delim__#"; + return s.replace(this.r,d).split(d); + } }; var HxOverrides = function() { }; +HxOverrides.__name__ = true; HxOverrides.substr = function(s,pos,len) { if(len == null) { len = s.length; @@ -37,7 +37,9 @@ HxOverrides.substr = function(s,pos,len) { HxOverrides.now = function() { return Date.now(); }; +Math.__name__ = true; var Reflect = function() { }; +Reflect.__name__ = true; Reflect.field = function(o,field) { try { return o[field]; @@ -58,6 +60,10 @@ Reflect.fields = function(o) { return a; }; var Std = function() { }; +Std.__name__ = true; +Std.string = function(s) { + return js_Boot.__string_rec(s,""); +}; Std.parseInt = function(x) { if(x != null) { var _g = 0; @@ -79,184 +85,36 @@ Std.parseInt = function(x) { return null; }; var Test = function() { }; +Test.__name__ = true; Test.main = function() { - console.log("src/Test.hx:6:","starting tests"); - var Query = xrfragment_Query; - console.log("src/Test.hx:10:",new xrfragment_Query("foo or bar").toObject()); - console.log("src/Test.hx:11:",new xrfragment_Query("class:fopoer or bar foo:bar").toObject().or[0]); - console.log("src/Test.hx:12:",new xrfragment_Query("-skybox class:foo").toObject().or[0]); - console.log("src/Test.hx:13:",new xrfragment_Query("foo/flop moo or bar").toObject().or[0]); - console.log("src/Test.hx:14:",new xrfragment_Query("-foo/flop moo or bar").toObject().or[0]); - console.log("src/Test.hx:15:",new xrfragment_Query("price:>4 moo or bar").toObject().or[0]); - console.log("src/Test.hx:16:",new xrfragment_Query("price:>=4 moo or bar").toObject().or[0]); - console.log("src/Test.hx:17:",new xrfragment_Query("price:<=4 moo or bar").toObject().or[0]); - console.log("src/Test.hx:18:",new xrfragment_Query("price:!=4 moo or bar").toObject().or[0]); - var q = new xrfragment_Query("price:!=4 moo or bar"); - var obj = q.toObject(); - q.test("price",4); - var ok = !q.qualify("slkklskdf"); - if(!ok) { - throw haxe_Exception.thrown("node should not be allowed"); - } - q = new xrfragment_Query("price:!=3 moo or bar"); - var obj = q.toObject(); - q.test("price",4); - var ok = q.qualify("slkklskdf"); - if(!ok) { - throw haxe_Exception.thrown("non-mentioned node should be allowed"); - } - q = new xrfragment_Query("moo or bar"); - var obj = q.toObject(); - var ok = !q.qualify("slkklskdf"); - if(!ok) { - throw haxe_Exception.thrown("node should not be allowed"); - } - obj = q.toObject(); - var ok = q.qualify("moo"); - if(!ok) { - throw haxe_Exception.thrown("moo should be allowed"); - } - var ok = q.qualify("bar"); - if(!ok) { - throw haxe_Exception.thrown("bar should be allowed"); - } - q = new xrfragment_Query("price:>3 moo or bar"); - var obj = q.toObject(); - q.test("price",4); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - var ok = q.qualify("bar"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - var ok = q.qualify("moo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - q = new xrfragment_Query("price:>3 price:<10 -bar"); - var obj = q.toObject(); - q.test("price",4); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - var ok = !q.qualify("bar"); - if(!ok) { - throw haxe_Exception.thrown("bar should not be allowed"); - } - q.test("price",20); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("price 20 should not be allowed"); - } - q = new xrfragment_Query("-bar"); - var obj = q.toObject(); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - var ok = !q.qualify("bar"); - if(!ok) { - throw haxe_Exception.thrown("bar should not be allowed"); - } - q = new xrfragment_Query("title:*"); - var obj = q.toObject(); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should not be allowed"); - } - q.test("foo","bar"); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should not be allowed"); - } - q.test("title","bar"); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - q = new xrfragment_Query("-bar +bar"); - var obj = q.toObject(); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("node should be allowed"); - } - var ok = q.qualify("bar"); - if(!ok) { - throw haxe_Exception.thrown("bar should be allowed"); - } - q = new xrfragment_Query("?discount"); - var obj = q.toObject(); - q.test("?discount","-foo"); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - q = new xrfragment_Query("?"); - q.test("?","-foo"); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - q = new xrfragment_Query("?"); - var ok = q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - q = new xrfragment_Query("?discount"); - q.test("?discount","-foo"); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - q = new xrfragment_Query("?discount +foo"); - var obj = q.toObject(); - q.test("?discount","-foo"); - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - var ok = !q.qualify("foo"); - if(!ok) { - throw haxe_Exception.thrown("foo should not be allowed"); - } - console.log("src/Test.hx:116:","all tests passed"); + console.log("src/Test.hx:7:","starting tests"); + Test.testUrl(); }; -var haxe_Exception = function(message,previous,native) { - Error.call(this,message); - this.message = message; - this.__previousException = previous; - this.__nativeException = native != null ? native : this; +Test.testUrl = function() { + var Url = xrfragment_Url; + var uri = "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3"; + console.log("src/Test.hx:15:",uri); + var tmp = Url.parse(uri); + console.log("src/Test.hx:16:",tmp == null ? "null" : haxe_ds_StringMap.stringify(tmp.h)); }; -haxe_Exception.thrown = function(value) { - if(((value) instanceof haxe_Exception)) { - return value.get_native(); - } else if(((value) instanceof Error)) { - return value; - } else { - var e = new haxe_ValueException(value); - return e; +var haxe_ds_StringMap = function() { + this.h = Object.create(null); +}; +haxe_ds_StringMap.__name__ = true; +haxe_ds_StringMap.stringify = function(h) { + var s = "{"; + var first = true; + for (var key in h) { + if (first) first = false; else s += ','; + s += key + ' => ' + Std.string(h[key]); } + return s + "}"; }; -haxe_Exception.__super__ = Error; -haxe_Exception.prototype = $extend(Error.prototype,{ - get_native: function() { - return this.__nativeException; - } -}); -var haxe_ValueException = function(value,previous,native) { - haxe_Exception.call(this,String(value),previous,native); - this.value = value; -}; -haxe_ValueException.__super__ = haxe_Exception; -haxe_ValueException.prototype = $extend(haxe_Exception.prototype,{ -}); var haxe_iterators_ArrayIterator = function(array) { this.current = 0; this.array = array; }; +haxe_iterators_ArrayIterator.__name__ = true; haxe_iterators_ArrayIterator.prototype = { hasNext: function() { return this.current < this.array.length; @@ -265,6 +123,72 @@ haxe_iterators_ArrayIterator.prototype = { return this.array[this.current++]; } }; +var js_Boot = function() { }; +js_Boot.__name__ = true; +js_Boot.__string_rec = function(o,s) { + if(o == null) { + return "null"; + } + if(s.length >= 5) { + return "<...>"; + } + var t = typeof(o); + if(t == "function" && (o.__name__ || o.__ename__)) { + t = "object"; + } + switch(t) { + case "function": + return ""; + case "object": + if(((o) instanceof Array)) { + var str = "["; + s += "\t"; + var _g = 0; + var _g1 = o.length; + while(_g < _g1) { + var i = _g++; + str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s); + } + str += "]"; + return str; + } + var tostr; + try { + tostr = o.toString; + } catch( _g ) { + return "???"; + } + if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { + var s2 = o.toString(); + if(s2 != "[object Object]") { + return s2; + } + } + var str = "{\n"; + s += "\t"; + var hasp = o.hasOwnProperty != null; + var k = null; + for( k in o ) { + if(hasp && !o.hasOwnProperty(k)) { + continue; + } + if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { + continue; + } + if(str.length != 2) { + str += ", \n"; + } + str += s + k + " : " + js_Boot.__string_rec(o[k],s); + } + s = s.substring(1); + str += "\n" + s + "}"; + return str; + case "string": + return o; + default: + return String(o); + } +}; var xrfragment_Query = function(str) { this.preset = ""; this.accept = false; @@ -275,11 +199,9 @@ var xrfragment_Query = function(str) { this.parse(str); } }; +xrfragment_Query.__name__ = true; xrfragment_Query.prototype = { - toObject: function() { - return this.q; - } - ,qualify: function(nodename) { + qualify: function(nodename) { if(this.q.copy_all) { this.accept = true; } @@ -460,12 +382,79 @@ xrfragment_Query.prototype = { } } }; +var xrfragment_Value = $hx_exports["xrfragment"]["Value"] = function() { +}; +xrfragment_Value.__name__ = true; +var xrfragment_Url = function() { }; +xrfragment_Url.__name__ = true; +xrfragment_Url.parse = function(qs) { + var fragment = qs.split("#"); + var splitArray = fragment[1].split("&"); + var regexPlus = new EReg("\\+","g"); + var resultMap = new haxe_ds_StringMap(); + var _g = 0; + var _g1 = splitArray.length; + while(_g < _g1) { + var i = _g++; + var splitByEqual = splitArray[i].split("="); + var key = splitByEqual[0]; + var v = new xrfragment_Value(); + if(splitByEqual.length > 1) { + var s = regexPlus.split(splitByEqual[1]).join(" "); + var value = decodeURIComponent(s.split("+").join(" ")); + xrfragment_Url.guessType(v,value); + if(value.split("|").length > 1) { + v.args = []; + var args = value.split("|"); + var _g2 = 0; + var _g3 = args.length; + while(_g2 < _g3) { + var i1 = _g2++; + var x = new xrfragment_Value(); + xrfragment_Url.guessType(x,args[i1]); + v.args.push(x); + } + } + resultMap.h[key] = v; + } + } + return resultMap; +}; +xrfragment_Url.guessType = function(v,str) { + var isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); + var isInt = new EReg("^[0-9]+$",""); + var isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); + 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(isColor.match(str)) { + v.color = str; + } + if(isFloat.match(str)) { + v.float = parseFloat(str); + } + if(isInt.match(str)) { + v.int = Std.parseInt(str); + } +}; if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) { HxOverrides.now = performance.now.bind(performance); } +String.__name__ = true; +Array.__name__ = true; +js_Boot.__toStr = ({ }).toString; var xrfragment_Query_ok = $hx_exports["xrfragment"]["Query"]["ok"] = // haxe workarounds - Array.prototype.contains = Array.prototype.includes if (typeof Array.prototype.remove !== "function") { diff --git a/test/generated/test.py b/test/generated/test.py index 935bbba..e046571 100644 --- a/test/generated/test.py +++ b/test/generated/test.py @@ -7,6 +7,8 @@ import sys as python_lib_Sys import functools as python_lib_Functools import re as python_lib_Re import traceback as python_lib_Traceback +from io import StringIO as python_lib_io_StringIO +import urllib.parse as python_lib_urllib_Parse class _hx_AnonObject: @@ -62,6 +64,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,6 +88,26 @@ 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: @@ -100,7 +123,7 @@ class Reflect: class Std: _hx_class_name = "Std" __slots__ = () - _hx_statics = ["isOfType", "string", "parseInt"] + _hx_statics = ["isOfType", "string", "parseInt", "shortenPossibleNumber", "parseFloat"] @staticmethod def isOfType(v,t): @@ -258,6 +281,38 @@ class Std: return None return None + @staticmethod + def shortenPossibleNumber(x): + r = "" + _g = 0 + _g1 = len(x) + while (_g < _g1): + i = _g + _g = (_g + 1) + c = ("" if (((i < 0) or ((i >= len(x))))) else x[i]) + _g2 = HxString.charCodeAt(c,0) + if (_g2 is None): + break + else: + _g3 = _g2 + if (((((((((((_g3 == 57) or ((_g3 == 56))) or ((_g3 == 55))) or ((_g3 == 54))) or ((_g3 == 53))) or ((_g3 == 52))) or ((_g3 == 51))) or ((_g3 == 50))) or ((_g3 == 49))) or ((_g3 == 48))) or ((_g3 == 46))): + r = (("null" if r is None else r) + ("null" if c is None else c)) + else: + break + return r + + @staticmethod + def parseFloat(x): + try: + return float(x) + except BaseException as _g: + None + if (x is not None): + r1 = Std.shortenPossibleNumber(x) + if (r1 != x): + return Std.parseFloat(r1) + return Math.NaN + class Float: pass @@ -274,137 +329,33 @@ class Dynamic: pass class Test: _hx_class_name = "Test" __slots__ = () - _hx_statics = ["main"] + _hx_statics = ["main", "testUrl"] @staticmethod def main(): print("starting tests") - Query = xrfragment_Query - print(str(xrfragment_Query("foo or bar").toObject())) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("class:fopoer or bar foo:bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("-skybox class:foo").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("foo/flop moo or bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("-foo/flop moo or bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("price:>4 moo or bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("price:>=4 moo or bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("price:<=4 moo or bar").toObject(),"or"), 0))) - print(str(HxOverrides.arrayGet(Reflect.field(xrfragment_Query("price:!=4 moo or bar").toObject(),"or"), 0))) - q = xrfragment_Query("price:!=4 moo or bar") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("price",4) - ok = (not Reflect.field(q,"qualify")("slkklskdf")) - if (not ok): - raise haxe_Exception.thrown("node should not be allowed") - q = xrfragment_Query("price:!=3 moo or bar") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("price",4) - ok = Reflect.field(q,"qualify")("slkklskdf") - if (not ok): - raise haxe_Exception.thrown("non-mentioned node should be allowed") - q = xrfragment_Query("moo or bar") - obj = Reflect.field(q,"toObject")() - ok = (not Reflect.field(q,"qualify")("slkklskdf")) - if (not ok): - raise haxe_Exception.thrown("node should not be allowed") - obj = Reflect.field(q,"toObject")() - ok = Reflect.field(q,"qualify")("moo") - if (not ok): - raise haxe_Exception.thrown("moo should be allowed") - ok = Reflect.field(q,"qualify")("bar") - if (not ok): - raise haxe_Exception.thrown("bar should be allowed") - q = xrfragment_Query("price:>3 moo or bar") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("price",4) - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - ok = Reflect.field(q,"qualify")("bar") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - ok = Reflect.field(q,"qualify")("moo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - q = xrfragment_Query("price:>3 price:<10 -bar") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("price",4) - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - ok = (not Reflect.field(q,"qualify")("bar")) - if (not ok): - raise haxe_Exception.thrown("bar should not be allowed") - Reflect.field(q,"test")("price",20) - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("price 20 should not be allowed") - q = xrfragment_Query("-bar") - obj = Reflect.field(q,"toObject")() - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - ok = (not Reflect.field(q,"qualify")("bar")) - if (not ok): - raise haxe_Exception.thrown("bar should not be allowed") - q = xrfragment_Query("title:*") - obj = Reflect.field(q,"toObject")() - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("node should not be allowed") - Reflect.field(q,"test")("foo","bar") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("node should not be allowed") - Reflect.field(q,"test")("title","bar") - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - q = xrfragment_Query("-bar +bar") - obj = Reflect.field(q,"toObject")() - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("node should be allowed") - ok = Reflect.field(q,"qualify")("bar") - if (not ok): - raise haxe_Exception.thrown("bar should be allowed") - q = xrfragment_Query("?discount") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("?discount","-foo") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - q = xrfragment_Query("?") - Reflect.field(q,"test")("?","-foo") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - q = xrfragment_Query("?") - ok = Reflect.field(q,"qualify")("foo") - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - q = xrfragment_Query("?discount") - Reflect.field(q,"test")("?discount","-foo") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - q = xrfragment_Query("?discount +foo") - obj = Reflect.field(q,"toObject")() - Reflect.field(q,"test")("?discount","-foo") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - ok = (not Reflect.field(q,"qualify")("foo")) - if (not ok): - raise haxe_Exception.thrown("foo should not be allowed") - print("all tests passed") + Test.testUrl() + + @staticmethod + def testUrl(): + Url = xrfragment_Url + uri = "http://foo.com?foo=1#bar=flop&a=1,2&b=c|d|1,2,3" + print(str(uri)) + tmp = Url.parse(uri) + print(str(("null" if ((tmp is None)) else tmp.toString()))) + + +class haxe_IMap: + _hx_class_name = "haxe.IMap" + __slots__ = () class haxe_Exception(Exception): _hx_class_name = "haxe.Exception" - __slots__ = ("_hx___nativeStack", "_hx___skipStack", "_hx___nativeException", "_hx___previousException") - _hx_fields = ["__nativeStack", "__skipStack", "__nativeException", "__previousException"] - _hx_methods = ["unwrap", "get_native"] - _hx_statics = ["caught", "thrown"] + __slots__ = ("_hx___nativeStack", "_hx___nativeException", "_hx___previousException") + _hx_fields = ["__nativeStack", "__nativeException", "__previousException"] + _hx_methods = ["unwrap"] + _hx_statics = ["caught"] _hx_interfaces = [] _hx_super = Exception @@ -413,7 +364,6 @@ class haxe_Exception(Exception): self._hx___previousException = None self._hx___nativeException = None self._hx___nativeStack = None - self._hx___skipStack = 0 super().__init__(message) self._hx___previousException = previous if ((native is not None) and Std.isOfType(native,BaseException)): @@ -430,9 +380,6 @@ class haxe_Exception(Exception): def unwrap(self): return self._hx___nativeException - def get_native(self): - return self._hx___nativeException - @staticmethod def caught(value): if Std.isOfType(value,haxe_Exception): @@ -442,17 +389,6 @@ class haxe_Exception(Exception): else: return haxe_ValueException(value,None,value) - @staticmethod - def thrown(value): - if Std.isOfType(value,haxe_Exception): - return value.get_native() - elif Std.isOfType(value,BaseException): - return value - else: - e = haxe_ValueException(value) - e._hx___skipStack = (e._hx___skipStack + 1) - return e - class haxe_NativeStackTrace: @@ -495,6 +431,36 @@ class haxe_ValueException(haxe_Exception): +class haxe_ds_StringMap: + _hx_class_name = "haxe.ds.StringMap" + __slots__ = ("h",) + _hx_fields = ["h"] + _hx_methods = ["keys", "toString"] + _hx_interfaces = [haxe_IMap] + + def __init__(self): + self.h = dict() + + def keys(self): + return python_HaxeIterator(iter(self.h.keys())) + + def toString(self): + s_b = python_lib_io_StringIO() + s_b.write("{") + it = self.keys() + i = it + while i.hasNext(): + i1 = i.next() + s_b.write(Std.string(i1)) + s_b.write(" => ") + s_b.write(Std.string(Std.string(self.h.get(i1,None)))) + if it.hasNext(): + s_b.write(", ") + s_b.write("}") + return s_b.getvalue() + + + class haxe_iterators_ArrayIterator: _hx_class_name = "haxe.iterators.ArrayIterator" __slots__ = ("array", "current") @@ -1519,6 +1485,88 @@ class xrfragment_Query: self.accept = True + +class xrfragment_Value: + _hx_class_name = "xrfragment.Value" + __slots__ = ("x", "y", "z", "color", "string", "int", "float", "args") + _hx_fields = ["x", "y", "z", "color", "string", "int", "float", "args"] + + def __init__(self): + self.args = None + self.float = None + self.int = None + self.string = None + self.color = None + self.z = None + self.y = None + self.x = None + + + +class xrfragment_Url: + _hx_class_name = "xrfragment.Url" + __slots__ = () + _hx_statics = ["parse", "guessType"] + + @staticmethod + def parse(qs): + fragment = qs.split("#") + _this = (fragment[1] if 1 < len(fragment) else None) + splitArray = _this.split("&") + regexPlus = EReg("\\+","g") + resultMap = haxe_ds_StringMap() + _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("=") + key = (splitByEqual[0] if 0 < len(splitByEqual) else None) + v = xrfragment_Value() + 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])) + xrfragment_Url.guessType(v,value) + if (len(value.split("|")) > 1): + v.args = list() + args = value.split("|") + _g2 = 0 + _g3 = len(args) + while (_g2 < _g3): + i1 = _g2 + _g2 = (_g2 + 1) + x = xrfragment_Value() + xrfragment_Url.guessType(x,(args[i1] if i1 >= 0 and i1 < len(args) else None)) + _this2 = v.args + _this2.append(x) + resultMap.h[key] = v + return resultMap + + @staticmethod + def guessType(v,_hx_str): + isColor = EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","") + isInt = EReg("^[0-9]+$","") + isFloat = EReg("^[0-9]+\\.[0-9]+$","") + 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)) + isColor.matchObj = python_lib_Re.search(isColor.pattern,_hx_str) + if (isColor.matchObj is not None): + v.color = _hx_str + isFloat.matchObj = python_lib_Re.search(isFloat.pattern,_hx_str) + if (isFloat.matchObj is not None): + v.float = Std.parseFloat(_hx_str) + isInt.matchObj = python_lib_Re.search(isInt.pattern,_hx_str) + if (isInt.matchObj is not None): + v.int = Std.parseInt(_hx_str) + Math.NEGATIVE_INFINITY = float("-inf") Math.POSITIVE_INFINITY = float("inf") Math.NaN = float("nan")