Added library option -I.

This commit is contained in:
Christian Rinderknecht 2019-03-14 14:27:00 +01:00
parent 5f129d924a
commit 36e43a807e
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
4 changed files with 37 additions and 25 deletions

View File

@ -14,13 +14,14 @@ let help () =
printf "Usage: %s [<option> ...] [<input>.li | \"-\"]\n" file; printf "Usage: %s [<option> ...] [<input>.li | \"-\"]\n" file;
print_endline "where <input>.li is the Ligo source file (default: stdin),"; print_endline "where <input>.li is the Ligo source file (default: stdin),";
print_endline "and each <option> (if any) is one of the following:"; print_endline "and each <option> (if any) is one of the following:";
print_endline " -I <paths> Library paths (colon-separated)";
print_endline " -c, --copy Print lexemes of tokens and markup (lexer)"; print_endline " -c, --copy Print lexemes of tokens and markup (lexer)";
print_endline " -t, --tokens Print tokens (lexer)"; print_endline " -t, --tokens Print tokens (lexer)";
print_endline " -u, --units Print tokens and markup (lexer)"; print_endline " -u, --units Print tokens and markup (lexer)";
print_endline " -q, --quiet No output, except errors (default)"; print_endline " -q, --quiet No output, except errors (default)";
print_endline " --columns Columns for source locations"; print_endline " --columns Columns for source locations";
print_endline " --bytes Bytes for source locations"; print_endline " --bytes Bytes for source locations";
print_endline " --verbose=<stages> cmdline, cpp, ast"; print_endline " --verbose=<stages> cmdline, cpp, ast (colon-separated)";
print_endline " --version Commit hash on stdout"; print_endline " --version Commit hash on stdout";
print_endline " -h, --help This help"; print_endline " -h, --help This help";
exit 0 exit 0
@ -39,9 +40,12 @@ and columns = ref false
and bytes = ref false and bytes = ref false
and verbose = ref Utils.String.Set.empty and verbose = ref Utils.String.Set.empty
and input = ref None and input = ref None
and libs = ref []
let split_at_colon = Str.(split (regexp ":")) let split_at_colon = Str.(split (regexp ":"))
let add_path p = libs := !libs @ split_at_colon p
let add_verbose d = let add_verbose d =
verbose := List.fold_left (Utils.swap Utils.String.Set.add) verbose := List.fold_left (Utils.swap Utils.String.Set.add)
!verbose !verbose
@ -49,6 +53,7 @@ let add_verbose d =
let specs = let specs =
let open! Getopt in [ let open! Getopt in [
'I', nolong, None, Some add_path;
'c', "copy", set copy true, None; 'c', "copy", set copy true, None;
't', "tokens", set tokens true, None; 't', "tokens", set tokens true, None;
'u', "units", set units true, None; 'u', "units", set units true, None;
@ -92,6 +97,10 @@ let string_of convert = function
None -> "None" None -> "None"
| Some s -> sprintf "Some %s" (convert s) | Some s -> sprintf "Some %s" (convert s)
let string_of_path p =
let apply s a = if a = "" then s else s ^ ":" ^ a
in List.fold_right apply p ""
let quote s = sprintf "\"%s\"" s let quote s = sprintf "\"%s\"" s
let verbose_str = let verbose_str =
@ -108,7 +117,8 @@ let print_opt () =
printf "columns = %b\n" !columns; printf "columns = %b\n" !columns;
printf "bytes = %b\n" !bytes; printf "bytes = %b\n" !bytes;
printf "verbose = \"%s\"\n" verbose_str; printf "verbose = \"%s\"\n" verbose_str;
printf "input = %s\n" (string_of quote !input) printf "input = %s\n" (string_of quote !input);
printf "libs = %s\n" (string_of_path !libs)
;; ;;
if Utils.String.Set.mem "cmdline" !verbose then print_opt ();; if Utils.String.Set.mem "cmdline" !verbose then print_opt ();;
@ -132,6 +142,7 @@ and quiet = !quiet
and offsets = not !columns and offsets = not !columns
and mode = if !bytes then `Byte else `Point and mode = if !bytes then `Byte else `Point
and verbose = !verbose and verbose = !verbose
and libs = !libs
;; ;;
if Utils.String.Set.mem "cmdline" verbose then if Utils.String.Set.mem "cmdline" verbose then
@ -144,6 +155,7 @@ if Utils.String.Set.mem "cmdline" verbose then
printf "offsets = %b\n" offsets; printf "offsets = %b\n" offsets;
printf "mode = %s\n" (if mode = `Byte then "`Byte" else "`Point"); printf "mode = %s\n" (if mode = `Byte then "`Byte" else "`Point");
printf "verbose = \"%s\"\n" verbose_str; printf "verbose = \"%s\"\n" verbose_str;
printf "input = %s\n" (string_of quote input) printf "input = %s\n" (string_of quote input);
printf "I = %s\n" (string_of_path libs)
end end
;; ;;

View File

@ -25,6 +25,10 @@ val verbose : Utils.String.Set.t
val input : string option val input : string option
(* Paths where to find Ligo files for inclusion *)
val libs : string list
(* If the value [cmd] is (* If the value [cmd] is
* [Quiet], then no output from the lexer and parser should be * [Quiet], then no output from the lexer and parser should be
expected, safe error messages: this is the default value; expected, safe error messages: this is the default value;

View File

@ -9,6 +9,14 @@ let () = Printexc.record_backtrace true
let external_ text = let external_ text =
Utils.highlight (Printf.sprintf "External error: %s" text); exit 1;; Utils.highlight (Printf.sprintf "External error: %s" text); exit 1;;
(* Path for CPP inclusions (#include) *)
let lib_path =
match EvalOpt.libs with
[] -> ""
| libs -> let mk_I dir path = Printf.sprintf " -I %s%s" dir path
in List.fold_right mk_I libs ""
(* Preprocessing the input source and opening the input channels *) (* Preprocessing the input source and opening the input channels *)
let prefix = let prefix =
@ -27,9 +35,11 @@ let pp_input =
let cpp_cmd = let cpp_cmd =
match EvalOpt.input with match EvalOpt.input with
None | Some "-" -> None | Some "-" ->
Printf.sprintf "cpp -traditional-cpp - -o %s" pp_input Printf.sprintf "cpp -traditional-cpp%s - -o %s"
lib_path pp_input
| Some file -> | Some file ->
Printf.sprintf "cpp -traditional-cpp %s -o %s" file pp_input Printf.sprintf "cpp -traditional-cpp%s %s -o %s"
lib_path file pp_input
let () = let () =
if Utils.String.Set.mem "cpp" EvalOpt.verbose if Utils.String.Set.mem "cpp" EvalOpt.verbose
@ -41,6 +51,5 @@ let () =
module Lexer = Lexer.Make (LexToken) module Lexer = Lexer.Make (LexToken)
let () = Lexer.trace ~offsets:EvalOpt.offsets let () = Lexer.trace ~offsets:EvalOpt.offsets
EvalOpt.mode (Some pp_input) EvalOpt.cmd EvalOpt.mode (Some pp_input) EvalOpt.cmd

View File

@ -25,14 +25,13 @@ let print_error ?(offsets=true) mode Region.{region; value} =
let reg = region#to_string ~file ~offsets mode in let reg = region#to_string ~file ~offsets mode in
Utils.highlight (sprintf "Parse error %s:\n%s%!" reg msg) Utils.highlight (sprintf "Parse error %s:\n%s%!" reg msg)
(* Path to the Ligo standard library *) (* Path for CPP inclusions (#include) *)
(*
let lib_path = let lib_path =
match EvalOpt.libs with match EvalOpt.libs with
[] -> "" [] -> ""
| libs -> let mk_I dir path = Printf.sprintf " -I %s%s" dir path | libs -> let mk_I dir path = Printf.sprintf " -I %s%s" dir path
in List.fold_right mk_I libs "" in List.fold_right mk_I libs ""
*)
(* Preprocessing the input source and opening the input channels *) (* Preprocessing the input source and opening the input channels *)
@ -52,9 +51,11 @@ let pp_input =
let cpp_cmd = let cpp_cmd =
match EvalOpt.input with match EvalOpt.input with
None | Some "-" -> None | Some "-" ->
Printf.sprintf "cpp -traditional-cpp - -o %s" pp_input Printf.sprintf "cpp -traditional-cpp%s - -o %s"
lib_path pp_input
| Some file -> | Some file ->
Printf.sprintf "cpp -traditional-cpp %s -o %s" file pp_input Printf.sprintf "cpp -traditional-cpp%s %s -o %s"
lib_path file pp_input
let () = let () =
if Utils.String.Set.mem "cpp" EvalOpt.verbose if Utils.String.Set.mem "cpp" EvalOpt.verbose
@ -97,17 +98,3 @@ let () =
let () = close_all () in let () = close_all () in
print_error ~offsets EvalOpt.mode error print_error ~offsets EvalOpt.mode error
| Sys_error msg -> Utils.highlight msg | Sys_error msg -> Utils.highlight msg
(*
(* Temporary: force dune to build AST2.ml *)
let () =
let open AST2 in
let _ = s_ast in
()
(* Temporary: force dune to build AST2.ml *)
let () =
let open Typecheck2 in
let _ = temporary_force_dune in
()
*)