with open('chat/public/builder.js','r',encoding='utf8') as f:
    s=f.read()
paren=brack=brace=0
backtick=False
for i,c in enumerate(s):
    if c=='`': backtick=not backtick
    if not backtick:
        if c=='(': paren+=1
        if c==')': paren-=1
        if c=='[': brack+=1
        if c==']': brack-=1
        if c=='{': brace+=1
        if c=='}': brace-=1
    if paren<0 or brack<0 or brace<0:
        print('mismatch at',i,'char',c,'counts',paren,brack,brace)
        # print context
        start=max(0,i-100); end=min(len(s),i+100)
        print(s[start:end])
        raise SystemExit(1)
print('final',paren,brack,brace,backtick)
