Commit 65087b24 authored by Benedikt Engeser's avatar Benedikt Engeser

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

parents ce774ded 142978c2
......@@ -14,7 +14,10 @@
<target name="generate">
<jflex file="${jflex}/Lexer.jflex" destdir="${java}" />
<cup srcfile="${cup}/Parser.cup" destdir="${java}"
parser="Parser" interface="true" locations="true" />
parser="Parser"
interface="true"
locations="true"
debugsymbols="true" />
</target>
<path id="libraries"> <files includes="${lib}/java-cup-11b-runtime.jar" /> </path>
......
......@@ -180,10 +180,6 @@ action code {:
}
}
Stack<ComplexSymbol> head_tokens = new Stack<ComplexSymbol> ();
List<IProductionRightPart> rhs_accumulator = new ArrayList<IProductionRightPart>();
protected void ast_add_rhs_part(IProductionRightPart part)
......@@ -201,13 +197,9 @@ action code {:
rhs_accumulator.clear();
}
protected void ast_add_precedence(ComplexSymbol head, Object lst)
protected void ast_add_precedence(Object lst, Range range)
{
Precedence p = new Precedence(_cur_side, (List<Terminal>) lst,
new Range(Position.fromComplexSymbolLeft(head),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()
)
));
Precedence p = new Precedence(_cur_side, (List<Terminal>) lst, range);
parserResult.precedences.add(p);
}
......@@ -376,39 +368,35 @@ import_list ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
import_spec ::=
IMPORT {:
head_tokens.push((ComplexSymbol) stack.peek());
:}
IMPORT : import_token
import_id
{:
SEMI : semi {:
/* save this import on the imports list */
context.import_list.push(multipart_name);
Import imprt = new Import(
new Name (multipart_name, null), // TODO: from, to
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token)));
new Range(Position.fromLocation(import_tokenxleft),
Position.fromLocation(semixright)));
parserResult.imports.add(imprt);
/* reset the accumulated multipart name */
multipart_name = new String();
:}
SEMI
;
class_name ::=
empty |
CLASS {:
head_tokens.push((ComplexSymbol) stack.peek());
:} ID:id SEMI
CLASS : cls ID:id SEMI : semi
{:
context.parser_class_name = id;
context.symbol_const_class_name = id + "Sym";
parserResult.className = new ClassName (
new Name(id, null), //jrTODO: positions
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek())));
new Name(id, new Range(Position.fromLocation(idxleft),
Position.fromLocation(idxright))),
new Range(Position.fromLocation(clsxleft),
Position.fromLocation(semixright)));
:}
;
......@@ -425,9 +413,7 @@ code_parts ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
action_code_part ::=
ACTION {:
head_tokens.push((ComplexSymbol) stack.peek());
:} CODE CODE_STRING : user_code opt_semi
ACTION CODE CODE_STRING : user_code opt_semi
{:
if (context.action_code!=null)
errMan.Warning(ErrorSource.Parser,
......@@ -435,11 +421,14 @@ action_code_part ::=
Position.fromLocation(user_codexleft));
else { /* save the user included code string */
context.action_code = user_code;
int debug_id = get_new_debug_id();
parserResult.actionCode = new SpecialCodeBlock(
debug_id,
SpecialCodeBlock.BlockType.Action,
user_code,
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token))); // jrTODO!
new Range(Position.fromLocation(user_codexleft),
Position.fromLocation(user_codexright)));
}
:}
;
......@@ -447,9 +436,7 @@ action_code_part ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
parser_code_part ::=
PARSER {:
head_tokens.push((ComplexSymbol) stack.peek());
:} CODE CODE_STRING:user_code opt_semi
PARSER CODE CODE_STRING:user_code opt_semi
{:
if (context.parser_code!=null)
errMan.Warning(ErrorSource.Parser,
......@@ -457,11 +444,13 @@ parser_code_part ::=
Position.fromLocation(user_codexleft));
else { /* save the user included code string */
context.parser_code = user_code;
int debug_id = get_new_debug_id();
parserResult.parserCode = new SpecialCodeBlock(
debug_id,
SpecialCodeBlock.BlockType.Parser,
user_code,
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token))); // jrTODO!
new Range(Position.fromLocation(user_codexleft),
Position.fromLocation(user_codexright)));
}
:}
;
......@@ -469,20 +458,20 @@ parser_code_part ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
init_code ::=
INIT {:
head_tokens.push((ComplexSymbol) stack.peek());
:} WITH CODE_STRING:user_code opt_semi
INIT WITH CODE_STRING:user_code opt_semi
{:
if (context.init_code!=null)
errMan.Warning(ErrorSource.Parser, "Redundant init code (skipping)",
Position.fromLocation(user_codexleft));
else {/* save the user code */
context.init_code = user_code;
int debug_id = get_new_debug_id();
parserResult.initCode = new SpecialCodeBlock(
debug_id,
SpecialCodeBlock.BlockType.Init,
user_code,
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token))); // jrTODO!
new Range(Position.fromLocation(user_codexleft),
Position.fromLocation(user_codexright)));
}
:}
;
......@@ -490,9 +479,7 @@ init_code ::=
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
scan_code ::=
SCAN {:
head_tokens.push((ComplexSymbol) stack.peek());
:} WITH CODE_STRING:user_code opt_semi
SCAN WITH CODE_STRING:user_code opt_semi
{:
if (context.scan_code!=null)
errMan.Warning(ErrorSource.Parser, "Redundant scan code (skipping)",
......@@ -500,11 +487,13 @@ scan_code ::=
else {
/* save the user code */
context.scan_code = user_code;
int debug_id = get_new_debug_id();
parserResult.scanCode = new SpecialCodeBlock(
debug_id,
SpecialCodeBlock.BlockType.Scan,
user_code,
new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) cur_token))); // jrTODO!
new Range(Position.fromLocation(user_codexleft),
Position.fromLocation(user_codexright)));
}
:}
......@@ -654,15 +643,13 @@ precedence_l ::= precedence_l preced | preced;
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
preced ::=
PRECEDENCE
{:
head_tokens.push((ComplexSymbol) stack.peek());
:}
PRECEDENCE : prec
preced_type
terminal_list:lst SEMI
terminal_list:lst SEMI : semi
{:
ComplexSymbol head = head_tokens.pop();
ast_add_precedence(head, lst);
ast_add_precedence(lst, new Range(
Position.fromLocation(precxleft),
Position.fromLocation(semixright)));
:}
;
......@@ -717,10 +704,8 @@ term_id ::= symbol_id:sym
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
start_spec ::=
START{:
head_tokens.push((ComplexSymbol) stack.peek());
:} WITH nt_id:start_name
{:
START : start WITH nt_id : start_name
SEMI : semi {:
/* verify that the name has been declared as a non terminal */
non_terminal nt = (non_terminal)non_terms.get(start_name);
if (nt == null)
......@@ -745,16 +730,14 @@ start_spec ::=
context.start_production = p;
new_rhs();
//jrTODO: position, start symbol?, side effects?
Range range = new Range(Position.fromComplexSymbolLeft(head_tokens.pop()),
Position.fromComplexSymbolRight((ComplexSymbol) stack.peek()));
Range range = new Range(Position.fromLocation(startxleft),
Position.fromLocation(semixright));
Range innerRange = new Range(Position.fromLocation(start_namexleft),
Position.fromLocation(start_namexright));
parserResult.startWith = new StartWith(new NonTerminal (new Name (start_name, innerRange), innerRange), range);
parserResult.startWith = new StartWith(new NonTerminal (
new Name (start_name, innerRange), innerRange), range);
}
:}
SEMI
|
empty
;
......
......@@ -49,7 +49,7 @@ public class GetDebuggerMappingVisitor extends Visitor<Object>
this.mappings = new ArrayList<Mapping>();
}
private void doCheck(ActionCodeBlock node) {
private void doCheck(CodeBlock node) {
if (node == null)
return;
......@@ -73,6 +73,6 @@ public class GetDebuggerMappingVisitor extends Visitor<Object>
@Override
public void postVisit (SpecialCodeBlock node, Object data) {
// doCheck(node);
doCheck(node);
}
}
......@@ -6,15 +6,9 @@ import de.in.tum.www2.cup.analysis.AbstractVisitor;
public class ActionCodeBlock extends CodeBlock
implements IProductionRightPart
{
private int debugId;
public int getDebugId() {
return debugId;
}
public ActionCodeBlock(int debugId, String blob, Range range) {
super(blob, range);
this.debugId = debugId;
super(debugId, blob, range);
}
@Override
......
......@@ -4,11 +4,20 @@ import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.Position;
public abstract class CodeBlock extends AbstractNode {
private int debugId;
private String blob;
public int getDebugId() {
return debugId;
}
public String blob;
public CodeBlock(String blob, Range range) {
public String getBlob() {
return blob;
}
public CodeBlock(int debugId, String blob, Range range) {
super(range);
this.debugId = debugId;
this.blob = blob;
}
......
......@@ -19,8 +19,8 @@ public class SpecialCodeBlock extends CodeBlock
return bt;
}
public SpecialCodeBlock(BlockType bt, String blob, Range range) {
super(blob, range);
public SpecialCodeBlock(int debugId, BlockType bt, String blob, Range range) {
super(debugId, blob, range);
this.bt = bt;
}
......
......@@ -124,7 +124,7 @@ public class DocumentDidChangeJob extends Job {
IFile file = ((FileEditorInput) myEditor.getEditorInput()).getFile();
CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file);
if (jobs.contains(JobsToDo.parseCode)) {
InputStream in = new ByteArrayInputStream(codeText.getBytes());
......@@ -140,10 +140,10 @@ public class DocumentDidChangeJob extends Job {
e.printStackTrace();
}
//errorReporter.pushToUIThread();
// TODO
// errorReporter.pushToUIThread();
// errorReporter.pushToUIThread();
// TODO
// errorReporter.pushToUIThread();
if (result != null) {
// System.out.println(result.toString());
......@@ -160,31 +160,30 @@ public class DocumentDidChangeJob extends Job {
} else {
return Status.CANCEL_STATUS;
}
}
/*
if (jobs.contains(JobsToDo.buildTable)) {
lalrResult = null;
// try {
// if (!p.hasParseErrors()) {
// lalrResult = LALRResult.Compute(context,
// context.start_production);
// }
// } catch (internal_error e) {
try {
// if (!p.hasParseErrors()) {
lalrResult = LALRResult.Compute(context,
context.start_production);
// }
} catch (internal_error e) {
// TODO Auto-generated catch block
// e.printStackTrace();
// }
errorReporter.pushToUIThread();
e.printStackTrace();
}
// errorReporter.pushToUIThread();
if (lalrResult != null) {
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(lalrResult, revNumber, context);
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(
lalrResult, revNumber, context);
resultLaLrModelJob.setSystem(true);
resultLaLrModelJob.schedule();
try {
......@@ -196,7 +195,7 @@ public class DocumentDidChangeJob extends Job {
} else {
return Status.CANCEL_STATUS;
}
}*/
}
System.out.println(jobs);
......@@ -208,7 +207,7 @@ public class DocumentDidChangeJob extends Job {
CallbackJob cb = new CallbackJob(myEditor);
cb.setSystem(true);
cb.schedule();
return Status.OK_STATUS;
}
......@@ -261,14 +260,15 @@ public class DocumentDidChangeJob extends Job {
LALRResult lalrResult;
long lalrResulRevisionNumber;
CupContext lalrContext;
public LaLrResultJob(LALRResult result, long revisionNumber, CupContext context) {
public LaLrResultJob(LALRResult result, long revisionNumber,
CupContext context) {
super("LaLr Result UI Job");
this.lalrResult = result;
this.lalrResulRevisionNumber = revisionNumber;
this.lalrContext = context;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IDocumentProvider provider = myEditor.getDocumentProvider();
......@@ -277,15 +277,16 @@ public class DocumentDidChangeJob extends Job {
.getEditorInput());
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setLaLrResultModel(this.lalrResult, lalrResulRevisionNumber, lalrContext);
model.setLaLrResultModel(this.lalrResult,
lalrResulRevisionNumber, lalrContext);
return Status.OK_STATUS;
}
}
return Status.CANCEL_STATUS;
}
}
class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob;
......
......@@ -30,10 +30,12 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.EntityConnectionData;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider;
import org.eclipse.zest.core.viewers.IEntityStyleProvider;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.internal.ZoomManager;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm;
......@@ -314,9 +316,10 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
}
visitedStates.add(state.getState());
lalr_transition trans = state.getState().transitions();
//System.out.println("Trans Symbol is non term: "+trans.on_symbol().is_non_term());
while (trans != null) {
if (visitedStates.contains(trans.to_state())
|| !trans.on_symbol().is_non_term()) {
|| trans.on_symbol().is_non_term()) {
trans = trans.next();
continue;
} else {
......@@ -333,7 +336,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
trans = state.getState().transitions();
while (trans != null) {
if (visitedStates.contains(trans.to_state())
|| trans.on_symbol().is_non_term()) {
|| !trans.on_symbol().is_non_term()) {
trans = trans.next();
continue;
} else {
......@@ -531,7 +534,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
}
static class ParserConflictLabelProvider extends LabelProvider implements
IEntityStyleProvider {
IEntityStyleProvider, IEntityConnectionStyleProvider {
private List<ParserConflictConnection> connections;
......@@ -570,8 +573,8 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
@Override
public Color getNodeHighlightColor(Object entity) {
// TODO Auto-generated method stub
return null;
Device device = Display.getCurrent();
return device.getSystemColor(SWT.COLOR_BLUE);
}
@Override
......@@ -600,10 +603,10 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
ParserConflictNode n = (ParserConflictNode) entity;
if (showColordStartState && n.id == 0) {
Device device = Display.getCurrent();
return new Color(device, 255, 0, 0);
return device.getSystemColor(SWT.COLOR_RED);
} else if (showColordEndStates && n.getConnectedTo().isEmpty()) {
Device device = Display.getCurrent();
return new Color(device, 255, 255, 0);
return device.getSystemColor(SWT.COLOR_GREEN);
}
return null;
}
......@@ -612,7 +615,6 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
@Override
public Color getForegroundColour(Object entity) {
// TODO Auto-generated method stub
return null;
}
......@@ -633,6 +635,29 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
// TODO Auto-generated method stub
return false;
}
@Override
public int getConnectionStyle(Object src, Object dest) {
return ZestStyles.CONNECTIONS_DIRECTED;
}
@Override
public Color getColor(Object src, Object dest) {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getHighlightColor(Object src, Object dest) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getLineWidth(Object src, Object dest) {
// TODO Auto-generated method stub
return 0;
}
}
}
......@@ -46,6 +46,7 @@ import org.eclipse.ui.progress.UIJob;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.EntityConnectionData;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider;
import org.eclipse.zest.core.viewers.IEntityStyleProvider;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
......@@ -54,6 +55,7 @@ import org.eclipse.zest.core.viewers.internal.ZoomManager;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm;
......@@ -112,7 +114,9 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
ParserReduceLabelProvider labelProvider = new ParserReduceLabelProvider(
nodeModel.getConnections());
graphViewer.setLabelProvider(labelProvider);
//graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
graphViewer.setInput(nodeModel.getNodes());
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
......@@ -212,6 +216,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
if (e.widget instanceof Combo) {
Combo c = (Combo)e.widget;
int idx = c.getSelectionIndex();
String s = levels[idx];
zoomManager.setZoomAsText(levels[idx]);
}
System.out.println(e.widget + " - Default Selection");
......@@ -237,7 +242,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
graphViewer.applyLayout();
synchronized (CupReduceGraphView.modelBuildLock) {
graphViewer.refresh();
}
}
}
@Override
......@@ -516,7 +521,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
static class ParserReduceLabelProvider extends LabelProvider implements
IEntityStyleProvider {
IEntityStyleProvider, IEntityConnectionStyleProvider {
private List<ParserReduceConnection> connections;
......@@ -555,8 +560,8 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
@Override
public Color getNodeHighlightColor(Object entity) {
// TODO Auto-generated method stub
return null;
Device device = Display.getCurrent();
return device.getSystemColor(SWT.COLOR_BLUE);
}
@Override
......@@ -585,10 +590,10 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
ParserReduceNode n = (ParserReduceNode) entity;
if (showColordStartState && n.id == 0) {
Device device = Display.getCurrent();
return new Color(device, 255, 0, 0);
return device.getSystemColor(SWT.COLOR_RED);
} else if (showColordEndStates && n.getConnectedTo().isEmpty()) {
Device device = Display.getCurrent();
return new Color(device, 255, 255, 0);
return device.getSystemColor(SWT.COLOR_GREEN);
}
return null;
}
......@@ -597,7 +602,6 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
@Override
public Color getForegroundColour(Object entity) {
// TODO Auto-generated method stub
return null;
}
......@@ -619,6 +623,29 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
return false;
}
@Override
public int getConnectionStyle(Object src, Object dest) {
return ZestStyles.CONNECTIONS_DIRECTED;
}
@Override
public Color getColor(Object src, Object dest) {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getHighlightColor(Object src, Object dest) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getLineWidth(Object src, Object dest) {
// TODO Auto-generated method stub
return 0;
}
}
static class CupToolTipHelper extends PopUpHelper {
......
<project name="MyProject" default="compile" basedir=".">
<target name="compile">
</target>
<property name="java" location="src" />
<property name="classes" location="bin/cls" />
<property name="result" location="bin/jar" />
<property name="lib" location="lib" />
<property name="tools" location="tools" />
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="${tools}/JFlex.jar" />
<taskdef name="cup" classname="java_cup.anttask.CUPTask" classpath="${tools}/java-cup-11b.jar" />
<target name="generate">
<jflex file="lexer.jflex" destdir="${java}" />
<cup srcfile="parser.cup" destdir="${java}"
parser="Parser"
interface="true"
locations="true"
debugsymbols="true" />
</target>
<path id="libraries">
<files includes="${lib}/java-cup-11b-runtime.jar" />
</path>
<target name="compile" depends="generate">
<mkdir dir="${classes}"/>
<mkdir dir="${result}"/>
<javac srcdir="${java}" destdir="${classes}">
<classpath refid="libraries" />
</javac>
</target>
<target name="clean">
<delete file="${java}/Parser.java" />
<delete file="${java}/sym.java" />
<delete file="${java}/Scanner.java" />
<delete dir="${classes}" />
<delete dir="${result}" />
</target>
</project>
\ No newline at end of file
my lexer.
\ No newline at end of file
package de.in.tum.www2.cup.internal;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.ComplexSymbolFactory.Location;
import java_cup.runtime.Symbol;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.ErrorManager;
import de.in.tum.www2.cup.ErrorSource;
import java.lang.Error;
import java.io.InputStreamReader;
%%
%class Lexer
%implements sym
%public
%unicode