File tree Expand file tree Collapse file tree 3 files changed +26
-12
lines changed
Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 1- use std:: { path:: PathBuf , str:: FromStr } ;
2-
31use lang_engine:: Engine ;
42
53#[ macro_use] extern crate log;
64
7- fn main ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
5+ fn main ( ) {
86 pretty_env_logger:: formatted_builder ( )
97 . target ( pretty_env_logger:: env_logger:: Target :: Stdout )
108 . format_module_path ( true )
119 . filter_level ( log:: LevelFilter :: Trace )
1210 . init ( ) ;
1311
14- info ! ( "creating engine " ) ;
12+ debug ! ( "initialized logger " ) ;
1513
1614 let mut engine = Engine :: default ( ) ;
1715
18- match engine. exec_file ( & PathBuf :: from_str ( "./script.tsh" ) ?) {
16+
17+ let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
18+ if args. len ( ) < 2 {
19+ error ! ( "no input file provided" ) ;
20+ return ;
21+ }
22+
23+ let file_path = & args[ 1 ] ;
24+ let absolute_path = match std:: fs:: canonicalize ( file_path) {
25+ Ok ( path) => path,
26+ Err ( err) => {
27+ error ! ( "Could not get absolute path: {}" , err) ;
28+ return ;
29+ }
30+ } ;
31+
32+ match engine. exec_file ( & absolute_path) {
1933 Ok ( status) => info ! ( "finished with status {status}" ) ,
2034 Err ( err) => error ! ( "{err}" )
2135 } ;
22-
23- Ok ( ( ) )
2436}
Original file line number Diff line number Diff line change @@ -24,12 +24,13 @@ pub struct Engine {
2424
2525impl Engine {
2626 pub fn create ( ) -> Self {
27- Self {
28-
29- }
27+ debug ! ( "created engine" ) ;
28+ Self { }
3029 }
3130
3231 pub fn exec_file ( & mut self , file : & PathBuf ) -> EngineResult < i32 > {
32+ debug ! ( "executing file {file:?}" ) ;
33+
3334 let code = if file. is_file ( ) && ( file. is_absolute ( ) || file. is_relative ( ) ) {
3435 std:: fs:: read_to_string ( file) . map_err ( |_| error:: EngineError :: UnknownError ) ?
3536 } else {
@@ -45,8 +46,9 @@ impl Engine {
4546 }
4647
4748 pub fn exec ( & mut self , code : & str ) -> EngineResult < i32 > {
49+ debug ! ( "executing script" ) ;
50+
4851 let mut lexer = Lexer :: create ( code, None ) ;
49-
5052 println ! ( "{:#?}" , lexer. tokenize( ) ) ;
5153
5254 lexer. print_errors ( ) ;
Original file line number Diff line number Diff line change 1- var test = "
1+ var test = ""
You can’t perform that action at this time.
0 commit comments