Add a getLine method to Script.

It returns the rest of the line (minus // style comments) as the token. I
needed it in another project but this is my central repository for
script.py.
This commit is contained in:
Bill Currie 2013-11-24 11:21:40 +09:00
parent eeaf2bc43f
commit 6996e7295a

View file

@ -61,6 +61,24 @@ class Script:
continue
return True
return False
def getLine(self):
start = self.pos
end = start
while self.pos < len(self.text):
if self.text[self.pos] == "\n":
self.line += 1
self.pos += 1
break
if self.text[self.pos:self.pos + 2] == "//":
break
self.pos += 1
end = self.pos
if self.unget:
self.unget = False
self.token = self.token + self.text[start:end]
else:
self.token = self.text[start:end]
return self.pos < len(self.text)
def getToken(self, crossline=False):
if self.unget:
self.unget = False