checkpoint
[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     private final HashSet<Tree<?>> ht;
12     public Ambiguous(Forest<?> ambiguity, HashSet<Tree<?>> ht) {
13         this.ambiguity = ambiguity;
14         this.ht = ht;
15     }
16     public String toString() {
17         // FIXME: print the input region that was ambiguously matched
18         StringBuffer sb = new StringBuffer();
19         sb.append("unresolved ambiguity; shared subtrees are shown as \"*\" ");
20         for(Tree<?> result : ht) {
21             sb.append("\n  possibility: ");
22             StringBuffer sb2 = new StringBuffer();
23             result.toPrettyString(sb2);
24             sb.append(StringUtil.indent(sb2.toString(), 15));
25         }
26         return sb.toString();
27     }
28 }