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