KeywordHandler.hx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, "None" => true
  13. ];
  14. public static inline function handleKeywords(name:String)
  15. {
  16. if(keywords.exists(name))
  17. return "_hx_" + name;
  18. return name;
  19. }
  20. public static function unhandleKeywords(name:String)
  21. {
  22. if (name.substr(0,4) == "_hx_") {
  23. var real = name.substr(4);
  24. if (keywords.exists(real)) return real;
  25. }
  26. return name;
  27. }
  28. }