title: java parsing data file format
body: <p>I have a data file, which looks like this:</p>
  
  <p><pre><code>
  0.5, 0.0 [
   1.5, -1.0 [
    inputs
   ]
   ;
   0.5, 1.0 [
    inputs
   ]
  ]
  </pre></code></p>
  
  <p>Which I'm trying to parse into a tree-like structure. In the above example, the tree should end up like so:</p>
  
  <pre><code>
               Node (0.5, 0.0)
               /             \
     Node (1.5, -1.0)   Node (0.5, 1.0)
                   \     /
                 Inputs Node
  </code></pre>
  
  <p>Pretty much the tree structure is like any basic tree (with the exception that all the bottom-most nodes connect to the same inputs node.</p>
  
  <p>So far, to parse it, I have the following:</p>
  
  <pre><code>
  private void createSubLayer (String net, Node parent, int level) {
    level++;
    String[] nodes = net.split(";");
  
    for (String node : nodes) {
     if (node.equals("inputs")) {
      System.out.println("Connecting input @ " + level);
      for (Node n : inputs) {
       parent.connect(n);
      }
     }
     else {
      Node newNode;
      String[] nodeInfo = node.split("\\[", 2);
      String nodeDetails = nodeInfo[0];
      System.out.println(nodeInfo.length);
      System.out.println(nodeDetails);
      String subNet = nodeInfo[1].substring(0, nodeInfo[1].length() - 1);
      String[] nodeTW = nodeDetails.split(",");
      double threshhold = Double.parseDouble(nodeTW[0]);
      double weight = (nodeTW.length == 2) ? Double.parseDouble(nodeTW[1]) : 0.0;
      newNode = new Node(threshhold);
      newNode.setWeight(weight);
      System.out.println("Connecting new node @ " + level + "\n\tThreshhold: " + threshhold + "\n\tWeight: " + weight);
      if (parent != null) {
       parent.connect(newNode);
      }
      else {
       root = newNode;
      }
  
      System.out.println("Using subnet: " + subNet);
      createSubLayer(subNet, newNode, level);
     }
    }
   }
  </code></pre>
  
  <p>And I'm calling it with</p>
  
  <pre><code>
  createSubLayer(data_file_contents, null, 0);
  </code></pre>
  
  <p>So far, this works fine for very basic data such as </p>
  
  <pre><code>
  1.9, 1.0[inputs]
  </code></pre>
  
  <p>However, the problem seems to be arising when I am splitting by the semi-colon in the first example. For obvious reasons, splitting this first results in (using the first example):</p>
  
  <pre><code>
  0.5, 0.0 [
      1.5, -1.0 [
          inputs
      ]
  </code></pre>
  
  <p>and</p>
  
  <pre><code>
      0.5, 1.0 [
          inputs
      ]
  ]
  </code></pre>
  
  <p>Which is not the intended result.</p>
  
  <p>How may I go about modifying this parsing process (or if need be, modifying the data file structure) to create the desired results? (dont worry about the Node.connect() calls or anything else, as long as I can get the structure correct)</p>
  
  <p>As a fairly straightforward comparison, this structuring is essentially like an XML document, or JSON, or other similar formats, just lacking attribute and node names (since there are always only the two numeric attributes in order, and the node contents).</p>
  
  <p>Thank you for any help!</p>