Skip to content

Commit 0d58b55

Browse files
committed
Tester works, yay Marius!
1 parent 7b322a0 commit 0d58b55

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

Python/ini_converting/ini_parser.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def get_parsed_tokens(tokens, parsed, token_idx, depth=-1):
1+
def get_parsed_tokens(tokens, parsed, token_idx, depth=0):
22
"""
33
start -> tabs -> property -> equals -> value -> newline
44
^ v ^ v
@@ -10,46 +10,40 @@ def get_parsed_tokens(tokens, parsed, token_idx, depth=-1):
1010
while token_idx[0] < len(tokens):
1111
token = tokens[token_idx[0]]
1212

13-
if depth == -1:
14-
parsed.append([])
15-
get_parsed_tokens(tokens, parsed[-1], token_idx, depth + 1)
16-
17-
elif state == "start" and token["type"] == "TABS" and is_deeper(depth, token):
18-
parsed.append(
19-
{ "type": "lines_tokens", "content": [
20-
[
21-
22-
]
23-
]}
24-
)
25-
get_parsed_tokens(tokens, parsed[-1]["content"][0], token_idx, depth + 1)
13+
if state == "start" and token["type"] == "TABS" and is_deeper(depth, token):
14+
children = { "type": "children", "content": [] }
15+
parsed[-1].append(children)
16+
get_parsed_tokens(tokens, children["content"], token_idx, depth + 1)
17+
elif state == "start" and is_less_deep(depth, token):
18+
return
2619

27-
elif state == "start" and token["type"] == "TABS":
28-
parsed.append( { "type": "extra", "content": token["content"] } )
20+
elif state == "start":
21+
parsed.append([])
22+
state = "not-start"
23+
elif state == "not-start" and token["type"] == "TABS":
24+
parsed[-1].append( { "type": "extra", "content": token["content"] } )
2925
state = "tabs"
3026
token_idx[0] += 1
31-
elif (state == "start" or state == "tabs") and token["type"] == "WORD":
32-
parsed.append( { "type": "property", "content": token["content"] } )
27+
elif (state == "not-start" or state == "tabs") and token["type"] == "WORD":
28+
parsed[-1].append( { "type": "property", "content": token["content"] } )
3329
state = "property"
3430
token_idx[0] += 1
35-
elif state == "start" and is_less_deep(depth, token):
36-
return
3731

3832
elif state == "property" and token["type"] == "EQUALS":
39-
parsed.append( { "type": "extra", "content": token["content"] } )
33+
parsed[-1].append( { "type": "extra", "content": token["content"] } )
4034
state = "equals"
4135
token_idx[0] += 1
4236
elif state == "equals" and token["type"] == "WORD":
43-
parsed.append( { "type": "value", "content": token["content"] } )
37+
parsed[-1].append( { "type": "value", "content": token["content"] } )
4438
state = "value"
4539
token_idx[0] += 1
4640
elif state == "value" and token["type"] == "NEWLINES":
47-
parsed.append( { "type": "extra", "content": token["content"] } )
41+
parsed[-1].append( { "type": "extra", "content": token["content"] } )
4842
state = "start"
4943
token_idx[0] += 1
5044

5145
else:
52-
parsed.append( { "type": "extra", "content": token["content"] } )
46+
parsed[-1].append( { "type": "extra", "content": token["content"] } )
5347
token_idx[0] += 1
5448

5549
return parsed
@@ -65,4 +59,4 @@ def is_deeper(depth, token):
6559

6660

6761
def get_depth(token):
68-
return len(token["content"])
62+
return len(token["content"]) if token["type"] == "TABS" else 0

0 commit comments

Comments
 (0)