package org.spoofax.jsglr2.recovery;

import org.metaborg.parsetable.productions.IProduction;
import org.spoofax.jsglr2.messages.Message;
import org.spoofax.jsglr2.messages.SourceRegion;
import org.spoofax.jsglr2.parser.Position;

public class RecoveryMessages {

    public static Message get(IProduction production, Position start, Position end) {
        SourceRegion region = new SourceRegion(start, end);

        String message;

        if("WATER".equals(production.constructor()))
            message = "Not expected";
        else if("INSERTION".equals(production.constructor())) {
            String insertion;

            if (production.isLiteral())
                insertion = production.lhs().descriptor().replaceAll("^\"|\"$", "");
            else
                insertion = "Token";

            message = insertion + " expected";
        } else
            message = "Invalid syntax";

        return Message.error(message, region);
    }

}

@@ -83,24 +83,79 @@
 Production;%0A
+import org.metaborg.parsetable.symbols.ILiteralSymbol;%0A
 import org.s
@@ -742,62 +742,52 @@
 n = 
-production.lhs().descriptor().replaceAll(%22%5E%5C%22%7C%5C%22$%22, %22%22
+((ILiteralSymbol) production.lhs()).literal(
 );%0A 

Simplify retrieval of literal for insertion recovery messages