let filename = !filename in
(* Parse the input file. *)
- let file = Parse.parse_from_file filename in
+ let file = Parse.parse_goalfile filename in
Ast.print_file stdout file;
function
| Ast.Goal (name, [], _, _, _) ->
if !initial_targets = [] then
- initial_targets := name :: !initial_targets
+ initial_targets := Ast.ECall (name, []) :: !initial_targets
| Ast.Goal (name, _, _, _, _) ->
if !initial_targets = [] then
failwithf "%s: first target ā%sā has parameters and so cannot be used as the default target"
) file;
let initial_targets = List.rev !initial_targets in
-
- eprintf "initial targets:";
- List.iter (eprintf " %s") initial_targets;
- eprintf "\n"
+ ignore initial_targets
let () = main ()
open Printf
-let parse lexbuf =
- let print_position fp lexbuf =
- let pos = lexbuf.lex_curr_p in
- fprintf fp "%s:%d:%d"
- pos.pos_fname pos.pos_lnum (pos.pos_cnum - pos.pos_bol)
- in
+let print_position fp lexbuf =
+ let pos = lexbuf.lex_curr_p in
+ 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
with
| SyntaxError msg ->
eprintf "%a: parse error\n" print_position lexbuf;
exit 1
-let parse_from_file filename =
+let parse_expr lexbuf =
+ try Parser.expr Lexer.read lexbuf
+ with
+ | SyntaxError msg ->
+ eprintf "%a: %s\n" print_position lexbuf msg;
+ exit 1
+ | Parser.Error ->
+ eprintf "%a: parse error\n" print_position lexbuf;
+ exit 1
+
+(* This is used to parse the Goalfile. *)
+let parse_goalfile 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 lexbuf in
+ let file : Ast.file = parse_file lexbuf in
close_in fp;
file
+
+(* 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>" };
+ parse_expr lexbuf
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-val parse : Lexing.lexbuf -> Ast.file
-val parse_from_file : string -> Ast.file
+val parse_goalfile : string -> Ast.file
+val parse_cli_expr : string -> Ast.expr
%token RIGHT_PAREN
%token <Ast.substs> STRING
-%type <Ast.expr> expr
%type <Ast.stmt> stmt
-(* Start non-terminal. *)
+(* Start nonterminals. *)
%start <Ast.file> file
+%start <Ast.expr> expr
%%
file: