package org.metaborg.meta.nabl2.solver;

import java.io.Serializable;
import java.util.Map;

import com.google.common.collect.Maps;

public class Fresh implements Serializable {

    private static final long serialVersionUID = 42L;

    private final Map<String,Integer> counters;

    public Fresh() {
        counters = Maps.newConcurrentMap();
    }

    public String fresh(String base) {
        // to prevent accidental name clashes, ensure the base contains no dashes,
        // and then use dashes as our connecting character.
        base = base.replaceAll("-", "_");
        int k = counters.getOrDefault(base, 0) + 1;
        counters.put(base, k);
        return base + "-" + k;
    }

    public void reset() {
        counters.clear();
    }

}
@@ -383,24 +383,124 @@
 ing base) %7B%0A
+        // remove any number suffix from the base%0A        base = base.replaceFirst(%22-%5B0-9%5D+$%22, %22%22);%0A
         // t

Remove trailing numbers from base.