Commit 9c74f016 authored by Johannes Roith's avatar Johannes Roith

More reorganization.

parent 4f414a07
......@@ -56,14 +56,14 @@ import de.in.tum.www2.cup.internal.lalr_transition;
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.CupReduceGraphView.GraphNodeContentProvider;
import de.tum.in.www2.cupplugin.editors.CupReduceGraphView.ModelRebuildJob;
import de.tum.in.www2.cupplugin.editors.CupReduceGraphView.ParserNodeModelContentProvider;
import de.tum.in.www2.cupplugin.editors.CupReduceGraphView.ParserReduceConnection;
import de.tum.in.www2.cupplugin.editors.CupReduceGraphView.ParserReduceLabelProvider;
import de.tum.in.www2.cupplugin.editors.CupReduceGraphView.ParserReduceNode;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.GraphNodeContentProvider;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ModelRebuildJob;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserNodeModelContentProvider;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceConnection;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceLabelProvider;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceNode;
public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
IZoomableWorkbenchPart, CupEditorPageVisibility,
......
......@@ -29,6 +29,8 @@ import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.debug.Debugger;
import de.tum.in.www2.cupplugin.views.CupOverviewView;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView;
import de.tum.in.www2.cupplugin.views.CupReduceTableView;
public class MultiPageEditor extends MultiPageEditorPart implements
IResourceChangeListener {
......
package de.tum.in.www2.cupplugin.syntax;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.swt.SWT;
import de.in.tum.www2.cup.CupScanner;
import de.in.tum.www2.cup.CupSymbol;
import de.in.tum.www2.cup.Declarations;
import de.in.tum.www2.cup.NoopErrorReporter;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
public class CupTokenScanner implements ITokenScanner {
private CupScanner scanner;
private CupSymbol last;
private int offset;
private Declarations decls;
private HashSet<Integer> constants;
public Declarations getDeclarations() {
return decls;
}
public void updateDeclarations(Declarations decls) {
this.decls = decls;
}
public CupTokenScanner() {
constants = new HashSet<Integer>();
}
static final Token keyword = new Token(new TextAttribute(
CupTextEditor.KEYWORD, null, SWT.BOLD));
static final Token literal = new Token(new TextAttribute(
CupTextEditor.STRING));
static final Token terminal = new Token(new TextAttribute(
CupTextEditor.TERMINAL));
static final Token nonterminal = new Token(new TextAttribute(
CupTextEditor.NONTERMINAL));
static final Token specialErrorTerminal = new Token(new TextAttribute(
CupTextEditor.SPECIAL_ERROR_TERMINAL));
public void setRange(IDocument document, int offset, int length) {
StringReader reader = new StringReader(document.get().substring(
offset, offset + length));
scanner = new CupScanner(new NoopErrorReporter(), reader);
this.last = null;
this.offset = offset;
}
public IToken nextToken() {
try {
last = scanner.next_token();
} catch (IOException e) {
last = null;
return Token.EOF;
}
if (last.isEOF())
return Token.EOF;
if (last.isKeyword())
return keyword;
if (constants.contains(last.getSymbolId()))
return literal;
if (last.isTerminal(decls))
return terminal;
if (last.isNonTerminal(decls))
return nonterminal;
if (last.isSpecialErrorTerminal())
return specialErrorTerminal;
return Token.UNDEFINED;
}
public int getTokenOffset() {
int mOffset = this.offset + last.getLeft();
return mOffset;
}
public int getTokenLength() {
int length = last.getRight() - last.getLeft();
return length;
}
}
package de.tum.in.www2.cupplugin.syntax;
import java.io.StringReader;
import java.util.HashSet;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.swt.SWT;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ast.AbstractNode;
import de.in.tum.www2.cup.ast.ActionCodeBlock;
import de.in.tum.www2.cup.ast.IProductionRightPart;
import de.in.tum.www2.cup.ast.LabeledProductionSymbolRef;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.java.JavaScanner;
import de.in.tum.www2.java.JavaSymbol;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
public class JavaTokenScanner implements ITokenScanner {
private ParserResult ast;
private JavaScanner scanner;
private JavaSymbol last;
private int offset;
private Range previousCodeBlockRange;
private HashSet<String> currentLabels = null;
public JavaTokenScanner() {
this.currentLabels = new HashSet<String>();
}
public void updateParserResult(ParserResult result) {
this.ast = result;
this.previousCodeBlockRange = null;
}
private void refreshSpecialSymbols(Position pos) {
// System.out.println("TRYING TO FIND POSITION: " + pos);
this.currentLabels.clear();
AbstractNode node = ast.findAtPosition(pos);
if (node == null)
return;
previousCodeBlockRange = node.getRange();
if (node instanceof ActionCodeBlock) {
ActionCodeBlock codeBlock = (ActionCodeBlock) node;
AbstractNode parent = codeBlock.getParent();
if (parent instanceof ProductionRight) {
ProductionRight pr = (ProductionRight) parent;
for (IProductionRightPart part : pr.getList()) {
if (part instanceof LabeledProductionSymbolRef) {
LabeledProductionSymbolRef lpsr = (LabeledProductionSymbolRef) part;
String label = lpsr.label;
currentLabels.add(label);
currentLabels.add(label + "xleft");
currentLabels.add(label + "xright");
currentLabels.add(label + "left");
currentLabels.add(label + "right");
}
}
}
}
}
public void setRange(IDocument document, int offset, int length) {
StringReader reader = new StringReader(document.get().substring(
offset, offset + length));
this.scanner = new JavaScanner(reader);
this.last = null;
this.offset = offset;
if (ast == null) {
this.currentLabels.clear();
} else {
// TODO: we convert offset to line number / position.
// TODO: centralize this type of code, so we have our bugs in
// one place :-)
int line;
int column;
try {
line = document.getLineOfOffset(offset);
column = offset - document.getLineOffset(line);
} catch (BadLocationException e) {
e.printStackTrace();
return;
}
line += 1;
column += 2; // TODO: adding two here is a hack!
Position pos = new Position(line, column, -1);
if (previousCodeBlockRange != null
&& previousCodeBlockRange.contains(pos)) {
// the old AST is till valid and we are within the same code
// block.
// -> just keep the existing labels.
return;
} else {
refreshSpecialSymbols(pos);
}
}
}
static final Token javaComment = new Token(new TextAttribute(
CupTextEditor.COMMENT));
static final Token javaKeyword = new Token(new TextAttribute(
CupTextEditor.JAVA_KEYWORD));
static final Token javaTextualLiteral = new Token(new TextAttribute(
CupTextEditor.JAVA_TEXTUAL));
static final Token cupDefinedVariable = new Token(new TextAttribute(
CupTextEditor.JAVA_CUP_DEFINED, null, SWT.ITALIC));
public IToken nextToken() {
try {
last = scanner.next_token();
} catch (Exception e) {
last = null;
return Token.EOF;
} catch (Error err) {
last = null;
return Token.EOF;
}
if (last.isEOF())
return Token.EOF;
if (last.isComment())
return javaComment;
if (last.isKeyword() || last.isBooleanLiteral()
|| last.isNullLiteral())
return javaKeyword;
if (last.isTextualLiteral())
return javaTextualLiteral;
if (last.getValue() instanceof String) {
String lastValueStr = (String) last.getValue();
if (lastValueStr.equals("RESULT")
|| currentLabels.contains(lastValueStr))
return cupDefinedVariable;
}
return Token.UNDEFINED;
}
public int getTokenOffset() {
return this.offset + (last.getLeft());
}
public int getTokenLength() {
return last.getRight() - last.getLeft() + 1;
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.syntax;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
public class SingleTokenScanner extends RuleBasedScanner {
/**
* Creates a single token scanner.
*/
public SingleTokenScanner(TextAttribute attribute) {
setDefaultReturnToken(new Token(attribute));
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.editors;
package de.tum.in.www2.cupplugin.views;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -79,6 +79,8 @@ import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.editors.CupEditorPageVisibility;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
......
package de.tum.in.www2.cupplugin.editors;
package de.tum.in.www2.cupplugin.views;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Composite;
......
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