Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

avoid name collision with ocaml config.ml

  • Loading branch information...
commit 8c3d08fe1edf143f9a4c9dab7d097a2550b1d40d 1 parent b95fbb4
camlspotter camlspotter authored

Showing 2 changed files with 66 additions and 0 deletions. Show diff stats Hide diff stats

  1. +58 0 chconfig.ml
  2. +8 0 chconfig.mli
58 chconfig.ml
... ... @@ -0,0 +1,58 @@
  1 +open Base
  2 +open Str
  3 +type t = {
  4 + name : string;
  5 + path : string option;
  6 + modules : string list
  7 +}
  8 +
  9 +let name = ref ""
  10 +let path = ref None
  11 +let modules = ref []
  12 +let configs = ref []
  13 +
  14 +let chop s =
  15 + let r =
  16 + regexp "[\r\n]"
  17 + in
  18 + global_replace r "" s
  19 +
  20 +let add_current () =
  21 + if !name <> "" then
  22 + configs := { name = !name; modules = List.rev !modules; path= !path } ::
  23 + !configs;
  24 + name := "";
  25 + path := None;
  26 + modules := []
  27 +
  28 +let r_package =
  29 + regexp "^- *\\(.*\\)$"
  30 +
  31 +let r_path =
  32 + regexp "^PATH *:: *\\(.*\\)$"
  33 +
  34 +let parse_line s =
  35 + if s = "" then
  36 + ()
  37 + else if string_match r_path s 0 then
  38 + path := Some (matched_group 1 s)
  39 + else if string_match r_package s 0 then begin
  40 + add_current ();
  41 + name := matched_group 1 s
  42 + end else
  43 + modules := s :: !modules
  44 +
  45 +let read path =
  46 + configs := [];
  47 + name := "";
  48 + try
  49 + open_in_with path begin fun ch ->
  50 + while true do
  51 + parse_line @@ chop @@ input_line ch
  52 + done;
  53 + end;
  54 + failwith "must not happen"
  55 + with End_of_file ->
  56 + add_current ();
  57 + List.rev !configs
  58 +
8 chconfig.mli
... ... @@ -0,0 +1,8 @@
  1 +type t = {
  2 + name : string;
  3 + path:string option;
  4 + modules : string list
  5 +}
  6 +
  7 +val read : string -> t list
  8 +

0 comments on commit 8c3d08f

Please sign in to comment.
Something went wrong with that request. Please try again.