11import os
22from rich .console import Console
33
4- HACKER_DIR = os .path .expanduser ("~/.hackeros/hacker-lang" ) # Updated path
4+ HACKER_DIR = os .path .expanduser ("~/.hackeros/hacker-lang" )
55
66def parse_hacker_file (file_path , verbose = False , console = None ):
77 if console is None :
88 console = Console ()
9-
109 deps = set ()
11- libs = set ()
10+ libs = set () # Custom libraries that are binaries
1211 vars_dict = {}
1312 cmds = []
14- includes = []
13+ includes = [] # Libraries that are .hacker files
14+ binaries = [] # Paths to binary libraries to embed or call
1515 errors = []
1616 in_config = False
17+ config_data = {}
1718 line_num = 0
18-
1919 try :
2020 with open (file_path , 'r' ) as f :
2121 for line in f :
2222 line_num += 1
2323 line = line .strip ()
2424 if not line :
2525 continue
26-
2726 if line == '[' :
2827 if in_config :
2928 errors .append (f"Line { line_num } : Nested config section" )
@@ -34,10 +33,11 @@ def parse_hacker_file(file_path, verbose=False, console=None):
3433 errors .append (f"Line { line_num } : Closing ] without [" )
3534 in_config = False
3635 continue
37-
3836 if in_config :
37+ if '=' in line :
38+ key , value = line .split ('=' , 1 )
39+ config_data [key .strip ()] = value .strip ()
3940 continue
40-
4141 if line .startswith ('//' ):
4242 dep = line [2 :].strip ()
4343 if dep :
@@ -47,19 +47,24 @@ def parse_hacker_file(file_path, verbose=False, console=None):
4747 elif line .startswith ('#' ):
4848 lib = line [1 :].strip ()
4949 if lib :
50- lib_path = os .path .join (HACKER_DIR , "libs" , lib , "main.hacker" )
51- if os .path .exists (lib_path ):
50+ lib_dir = os .path .join (HACKER_DIR , "libs" , lib )
51+ lib_hacker_path = os .path .join (lib_dir , "main.hacker" )
52+ lib_bin_path = os .path .join (HACKER_DIR , "libs" , lib ) # Assuming binary is libs/lib (file)
53+ if os .path .exists (lib_hacker_path ):
5254 includes .append (lib )
53- sub_deps , sub_libs , sub_vars , sub_cmds , sub_includes , sub_errors = parse_hacker_file (lib_path , verbose , console )
55+ sub_deps , sub_libs , sub_vars , sub_cmds , sub_includes , sub_binaries , sub_errors , _ = parse_hacker_file (lib_hacker_path , verbose , console )
5456 deps .update (sub_deps )
5557 libs .update (sub_libs )
5658 vars_dict .update (sub_vars )
5759 cmds .extend (sub_cmds )
5860 includes .extend (sub_includes )
61+ binaries .extend (sub_binaries )
5962 for err in sub_errors :
6063 errors .append (f"In { lib } : { err } " )
64+ elif os .path .exists (lib_bin_path ) and os .access (lib_bin_path , os .X_OK ):
65+ binaries .append (lib_bin_path )
6166 else :
62- libs .add (lib )
67+ libs .add (lib ) # To be installed
6368 else :
6469 errors .append (f"Line { line_num } : Empty library/include" )
6570 elif line .startswith ('>' ):
@@ -117,21 +122,19 @@ def parse_hacker_file(file_path, verbose=False, console=None):
117122 pass
118123 else :
119124 errors .append (f"Line { line_num } : Invalid syntax" )
120-
121125 if in_config :
122126 errors .append ("Unclosed config section" )
123-
124127 if verbose :
125128 console .print (f"[blue]System Deps: { deps } [/blue]" )
126129 console .print (f"[blue]Custom Libs: { libs } [/blue]" )
127130 console .print (f"[blue]Vars: { vars_dict } [/blue]" )
128131 console .print (f"[blue]Cmds: { cmds } [/blue]" )
129132 console .print (f"[blue]Includes: { includes } [/blue]" )
133+ console .print (f"[blue]Binaries: { binaries } [/blue]" )
134+ console .print (f"[blue]Config: { config_data } [/blue]" )
130135 if errors :
131136 console .print (f"[yellow]Errors: { errors } [/yellow]" )
132-
133- return deps , libs , vars_dict , cmds , includes , errors
134-
137+ return deps , libs , vars_dict , cmds , includes , binaries , errors , config_data
135138 except FileNotFoundError :
136139 console .print (f"[bold red]File { file_path } not found[/bold red]" )
137- return set (), set (), {}, [], [], [f"File { file_path } not found" ]
140+ return set (), set (), {}, [], [], [], [ f"File { file_path } not found" ], {}
0 commit comments