Commit 88c32f6f authored by Michael Schwarz's avatar Michael Schwarz

function to move production to the very end and insert threshold if

required
parent dd218ed2
......@@ -565,6 +565,10 @@ class ConflictPanel extends Composite {
public void widgetSelected(SelectionEvent e){
if(!(conflict instanceof ShiftReduceConflict)) {
//DEBUG
cupConflictsView.moveItemToVeryEnd(((ReduceReduceConflict)conflict).getConflictItem1());
return;
}
if(resolutionOptions.getSelectionIndex() == 0){
......
......@@ -33,14 +33,17 @@ import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.AbstractNode;
import de.in.tum.www2.cup.ast.IProductionRightPart;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.ast.Precedence;
import de.in.tum.www2.cup.ast.Production;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.ast.ProductionSymbolRef;
import de.in.tum.www2.cup.ast.SymbolDeclaration;
import de.in.tum.www2.cup.ast.Terminal;
import de.in.tum.www2.cup.internal.internal_error;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lr_item_core;
import de.in.tum.www2.cup.internal.terminal;
import de.tum.in.www2.cupplugin.Colors;
......@@ -587,4 +590,41 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
return false;
}
}
public void moveItemToVeryEnd(lalr_item item){
Production p =(Production)item.the_production().getAstNode().getParent();
IDocument document = editor.getDocument();
if(p.getRightHandSides().size() == 1){
// Base case
try {
String pString = document.get(p.getBegin().getOffsetFromStart(),
p.getEnd().getOffsetFromStart() - p.getBegin().getOffsetFromStart());
ParserResult r = Model.getInstanceForDocument(document).getAstModel();
int positionForProd = 0;
// Grammar can be assumed to have at least two productions -> safe
positionForProd = r.productions.get(r.productions.size()-1).getEnd().getOffsetFromStart();
String toInsert = "\n\n//Moved by CUP Eclipse plugin\n" + pString;
if(ignoreRRAfterLine == -1){
toInsert = "\n\n// " + TRESHOLD_STRING + "\n // After this the order of productions matters" + toInsert;
}
document.replace(positionForProd, 0, toInsert);
// We have a guarantee that we are moving stuff backwards, so this works
document.replace(p.getBegin().getOffsetFromStart(), p.getEnd().getOffsetFromStart() - p.getBegin().getOffsetFromStart(), "");
return;
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return;
}
}
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