1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.*;
5 import edu.berkeley.sbp.util.*;
6 import edu.berkeley.sbp.Sequence.Position;
10 /** if ambiguity checking is enabled, this exception is thrown to signal that the parse was ambiguous */
11 public class Ambiguous extends Exception {
13 final Forest<?> ambiguity;
14 private final HashSet<Tree<?>> ht;
17 * @param ht a specially-constructed set of trees with shared nodes replaced by '*'
19 Ambiguous(Forest<?> ambiguity, HashSet<Tree<?>> ht) {
20 this.ambiguity = ambiguity;
24 public Forest<?> getAmbiguity() { return ambiguity; }
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(); }
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));