Skip to content

Commit 83fb7c3

Browse files
committed
Parser passes nested.ini test!
1 parent 388d568 commit 83fb7c3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Python/ini_converting/ini_parser.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def get_parsed_tokens(tokens, parsed, token_idx, depth=0):
1+
def get_parsed_tokens(tokens, parsed, token_idx, depth=-1):
22
"""
33
start -> tabs -> property -> equals -> value -> newline
44
^ v ^ v
@@ -13,13 +13,21 @@ def get_parsed_tokens(tokens, parsed, token_idx, depth=0):
1313
if state == "start" and token["type"] == "TABS" and is_less_deep(depth, token):
1414
return
1515
elif state == "start" and token["type"] == "TABS" and is_deeper(depth, token):
16-
parsed.append( { "type": "lines_tokens", "content": [] } )
17-
get_parsed_tokens(tokens, parsed[-1]["content"], token_idx, depth + 1)
18-
elif state == "start" and token["type"] == "TABS":
19-
parsed.append( [ { "type": "lines_tokens", "content": [] } ] )
16+
parsed.append(
17+
{ "type": "lines_tokens", "content": [
18+
[
19+
{ "type": "extra", "content": token["content"] }
20+
]
21+
]}
22+
)
2023
token_idx[0] += 1
21-
get_parsed_tokens(tokens, parsed[-1], token_idx, depth)
22-
elif (state == "start" or state == "tabs") and token["type"] == "WORD":
24+
get_parsed_tokens(tokens, parsed[-1]["content"][0], token_idx, depth + 1)
25+
elif state == "start" and token["type"] == "TABS":
26+
return
27+
elif state == "start" and token["type"] == "WORD" and depth == -1:
28+
parsed.append([])
29+
get_parsed_tokens(tokens, parsed[-1], token_idx, depth + 1)
30+
elif state == "start" and token["type"] == "WORD":
2331
parsed.append( { "type": "property", "content": token["content"] } )
2432
state = "property"
2533
token_idx[0] += 1

0 commit comments

Comments
 (0)