shell-lite 0.4.3__py3-none-any.whl → 0.4.4__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
@@ -128,8 +128,23 @@ class WebBuilder:
128
128
  pass
129
129
  class Interpreter:
130
130
  def __init__(self):
131
- print('DEBUG: VERSION 2 LOADED')
131
+ print('DEBUG: ShellLite v0.04.4')
132
132
  self.global_env = Environment()
133
+ self.global_env.set('str', str)
134
+ self.global_env.set('int', int)
135
+ self.global_env.set('float', float)
136
+ self.global_env.set('list', list)
137
+ self.global_env.set('len', len)
138
+ self.global_env.set('input', input)
139
+ self.global_env.set('range', range)
140
+
141
+ # English-like helpers
142
+ self.global_env.set('wait', time.sleep)
143
+ self.global_env.set('append', lambda l, x: l.append(x))
144
+ self.global_env.set('remove', lambda l, x: l.remove(x))
145
+ self.global_env.set('empty', lambda l: len(l) == 0)
146
+ self.global_env.set('contains', lambda l, x: x in l)
147
+
133
148
  self.current_env = self.global_env
134
149
  self.functions: Dict[str, FunctionDef] = {}
135
150
  self.classes: Dict[str, ClassDef] = {}
@@ -263,6 +278,12 @@ class Interpreter:
263
278
  def _builtin_push(self, lst, item):
264
279
  lst.append(item)
265
280
  return None
281
+ def _builtin_upper(self, s):
282
+ return str(s).upper()
283
+ def _builtin_sum_range(self, start, end):
284
+ return sum(range(int(start), int(end)))
285
+ def _builtin_range_list(self, start, end):
286
+ return list(range(int(start), int(end)))
266
287
  def _init_std_modules(self):
