shell-lite 0.5.3.2__py3-none-any.whl → 0.5.3.3__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.
shell_lite/interpreter.py CHANGED
@@ -490,9 +490,9 @@ class Interpreter:
490
490
  code_parts.append(colors[node.color.lower()])
491
491
  if code_parts:
492
492
  ansi_code = "\033[" + ";".join(code_parts) + "m"
493
- print(f"{ansi_code}{value}\033[0m")
493
+ print(f"{ansi_code}{value}\033[0m", flush=True)
494
494
  return value
495
- print(value)
495
+ print(value, flush=True)
496
496
  return value
497
497
  def visit_If(self, node: If):
498
498
  condition = self.visit(node.condition)
@@ -615,7 +615,6 @@ class Interpreter:
615
615
  finally:
616
616
  self.web.pop()
617
617
  return result
618
- return result
619
618
  try:
620
619
  func = self.current_env.get(node.name)
621
620
  if callable(func):
shell_lite/parser_gbp.py CHANGED
@@ -105,6 +105,8 @@ class GeometricBindingParser:
105
105
  return self.bind_return(node)
106
106
  elif head_type == 'REPEAT':
107
107
  return self.bind_repeat(node)
108
+ elif head_type == 'FOREVER':
109
+ return self.bind_forever(node)
108
110
  elif head_type == 'START':
109
111
  return self.bind_start(node)
110
112
  elif head_type == 'LISTEN':
@@ -139,6 +141,112 @@ class GeometricBindingParser:
139
141
  count = self.parse_expr_iterative(expr_tokens)
140
142
  body = [self.bind_node(child) for child in node.children]
141
143
  return Repeat(count, body)
144
+
145
+ def bind_forever(self, node: GeoNode) -> Forever:
146
+ body = [self.bind_node(child) for child in node.children]
147
+ return Forever(body)
148
+
149
+ def bind_for(self, node: GeoNode) -> Node:
150
+ # 'for i in range 1 10' or 'for item in list'
151
+ # node.tokens starts with FOR/LOOP
152
+ # Next should be ID (var name)
153
+ if len(node.tokens) < 3:
154
+ return None # Error?
155
+
156
+ var_name = node.tokens[1].value
157
+
158
+ # Check for 'IN'
159
+ in_index = -1
160
+ for i, t in enumerate(node.tokens):
161
+ if t.type == 'IN':
162
+ in_index = i
163
+ break
164
+
165
+ if in_index == -1:
166
+ # Maybe 'loop 10 times'? No, that's Repeat (handled by bind_repeat if HEAD is REPEAT)
167
+ # But if HEAD is LOOP?
168
+ if node.head_token.type == 'LOOP':
169
+ # loop 200 times
170
+ # Delegated to bind_repeat logic if we can re-route, OR implement here
171
+ # Look for TIMES
172
+ if node.tokens[-1].type == 'TIMES':
173
+ expr_tokens = self._extract_expr_tokens(node.tokens, start=1)
174
+ expr_tokens.pop() # remove TIMES
175
+ count = self.parse_expr_iterative(expr_tokens)
176
+ body = [self.bind_node(child) for child in node.children]
177
+ return Repeat(count, body)
178
+ return None
179
+
180
+ # It is a FOR loop
181
+ # Check for RANGE
182
+ range_index = -1
183
+ for i, t in enumerate(node.tokens):
184
+ if t.type == 'RANGE':
185
+ range_index = i
186
+ break
187
+
188
+ if range_index != -1:
189
+ # for i in range 1 10
190
+ # Extract args after RANGE
191
+ args_tokens = node.tokens[range_index+1:]
192
+ # We need to split by space/comma? parse_expr_iterative might consume all?
193
+ # Range takes start, end, step.
194
+ # We can cheat and wrap them in a Call to 'range'?
195
+ # Or parse sub-expressions.
196
+ # Simplification: Assume numbers/vars separated by nothing (since lexer doesn't produce commas for spaces)
197
+ # But parse_expr_iterative consumes everything.
198
+ # We need to split manually if they are distinct expressions.
199
+ # Let's try to parse one expr, see where it ends? Not easy with shunting yard.
200
+
201
+ # Fallback: Create a Call('range', ...)
202
+ # Actually, interpreter expects 'count' for For loop?
203
+ # No, AST For node: For(count, body) -> interpreted as Repeat?
204
+ # Wait, AST For(count, body) vs ForIn(var_name, iterable, body)
205
+
206
+ # Let's see AST definition.
207
+ pass
208
+
209
+ # It is likely a ForIn
210
+ # iterable is everything after IN
211
+ iterable_tokens = self._extract_expr_tokens(node.tokens, start=in_index+1)
212
+ iterable = self.parse_expr_iterative(iterable_tokens)
213
+ body = [self.bind_node(child) for child in node.children]
214
+
215
+ # Handle 'range 1 10' as an iterable (Call to range)
216
+ if node.tokens[in_index+1].type == 'RANGE':
217
+ # tokens: FOR i IN RANGE 1 10
218
+ # We want Call('range', [1, 10])
219
+ # Extract numbers after RANGE
220
+ args_tokens = self._extract_expr_tokens(node.tokens, start=in_index+2)
221
+ # Assumption: args are space separated expressions.
222
+ # parse_expr_iterative consumes all.
223
+ # We need to manually split if there are multiple args?
224
+ # But 'range 1 10' in ShellLite usually means two numbers.
225
+ # If we just Pass all tokens to parse_expr_iterative, it might just return the first one if not connected by operator.
226
+ # For 'range 1 10', we have NUMBER 1, NUMBER 10.
227
+ # We need to build a list of args.
228
+ range_args = []
229
+ k = 0
230
+ while k < len(args_tokens):
231
+ # Try to parse one expression?
232
+ # This is hard with current parser structure.
233
+ # SIMPLE HACK: Just take the next two tokens as numbers?
234
+ # Or treat them as separate expression?
235
+ if args_tokens[k].type in ('NUMBER', 'STRING', 'ID'):
236
+ t = args_tokens[k]
237
+ val = None
238
+ if t.type == 'NUMBER':
239
+ val = Number(int(t.value) if '.' not in t.value else float(t.value))
240
+ elif t.type == 'STRING':
241
+ val = String(t.value)
242
+ elif t.type == 'ID':
243
+ val = VarAccess(t.value)
244
+ if val: range_args.append(val)
245
+ k += 1
246
+
247
+ iterable = Call('range', range_args)
248
+
249
+ return ForIn(var_name, iterable, body)
142
250
  def bind_print(self, node: GeoNode) -> Print:
