Beispiel #1
0
  private static void namespace_parse(String namespace, String script, Environment env) {
    int sep, term;
    String new_name;
    while (!script.equals("")) {
      switch (script.charAt(0)) {
        case '#':
          if ((sep = findAtLevel(script, 0, SEPARATOR)) == FIND_FAIL) {
            throw new Namespace.InvalidNamespaceDeclarationException(
                "separator \'" + SEPARATOR + "\' not found");
          }

          if ((term = findAtLevel(script, sep, TERMINATOR)) == FIND_FAIL) {
            throw new Namespace.InvalidNamespaceDeclarationException(
                "terminator \'" + TERMINATOR + "\' not found");
          }

          new_name = script.substring(1, sep).trim();

          env.namespace(namespace, new_name);

          namespace_parse(
              namespace.equals("") ? new_name : namespace + "." + new_name,
              script.substring(sep + 1, term),
              env);
          script = script.substring(term + 1);
          break;
        case '~':
          if ((sep = findAtLevel(script, 0, SEPARATOR)) == FIND_FAIL) {
            throw new DataType.InvalidTypeDeclarationException(
                "separator \'" + SEPARATOR + "\' not found");
          }

          if ((term = findAtLevel(script, sep, TERMINATOR)) == FIND_FAIL) {
            throw new DataType.InvalidTypeDeclarationException(
                "terminator \'" + TERMINATOR + "\' not found");
          }

          {
            new_name = script.substring(1, sep).trim();
            String[] raw_attr = script.substring(sep + 1, term).split(",");
            String[] attr_names = new String[raw_attr.length];
            String[] attr_types = new String[raw_attr.length];

            String[] temp;
            for (int i = 0; i < raw_attr.length; ++i) {
              temp = raw_attr[i].split("[|]");

              if (temp.length != 2 || temp[0] == "" || temp[1] == "") {
                // TODO add error
              }

              attr_names[i] = temp[0];
              attr_types[i] = temp[1];
            }

            env.defineType(new_name, namespace, attr_names, attr_types);
          }

          script = script.substring(term + 1);
          break;
      }
    }
  }