Commit d5875247 authored by Johannes Roith's avatar Johannes Roith

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

parents 7665be2b 246cec35
......@@ -296,6 +296,7 @@ public class Controller {
.getLaLrRevisionNumber();
if (modelLaLrRev != RevisionManager.get(document)) {
addJobToDo(job);
addJobToDo(JobsToDo.parseCode);
}
break;
default:
......
......@@ -106,11 +106,11 @@ public class DocumentDidChangeJob extends Job {
return Status.CANCEL_STATUS;
IFile file = ((FileEditorInput) myEditor.getEditorInput()).getFile();
CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file);
CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file);
errorReporter.resetOnNextPush();
CupParser parser = null;
if (jobs.contains(JobsToDo.parseCode)) {
InputStream in = new ByteArrayInputStream(codeText.getBytes());
......@@ -121,7 +121,7 @@ public class DocumentDidChangeJob extends Job {
} catch (Exception e1) {
e1.printStackTrace();
}
context = parser.getContext();
errorReporter.pushToUIThread();
......@@ -145,11 +145,17 @@ public class DocumentDidChangeJob extends Job {
lalrResult = null;
try {
if (parser != null && !parser.hasParseErrors()) {
lalrResult = LALRResult.Compute(context,
context.start_production);
lalrResult = LALRResult.Compute(context,
context.start_production);
} else {
System.out.println("LALRResult.Compute was not called, " +
"because the parser has reported errors.");
System.out.println("LALRResult.Compute was not called, "
+ "because the parser has reported errors.");
if (parser == null) {
System.out.println("Null parser");
} else {
System.out.println("Parser has Errors: "
+ parser.hasParseErrors());
}
}
} catch (internal_error e) {
......@@ -171,7 +177,7 @@ public class DocumentDidChangeJob extends Job {
return Status.CANCEL_STATUS;
}
}
errorReporter.pushToUIThread();
System.out.println(jobs);
......
......@@ -112,7 +112,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
actionTableView = new CupActionTableView(composite, doc);
actionTableView = new CupActionTableView(composite, editor);
addPage(ACTION_TABLE_PAGE_INDEX, composite);
setPageText(ACTION_TABLE_PAGE_INDEX, "Action Table");
}
......
package de.tum.in.www2.cupplugin.views;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.parse_action;
import de.in.tum.www2.cup.internal.parse_action_row;
import de.in.tum.www2.cup.internal.parse_action_table;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.ICupEditorPageVisibility;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupActionTableView implements ICupEditorPageVisibility,
ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private CupTextEditor editor;
private IDocument doc;
private TreeViewer treeViewer;
private boolean isVisible = false;
private List<ActionNode> stateList;
public CupActionTableView(Composite parent, CupTextEditor editor) {
this.editor = editor;
this.doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
this.stateList = new LinkedList<ActionNode>();
Controller.getInstance(editor).registerObserver(this);
Model.getInstanceForDocument(doc).registerModelObserver(this);
public class CupActionTableView {
parent.setLayout(new FillLayout());
public CupActionTableView(Composite parent, IDocument doc) {
this.treeViewer = new TreeViewer(parent, SWT.H_SCROLL
| SWT.BORDER);
treeViewer.setContentProvider(new ActionNodeContentProvider());
treeViewer.setLabelProvider(new ActionNodeLabelProvider());
// the viewer field is an already configured TreeViewer
Tree tree = (Tree) treeViewer.getControl();
tree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem item = (TreeItem) e.item;
if (item.getItemCount() > 0) {
item.setExpanded(!item.getExpanded());
// update the viewer
treeViewer.refresh();
}
}
});
treeViewer.setInput(stateList);
}
@Override
public void willBecomeVisible() {
System.out.println("CupActionTableView will become visible.");
isVisible = true;
if (!Controller.getInstance(editor).requestJobRun()) {
ModelChange(Model.getInstanceForDocument(doc));
}
}
@Override
public void becameHidden() {
System.out.println("CupActionTableView became hidden.");
isVisible = false;
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if (isVisible) {
requestedJobs = EnumSet.of(JobsToDo.buildTable);
}
return requestedJobs;
}
@Override
public void ModelChange(Model model) {
if (!isVisible) {
return;
}
stateList.clear();
LALRResult lalrResult = model.getLaLrResult();
System.out.println(lalrResult.getActionTable().toString());
parse_action_table table = lalrResult.getActionTable();
CupContext context = model.getLaLrContext();
for (int row = 0; row < table.num_states(); row++) {
ActionNode n = new ActionNode(row, "State " + row);
stateList.add(n);
for (int col = 0; col < parse_action_row.size(context); col++) {
n.getChildren().add(new ActionNodeChild(n, (table.under_state[row].under_term[col]).toString()));
}
}
treeViewer.refresh();
}
static class ActionNode {
private final int index;
private final String name;
private final List<ActionNodeChild> children;
public ActionNode(int index, String name) {
this.index = index;
this.name = name;
this.children = new LinkedList<ActionNodeChild>();
}
public int getIndex() {
return index;
}
public String getName() {
return name;
}
public List<ActionNodeChild> getChildren() {
return children;
}
}
static class ActionNodeChild {
private final ActionNode parent;
private final String name;
public ActionNodeChild(ActionNode parent, String name) {
this.parent = parent;
this.name = name;
}
public ActionNode getParent() {
return parent;
}
public String getName() {
return name;
}
}
class ActionNodeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof ActionNode) {
return new ActionNode[] { (ActionNode) inputElement };
} else if (inputElement instanceof ActionNode[]) {
return (ActionNode[]) inputElement;
} else if (inputElement instanceof List) {
return ((List)inputElement).toArray();
}
return new Object[0];
}
@Override
public Object[] getChildren(Object parentElement) {
if(parentElement instanceof ActionNode) {
ActionNode n = (ActionNode)parentElement;
return n.getChildren().toArray();
}
return null;
}
@Override
public Object getParent(Object element) {
if(element instanceof ActionNodeChild) {
ActionNodeChild c = (ActionNodeChild)element;
return c.getParent();
}
return null;
}
@Override
public boolean hasChildren(Object element) {
if(element instanceof ActionNode) {
ActionNode n = (ActionNode)element;
return !n.getChildren().isEmpty();
}
return false;
}
}
class ActionNodeLabelProvider extends StyledCellLabelProvider {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof ActionNode) {
ActionNode n = (ActionNode) element;
cell.setText(n.getName());
} if (element instanceof ActionNodeChild) {
ActionNodeChild c = (ActionNodeChild)element;
cell.setText(c.getName());
}
}
public void setFocus() {
treeViewer.getControl().setFocus();
}
}
}
......@@ -468,6 +468,7 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
private final String name;
private List<ParserConflictNode> connections;
private String description;
private boolean isNonTerm = false;
public ParserConflictNode(int id, String name) {
this.id = id;
......@@ -495,6 +496,14 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
public void setDescription(String description) {
this.description = description;
}
public boolean getIsNonTerm() {
return isNonTerm;
}
public void setIsNonTerm(boolean isNonTerm) {
this.isNonTerm = isNonTerm;
}
}
static class ParserConflictConnection {
......@@ -573,6 +582,7 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
ParserConflictNode n = new ParserConflictNode(dfsNode
.getState().index(), "State "
+ dfsNode.getState().index());
n.setIsNonTerm(dfsNode.getPredTransition().on_symbol().is_non_term());
nodes.add(n);
ParserConflictConnection con = new ParserConflictConnection(""
+ counter, dfsNode.getPredTransition().on_symbol()
......@@ -704,6 +714,13 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
@Override
public Color getColor(Object src, Object dest) {
if(dest instanceof ParserConflictNode) {
ParserConflictNode n = (ParserConflictNode)dest;
if(n.isNonTerm) {
Device device = Display.getCurrent();
return device.getSystemColor(SWT.COLOR_DARK_MAGENTA);
}
}
return null;
}
......@@ -722,7 +739,7 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if (isVisible) {
requestedJobs = EnumSet.of(JobsToDo.buildTable, JobsToDo.parseCode);
requestedJobs = EnumSet.of(JobsToDo.buildTable);
}
return requestedJobs;
}
......
......@@ -870,7 +870,7 @@ public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if (isVisible) {
requestedJobs = EnumSet.of(JobsToDo.buildTable, JobsToDo.parseCode);
requestedJobs = EnumSet.of(JobsToDo.buildTable);
}
return requestedJobs;
}
......
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