Commit b53a2950 authored by Michael Schwarz's avatar Michael Schwarz

Detect if both precedences are from same terminal and offer to insert

assoc.
parent f63e1f38
......@@ -71,6 +71,10 @@ public class ConflictResolutionManager {
}
}
}
public CupContext getLaLrContext() {
return lalrContext;
}
public boolean isUseDijkstar() {
return useDijkstar;
......
......@@ -20,6 +20,10 @@ public class ProductionRight extends AbstractNode {
return lst;
}
public Terminal getPrecedenceLike(){
return precedenceLike;
}
// We store the index that is used by the (lowercase)
// production class to identify productions.
// This should allow us to match productions and also
......
......@@ -17,6 +17,7 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
......@@ -30,7 +31,10 @@ import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.IProductionRightPart;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.ast.ProductionSymbolRef;
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.lalr_state;
......@@ -63,7 +67,7 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
class ConflictPanel extends Composite {
private static final int BASE_HEIGHT = 60;
private static final int BASE_HEIGHT = 85;
private static final int COLUMNS = 3;
private static final int HEADING_FONT_SIZE = 14;
......@@ -73,11 +77,13 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
private Link stateLabel;
private Label symbolLabel;
private Combo resolutionOptions;
private Composite detailWrapper;
private Link detailText;
private Label resolutionHint;
private List<Range> links = new ArrayList<Range>();
private Color backgroundColorReduce;
private Color foregroundColorReduce;
private Color backgroundColorShift;
......@@ -144,7 +150,13 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
resolutionHintData.grabExcessHorizontalSpace = true;
resolutionHintData.horizontalSpan = COLUMNS;
resolutionHint.setLayoutData(resolutionHintData);
}
this.resolutionOptions = new Combo(this,SWT.DROP_DOWN);
GridData resolutionOptionsData = new GridData();
resolutionOptionsData.grabExcessHorizontalSpace = true;
resolutionOptionsData.horizontalSpan = COLUMNS;
resolutionOptions.setLayoutData(resolutionOptionsData);
}
private Composite makeDetailWrapper(int columns) {
Composite detailWrapper = new Composite(this, SWT.WRAP);
......@@ -267,6 +279,11 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
}
symbolLabel.setText(symbolsBuilder.toString());
resolutionOptions.removeAll();
resolutionOptions.add("Use first");
resolutionOptions.add("Use second");
} else if (conflict instanceof ShiftReduceConflict) {
ShiftReduceConflict src = (ShiftReduceConflict) conflict;
changeColors(backgroundColorShift, foregroundColorShift);
......@@ -319,7 +336,42 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
gridData.heightHint += detailText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
terminal sourceOfShiftPrec = src.getTerminal();
terminal sourceOfReducePrec = null;
// If the precedence is specifically set via %prec
if(conflict1Ast.hasSpecifiedPrecedence()){
sourceOfReducePrec = terminal.getShared(crm.getLaLrContext()).find(
conflict1Ast.getPrecedenceLike().getNameStringOrNull());
}
// Terminal defining precedence is the last one in the current production
else {
for(IProductionRightPart part : conflict1Ast.getList()){
if(part instanceof ProductionSymbolRef){
ProductionSymbolRef ppsr = (ProductionSymbolRef)part;
terminal candidate = terminal.getShared(crm.getLaLrContext()).find(
ppsr.getNameStringOrNull());
if(candidate != null){
sourceOfReducePrec = candidate;
}
}
}
}
int reducePred = src.getConflictItem1().the_production().precedence_num();
int shiftPred = src.getTerminal().precedence_num();
resolutionOptions.removeAll();
if(sourceOfShiftPrec.equals(sourceOfReducePrec)) {
// If the precedence of the terminal and the production come from the same terminal
resolutionOptions.add("Shift (== make " + src.getTerminal().name() +" right associative");
resolutionOptions.add("Reduce (== make " + src.getTerminal().name() +" left associative");
}
} else {
throw new RuntimeException("unexpected conflict type.");
}
......
......@@ -88,6 +88,8 @@ public abstract class TooltipBase {
popup.setLocation(p);
}
//FIXME: in order to prevent a new icon in the tray for every popup, use an
// invisible Dialog
public TooltipBase(Display display) {
popup = new Shell(display, SWT.BALLOON);
......
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