KeywordHandler.hx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package python.internal;
  2. import haxe.ds.StringMap;
  3. using Lambda;
  4. class KeywordHandler {
  5. static var keywords:StringMap<Bool> = [
  6. "and" => true, "del" => true, "from" => true, "not" => true, "while" => true,
  7. "as" => true, "elif" => true, "global" => true, "or" => true, "with" => true,
  8. "assert" => true, "else" => true, "if" => true, "pass" => true, "yield" => true,
  9. "break" => true, "except" => true, "import" => true, "print" => true, "float" => true,
  10. "class" => true, "exec" => true, "in" => true, "raise" => true,
  11. "continue" => true, "finally" => true, "is" => true, "return" => true,
  12. "def" => true, "for" => true, "lambda" => true, "try" => true,
  13. "None" => true, "list" => true
  14. ];
  15. public static inline function handleKeywords(name:String)
  16. {
  17. if(keywords.exists(name))
  18. return "_hx_" + name;
  19. return name;
  20. }
  21. public static function unhandleKeywords(name:String)
  22. {
  23. if (name.substr(0,4) == "_hx_") {
  24. var real = name.substr(4);
  25. if (keywords.exists(real)) return real;
  26. }
  27. return name;
  28. }
  29. }