easycoder 241218.1__py2.py3-none-any.whl → 241231.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of easycoder might be problematic. Click here for more details.

easycoder/ec_program.py CHANGED
@@ -11,23 +11,18 @@ class Program:
11
11
 
12
12
  def __init__(self, argv):
13
13
  print(f'EasyCoder version {version("easycoder")}')
14
- scriptName = None
15
14
  if len(argv) == 0:
16
15
  print('No script supplied')
17
16
  exit()
18
17
  self.classes=[Core]
19
- for n in range(len(argv)):
20
- arg = argv[n]
21
- if arg == '-g':
22
- from .ec_graphics import Graphics
23
- self.classes.append(Graphics)
24
- else:
25
- scriptName = arg
18
+ scriptName = argv[0]
19
+ if scriptName.endswith('.ecg'):
20
+ from .ec_graphics import Graphics
21
+ self.classes.append(Graphics)
26
22
 
27
23
  f = open(scriptName, 'r')
28
24
  source = f.read()
29
25
  f.close()
30
- self.argv = argv
31
26
  self.domains = []
32
27
  self.domainIndex = {}
33
28
  self.name = '<anon>'
@@ -43,6 +38,8 @@ class Program:
43
38
  self.condition = self.compiler.condition
44
39
  self.processClasses()
45
40
  self.queue = deque()
41
+ self.externalControl = False
42
+ self.quit = False
46
43
 
47
44
  def start(self):
48
45
  startCompile = time.time()
@@ -203,57 +200,72 @@ class Program:
203
200
 
204
201
  # Tokenise the script
205
202
  def tokenise(self, script):
206
- index = 0
207
- lino = 0
208
- for line in script.lines:
203
+ token = ''
204
+ literal = False
205
+ for lino in range(0, len(script.lines)):
206
+ line = script.lines[lino]
209
207
  length = len(line)
210
- token = ''
211
- inSpace = True
208
+ if length == 0:
209
+ continue
210
+ # Look for the first non-space
212
211
  n = 0
213
- while n < length:
212
+ while n < length and line[n].isspace():
213
+ n += 1
214
+ # The whole line may be empty
215
+ if n == length:
216
+ if literal:
217
+ token += '\n'
218
+ continue
219
+ # If in an unfinished literal, the first char must be a backtick to continue adding to it
220
+ if literal:
221
+ if line[n] != '`':
222
+ # Close the current token
223
+ if len(token) > 0:
224
+ script.tokens.append(Token(lino, token))
225
+ token = ''
226
+ literal = False
227
+ n += 1
228
+ for n in range(n, length):
214
229
  c = line[n]
215
- if len(c.strip()) == 0:
216
- if (inSpace):
217
- n += 1
230
+ # Test if we are in a literal
231
+ if not literal:
232
+ if c.isspace():
233
+ if len(token) > 0:
234
+ script.tokens.append(Token(lino, token))
235
+ token = ''
218
236
  continue
219
- script.tokens.append(Token(lino, token))
220
- index += 1
221
- token = ''
222
- inSpace = True
223
- n += 1
224
- continue
225
- inSpace = False
237
+ elif c == '!':
238
+ break
239
+ # Test for the start or end of a literal
226
240
  if c == '`':
227
- m = n
228
- n += 1
229
- while n < len(line) - 1:
230
- if line[n] == '`':
231
- break
232
- n += 1
233
- # n += 1
234
- token = line[m:n+1]
235
- elif c == '!':
236
- break
241
+ if literal:
242
+ token += c
243
+ literal = False
244
+ else:
245
+ token += c
246
+ literal = True
247
+ m = n
248
+ continue
237
249
  else:
238
250
  token += c
239
- n += 1
240
251
  if len(token) > 0:
241
- script.tokens.append(Token(lino, token))
242
- index += 1
243
- lino += 1
252
+ if literal:
253
+ token += '\n'
254
+ else:
255
+ script.tokens.append(Token(lino, token))
256
+ token = ''
244
257
  return
258
+
259
+ def finish(self):
260
+ self.quit = True
245
261
 
246
- # Run the script
247
- def run(self, pc):
248
- # print(f'Run from {pc}')
249
- length = len(self.queue)
250
- self.queue.append(pc)
251
- if length > 0:
252
- return
253
-
262
+ # Flush the queue
263
+ def flush(self):
254
264
  while len(self.queue):
255
265
  self.pc = self.queue.popleft()
256
266
  while True:
267
+ if self.quit:
268
+ return
257
269
  command = self.code[self.pc]
258
270
  domainName = command['domain']
259
271
  if domainName == None:
@@ -272,11 +284,20 @@ class Program:
272
284
  self.pc = handler(command)
273
285
  try:
274
286
  if self.pc == 0 or self.pc >= len(self.code):
275
- return 0
287
+ break
276
288
  except:
277
- return 0
278
- if self.pc < 0:
279
- return -1
289
+ break
290
+
291
+ def setExternalControl(self):
292
+ self.externalControl = True
293
+
294
+ # Run the script
295
+ def run(self, pc):
296
+ length = len(self.queue)
297
+ self.queue.append(pc)
298
+ if not self.externalControl:
299
+ if length == 0:
300
+ return self.flush()
280
301
 
281
302
  def nonNumericValueError(self):
282
303
  FatalError(self.compiler, 'Non-numeric value')
@@ -322,10 +343,3 @@ class Program:
322
343
  if v1 < v2:
323
344
  return -1
324
345
  return 0
325
-
326
- # This is the program launcher
327
- def Main():
328
- if (len(sys.argv) > 1):
329
- Program(sys.argv[1:]).start()
330
- else:
331
- print('Syntax: easycoder <scriptname> [plugins]')