-// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
package edu.berkeley.sbp;
import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.Sequence.Position;
+import edu.berkeley.sbp.Sequence.Pos;
+import edu.berkeley.sbp.Sequence.Pos;
import edu.berkeley.sbp.GSS.Phase;
-import edu.berkeley.sbp.Node;
+import edu.berkeley.sbp.StateNode;
import edu.berkeley.sbp.util.*;
import java.io.*;
import java.util.*;
return ret.toString();
}
- private static boolean important(Position p) {
+ private static boolean important(Pos p) {
if (p.isLast()) return false;
if (p.element() == null) return false;
if (!(p.element() instanceof Union)) return false;
return (c >= 'A' && c <= 'Z');
}
- static <Tok> void barf(HashMap<Element,Input.Location> sb, Node n, int indent, boolean skip, int count, Input.Location loc) {
+ static <Tok> void barf(HashMap<Element,Input.Location> sb, StateNode n, int indent, boolean skip, int count, Input.Location loc) {
if (count <= 0) {
barf(sb, n, indent, skip, loc);
} else {
/*
FIXME: removed
- for(Node nn : (Iterable<Node>)n.parents())
+ for(StateNode nn : (Iterable<StateNode>)n.parents())
barf(sb, nn, indent, skip, count-1, n.phase().getLocation());
*/
}
}
- static <Tok> void barf(HashMap<Element,Input.Location> sb, Node n, int indent, boolean skip, Input.Location loc) {
+ static <Tok> void barf(HashMap<Element,Input.Location> sb, StateNode n, int indent, boolean skip, Input.Location loc) {
if (touched.contains(n)) return;
touched.add(n);
String s = "";
for(int i=0; i< indent; i++) s += " ";
- Node parent = n;
+ StateNode parent = n;
boolean done = false;
boolean alldone = false;
boolean go = false;
boolean force = false;
- for(Position p : (Iterable<Position>)parent.state()) {
+ for(Pos pp : (Iterable<Pos>)parent.state().positions()) {
+ Pos p = (Pos)pp;
if (skip) p = p.next();
int raise = 0;
done = false;
// FIXME
- private static HashSet<Node> touched = new HashSet<Node>();
- static <Tok> void complain(Node n, HashMap<String,HashSet<String>> errors, boolean force, int indent) {
+ private static HashSet<StateNode> touched = new HashSet<StateNode>();
+ static <Tok> void complain(StateNode n, HashMap<String,HashSet<String>> errors, boolean force, int indent) {
if (touched.contains(n)) return;
touched.add(n);
- for(Position p : (Iterable<Position>)n.state()) {
+ for(Pos p : (Iterable<Pos>)n.state()) {
//if (!p.isLast() && !p.next().isLast()) continue;
if (((p.isFirst() || p.isLast()) && !force)/* || p.owner().name==null*/ ||
!important(p)) {
/*
FIXME: removed
- for(Node n2 : n.parents())
+ for(StateNode n2 : n.parents())
complain(n2, errors, force
//| p.isFirst()
, indent);
return ANSI.purple(ret.toString());
}
- static void error(String message, GSS.Phase phase) throws ParseFailed {
- error(message, phase.getLocation(), phase.getToken(),
- phase, phase.getRegion(), phase.getGSS().getInput(), phase.getGSS());
+ static void error(String message, GSS.Phase phase, Object token, Input.Region region) throws ParseFailed {
+ error(message,
+ token,
+ /*phase*/null,
+ region,
+ phase.getGSS().getInput(),
+ phase.getGSS());
}
- static void error(String message,
- Input.Location loc,
- Object token,
- Iterable<Node> nodes,
- Input.Region region,
- Input input,
- GSS gss) throws ParseFailed{
+ private static void error(String message,
+ Object token,
+ Iterable<StateNode> nodes,
+ Input.Region region,
+ Input input,
+ GSS gss) throws ParseFailed{
String lookAhead = token==null ? "<EOF>" : token.toString();
StringBuffer ret = new StringBuffer();
ret.append(ANSI.bold(ANSI.red(message)));
- if (token != null) {
- ret.append(" \'");
- ret.append(ANSI.cyan(StringUtil.escapify(token+"", "\\\'\r\n")));
- ret.append("\'");
- }
+ String toks = token+"";
ret.append(" at ");
ret.append(ANSI.yellow(region+""));
if (input != null) {
*/
}
HashMap<Element,Input.Location> hm = new HashMap<Element,Input.Location>();
- for(Node no : nodes)
- barf(hm, no, 0, false, region.getStart());
+ if (nodes!=null)
+ for(StateNode no : nodes)
+ barf(hm, no, 0, false, region.getStart());
ret.append("\n expected: ");
Set<Element> hs = hm.keySet();
if (hs.size() == 1) {
/*
ret.append("\n The author of SBP apologizes for the these nearly-useless error messages:\n\n");
HashMap<String,HashSet<String>> errors = new HashMap<String,HashSet<String>>();
- for(Node n : nodes) {
+ for(StateNode n : nodes) {
//System.out.println(n.state);
complain(n, errors, false, 0);
}