From 6bb5a0f731812203a5a350676360aac3bc9818b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 10 Jun 2019 22:16:08 +0200 Subject: [PATCH 1/2] Auto-detect syntax based on file extension --- src/bin/cli.ml | 4 ++-- src/main/run_source.ml | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 1118ac02c..7e0606311 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -68,9 +68,9 @@ let syntax = let open Arg in let info = let docv = "SYNTAX" in - let doc = "$(docv) is the syntax that will be used. Currently supported syntaxes are \"pascaligo\" and \"cameligo\". \"pascaligo\" is the default." in + let doc = "$(docv) is the syntax that will be used. Currently supported syntaxes are \"pascaligo\" and \"cameligo\". By default, the syntax is guessed from the extension (.ligo and .mligo, respectively)." in info ~docv ~doc ["syntax" ; "s"] in - value @@ opt string "pascaligo" info + value @@ opt string "auto" info let compile_file = let f source entry_point syntax = diff --git a/src/main/run_source.ml b/src/main/run_source.ml index 79f71ce97..e97d9d855 100644 --- a/src/main/run_source.ml +++ b/src/main/run_source.ml @@ -95,7 +95,22 @@ let parsify_expression_ligodity = fun source -> Simplify.Ligodity.simpl_expression raw in ok simplified +let detect_syntax = fun syntax source -> + if String.equal syntax "auto" then + begin + let subr s n = + String.sub s (String.length s - n) n in + if String.equal (subr source 5) ".ligo" + then ok "pascaligo" + else if String.equal (subr source 6) ".mligo" + then ok "cameligo" + else simple_fail "cannot auto-detect syntax, pleas use -s name_of_syntax" + end + else + ok syntax + let parsify = fun syntax source -> + let%bind syntax = detect_syntax syntax source in let%bind parsify = match syntax with | "pascaligo" -> ok parsify_pascaligo | "cameligo" -> ok parsify_ligodity @@ -104,6 +119,7 @@ let parsify = fun syntax source -> parsify source let parsify_expression = fun syntax source -> + let%bind syntax = detect_syntax syntax source in let%bind parsify = match syntax with | "pascaligo" -> ok parsify_expression_pascaligo | "cameligo" -> ok parsify_expression_ligodity From fdfb00b7a6a6ea008fb9f8e41173439d3183000b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 12 Jun 2019 01:28:38 +0200 Subject: [PATCH 2/2] Distinguish parameter and storage arguments in --help --- src/bin/cli.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 7e0606311..e10c0c28c 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -57,9 +57,9 @@ let entry_point n = info ~docv ~doc [] in required @@ pos n (some string) (Some "main") info -let expression n = +let expression purpose n = let open Arg in - let docv = "EXPRESSION" in + let docv = purpose ^ "_EXPRESSION" in let doc = "$(docv) is the expression that will be compiled." in let info = info ~docv ~doc [] in required @@ pos n (some string) None info @@ -97,7 +97,7 @@ let compile_parameter = ok () in let term = - Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax) in let cmdname = "compile-parameter" in let docs = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in (term , Term.info ~docs cmdname) @@ -112,7 +112,7 @@ let compile_storage = ok () in let term = - Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression "STORAGE" 2 $ syntax) in let cmdname = "compile-storage" in let docs = "Subcommand: compile an initial storage in ligo syntax to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which originates a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in (term , Term.info ~docs cmdname) @@ -126,7 +126,7 @@ let dry_run = ok () in let term = - Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ expression 3 $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ syntax) in let cmdname = "dry-run" in let docs = "Subcommand: run a smart-contract with the given storage and input." in (term , Term.info ~docs cmdname) @@ -140,7 +140,7 @@ let run_function = ok () in let term = - Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax) in let cmdname = "run-function" in let docs = "Subcommand: run a function with the given parameter." in (term , Term.info ~docs cmdname)