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