def match_handle(loc, tokens):
    """Process match blocks."""
    if len(tokens) == 4:
        matches, match_type, item, stmts = tokens
        cond = None
    elif len(tokens) == 5:
        matches, match_type, item, cond, stmts = tokens
    else:
        raise CoconutInternalException("invalid match statement tokens", tokens)

    if match_type == "in":
        invert = False
    elif match_type == "not in":
        invert = True
    else:
        raise CoconutInternalException("invalid match type", match_type)

    matching = Matcher(loc, match_check_var)
    matching.match(matches, match_to_var)
    if cond:
        matching.add_guard(cond)
    return (
        match_to_var + " = " + item + "\n"
        + matching.build(stmts, invert=invert)
    )
def match_handle ( loc , tokens ) : if len ( tokens ) == 4 : matches , match_type , item , stmts = tokens cond = None elif len ( tokens ) == 5 : matches , match_type , item , cond , stmts = tokens else : raise CoconutInternalException ( "invalid match statement tokens" , tokens ) if match_type == "in" : invert = False elif match_type == "not in" : invert = True else : raise CoconutInternalException ( "invalid match type" , match_type ) matching = Matcher ( loc , match_check_var ) matching . match ( matches , match_to_var ) if cond : matching . add_guard ( cond ) return ( match_to_var + " = " + item + "\n" + matching . build ( stmts , invert = invert ) )
Process match blocks.