Skip to content

Commit 060acf2

Browse files
committed
fixing new line problem in tokenizer
1 parent 4d463d9 commit 060acf2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

data_processing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,14 @@ def getTokenizer(python_code):
214214
indents = 0
215215
last_token = a[0]
216216
for i__ in a[1:-1]:
217+
if i__.exact_type == 56:
218+
tokens.append("\n")
219+
continue
217220
if i__.exact_type == 6: # Dedent
218221
indents -= 1
219222
if i__.exact_type == 5: # Indent
220223
indents += 1
221-
if last_token.exact_type == 4 or last_token.exact_type == 56: # Newline
224+
if last_token.exact_type == 4: # Newline
222225
tokens.append(indents * '\t')
223226

224227
if i__.exact_type == 3:

test.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ def perfect_number_checker(num):
2525
indents = 0
2626
last_token = a[0]
2727
for i__ in a[1:-1]:
28+
if i__.exact_type == 56:
29+
tokens.append("\n")
30+
continue
2831
if i__.exact_type == 6: # Dedent
2932
indents -= 1
3033
if i__.exact_type == 5: # Indent
3134
indents += 1
32-
if last_token.exact_type == 4 or last_token.exact_type == 56: # Newline
35+
if last_token.exact_type == 4: # Newline
3336
tokens.append(indents*'\t')
3437

3538
if i__.exact_type == 3:

0 commit comments

Comments
 (0)