def get_matches(tokens, qbegin, automaton):
    """
    Yield tuples of automaton matches positions as (match end, match value) from
    matching `tokens` sequence of token ids starting at the `qbegin` absolute
    query start position position using the `automaton`.
    """
    qtokens = tuple(tokens)
    for qend, matched_value in automaton.iter(qtokens):
        qend = qbegin + qend + 1
        yield qend, matched_value
