corrected the reporting+alignment of error locations
[sbp.git] / src / edu / berkeley / sbp / Ambiguous.java
index cb55ffa..6138577 100644 (file)
@@ -6,14 +6,26 @@ import java.io.*;
 import java.util.*;
 
 /** if ambiguity checking is enabled, this exception is thrown to signal that the parse was ambiguous */
-public class Ambiguous extends RuntimeException {
-    public final Forest<?> ambiguity;
-    public Ambiguous(Forest<?> ambiguity) { this.ambiguity = ambiguity; }
+public class Ambiguous extends Exception {
+    final Forest<?> ambiguity;
+    private final HashSet<Tree<?>> ht;
+    Ambiguous(Forest<?> ambiguity, HashSet<Tree<?>> ht) {
+        this.ambiguity = ambiguity;
+        this.ht = ht;
+    }
+
+    public Forest<?> getAmbiguity() { return ambiguity; }
+
     public String toString() {
+        // FIXME: print the input region that was ambiguously matched
         StringBuffer sb = new StringBuffer();
-        sb.append("unresolved ambiguity "/*"at " + ambiguity.getLocation() + ":"*/);
-        for(Tree<?> result : ambiguity.expand(false))
-            sb.append("\n\n" + result.toPrettyString());
+        sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
+        for(Tree<?> result : ht) {
+            sb.append("\n  possibility: ");
+            StringBuffer sb2 = new StringBuffer();
+            result.toPrettyString(sb2);
+            sb.append(StringUtil.indent(sb2.toString(), 15));
+        }
         return sb.toString();
     }
 }