143
251
  expr_tokens = self._extract_expr_tokens(node.tokens, start=1)
144
252
  expr = self.parse_expr_iterative(expr_tokens)
@@ -352,7 +460,39 @@ class GeometricBindingParser:
352
460
  i = j # Advance past list
353
461
  elif t.type == 'ID':
354
462
  if i+1 < len(tokens) and tokens[i+1].type == 'LPAREN':
355
- values.append(VarAccess(t.value))
463
+ # Function call: ID(args)
464
+ name = t.value
465
+
466
+ # Find matching RPAREN
467
+ depth = 1
468
+ j = i + 2 # Skip ID and LPAREN
469
+ elements_tokens = []
470
+ current_elem = []
471
+
472
+ arg_tokens_start = j
473
+ # Check for empty call "func()"
474
+ if j < len(tokens) and tokens[j].type == 'RPAREN':
475
+ i = j # Advance to RPAREN
476
+ values.append(Call(name, []))
477
+ else:
478
+ while j < len(tokens):
479
+ if tokens[j].type == 'LPAREN': depth += 1
480
+ elif tokens[j].type == 'RPAREN': depth -= 1
481
+
482
+ if depth == 0:
483
+ if current_elem: elements_tokens.append(current_elem)
484
+ break
485
+
486
+ if tokens[j].type == 'COMMA' and depth == 1:
487
+ elements_tokens.append(current_elem)
488
+ current_elem = []
489
+ else:
490
+ current_elem.append(tokens[j])
491
+ j += 1
492
+
493
+ args = [self.parse_expr_iterative(elem) for elem in elements_tokens if elem]
494
+ values.append(Call(name, args))
495
+ i = j # Advance to RPAREN
356
496
  else:
357
497
  values.append(VarAccess(t.value))
