Commits

juster  committed e2937f6

Move param list functions into Bashparam module.

  • Participants
  • Parent commits a4622fb

Comments (0)

Files changed (3)

File bashexpand.ml

     exception ExpandError       of int
     exception UnbalancedBracket of int
 
-    let param_lookup expander name plist =
-      let param = try List.assoc name plist
-        with Not_found -> Param("")
-      in expander param
-
-    (** Lookup the value of a parameter in string context.
-        This is like $FOO in bash. *)
-    let param_str_ctx = param_lookup Bashparam.string_of_param
-
-    (** Lookup the value of a parameter in array context.
-        This is like ${FOO[@]} in bash. *)
-    (* Commented out because we don't use this, yet. *)
-    (* let param_arr_ctx = param_lookup Bashparams.string_of_array *)
-
-    let set_param name param plist =
-      (name, param) :: List.remove_assoc name plist
-
     (** Search and destroy parameters ($VARs) in a string. **)
     let parameter_expand str params =
 
             let expand_param_subst name idx =
               (* XXX: What about badly formed input? *)
               match expand_until_curly (idx + 1) with (newidx, subst) ->
-                let pval = param_str_ctx name params in
+                let pval = assoc_str name params in
                 let expstr =
                   match str.[idx] with
                   | '-' -> if "" = pval then subst else pval
             in
 
             match str.[idx] with
-            | '}' -> (idx+1, param_str_ctx name params)
+            | '}' -> (idx+1, assoc_str name params)
             | ':' -> expand_param_subst name (idx+1)
             |  _  -> raise Not_found
           in (* end of expand_inbraces *)
           | '$' ->
               begin
                 try match expand_name (idx+1) with (newidx, name) ->
-                  (newidx, param_str_ctx name params)
+                  (newidx, assoc_str name params)
                 with Invalid_argument(_) -> raise (ExpandError idx)
               end
           | '{' ->
               end
           | _ ->
               match extract_name idx with (newidx, name) ->
-                (newidx, param_str_ctx name params)
+                (newidx, assoc_str name params)
         in (* end of expand_name *)
 
         try

File bashparam.ml

 let string_of_param param =
   match param with
     Param(str) -> str | ParamArray (_) -> string_of_param_elem param 0
+
+let make_lookup expander name plist =
+  let param = try List.assoc name plist
+  with Not_found -> Param("")
+  in expander param
+
+(** Lookup the value of a parameter in string context.
+    This is like $FOO in bash. *)
+let assoc_str = make_lookup string_of_param
+
+(** Lookup the value of a parameter in array context.
+    This is like ${FOO[@]} in bash. *)
+let assoc_arr = make_lookup string_of_array_param

File bashparam.mli

 val string_of_param_elem  : bash_param -> int -> string
 val string_of_array_param : bash_param -> string
 val string_of_param       : bash_param -> string
+
+val assoc_str : string -> (string * bash_param) list -> string
+val assoc_arr : string -> (string * bash_param) list -> string