394aab6b27482a11aedd0d840df615e608b81e55
[sbp.git] / src / edu / berkeley / sbp / Ambiguous.java
1 package edu.berkeley.sbp;
2 import edu.berkeley.sbp.*;
3 import edu.berkeley.sbp.util.*;
4 import edu.berkeley.sbp.Sequence.Position;
5 import java.io.*;
6 import java.util.*;
7
8 /** if ambiguity checking is enabled, this exception is thrown to signal that the parse was ambiguous */
9 public class Ambiguous extends Exception {
10     public final Forest ambiguity;
11     public Ambiguous(Forest ambiguity) {
12         this.ambiguity = ambiguity;
13     }
14     public String toString() {
15         // FEATURE: more legible printout desperately needed
16         StringBuffer sb = new StringBuffer();
17         sb.append("unresolved ambiguity ");
18         HashSet<Forest> hf = new HashSet<Forest>();
19         ambiguity.gather(hf);
20         HashSet<Tree> ht = new HashSet<Tree>();
21         ambiguity.expand(ht, hf, new Tree(null, "...", null, false));
22         for(Tree<?> result : ht) {
23             sb.append("\n\n");
24             result.toPrettyString(sb);
25         }
26         return sb.toString();
27     }
28 }