package MlFront_Thunk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ThunkLuaLibStringDk.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module M (Params : ThunkLuaParams.S) (I : Lua.Lib.CORE) = struct
  module V = I.V
  module R = ThunkLuaErrors.Raise (V)

  let ( **-> ) = V.( **-> )
  let ( **->> ) x y = x **-> V.result y
  let ( *****->> ) = V.dots_arrow

  let stringdk_module () =
    [
      ( "quote_posix_shell",
        V.efunc (V.string **->> V.string)
          ThunkLexers.PosixShellLexer.Token.quote_literal_if_needed );
      ( "quote_value_shell",
        V.efunc (V.string **->> V.string)
          ThunkLexers.ValueShellLexer.Token.quote_literal_if_needed );
      ( "quote_windows_batch",
        V.efunc (V.string **->> V.string)
          MlFront_Core.Platform.Windows.cmd_quote_word );
      ( "sanitizesubpath",
        V.efunc (V.string **-> V.resultvs) (fun s ->
            match MlFront_Core.FilePath.of_string s with
            | Error msg ->
                [
                  V.LuaValueBase.Nil;
                  V.string.embed
                    (Printf.sprintf "`%s` is not a subdirectory: %s" s msg);
                ]
            | Ok fp ->
                let fp = MlFront_Core.FilePath.normalize fp in
                if MlFront_Core.FilePath.is_strictly_relative fp then
                  match MlFront_Core.FilePath.validate_portability fp with
                  | Error msg ->
                      [
                        V.LuaValueBase.Nil;
                        V.string.embed
                          (Printf.sprintf "`%s` is not a subdirectory: %s" s msg);
                      ]
                  | Ok (_ : MlFront_Core.FilePath.Portable.t) ->
                      (* normalize empty to "." *)
                      let fps = MlFront_Core.FilePath.to_string fp in
                      if String.equal fps "" then [ V.string.embed "." ]
                      else [ V.string.embed fps ]
                else
                  [
                    V.LuaValueBase.Nil;
                    V.string.embed
                      (Printf.sprintf
                         "`%s` is not a strictly relative subdirectory" s);
                  ]) );
    ]

  let init g =
    (* The declarative modes do not have access to this library. *)
    if ThunkLuaParams.is_not_declarative_mode Params.mode then
      I.register_module "stringdk" (stringdk_module ()) g
end