]> git.saurik.com Git - cycript.git/blobdiff - Complete.cpp
Package everything for Android in simple zip file.
[cycript.git] / Complete.cpp
index 3d14193817461c6948b27fc9c34c5c735a1dc72d..1b1d0dc3742749700f7d227eee454ba05e8b393c 100644 (file)
@@ -1,5 +1,5 @@
-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015  Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016  Jay Freeman (saurik)
 */
 
 /* GNU Affero General Public License, Version 3 {{{ */
 #include "cycript.hpp"
 
 #include "Driver.hpp"
-#include "Cycript.tab.hh"
 #include "Replace.hpp"
 #include "String.hpp"
 
 static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) {
     std::stringstream stream;
     stream << '(' << code << ')';
-    CYDriver driver(pool, stream);
-
-    cy::parser parser(driver);
-    if (parser.parse() != 0 || !driver.errors_.empty())
+    CYDriver driver(pool, *stream.rdbuf());
+    if (driver.Parse() || !driver.errors_.empty())
         return NULL;
 
     CYOptions options;
@@ -54,13 +51,12 @@ static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) {
 _visible char **CYComplete(const char *word, const std::string &line, CYUTF8String (*run)(CYPool &pool, const std::string &)) {
     CYLocalPool pool;
 
-    std::istringstream stream(line);
+    std::stringbuf stream(line);
     CYDriver driver(pool, stream);
 
     driver.auto_ = true;
 
-    cy::parser parser(driver);
-    if (parser.parse() != 0 || !driver.errors_.empty())
+    if (driver.Parse() || !driver.errors_.empty())
         return NULL;
 
     if (driver.mode_ == CYDriver::AutoNone)
@@ -93,6 +89,10 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
                 prefix << (*part)->word_ << ':';
         } break;
 
+        case CYDriver::AutoResolve:
+            expression = $M(driver.context_, $S("$cyr"));
+        break;
+
         default:
             _assert(false);
     }
@@ -105,9 +105,24 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "       var before = prefix.length;\n"
     "       prefix += word;\n"
     "       var entire = prefix.length;\n"
-    "       for (var name in object)\n"
-    "           if (name.substring(0, entire) == prefix)\n"
-    "               names.push(name.substr(before));\n"
+    "       if (false) {\n"
+    "           for (var name in object)\n"
+    "               if (name.substring(0, entire) == prefix)\n"
+    "                   names.push(name.substr(before));\n"
+    "       } else do {\n"
+    "           if (object.hasOwnProperty(\"cy$complete\")) {\n"
+    "               names = names.concat(object.cy$complete(prefix));\n"
+    "               continue;\n"
+    "           }\n"
+    "           try {\n"
+    "               var local = Object.getOwnPropertyNames(object);\n"
+    "           } catch (e) {\n"
+    "               continue;\n"
+    "           }\n"
+    "           for (var name of local)\n"
+    "               if (name.substring(0, entire) == prefix)\n"
+    "                   names.push(name.substr(before));\n"
+    "       } while (object = typeof object === 'object' ? Object.getPrototypeOf(object) : object.__proto__);\n"
     "       return names;\n"
     "   }\n"
     ), expression, $S(begin.c_str()), $S(word))));