Commit 0a1e355b authored by Alexandru Dura's avatar Alexandru Dura
Browse files

Issue #2: add the parent node to the isBubbleUpChild predicate

This should allow clients to be more selective for cases when we want
to bypass the parent of a node.
parent c4befba8
......@@ -39,6 +39,7 @@ public class SPPFTrivialProductionRemover implements SPPFNodeVisitor {
HashSet<SPPFNode.FamilyNode> newChildren = new HashSet<>();
HashSet<SPPFNode.FamilyNode> childrenToRemove = new HashSet<>();
Category nc = ((SymbolLabel)n.getLabel()).getSymbol(grammar);
for (SPPFNode.FamilyNode f : n.getChildren()) {
SPPFNode[] childArray = new SPPFNode[f.getNumChildren()];
......@@ -56,7 +57,7 @@ public class SPPFTrivialProductionRemover implements SPPFNodeVisitor {
continue;
SymbolLabel label = (SymbolLabel)ff.getChild(0).getLabel();
if (isBubleUpChild(label.getSymbol(grammar))) {
if (isBubleUpChild(nc, label.getSymbol(grammar))) {
bubbleUpChild = ff.getChild(0);
break;
}
......@@ -81,7 +82,7 @@ public class SPPFTrivialProductionRemover implements SPPFNodeVisitor {
n.getChildren().addAll(newChildren);
}
public boolean isBubleUpChild(Category c) {
public boolean isBubleUpChild(Category p, Category c) {
return false;
}
}
......@@ -191,7 +191,7 @@ public class EarleyParserTest {
dec.visit(root);
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isBubleUpChild(Category c) {
@Override public boolean isBubleUpChild(Category p, Category c) {
if (c.getName().equals("METAVARID"))
return true;
if (c.getName().equals("GAP"))
......@@ -238,7 +238,7 @@ public class EarleyParserTest {
dec.visit(root);
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isBubleUpChild(Category c) {
@Override public boolean isBubleUpChild(Category p, Category c) {
if (c.getName().equals("METAVARID"))
return true;
if (c.getName().equals("GAP"))
......@@ -286,7 +286,7 @@ public class EarleyParserTest {
Util.dumpParseResult("testJava3.dot", root, g);
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isBubleUpChild(Category c) {
@Override public boolean isBubleUpChild(Category p, Category c) {
if (c.getName().equals("METAVARID"))
return true;
if (c.getName().equals("GAP"))
......@@ -331,7 +331,7 @@ public class EarleyParserTest {
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isBubleUpChild(Category c) {
@Override public boolean isBubleUpChild(Category p, Category c) {
if (c.getName().equals("METAVARID"))
return true;
if (c.getName().equals("GAP"))
......@@ -423,7 +423,7 @@ public class EarleyParserTest {
assertNotNull(root);
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isBubleUpChild(Category c) {
@Override public boolean isBubleUpChild(Category p, Category c) {
if (c.getName().equals("METAVARID"))
return true;
if (c.getName().equals("GAP"))
......
Markdown is supported
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