@@ -15,22 +15,15 @@ def get_parsed_tokens(tokens, parsed=None, token_idx=None, depth=0):
15
15
while token_idx [0 ] < len (tokens ):
16
16
token = tokens [token_idx [0 ]]
17
17
18
- # if state == "newline" and token["type"] == "EXTRA":
19
- # parsed[-1].append( { "type": "extra", "content": token["content"] } )
20
- # token_idx[0] += 1
21
- # elif state == "newline" and token["type"] == "NEWLINES":
22
- # parsed[-1].append( { "type": "extra", "content": token["content"] } )
23
- # token_idx[0] += 1
24
-
25
- if state == "newline" and token ["type" ] == "TABS" and is_deeper (depth , token ):
18
+ if state == "newline" and is_deeper (depth , token ):
26
19
children = { "type" : "children" , "content" : [] }
27
20
parsed [- 1 ].append (children )
28
21
get_parsed_tokens (tokens , children ["content" ], token_idx , depth + 1 )
29
- # state = "start" # TODO: Should state be set to start on this comment's line?
22
+ # " state" is deliberately not being changed here.
30
23
elif state == "newline" and is_same_depth (token , depth ):
31
24
parsed .append ([])
32
25
state = "start"
33
- elif state == "newline" and depth > 0 and is_shallower (depth , token , tokens , token_idx [0 ] + 1 ):
26
+ elif state == "newline" and is_shallower (depth , token , tokens , token_idx [0 ] + 1 ):
34
27
return
35
28
elif state == "newline" and (len (parsed ) == 0 or token ["type" ] == "WORD" ):
36
29
parsed .append ([])
@@ -69,7 +62,7 @@ def is_same_depth(token, depth):
69
62
70
63
71
64
def is_shallower (depth , token , tokens , next_token_idx ):
72
- if token ["type" ] == "NEWLINES" :
65
+ if depth == 0 or token ["type" ] == "NEWLINES" :
73
66
return False
74
67
75
68
while next_token_idx < len (tokens ):
@@ -86,6 +79,9 @@ def is_shallower(depth, token, tokens, next_token_idx):
86
79
87
80
88
81
def is_deeper (depth , token ):
82
+ if token ["type" ] != "TABS" :
83
+ return False
84
+
89
85
new_depth = get_depth (token )
90
86
91
87
if new_depth > depth + 1 :
0 commit comments