# Generated by re2py
# re2py $INPUT -o $OUTPUT

NONE = -1

YYMAXNMATCH = 3




def lex_tags(str):
    cur = 0
    
    yystate = 0
    while True:
        match yystate:
            case 0:
                mar = cur
                yych = str[cur]
                if yych == 0x62:
                    cur += 1
                    yystate = 2
                    continue
                yyt1 = NONE
                yystate = 1
                continue
            case 1:
                y = yyt1
                x = yyt1
                yyt1 = NONE
                if x != yyt1: x += -1
                return NONE if x == NONE else y - x
            case 2:
                yych = str[cur]
                if yych == 0x61:
                    cur += 1
                    yystate = 3
                    continue
                cur = mar
                yyt1 = NONE
                yystate = 1
                continue
            case 3:
                yyt1 = cur
                yystate = 1
                continue
            case _:
                raise "internal lexer error"


def lex_captures(str):
    cur = 0
    yypmatch = [NONE] * (YYMAXNMATCH * 2)
    
    yystate = 0
    while True:
        match yystate:
            case 0:
                yych = str[cur]
                if yych == 0x61:
                    yyt1 = cur
                    cur += 1
                    yystate = 2
                    continue
                yyt1 = cur
                yyt2 = NONE
                yystate = 1
                continue
            case 1:
                yynmatch = 3
                yypmatch[0] = yyt1
                yypmatch[3] = yyt2
                yypmatch[5] = yyt2
                yypmatch[1] = cur
                yypmatch[2] = yyt2
                yyt2 = NONE
                if yypmatch[2] != yyt2: yypmatch[2] += -1
                yypmatch[4] = yypmatch[2]
                return yypmatch[4]
            case 2:
                yyt2 = cur
                yystate = 1
                continue
            case _:
                raise "internal lexer error"


assert lex_tags(b"\0") == -1
assert lex_tags(b"ba\0") == 1
assert lex_captures(b"\0") == -1
assert lex_captures(b"a\0") == 0
codegen/python/nested_fixed_tags.re:24:25: warning: rule matches empty string [-Wmatch-empty-string]
codegen/python/nested_fixed_tags.re:32:17: warning: rule matches empty string [-Wmatch-empty-string]