267
288
  self.std_modules = {
268
289
  'math': {
@@ -1519,7 +1540,7 @@ class Interpreter:
1519
1540
  self.wfile.write(str(e).encode())
1520
1541
  except: pass
1521
1542
  server = HTTPServer(('0.0.0.0', port_val), ShellLiteHandler)
1522
- print(f"\n ShellLite Server v0.04.3 is running!")
1543
+ print(f"\n ShellLite Server v0.04.4 is running!")
1523
1544
  print(f" \u001b[1;36m➜\u001b[0m Local: \u001b[1;4;36mhttp://localhost:{port_val}/\u001b[0m\n")
1524
1545
  try: server.serve_forever()
1525
1546
  except KeyboardInterrupt:
@@ -1688,27 +1709,6 @@ class Interpreter:
1688
1709
  except FileNotFoundError:
1689
1710
  raise FileNotFoundError(f"File '{path}' not found.")
1690
1711
  raise RuntimeError(f"Read failed: {e}")
1691
- if __name__ == '__main__':
1692
- import sys
1693
- if len(sys.argv) < 2:
1694
- print("Usage: python -m src.interpreter <file.shl>")
1695
- sys.exit(1)
1696
- filename = sys.argv[1]
1697
- try:
1698
- with open(filename, 'r', encoding='utf-8') as f:
1699
- code = f.read()
1700
- lexer = Lexer(code)
1701
- tokens = lexer.tokenize()
1702
- parser = Parser(tokens)
1703
- ast = parser.parse()
1704
- interpreter = Interpreter()
1705
- for stmt in ast:
1706
- interpreter.visit(stmt)
1707
- except Exception as e:
1708
- print(f"Error: {e}")
1709
- import traceback
1710
- traceback.print_exc()
1711
-
1712
1712
  def _builtin_upper(self, s, only_letters=False):
1713
1713
  if not only_letters:
1714
1714
  return s.upper()
shell_lite/lexer.py CHANGED
@@ -25,8 +25,8 @@ class Lexer:
25
25
  continue
26
26
  indent_level = len(line) - len(line.lstrip())
27
27
  if stripped_line.startswith('#'):
28
- self.tokens.append(Token('COMMENT', stripped_line, self.line_number, indent_level + 1))
29
- self.tokens.append(Token('NEWLINE', '', self.line_number, len(line) + 1))
28
+ # self.tokens.append(Token('COMMENT', stripped_line, self.line_number, indent_level + 1))
29
+ # self.tokens.append(Token('NEWLINE', '', self.line_number, len(line) + 1))
30
30
  continue
31
31
  if indent_level > self.indent_stack[-1]:
32
32
  self.indent_stack.append(indent_level)
@@ -165,7 +165,8 @@ class Lexer:
165
165
  'while': 'WHILE', 'until': 'UNTIL',
166
166
  'repeat': 'REPEAT', 'forever': 'FOREVER',
167
167
  'stop': 'STOP', 'skip': 'SKIP', 'exit': 'EXIT',
168
- 'each': 'FOR',
168
+ 'each': 'EACH',
169
+ 'check': 'CHECK',
169
170
  'unless': 'UNLESS', 'when': 'WHEN', 'otherwise': 'OTHERWISE',
170
171
  'then': 'THEN', 'do': 'DO',
171
172
  'print': 'PRINT', 'say': 'SAY', 'show': 'SAY',
@@ -182,7 +183,6 @@ class Lexer:
182
183
  'const': 'CONST',
183
184
  'and': 'AND', 'or': 'OR', 'not': 'NOT',
184
185
  'try': 'TRY', 'catch': 'CATCH', 'always': 'ALWAYS',
185
- 'error': 'ERROR',
186
186
  'use': 'USE', 'as': 'AS', 'share': 'SHARE',
187
187
  'execute': 'EXECUTE', 'run': 'EXECUTE',
188
188
  'alert': 'ALERT', 'prompt': 'PROMPT', 'confirm': 'CONFIRM',
@@ -225,14 +225,22 @@ class Lexer:
225
225
  'placeholder': 'PLACEHOLDER',
226
226
  'app': 'APP', 'title': 'ID', 'size': 'SIZE',
227
227
  'column': 'COLUMN', 'row': 'ROW',
228
- 'button': 'BUTTON', 'heading': 'HEADING', 'text': 'TEXT',
228
+ 'button': 'BUTTON', 'heading': 'HEADING',
229
229
  'sum': 'SUM', 'upper': 'UPPER', 'lower': 'LOWER',
230
- 'only': 'ONLY', 'letters': 'LETTERS',
231
- 'numbers': 'NUMBERS', 'digits': 'DIGITS',
232
- 'that': 'THAT', 'are': 'ARE', 'prime': 'PRIME',
233
230
  'increment': 'INCREMENT', 'decrement': 'DECREMENT',
234
231
  'multiply': 'MULTIPLY', 'divide': 'DIVIDE',
235
232
  'be': 'BE', 'by': 'BY',
233
+ 'plus': 'PLUS', 'minus': 'MINUS', 'divided': 'DIV',
234
+ 'greater': 'GREATER', 'less': 'LESS', 'equal': 'EQUAL',
235
+ 'define': 'DEFINE', 'function': 'FUNCTION',
236
+ 'contains': 'CONTAINS', 'empty': 'EMPTY',
237
+ 'remove': 'REMOVE',
238
+ 'than': 'THAN',
239
+ 'doing': 'DOING',
240
+ 'make': 'MAKE', 'be': 'BE',
241
+ 'as': 'AS', 'long': 'LONG',
242
+ 'otherwise': 'OTHERWISE',
243
+ 'ask': 'ASK',
236
244
  }
237
245
  token_type = keywords.get(value, 'ID')
238
246
  self.tokens.append(Token(token_type, value, self.line_number, current_col))
shell_lite/main.py CHANGED
@@ -5,9 +5,9 @@ import urllib.request
5
5
  import zipfile
6
6
  import io
7
7
  import subprocess
8
- from .lexer_new import Lexer
9
- from .parser_new import Parser
10
- from .interpreter_new import Interpreter
8
+ from .lexer import Lexer
9
+ from .parser import Parser
10
+ from .interpreter import Interpreter
11
11
  from .ast_nodes import *
12
12
  import json
13
13
  def execute_source(source: str, interpreter: Interpreter):
@@ -72,7 +72,7 @@ def run_repl():
72
72
  print("\n" + "="*40)
73
73
  print(" ShellLite REPL - English Syntax")
74
74
  print("="*40)
75
- print("Version: v0.04.3 | Made by Shrey Naithani")
75
+ print("Version: v0.04.4 | Made by Shrey Naithani")
76
76
  print("Commands: Type 'exit' to quit, 'help' for examples.")
77
77
  print("Note: Terminal commands (like 'shl install') must be run in CMD/PowerShell, not here.")
78
78
 
@@ -203,7 +203,7 @@ def install_globally():
203
203
  ps_cmd = f'$oldPath = [Environment]::GetEnvironmentVariable("Path", "User"); if ($oldPath -notlike "*ShellLite*") {{ [Environment]::SetEnvironmentVariable("Path", "$oldPath;{install_dir}", "User") }}'
204
204
  subprocess.run(["powershell", "-Command", ps_cmd], capture_output=True)
205
205
 
206
- print(f"\n[SUCCESS] ShellLite (v0.04.3) is installed!")
206
+ print(f"\n[SUCCESS] ShellLite (v0.04.4) is installed!")
207
207
  print(f"Location: {install_dir}")
208
208
  print("\nIMPORTANT STEP REQUIRED:")
209
209
  print("1. Close ALL open terminal windows (CMD, PowerShell, VS Code).")