1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.util.*;
7 /** thrown to signal that a parse was ambiguous */
8 public class Ambiguous extends Exception {
10 private final Forest<?> ambiguity;
11 private final HashSet<Tree<?>> possibilities;
14 * @param possibilities is a specially-constructed set of trees with shared nodes replaced by '*'
16 Ambiguous(Forest<?> ambiguity, HashSet<Tree<?>> possibilities) {
17 this.ambiguity = ambiguity;
18 this.possibilities = possibilities;
21 public Forest<?> getForest() { return ambiguity; }
23 public String toString() {
24 StringBuffer sb = new StringBuffer();
25 sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
26 for(Tree<?> result : possibilities) {
27 sb.append("\n possibility: ");
28 StringBuffer sb2 = new StringBuffer();
29 result.toPrettyString(sb2);
30 sb.append(StringUtil.indent(sb2.toString(), 15));