Commit a46b502c authored by Alexandru Dura's avatar Alexandru Dura
Browse files

Remove useles interface PrettyPrintingInfo

parent 9ca28de4
......@@ -47,7 +47,7 @@ public class DottedRule {
return true;
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
String s = info.getCategory(r.head).toString() + " -> ";
for (int j = 0; j < r.body.length; ++j) {
if (j == dot) {
......
......@@ -50,7 +50,7 @@ public class EarleyItem {
return (rule.hashCode() * 31 + start) * 31 + (sppf == null ? 0 : sppf.hashCode());
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
String s = info.getCategory(rule.r.head).toString() + " -> ";
for (int j = 0; j < rule.r.body.length; ++j) {
if (j == rule.dot) {
......
......@@ -32,7 +32,7 @@ public class EarleyRule implements Comparable<EarleyRule> {
}
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
String s = info.getCategory(head).toString() + " -> ";
for (int j : body) {
s += info.getCategory(j).toString() + " ";
......
......@@ -2,7 +2,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeSet;
public class Grammar implements PrettyPrintingInfo {
public class Grammar {
private HashMap<Category, Integer> cat2int = new HashMap<>();
private HashMap<Integer, Category> int2cat = new HashMap<>();
private HashMap<Category, ArrayList<Rule>> grammarRules = new HashMap<>();
......@@ -82,7 +82,6 @@ public class Grammar implements PrettyPrintingInfo {
return s;
}
@Override
public Category getCategory(int i) {
Category c = int2cat.get(i);
if (c == null)
......
......@@ -16,7 +16,7 @@ public abstract class NodeLabel {
return 31 * start + end;
}
public abstract String prettyPrint(PrettyPrintingInfo info);
public abstract String prettyPrint(Grammar info);
}
class ItemLabel extends NodeLabel {
......@@ -37,7 +37,7 @@ class ItemLabel extends NodeLabel {
return super.hashCode() * 31 + item.hashCode();
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
return item.prettyPrint(info) + ", " + super.start + ", " + super.end;
}
}
......@@ -60,7 +60,7 @@ class SymbolLabel extends NodeLabel {
return super.hashCode() * 31 + symbol;
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
return info.getCategory(symbol).toString() + ", " + super.start + ", " + super.end;
}
}
interface PrettyPrintingInfo {
Category getCategory(int i);
}
......@@ -73,18 +73,17 @@ public class SPPFNode {
children.add(new FamilyNode(null, null));
}
public String prettyPrint(PrettyPrintingInfo info) {
public String prettyPrint(Grammar info) {
return label.prettyPrint(info);
}
public void accept(SPPFNodeVisitor visitor) {
visitor.visit(this);
}
}
interface SPPFNodeVisitor {
public void visit(SPPFNode.FamilyNode familyNode);
public void visit(SPPFNode n);
public NodeLabel getLabel() {
return label;
}
}
class DotVisitor implements SPPFNodeVisitor {
......@@ -92,9 +91,9 @@ class DotVisitor implements SPPFNodeVisitor {
private int nodeID = 0;
private HashMap<SPPFNode, Integer> visitedNodes = new HashMap<>();
private HashMap<SPPFNode.FamilyNode, Integer> visitedFamilies = new HashMap<>();
private PrettyPrintingInfo info;
private Grammar info;
public DotVisitor(PrintStream ps, PrettyPrintingInfo info) {
public DotVisitor(PrintStream ps, Grammar info) {
this.info = info;
this.ps = ps;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment