Commit 8648d393 authored by Michael Schwarz's avatar Michael Schwarz 🤔
Browse files

insert of precedence immediately before other prec (if declared) -

thereby keeping comments etc as they are
parent a8f4125f
......@@ -637,14 +637,23 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
private void insertPrecedence(terminal terminal,Precedence.Type assoc){
try {
IDocument document = editor.getDocument();
String toInsert = "precedence " + assoc.toString().toLowerCase() + " " + terminal.name()+ "; // Inserted by Eclipse plugin";
IDocument document = editor.getDocument();
ParserResult r = Model.getInstanceForDocument(document).getAstModel();
// Precedences are located immediately after the last symbol decl
int endOfLastDecl = r.symbols.get(r.symbols.size()-1).getEnd().getOffsetFromStart();
document.replace(endOfLastDecl, 0, "\nprecedence " + assoc.toString().toLowerCase() + " " + terminal.name()+"; // Inserted by Eclipse plugin");
int positionForPrec = 0;
if(r.precedences.size() == 0){
// Precedences are located immediately after the last symbol decl
positionForPrec = r.symbols.get(r.symbols.size()-1).getEnd().getOffsetFromStart();
toInsert = "\n\n//Precedences added by Eclipse plugin\n" + toInsert;
}
else {
positionForPrec = r.precedences.get(r.precedences.size()-1).getRange().getBegin().getOffsetFromStart();
toInsert = toInsert + "\n";
}
document.replace(positionForPrec, 0, toInsert);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......
Supports Markdown
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