class TemplateParser implements Parser {

    static List<String> splitDefine(String value) {
        List<String> vs = new ArrayList<String>();
        Matcher matcher = DEFINE_PATTERN.matcher(value);
        while (matcher.find()) {
            StringBuffer rep = new StringBuffer();
            matcher.appendReplacement(rep, "$1");
            String v = rep.toString();
            if (v.contains(",")) {
                if (!v.contains("<")) {
                    vs.addAll(Arrays.asList(v.split(",")));
                } else if (v.indexOf(',') < v.indexOf('<')) {
                    int j = v.indexOf('<');
                    int i = v.substring(0, j).lastIndexOf(',');
                    vs.addAll(Arrays.asList(v.substring(0, i).split(",")));
                    vs.add(v.substring(i + 1));
                } else {
                    vs.add(v);
                }
            } else {
                vs.add(v);
            }
        }
        if (vs.size() == 0) {
            vs = Arrays.asList(value.split(","));
        } else {
            StringBuffer tail = new StringBuffer();
            matcher.appendTail(tail);
            if (tail.toString().trim().length() > 0) {
                vs.add(tail.toString());
            }
        }
        return vs;
    }

}