def build_block(self, format_string):
first_block = Block(None, py3_wrapper=self.py3_wrapper)<EOL>block = first_block<EOL>for token in self.tokens(format_string):<EOL><INDENT>value = token.group(<NUM_LIT:0>)<EOL>if token.group("<STR_LIT>"):<EOL><INDENT>block = block.new_block()<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>if not block.parent:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>block = block.parent<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>block = block.switch()<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>key = token.group("<STR_LIT:key>")<EOL>format = token.group("<STR_LIT>")<EOL>block.add(Placeholder(key, format))<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>block.add(Literal(value))<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>block.add(Literal(value))<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>block.set_commands(token.group("<STR_LIT>"))<EOL><DEDENT>elif token.group("<STR_LIT>"):<EOL><INDENT>if value[<NUM_LIT:0>] in ["<STR_LIT:\\>", "<STR_LIT:{>", "<STR_LIT:}>"]:<EOL><INDENT>value = value[<NUM_LIT:1>:]<EOL><DEDENT>block.add(Literal(value))<EOL><DEDENT><DEDENT>if block.parent:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>self.block_cache[format_string] = first_block<EOL>
Parse the format string into blocks containing Literals, Placeholders
etc that we can cache and reuse.