-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve variable interpolation of Windows paths
Windows paths will routinely contain backslash characters, meaning that opam's variable interpolation (OpamFilter.expand_interpolations_in_file) will not work if the method is used to generate .config files. The function now attempts to process the file using opam-file-format. If this is successful, then variables expansions which occur inside quoted and triple-quoted strings will have backslash and double-quote characters escaped. Thus, if the lib variable is C:\OPAM\system\lib then the following .in file: opam-version: "2.0" variables { lib: "%{lib}%/ocaml" broken: %{lib}% } expands to: opam-version: "2.0" variables { lib: "C:\\OPAM\\system\\lib/ocaml" broken: C:\OPAM\system\lib } Signed-off-by: David Allsopp <david.allsopp@metastack.com>
- Loading branch information
Showing
7 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Copyright 2016 MetaStack Solutions Ltd. *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of the *) | ||
(* GNU Lesser General Public License version 2.1, with the special *) | ||
(* exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
(** OPAM format variable interpolation processor *) | ||
|
||
val main: (string -> unit) -> (string -> unit) -> Lexing.lexbuf -> unit | ||
(** [main unquoted quoted lexbuf] fully processes the given lexbuf. Strings are | ||
applied to [unquoted] until a ["] or ["""] sequence is encountered when the | ||
content within the single or triple-quoted string is applied to [quoted] | ||
(note that the quote marks themselves are passed to [unquoted]). Within | ||
either string type, backslash is the escape character. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Copyright 2016 MetaStack Solutions Ltd. *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of the *) | ||
(* GNU Lesser General Public License version 2.1, with the special *) | ||
(* exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
rule main unquoted quoted = parse | ||
| [^ '"' '\n' ]+ | ||
{ unquoted @@ Lexing.lexeme lexbuf; | ||
main unquoted quoted lexbuf } | ||
| ("\"\"\"" | '"') as quote | ||
{ unquoted quote; | ||
let triple = String.length quote = 3 in | ||
string triple unquoted quoted lexbuf } | ||
| '\n' { Lexing.new_line lexbuf; | ||
unquoted "\n"; | ||
main unquoted quoted lexbuf } | ||
| eof { () } | ||
|
||
|
||
and string triple unquoted quoted = parse | ||
| ( [^ '"' '\\' '\n' ]+ | '\\' [^ '\n' ]? )+ | ||
{ quoted @@ Lexing.lexeme lexbuf; | ||
string triple unquoted quoted lexbuf } | ||
| "\"\"\"" | ||
{ unquoted "\"\"\""; | ||
main unquoted quoted lexbuf } | ||
| '"' { if triple then begin | ||
quoted "\""; | ||
string triple unquoted quoted lexbuf | ||
end else begin | ||
unquoted "\""; | ||
main unquoted quoted lexbuf | ||
end } | ||
| '\n' { Lexing.new_line lexbuf; | ||
unquoted "\n"; | ||
string triple unquoted quoted lexbuf} | ||
| eof { () } |