Exemplo n.º 1
0
 /**
  * Add a function group.
  *
  * @param group The FunctionGroup to add.
  */
 public void addGroup(FunctionGroup group) {
   groupTable.put(group.getLowerCaseName(), group);
   groupTree.add(group);
   if (group.getName().length() > maxGroupLength) {
     maxGroupLength = group.getName().length();
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    System.out.println("waiting");

    try {
      ServerSocket serverSocket = new ServerSocket(34561);
      FunctionGroup langRuntime = new FunctionGroup(System.out);

      while (true) {
        Socket socket = serverSocket.accept();
        //                System.out.println("client connected");
        Thread myThread =
            new Thread(
                () -> {
                  try {
                    DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
                    PrintStream printStream = new PrintStream(socket.getOutputStream());
                    while (true) {
                      String line = dataInputStream.readLine();
                      //                            langRuntime.stripParenAndExecute(line);
                      printStream.println(langRuntime.getEnvironment().getBufferVariable());
                    }
                  } catch (IOException e) {
                  }
                });
        myThread.start();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  /**
   * Get the function matching the passed in string. The name includes the group prefix.
   *
   * @param fullName The name of the function data you want, including function group at the front.
   * @return The function data for the named function, or null if there is no such function.
   */
  public Function getFunctionMatching(String fullName) {
    int dot = fullName.lastIndexOf('.');
    if (dot == fullName.length() - 1 || dot == -1) return null;

    String groupName = fullName.substring(0, dot);

    FunctionGroup group = this.getGroup(groupName);
    if (group == null) return null;

    String functionName = fullName.substring(dot + 1);
    return group.getFunction(functionName);
  }
Exemplo n.º 4
0
  /**
   * Get a set of possibilities to complete the passed word.
   *
   * @param word The word you want to complete
   * @param types The types of completions you want.
   * @return A set of possibilities to complete the code.
   */
  public Collection<CodePossibility> getPossiblilities(String word, Type[] types) {
    ZDebug.print(4, "getPossiblilities( ", word, " )");

    // Optimisation
    if (word.length() > 0 && !Character.isLetter(word.charAt(0))) {
      return new ArrayList<CodePossibility>(0);
    }

    // Get what types of possibility the caller wants
    boolean listGroups = false, listFunctions = false, listKeywords = false;

    for (Type type : types) {
      switch (type) {
        case FUNCTION:
          listFunctions = true;
          break;
        case GROUP:
          listGroups = true;
          break;
        case KEYWORD:
          listKeywords = true;
          break;
      }
    }

    // Split up into parts (for functions and groups)
    String[] parts = word.split("\\.", -1);
    if (parts.length < 1) return new HashSet<CodePossibility>(0);

    String groupName = "";
    String funcName = null;
    for (int i = 0; i < parts.length - 1; i++) {
      if (i != 0) groupName += ".";
      groupName += parts[i];
    }

    ZDebug.print(5, "Word Before: '", word, "'");

    FunctionGroup currentGroup = this.getGroup(groupName);

    if (parts.length > 0) {
      funcName = parts[parts.length - 1];
    }

    TreeSet<CodePossibility> list = new TreeSet<CodePossibility>();

    // Suggest some keywords
    if (listKeywords) {
      for (String keyword : getKeywordsStartingWith(word)) {
        list.add(new CodePossibility(keyword, word));
      }
    }

    // Suggest some groups
    if (listGroups) {
      ZDebug.print(5, "Getting groups that start with: ", word);

      for (FunctionGroup group : getGroupsStartingWith(word)) {
        list.add(new CodePossibility(group, word));
      }
    }

    // Suggest some functions
    if (listFunctions) {
      if (currentGroup != null) {
        ZDebug.print(5, "Getting functions in '", currentGroup, "' that start with: ", funcName);
        for (Function function : currentGroup.getFunctionsStartingWith(funcName)) {
          list.add(new CodePossibility(function, funcName));
        }
      }
    }

    return list;
  }