Commit bf4fe419 authored by Benedikt Engeser's avatar Benedikt Engeser

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents d8805d54 6c69f21c
......@@ -7,6 +7,10 @@ public abstract class Conflict
{
private lalr_state state;
public lalr_state getState() {
return state;
}
public Conflict(lalr_state state) {
this.state = state;
}
......
......@@ -19,6 +19,7 @@ public class ConflictManager
}
public void addConflict(Conflict conflict) {
System.out.println("DEBUG: ADDING CONFLICT TO " + this + "!"); // TODO: remove
this.conflicts.add(conflict);
}
}
......
......@@ -17,7 +17,7 @@ class Demo
IErrorReporter er = new NoopErrorReporter();
FileInputStream input = new FileInputStream("/Users/jroith/testcup/testspeed.cup");
FileInputStream input = new FileInputStream("/Users/jroith/testcup/test.cup");
CupParser parser = new CupParser(er, input);
ParserResult res = parser.parse();
......
......@@ -58,8 +58,7 @@ public class LALRResult {
// if we have more conflicts than we expected issue a message and die
if (context.num_conflicts > expect_conflicts)
{
System.out.println("*** More conflicts encountered than expected " +
"-- parser generation aborted");
System.err.println("*** More conflicts encountered than expected.");
return result;
}
......
......@@ -8,6 +8,7 @@ public class Colors {
public static final RGB darkGray = new RGB (20, 20, 20);
// public static final RGB darkGray = new RGB (30, 30, 30);
public static final RGB gray = new RGB (150, 150, 150);
public static final RGB lightGray = new RGB (240, 240, 240);
public static final RGB blue = new RGB (53, 87, 197);
public static final RGB brightBlue = new RGB (38, 99, 236);
public static final RGB green = new RGB (44, 173, 57);
......
......@@ -13,9 +13,13 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
......@@ -37,17 +41,42 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private List<ConflictPanel> conflictPanels;
private ScrolledComposite scrolled;
private Composite list;
static class ConflictPanel extends Composite {
private Label conflictTypeLabel;
private Label stateLabel;
public ConflictPanel(Composite parent, int style) {
super(parent, style);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.grabExcessHorizontalSpace = true;
data.heightHint = 50;
setLayoutData(data);
setBackground(new Color(Display.getCurrent(), Colors.gray));
setBackground(new Color(Display.getCurrent(), Colors.lightGray));
GridLayout layout = new GridLayout();
layout.numColumns = 5;
layout.verticalSpacing = 3;
setLayout(layout);
this.conflictTypeLabel = new Label(this, SWT.NONE);
this.stateLabel = new Label(this, SWT.NONE);
}
public void update(Conflict conflict) {
if (conflict instanceof ReduceReduceConflict) {
conflictTypeLabel.setText("Reduce-Reduce conflict");
} else if (conflict instanceof ShiftReduceConflict) {
conflictTypeLabel.setText("Shift-Reduce conflict");
} else {
throw new RuntimeException("unexpected conflict type.");
}
stateLabel.setText("State: " + conflict.getState().index());
}
}
public CupConflictsView(Composite parent, Jumper jumper, CupTextEditor editor) {
......@@ -67,7 +96,7 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
this.scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
this.scrolled.setExpandHorizontal(true);
this.scrolled.setExpandVertical(true);
list = new Composite(scrolled, SWT.NONE);
list.setBackground(new Color(Display.getCurrent(), Colors.white));
scrolled.setContent(list);
......@@ -80,12 +109,22 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
refreshScrolledLayout ();
}
private void updateConflicts(List<Conflict> conflicts) {
int size = conflicts.size();
matchPanelNumber(size);
for (int i=0; i < size; i++) {
Conflict conflict = conflicts.get(i);
ConflictPanel panel = conflictPanels.get(i);
panel.update(conflict);
}
refreshScrolledLayout ();
}
private void matchPanelNumber(int number) {
int excessPanels = number - this.conflictPanels.size();
int excessPanels = this.conflictPanels.size() - number;
if (excessPanels > 0) {
// TODO!
// for (int i=0; i < excessPanels; i++)
// this.conflictPanels.remove(0);
for (int i=0; i < excessPanels; i++)
this.conflictPanels.remove(0);
} else {
while (this.conflictPanels.size() < number) {
conflictPanels.add (new ConflictPanel(list, SWT.NONE));
......@@ -95,7 +134,7 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
System.out.println("conflictPanels size: " + this.conflictPanels.size());
}
private void refreshScrolledLayout() {
scrolled.layout(true, true);
scrolled.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
......@@ -104,53 +143,43 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
public void dispose() {
System.out.println("CupConflictsView disposed!");
}
@Override
public void willBecomeVisible() {
System.out.println("CupConflictsView will become visible.");
this.isVisible = true;
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
System.out.println("NO RERUN!!!");
System.out.println("NO RERUN!!!"); // TODO
Model model = Model.getInstanceForDocument(editor.getDocument());
LALRResult result = model.getLaLrResult();
ConflictManager cm = result.getContext().getConflictManager();
matchPanelNumber(cm.getConflicts().size());
if (result != null) {
ConflictManager cm = result.getContext().getConflictManager();
updateConflicts(cm.getConflicts());
}
}
}
@Override
public void becameHidden() {
this.isVisible = false;
System.out.println("CupConflictsView became hidden.");
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if (isVisible) {
if (isVisible)
requestedJobs = EnumSet.of(JobsToDo.buildTable);
}
return requestedJobs;
}
@Override
public void modelChanged(Model model) {
System.out.println("MODEL CHANGED !!!!!!!!!!!");
LALRResult result = model.getLaLrResult();
if (result != null) {
ConflictManager cm = result.getContext().getConflictManager();
matchPanelNumber(cm.getConflicts().size());
updateConflicts(cm.getConflicts());
} else {
matchPanelNumber(0);
}
refreshScrolledLayout ();
}
}
}
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