Commit ffcbe160 authored by Michael Schwarz's avatar Michael Schwarz

Works for last as well

parent 18eeec17
...@@ -73,25 +73,43 @@ public class ReduceReduceReorder { ...@@ -73,25 +73,43 @@ public class ReduceReduceReorder {
int index = 1; int index = 1;
int start = pr.getRange().getBegin().getOffsetFromStart(); int start = pr.getRange().getBegin().getOffsetFromStart();
int end = 0; int end = 0;
String pString = "";
for(int i=0;i < rhs.size();i++){ for(int i=0;i < rhs.size();i++){
if(rhs.get(i).equals(pr)){ if(rhs.get(i).equals(pr)){
index = i; index = i;
break; break;
} }
} }
if(index == rhs.size()-1){
//TODO: take care of the SEMI if(index == 0){
end = rhs.get(1).getRange().getBegin().getOffsetFromStart();
pString = p.getName().name + " ::= " + document.get(start,end-(start)) + ";";
toInsert = "\n\n//Separated and moved by CUP Eclipse plugin\n" + pString;
//We want to remove the leading | as well
rangesToRemove.add(new RangeToRemove(start,(end-start)+1));
}
else if(index == rhs.size()-1){
end = pr.getRange().getEnd().getOffsetFromStart();
// +1 here because we don't need the |
pString = p.getName().name + " ::= " + document.get(start+1,end-(start+1)) + ";";
toInsert = "\n\n//Separated and moved by CUP Eclipse plugin\n" + pString;
// But we want to remove the entire thing
rangesToRemove.add(new RangeToRemove(start,end-start));
} }
else{ else{
end = rhs.get(index+1).getRange().getBegin().getOffsetFromStart(); end = rhs.get(index+1).getRange().getBegin().getOffsetFromStart();
// +1 here because we don't need the |
pString = p.getName().name + " ::= " + document.get(start+1,end-(start+1)) + ";";
toInsert = "\n\n//Separated and moved by CUP Eclipse plugin\n" + pString;
// But we want to remove the entire thing
rangesToRemove.add(new RangeToRemove(start,end-start));
} }
// +1 here because we don't need the |
String pString = p.getName().name + "::=" + document.get(start+1,end-(start+1)) + ";";
toInsert = "\n\n//Separated and moved by CUP Eclipse plugin\n" + pString;
// But we want to remove the entire thing
rangesToRemove.add(new RangeToRemove(start,end-start));
} catch (BadLocationException e) { } catch (BadLocationException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
......
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