Commit c073bc48 authored by Johannes Roith's avatar Johannes Roith

Don't runt ables if parse error occurred.

parent a15e9155
...@@ -8,17 +8,20 @@ public class ErrorManager ...@@ -8,17 +8,20 @@ public class ErrorManager
{ {
private IErrorReporter er; private IErrorReporter er;
private int error_count; private int error_count;
private int parser_error_count;
private int scanner_error_count;
private int lalr_error_count;
public boolean hasScanErrors (){ public boolean hasScanErrors (){
throw new RuntimeException("TODO: implement!"); return scanner_error_count != 0;
} }
public boolean hasParseErrors (){ public boolean hasParseErrors (){
throw new RuntimeException("TODO: implement!"); return parser_error_count != 0;
} }
public boolean hasLALRErrors (){ public boolean hasLALRErrors (){
throw new RuntimeException("TODO: implement!"); return lalr_error_count != 0;
} }
public boolean hasErrors (){ public boolean hasErrors (){
...@@ -104,6 +107,13 @@ public class ErrorManager ...@@ -104,6 +107,13 @@ public class ErrorManager
public void Error(ErrorSource source, String msg, Position start, Position end) { public void Error(ErrorSource source, String msg, Position start, Position end) {
er.report(ErrorType.Error, source, null, msg, start, end); er.report(ErrorType.Error, source, null, msg, start, end);
error_count++; error_count++;
switch (source) {
case Parser: parser_error_count++; break;
case Scanner: scanner_error_count++; break;
case LALR: lalr_error_count++; break;
default: break;
}
} }
} }
...@@ -109,25 +109,24 @@ public class DocumentDidChangeJob extends Job { ...@@ -109,25 +109,24 @@ public class DocumentDidChangeJob extends Job {
IFile file = ((FileEditorInput) myEditor.getEditorInput()).getFile(); IFile file = ((FileEditorInput) myEditor.getEditorInput()).getFile();
CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file); CupEditorErrorReporter errorReporter = new CupEditorErrorReporter(file);
CupParser parser = null;
if (jobs.contains(JobsToDo.parseCode)) { if (jobs.contains(JobsToDo.parseCode)) {
InputStream in = new ByteArrayInputStream(codeText.getBytes()); InputStream in = new ByteArrayInputStream(codeText.getBytes());
CupParser p = new CupParser(errorReporter, in); parser = new CupParser(errorReporter, in);
result = null; result = null;
context = null;
try { try {
result = p.parse(); result = parser.parse();
context = p.getContext(); } catch (Exception e1) {
} catch (Exception e) { e1.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
} }
context = parser.getContext();
errorReporter.pushToUIThread(); errorReporter.pushToUIThread();
if (result != null) { if (result != null) {
// System.out.println(result.toString());
ParserResultJob resultModelJob = new ParserResultJob(result, ParserResultJob resultModelJob = new ParserResultJob(result,
revNumber); revNumber);
resultModelJob.setSystem(true); resultModelJob.setSystem(true);
...@@ -135,33 +134,28 @@ public class DocumentDidChangeJob extends Job { ...@@ -135,33 +134,28 @@ public class DocumentDidChangeJob extends Job {
try { try {
resultModelJob.join(); resultModelJob.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
} }
} }
if (jobs.contains(JobsToDo.buildTable)) { if (jobs.contains(JobsToDo.buildTable)) {
lalrResult = null; lalrResult = null;
try { try {
if (parser != null && !parser.hasParseErrors()) {
// if (!p.hasParseErrors()) {
lalrResult = LALRResult.Compute(context, lalrResult = LALRResult.Compute(context,
context.start_production); context.start_production);
} else {
// } System.out.println("LALRResult.Compute was not called, " +
"because the parser has reported errors.");
}
} catch (internal_error e) { } catch (internal_error e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
// errorReporter.pushToUIThread();
if (lalrResult != null) { if (lalrResult != null) {
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(myEditor, LaLrResultJob resultLaLrModelJob = new LaLrResultJob(myEditor,
lalrResult, revNumber, context); lalrResult, revNumber, context);
...@@ -180,13 +174,11 @@ public class DocumentDidChangeJob extends Job { ...@@ -180,13 +174,11 @@ public class DocumentDidChangeJob extends Job {
errorReporter.pushToUIThread(); errorReporter.pushToUIThread();
System.out.println(jobs); System.out.println(jobs);
documentEvents.clear(); documentEvents.clear();
jobs.clear(); jobs.clear();
// nichts mehr ändern ab hier
iAmCurrentlyRunning = false; iAmCurrentlyRunning = false;
CallbackJob cb = new CallbackJob(myEditor); CallbackJob cb = new CallbackJob(myEditor);
cb.setSystem(true); cb.setSystem(true);
...@@ -239,70 +231,6 @@ public class DocumentDidChangeJob extends Job { ...@@ -239,70 +231,6 @@ public class DocumentDidChangeJob extends Job {
} }
class LocationPatchJob extends UIJob {
private List<DocumentEvent> documentEvents;
// TODO: can we be sure that we are the only one accessing the documentEvents list?
public LocationPatchJob(List<DocumentEvent> documentEvents) {
super("Location Patch Job");
this.documentEvents = new ArrayList<DocumentEvent> (documentEvents);
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
/*
System.out.println("RUNNING LocationPatchJob: ");
// TODO: combine consecutive 1-character insert events.
for (DocumentEvent event : documentEvents) {
System.out.println("PROCESSING DocumentEvent: ");
System.out.println(" Offset: " + event.getOffset());
System.out.println(" Replaced: " + event.getLength());
System.out.println(" New: " + event.getText().length());
IDocument document = event.getDocument();
try {
int offset = event.getOffset();
int startLineNumber = document.getLineOfOffset(offset);
// TODO: wrong! must take removed text into account.
int startColumn = offset - document.getLineOffset(event.getText().length());
Position start = new Position(startLineNumber+1, startColumn+1, offset+1);
// updating the offsets is easy
// how do we update the lines correctly?
// how do we find out how many lines have been removed?
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// event.getDocument().
}
// TODO: location Patch verifizieren
Position oldRemovedFrom = null;
int oldRemovedLength = 0;
int newLength = 0;
LocationPatchVisitor visitor = new LocationPatchVisitor(
oldRemovedFrom, oldRemovedLength, newLength);
if (result != null)
result.accept(visitor, null);
else {
System.out.println("ERROR: Can't run LocationPatchVisitor!");
}
*/
return Status.OK_STATUS;
}
}
class SetupJob extends UIJob { class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob; private DocumentDidChangeJob documentDidChangeJob;
......
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