Skip to content

Commit

Permalink
Do not consider commented-out lines when calculating indentation level.
Browse files Browse the repository at this point in the history
whitequark committed Dec 30, 2015
1 parent 58a0c8f commit 4b46909
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pythonparser/lexer.py
Original file line number Diff line number Diff line change
@@ -260,7 +260,8 @@ def _refill(self, eof_token):

# Should we emit indent/dedent?
if self.new_line and \
match.group(3) is None: # not a blank line
match.group(3) is None and \
match.group(4) is None: # not a blank line
whitespace = match.string[match.start(0):match.start(1)]
level = len(whitespace.expandtabs())
range = source.Range(self.source_buffer, match.start(1), match.start(1))
9 changes: 9 additions & 0 deletions pythonparser/test/test_lexer.py
Original file line number Diff line number Diff line change
@@ -77,6 +77,15 @@ def test_comment(self):
"pass", None,
"dedent", None)

self.assertLexes("class x:\n # foo\n pass",
"class", None,
"ident", "x",
":", None,
"newline", None,
"indent", None,
"pass", None,
"dedent", None)

def test_float(self):
self.assertLexes("0.0",
"float", 0.0)

0 comments on commit 4b46909

Please sign in to comment.