In debug mode (-d) print all shell scripts executed.
[goals.git] / src / parse.ml
index 9363143..19c57ac 100644 (file)
@@ -27,8 +27,10 @@ let print_position fp lexbuf =
   fprintf fp "%s:%d:%d"
     pos.pos_fname pos.pos_lnum (pos.pos_cnum - pos.pos_bol)
 
-let parse_file lexbuf =
-  try Parser.file Lexer.read lexbuf
+let parse_file env lexbuf =
+  try
+    let env' = Parser.file Lexer.read lexbuf in
+    Ast.Env.merge env env'
   with
   | SyntaxError msg ->
      eprintf "%a: %s\n" print_position lexbuf msg;
@@ -48,16 +50,22 @@ let parse_expr lexbuf =
      exit 1
 
 (* This is used to parse the Goalfile. *)
-let parse_goalfile filename =
+let parse_goalfile env filename =
+  Cmdline.debug "parse file: %s" filename;
   let fp = open_in filename in
-  let lexbuf = Lexing.from_channel fp in
-  lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename };
-  let file : Ast.file = parse_file lexbuf in
+  let lexbuf = Lexing.from_channel ~with_positions:true fp in
+  let pos = lexbuf.lex_curr_p in
+  lexbuf.lex_curr_p <- { pos with pos_fname = filename };
+  let env' = parse_file env lexbuf in
   close_in fp;
-  file
+  env'
 
-(* This is used to parse dependency expressions on the command line. *)
-let parse_cli_expr str =
-  let lexbuf = Lexing.from_string str in
-  lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = "<command line>" };
+(* This is used to parse expressions on the command line and
+ * the output from functions.
+ *)
+let parse_expr source str =
+  Cmdline.debug "parse expression: %S" str;
+  let lexbuf = Lexing.from_string ~with_positions:true str in
+  let pos = lexbuf.lex_curr_p in
+  lexbuf.lex_curr_p <- { pos with pos_fname = source };
   parse_expr lexbuf