make ANSI.clreol()
[sbp.git] / src / edu / berkeley / sbp / Ambiguous.java
1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.*;
5 import edu.berkeley.sbp.util.*;
6 import edu.berkeley.sbp.Sequence.Position;
7 import java.io.*;
8 import java.util.*;
9
10 /** if ambiguity checking is enabled, this exception is thrown to signal that the parse was ambiguous */
11 public class Ambiguous extends Exception {
12
13     final Forest<?> ambiguity;
14     private final HashSet<Tree<?>> ht;
15
16     /**
17      *  @param ht a specially-constructed set of trees with shared nodes replaced by '*'
18      */
19     Ambiguous(Forest<?> ambiguity, HashSet<Tree<?>> ht) {
20         this.ambiguity = ambiguity;
21         this.ht = ht;
22     }
23
24     public Forest<?> getAmbiguity() { return ambiguity; }
25
26     /** WARNING: this method is not considered part of the "stable API"; it may be removed in the future */
27     public Input.Region getRegion() { return ambiguity.getRegion(); }
28
29     public String toString() {
30         StringBuffer sb = new StringBuffer();
31         sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
32         for(Tree<?> result : ht) {
33             sb.append("\n    possibility: ");
34             StringBuffer sb2 = new StringBuffer();
35             result.toPrettyString(sb2);
36             sb.append(StringUtil.indent(sb2.toString(), 15));
37         }
38         return sb.toString();
39     }
40 }