1- # repl.py - REPL for Hacker Lang.
2- # Allows interactive input of Hacker Lang syntax, executes immediately via bash.
3- # Supports all syntax elements, with real-time feedback.
4-
51import os
62import subprocess
73import tempfile
84from rich .console import Console
95from rich .prompt import Prompt
10- from .parser import parse_hacker_file , generate_check_cmd
6+ from .parser import parse_hacker_file
117
128def run_repl (console , verbose = False ):
139 console .print (Panel ("Hacker Lang REPL - Type 'exit' to quit" , title = "REPL" , style = "bold magenta" ))
14- console .print ("Enter Hacker Lang commands (// , @, =, ?, >, #, !, [ ... ]). Multi-line config with [ ... ]. " )
10+ console .print ("Supports: // (system deps), # (libs/include) , @ (vars) , = (loops) , ? (conditionals), & (background), > (cmds), [ ... ], ! (comments) " )
1511
1612 lines = []
1713 in_config = False
@@ -42,12 +38,11 @@ def run_repl(console, verbose=False):
4238 lines .append (line )
4339
4440 if not in_config and line and not line .startswith ('!' ):
45- # Try parsing and executing
4641 with tempfile .NamedTemporaryFile (mode = 'w+' , suffix = '.hacker' , delete = False ) as temp_hacker :
4742 temp_hacker .write ('\n ' .join (lines ) + '\n ' )
4843 temp_hacker_path = temp_hacker .name
4944
50- deps , vars , cmds , includes , errors = parse_hacker_file (temp_hacker_path , verbose , console )
45+ deps , libs , vars , cmds , includes , errors = parse_hacker_file (temp_hacker_path , verbose , console )
5146 os .unlink (temp_hacker_path )
5247
5348 if errors :
@@ -62,12 +57,11 @@ def run_repl(console, verbose=False):
6257 temp_sh .write (f'export { var } ="{ value } "\n ' )
6358
6459 for dep in deps :
65- check_cmd = generate_check_cmd (dep )
66- if check_cmd :
67- temp_sh .write (f"{ check_cmd } \n " )
60+ if dep != "sudo" :
61+ temp_sh .write (f"command -v { dep } &> /dev/null || (sudo apt update && sudo apt install -y { dep } )\n " )
6862
6963 for include in includes :
70- lib_path = os .path .join (os .path .expanduser ("~/.hacker-lang" ), "libs" , f" { include } .hacker" )
64+ lib_path = os .path .join (os .path .expanduser ("~/.hacker-lang" ), "libs" , include , "main .hacker" )
7165 if os .path .exists (lib_path ):
7266 temp_sh .write (f"# Included from { include } \n " )
7367 with open (lib_path , 'r' ) as lib_file :
0 commit comments