-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.py
56 lines (46 loc) · 1.12 KB
/
Reader.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import re
def separateTokens(line):
tokens = []
lastIndex = 0
foundComment = False
for i in range(len(line)):
if line[i] == ';':
slicedLine = line[lastIndex:i]
if slicedLine.strip():
tokens.append(slicedLine)
#lastIndex = i + 1
foundComment = True
break
if line[i] == ' ' or line[i] == ',':
slicedLine = line[lastIndex:i]
if slicedLine:
tokens.append(slicedLine)
lastIndex = i + 1
if not foundComment:
tokens.append(line[lastIndex:len(line)])
if tokens == [] or tokens == ['']:
return None
return tokens
class FileReader:
def __init__(self):
self.file = None
self.fileLines = []
self.fileLineCount = 0
def loadFile(self, fileName):
self.file = open(fileName, "r")
self.__readFile()
def __readFile(self):
line = self.file.readline()
lineCount = 1
while line:
lineStripped = line.strip()
self.fileLines.append(lineStripped)
line = self.file.readline()
lineCount += 1
self.fileLineCount = lineCount
def getLineTokens(self):
tokens = []
for line in self.fileLines:
strippedLine = separateTokens(line)
tokens.append(strippedLine)
return tokens