MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / add_stmt

Method add_stmt

PyBasic/program.py:200–256  ·  view source on GitHub ↗

Adds the supplied token list to the program. The first token should be the line number. If a token list with the same line number already exists, this is replaced. :param tokenlist: List of BTokens representing a numbered program stat

(self, tokenlist, fIndex, tmpfile)

Source from the content-addressed store, hash-verified

198 return infile
199
200 def add_stmt(self, tokenlist, fIndex, tmpfile):
201 """
202 Adds the supplied token list
203 to the program. The first token should
204 be the line number. If a token list with the
205 same line number already exists, this is
206 replaced.
207
208 :param tokenlist: List of BTokens representing a
209 numbered program statement
210 fIndex: if >= 0: location in loaded program file of statment
211 if < 0: Indicates statement was not read and should
212 be added to temporary basic workfile
213 tmpfile: file handle of temporary basic workfile
214
215 """
216 try:
217 line_number = int(tokenlist[0].lexeme)
218 if fIndex >= 0:
219 self.__program[line_number] = fIndex
220 if tokenlist[1].lexeme == "DATA":
221 self.__data.addData(line_number,fIndex)
222 else:
223 if hasattr(tmpfile,'newlines'):
224 try:
225 tmpfile.readline()
226 except:
227 pass
228 newlines = tmpfile.newlines
229 else:
230 newlines = None
231 tmpfile.seek(0)
232 filelen = 0
233 for lines in tmpfile:
234 filelen += len(lines)
235 if newlines != None:
236 filelen += len(newlines) - 1
237 elif self.__imp != 'X':
238 filelen += 1
239
240 self.__program[line_number] = -(filelen+1)
241 if tokenlist[1].lexeme == "DATA":
242 self.__data.addData(line_number,-(filelen+1))
243 #self.__program[line_number] = -(len(tmpfile.read())+1)
244
245 fileLine = str(line_number)
246 for token in tokenlist[1:]:
247 # Add in quotes for strings
248 if token.category == Token.STRING:
249 fileLine += ' "' + token.lexeme + '"'
250 else:
251 fileLine += " " + token.lexeme
252 tmpfile.write(fileLine+"\n")
253
254 except TypeError as err:
255 raise TypeError("Invalid line number: " +
256 str(err))
257

Callers 1

mainFunction · 0.95

Calls 2

addDataMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected