@@ -1497,8 +1497,33 @@ let opam_variable_to_slang ~loc packages variable =
1497
1497
Blang. Expr (convert_with_package_name package_name))))
1498
1498
;;
1499
1499
1500
+ (* Handles the special case for packages whose names contain '+' characters
1501
+ where a special form of string interpolation is used. From the opam manual:
1502
+ Warning: if the package name contains a + character (e.g. conf-g++), their
1503
+ variables may only be accessed using opam 2.2 via string interpolation,
1504
+ with the following syntax:
1505
+
1506
+ "%{?conf-g++:your-variable:}%"
1507
+ *)
1508
+ let desugar_special_string_interpolation_syntax
1509
+ ((packages , variable , string_converter ) as fident )
1510
+ =
1511
+ match string_converter with
1512
+ | Some (package_and_variable, " " )
1513
+ when List. is_empty packages && String. is_empty (OpamVariable. to_string variable) ->
1514
+ (match String. lsplit2 package_and_variable ~on: ':' with
1515
+ | Some (package , variable ) ->
1516
+ ( [ Some (OpamPackage.Name. of_string package) ]
1517
+ , OpamVariable. of_string variable
1518
+ , None )
1519
+ | None -> fident)
1520
+ | _ -> fident
1521
+ ;;
1522
+
1500
1523
let opam_fident_to_slang ~loc fident =
1501
- let packages, variable, string_converter = OpamFilter. desugar_fident fident in
1524
+ let packages, variable, string_converter =
1525
+ OpamFilter. desugar_fident fident |> desugar_special_string_interpolation_syntax
1526
+ in
1502
1527
let slang = opam_variable_to_slang ~loc packages variable in
1503
1528
match string_converter with
1504
1529
| None -> slang
0 commit comments