Browse Source

implement keywordhandler with python types

frabbit 11 years ago
parent
commit
8bd6276274
2 changed files with 22 additions and 14 deletions
  1. 17 14
      std/python/internal/KeywordHandler.hx
  2. 5 0
      std/python/lib/Types.hx

+ 17 - 14
std/python/internal/KeywordHandler.hx

@@ -1,26 +1,29 @@
 package python.internal;
 
-import haxe.ds.StringMap;
 
-using Lambda;
+import python.lib.Types.Set;
+
 
 class KeywordHandler {
 
-	static var keywords:StringMap<Bool> = [
-		"and" => true,       "del" => true,       "from" => true,      "not" => true,       "while" => true,
-		"as" => true,        "elif" => true,      "global" => true,    "or" => true,        "with" => true,
-		"assert" => true,    "else" => true,      "if" => true,        "pass" => true,      "yield" => true,
-		"break" => true,     "except" => true,    "import" => true,    "print" => true,		"float" => true,
-		"class" => true,     "exec" => true,      "in" => true,        "raise" => true,
-		"continue" => true,  "finally" => true,   "is" => true,        "return" => true,
-		"def" => true,       "for" => true,       "lambda" => true,    "try" => true,
-		"None" => true,      "list" => true
-	];
+
+	static var keywords:Set<String> = new Set(
+    [
+        "and",       "del",       "from",      "not",       "while",
+        "as",        "elif",      "global",    "or",        "with",
+        "assert",    "else",      "if",        "pass",      "yield",
+        "break",     "except",    "import",    "print",     "float",
+        "class",     "exec",      "in",        "raise",
+        "continue",  "finally",   "is",        "return",
+        "def",       "for",       "lambda",    "try",
+        "None",      "list"
+    ]);
 
 	public static inline function handleKeywords(name:String)
     {
-        if(keywords.exists(name))
+        if (keywords.has(name)) {
             return "_hx_" + name;
+        }
         return name;
     }
 
@@ -28,7 +31,7 @@ class KeywordHandler {
     {
     	if (name.substr(0,4) == "_hx_") {
     		var real = name.substr(4);
-    		if (keywords.exists(real)) return real;
+    		if (keywords.has(real)) return real;
     	}
     	return name;
     }

+ 5 - 0
std/python/lib/Types.hx

@@ -127,6 +127,11 @@ extern class Set <T>
 		return python.lib.Builtin.len(this);
 	}
 
+	public inline function has (v:T):Bool
+	{
+		return untyped __python_in__(v, this);
+	}
+
 
 	public inline function minus (other:Set<T>):Set<T>
 	{