-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
32 lines (28 loc) · 871 Bytes
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from token import *
from sys import stdin
class Parser:
def parse(self):
line = stdin.readline() # Side
line = stdin.readline() # First line of map
while line != "\n":
# Parse map here
line = stdin.readline()
line = stdin.readline() # Score
tokens = []
line = stdin.readline() # First line of tokens
while line != "\n":
tokens.append(self.parsetoken(line))
line = stdin.readline()
return tokens
def parsetoken(self, line):
l = line.split()
if l[0] == "Flag":
return Flag(int(l[1]), int(l[2]))
if l[0] == "Soldier":
return Soldier(l[1], int(l[2]), int(l[3]), int(l[4]), l[5] == "True", l[6])
if l[0] == "Grenade":
return Grenade(int(l[1]), int(l[2]), int(l[3]))
if l[0] == "EnemyFlag":
return EnemyFlag(int(l[1]), int(l[2]))
if l[0] == "Enemy":
return Enemy(l[1], int(l[2]), int(l[3]), l[4] == "True", l[5])