# Buggy code
def lex_indent(self) -> None:
    """Analyze whitespace chars at the beginning of a line (indents)."""
    s = self.match(self.indent_exp)
    if s != "" and s[-1] in self.comment_or_newline:
        # Empty line (whitespace only or comment only).
        self.add_pre_whitespace(s[:-1])
        if s[-1] == "#":
            self.lex_comment()
        else:
            self.lex_break()
        self.lex_indent()
        return
    indent = self.calc_indent(s)
    if indent == self.indents[-1]:
        # No change in indent: just whitespace.
        self.add_pre_whitespace(s)
    elif indent > self.indents[-1]:
        # An increased indent (new block).
        self.indents.append(indent)
        self.add_token(Indent(s))
    else:
        # Decreased indent (end of one or more blocks).
        pre = self.pre_whitespace
        self.pre_whitespace = ""
        while indent < self.indents[-1]:
            self.add_token(Dedent(""))
            self.indents.pop()
        self.pre_whitespace = pre
        self.add_pre_whitespace(s)
        if indent != self.indents[-1]:
            # Error: indent level does not match a previous indent level.
            self.add_token(LexError("", INVALID_DEDENT))


# Traceback (RecursionError)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "mypy/__main__.py", line 5, in <module>
main(None)
File "mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/build.py", line 427, in process
next.process()
File "mypy/build.py", line 759, in process
tree = self.parse(self.program_text, self.path)
File "mypy/build.py", line 856, in parse
fast_parser=FAST_PARSER in self.manager.flags)
File "mypy/parse.py", line 98, in parse
tree = parser.parse(source)
File "mypy/parse.py", line 147, in parse
is_stub_file=self.is_stub_file)
File "mypy/lex.py", line 170, in lex
l.lex(string, first_line)
File "mypy/lex.py", line 378, in lex
map.get(c, default)()
File "mypy/lex.py", line 751, in lex_break
self.lex_indent()
File "mypy/lex.py", line 698, in lex_indent
self.lex_indent()
File "mypy/lex.py", line 698, in lex_indent
self.lex_indent()

[...]

File "mypy/lex.py", line 698, in lex_indent
self.lex_indent()
File "mypy/lex.py", line 697, in lex_indent
self.lex_break()
File "mypy/lex.py", line 735, in lex_break
s = self.match(self.break_exp)
RecursionError: maximum recursion depth exceeded

# Fixed code
def lex_indent(self) -> None:
    """Analyze whitespace chars at the beginning of a line (indents)."""
    s = self.match(self.indent_exp)
    while True:
        s = self.match(self.indent_exp)
        if s == "" or s[-1] not in self.comment_or_newline:
            break
        # Empty line (whitespace only or comment only).
        self.add_pre_whitespace(s[:-1])
        if s[-1] == "#":
            self.lex_comment()
        else:
            self.lex_break()
    indent = self.calc_indent(s)
    if indent == self.indents[-1]:
        # No change in indent: just whitespace.
        self.add_pre_whitespace(s)
    elif indent > self.indents[-1]:
        # An increased indent (new block).
        self.indents.append(indent)
        self.add_token(Indent(s))
    else:
        # Decreased indent (end of one or more blocks).
        pre = self.pre_whitespace
        self.pre_whitespace = ""
        while indent < self.indents[-1]:
            self.add_token(Dedent(""))
            self.indents.pop()
        self.pre_whitespace = pre
        self.add_pre_whitespace(s)
        if indent != self.indents[-1]:
            # Error: indent level does not match a previous indent level.
            self.add_token(LexError("", INVALID_DEDENT))