def parse_template(template):
    matches = []
    for argty, argidx in SUBSTITUTION_RE.findall(template):
        if argty == "Imm":
            arg = Immediate()
        elif argty == "Ident":
            arg = Ident()
        elif argty == "Mod":
            arg = Modifier()
        elif argty == "Off":
            arg = Offset()
        elif argty in "WXBHSDQV" or argty in ("WSP", "XSP", "WX"):
            arg = Register(argty)
        else:
            raise NotImplementedError(argty)
        matches.append((arg, int(argidx)))
    return matches