diff --git a/src/super_context.ml b/src/super_context.ml index 46c9c865..00a797ce 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -100,20 +100,36 @@ let expand_macro t ~syntax_version ~var = Exn.code_error "expand_macro can't expand variables" [ "var", String_with_vars.Var.sexp_of_t var ] +let expand t ~syntax_version ~var = + match + match String_with_vars.Var.destruct var with + | Var _ -> Left (expand_vars t ~syntax_version ~var) + | Macro (_, _) -> Right (expand_macro t ~syntax_version ~var) + with + | Right None + | Left None -> None + | Right (Some x) -> Some (Right x) + | Left (Some x) -> Some (Left x) + let (expand_vars_string, expand_vars_path) = let expand t ~scope ~dir ?(extra_vars=String.Map.empty) s = String_with_vars.expand ~mode:Single ~dir s ~f:(fun var syntax_version -> - match expand_vars t ~syntax_version ~var with + match expand t ~syntax_version ~var with | None -> String.Map.find extra_vars (String_with_vars.Var.full_name var) - | Some v -> + | Some (Left v) -> begin match Pform.Var.to_value_no_deps_or_targets ~scope v with | Some _ as v -> v | None -> Loc.fail (String_with_vars.Var.loc var) "Variable %a is not allowed in this context" String_with_vars.Var.pp var - end) + end + | Some (Right Ocaml_config) -> + String.Map.find t.ocaml_config (String_with_vars.Var.name var) + | Some (Right _) -> + Loc.fail (String_with_vars.Var.loc var) + "This percent form isn't allowed in this position") in let expand_vars t ~scope ~dir ?extra_vars s = expand t ~scope ~dir ?extra_vars s diff --git a/test/blackbox-tests/test-cases/macro-expand-error/run.t b/test/blackbox-tests/test-cases/macro-expand-error/run.t index 832d5db8..99d53da5 100644 --- a/test/blackbox-tests/test-cases/macro-expand-error/run.t +++ b/test/blackbox-tests/test-cases/macro-expand-error/run.t @@ -4,5 +4,5 @@ inappropariate place: $ dune build Info: creating file dune-project with this contents: (lang dune 1.0) File "dune", line 1, characters 14-21: - Error: macros of the form %{name:..} cannot be expanded here + Error: This percent form isn't allowed in this position [1] diff --git a/test/blackbox-tests/test-cases/ocaml-config-macro/run.t b/test/blackbox-tests/test-cases/ocaml-config-macro/run.t index 512709cd..af1b2a3d 100644 --- a/test/blackbox-tests/test-cases/ocaml-config-macro/run.t +++ b/test/blackbox-tests/test-cases/ocaml-config-macro/run.t @@ -2,6 +2,3 @@ the values are all platform specific. $ dune build - File "dune", line 3, characters 41-61: - Error: Unknown form: %{ocaml-config:system} - [1] \ No newline at end of file