358
498
  elif t.type == 'LPAREN':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: shell-lite
3
- Version: 0.5.3.2
3
+ Version: 0.5.3.3
4
4
  Summary: A lightweight, English-like scripting language.
5
5
  Home-page: https://github.com/Shrey-N/ShellDesk
6
6
  Author: Shrey Naithani
@@ -2,16 +2,16 @@ shell_lite/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
2
2
  shell_lite/ast_nodes.py,sha256=W2oefXuRjqnQybR5ZcdPU0qC5gxHZHcotQc3LAVDLM0,6129
3
3
  shell_lite/cli.py,sha256=14Kq1ohSXS3p-xdh0DPi7eXskUtSX81huSyGhktoOMA,250
4
4
  shell_lite/compiler.py,sha256=t2Imae9h03v3GIIKrCo16qCDDLKSxrpjrp83tv0SzUQ,24982
5
- shell_lite/interpreter.py,sha256=zQE7NopelZeHYT94ZbZYGTBSd_ZgaOCWNU86ugUwYuw,75964
5
+ shell_lite/interpreter.py,sha256=8DMbNZ9zFizJ8mpBDKjPUDf-1Nhxm7NtME9c-XVvxB8,75960
6
6
  shell_lite/js_compiler.py,sha256=yEGIkkIvHGU7o1htHEqlQr6BE0wL35PtL5PssNld9fc,5606
7
7
  shell_lite/lexer.py,sha256=cNLk_N59a7eKQaQp7Mqcnxy1um64-QgtDEi2eAsAWKE,14913
8
8
  shell_lite/main.py,sha256=Vg-BUReR3JsK-sdcwFYUIx5vy8AkSLmqfsOQRWAVFdU,20150
9
9
  shell_lite/parser.py,sha256=qsR2wQUWjUPXbXgnmv8pmOgfX99lYYH6tpxKH3PEnfQ,88471
10
- shell_lite/parser_gbp.py,sha256=IV5lD1IipDOqgoC6UdVpFnuWQBb73WmEAYMigDGTfcQ,16555
10
+ shell_lite/parser_gbp.py,sha256=M1wlJITxnkonVp8Z9ypuEVJ8k9Hg_C95TwzZoADvkBY,23229
11
11
  shell_lite/runtime.py,sha256=pSjBeA1dTQ-a94q3FLdv9lqZurdd6MJmfhFGHhOoQEM,16057
12
- shell_lite-0.5.3.2.dist-info/LICENSE,sha256=LlK8rVgwqMiti6NfaXa8xfvXAwfYe5SVrvcz3YpwHgg,37277
13
- shell_lite-0.5.3.2.dist-info/METADATA,sha256=ReF60tgHn2PTAYXb-W2lKM3B8F25iq-l8SukauYzKrc,10586
14
- shell_lite-0.5.3.2.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
15
- shell_lite-0.5.3.2.dist-info/entry_points.txt,sha256=tglL8tjyPIh1W85j6zFpNZjMpQe_xC-k-7BOhHLWfxc,45
16
- shell_lite-0.5.3.2.dist-info/top_level.txt,sha256=hIln5ltrok_Mn3ijlQeqMFF6hHBHCyhzqCO7KL358cg,11
17
- shell_lite-0.5.3.2.dist-info/RECORD,,
12
+ shell_lite-0.5.3.3.dist-info/LICENSE,sha256=LlK8rVgwqMiti6NfaXa8xfvXAwfYe5SVrvcz3YpwHgg,37277
13
+ shell_lite-0.5.3.3.dist-info/METADATA,sha256=mGfmA3oWVbJXargaZhSQw-iLR_HXciBPE2CQoDNXcoU,10586
14
+ shell_lite-0.5.3.3.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
15
+ shell_lite-0.5.3.3.dist-info/entry_points.txt,sha256=tglL8tjyPIh1W85j6zFpNZjMpQe_xC-k-7BOhHLWfxc,45
16
+ shell_lite-0.5.3.3.dist-info/top_level.txt,sha256=hIln5ltrok_Mn3ijlQeqMFF6hHBHCyhzqCO7KL358cg,11
17
+ shell_lite-0.5.3.3.dist-info/RECORD,,