Permalink
Browse files

Fix #74, also... clean up some whitespace and improve error reporting

  • Loading branch information...
1 parent b94ca2a commit ed3f64f215b7a774b43077976a76493aa799edc5 @matburt committed May 6, 2011
@@ -89,7 +89,7 @@ public void populateDisplay() {
if (this.actionMode.equals("edit")) {
mNode = appInst.getNode(mNodePath);
mNode.applyEdits(appInst.findEdits(mNode.nodeId));
-
+
Node parent = appInst.getParent(mNodePath);
mTitle.setText(mNode.nodeName);
mBody.setText(mNode.nodePayload);
@@ -290,7 +290,7 @@ public void runParser() {
Collections.sort(appInst.rootNode.subNodes, Node.comparator);
}
catch(Throwable e) {
- ErrorReporter.displayError(this, "An error occurred during parsing: " + e.toString());
+ ErrorReporter.displayError(this, "An error occurred during parsing, try re-syncing: " + e.toString());
}
}
@@ -147,13 +147,14 @@ public void parse(Node fileNode, BufferedReader breader)
String thisLine;
Stack<Node> nodeStack = new Stack();
+ Stack<Integer> starStack = new Stack();
Pattern propertiesLine = Pattern.compile("^\\s*:[A-Z]+:");
if(breader == null)
{
breader = this.getHandle(fileNode.nodeName);
}
nodeStack.push(fileNode);
- int nodeDepth = 0;
+ starStack.push(0);
while ((thisLine = breader.readLine()) != null) {
int numstars = 0;
@@ -187,7 +188,7 @@ public void parse(Node fileNode, BufferedReader breader)
newNode.todo = titleComp.todo;
newNode.priority = titleComp.priority;
newNode.tags.addAll(titleComp.tags);
- if (numstars > nodeDepth) {
+ if (numstars > starStack.peek()) {
try {
Node lastNode = nodeStack.peek();
newNode.setParentNode(lastNode);
@@ -197,19 +198,22 @@ public void parse(Node fileNode, BufferedReader breader)
} catch (EmptyStackException e) {
}
nodeStack.push(newNode);
- nodeDepth++;
+ starStack.push(numstars);
}
- else if (numstars == nodeDepth) {
+ else if (numstars == starStack.peek()) {
nodeStack.pop();
+ starStack.pop();
nodeStack.peek().addChildNode(newNode);
newNode.setParentNode(nodeStack.peek());
newNode.nodeId = this.getNodePath(newNode);
newNode.addProperty("ID", newNode.nodeId);
nodeStack.push(newNode);
+ starStack.push(numstars);
}
- else if (numstars < nodeDepth) {
- for (;numstars <= nodeDepth; nodeDepth--) {
+ else if (numstars < starStack.peek()) {
+ while (numstars <= starStack.peek()) {
nodeStack.pop();
+ starStack.pop();
}
Node lastNode = nodeStack.peek();
@@ -218,7 +222,7 @@ else if (numstars < nodeDepth) {
newNode.addProperty("ID", newNode.nodeId);
lastNode.addChildNode(newNode);
nodeStack.push(newNode);
- nodeDepth++;
+ starStack.push(numstars);
}
}
//content
@@ -268,8 +272,9 @@ else if (thisLine.indexOf("DEADLINE:") != -1 ||
lastNode.addPayload(thisLine);
}
}
- for (;nodeDepth > 0; nodeDepth--) {
+ while (starStack.peek() > 0) {
nodeStack.pop();
+ starStack.pop();
}
fileNode.parsed = true;
breader.close();

0 comments on commit ed3f64f

Please sign in to comment.