Skip to content

Commit

Permalink
Aaaand rewrite the parser entirely, yet again, based on the tools giv…
Browse files Browse the repository at this point in the history
…en by fsutil.
  • Loading branch information
robsimmons committed Oct 29, 2011
1 parent f1b4430 commit 50e816a
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 309 deletions.
4 changes: 2 additions & 2 deletions sources.cm
Original file line number Original file line Diff line number Diff line change
@@ -1,17 +1,17 @@
Group is Group is
$/basis.cm $/basis.cm
util/sources.cm util/sources.cm
src/fsutil.sml


(* Smackage data types *) (* Smackage data types *)
src/protocol.sml src/protocol.sml
src/semver.sml src/semver.sml
src/spec.sml src/spec.sml


(* Managing local data *) (* Managing local data *)
src/fsutil.sml
src/version-index.sml src/version-index.sml
src/configure.sml src/configure.sml
src/install.sml (* src/install.sml *)


(* Obtaining and manipulating code and packages *) (* Obtaining and manipulating code and packages *)
src/get-git.sml src/get-git.sml
Expand Down
4 changes: 2 additions & 2 deletions sources.mlb
Original file line number Original file line Diff line number Diff line change
@@ -1,17 +1,17 @@


$(SML_LIB)/basis/basis.mlb $(SML_LIB)/basis/basis.mlb
util/sources.mlb util/sources.mlb
src/fsutil.sml


(* Smackage data types *) (* Smackage data types *)
src/protocol.sml src/protocol.sml
src/semver.sml src/semver.sml
src/spec.sml src/spec.sml


(* Managing local data *) (* Managing local data *)
src/fsutil.sml
src/version-index.sml src/version-index.sml
src/configure.sml src/configure.sml
src/install.sml (* src/install.sml *)


(* Obtaining and manipulating code and packages *) (* Obtaining and manipulating code and packages *)
src/get-git.sml src/get-git.sml
Expand Down
15 changes: 9 additions & 6 deletions src/fsutil.sml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ struct
| trimStart (#"\t"::t) = trimStart t | trimStart (#"\t"::t) = trimStart t
| trimStart l = l | trimStart l = l


fun trimEnd (#"#"::t) = [] fun trimEnd (#"#"::t) accum = rev accum
| trimEnd (#"\n"::t) = [] | trimEnd (#"\n"::t) accum = rev accum
| trimEnd (h::t) = h :: trimEnd t | trimEnd (h::t) accum = trimEnd t (h :: accum)
| trimEnd [] = [] | trimEnd [] accum = rev accum
in in
String.implode (trimEnd (trimStart (String.explode s))) String.implode (trimEnd (trimStart (String.explode s)) [])
end end


fun getLines' trimmer splitter file = fun getLines' trimmer splitter file =
let let
fun loop accum stanzas = fun loop accum stanzas =
case TextIO.inputLine file of case TextIO.inputLine file of
NONE => rev (rev accum :: stanzas) before TextIO.closeIn file NONE =>
if null accum
then (rev stanzas before TextIO.closeIn file)
else (rev (rev accum :: stanzas) before TextIO.closeIn file)
| SOME s => | SOME s =>
if splitter s if splitter s
then (if null accum then (if null accum
Expand Down
18 changes: 12 additions & 6 deletions src/main.sml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct
( if null deps then raise NoDeps else () ( if null deps then raise NoDeps else ()
; if length deps = 1 then print "Resolving 1 dependency\n" ; if length deps = 1 then print "Resolving 1 dependency\n"
else print ("Resolving " ^ ltoi deps ^ "dependencies\n") else print ("Resolving " ^ ltoi deps ^ "dependencies\n")
; app (fn (pkg, spec) => install pkg (SOME spec) true) deps (* XXX here's the place to shortcut-stop if we have an acceptable
* version installed (issue #4) *)
; app (fn (pkg, spec, _) => install pkg (SOME spec) true) deps
; print ("Done resolving dependencies for `" ^ pkg ^ "`\n")) ; print ("Done resolving dependencies for `" ^ pkg ^ "`\n"))
end handle NoDeps => () end end handle NoDeps => () end


Expand Down Expand Up @@ -77,7 +79,7 @@ struct
if SmackLib.download (!Configure.smackHome) (pkg,ver,proto) if SmackLib.download (!Configure.smackHome) (pkg,ver,proto)
then print ( "Package `" ^ name ^ "` already installed.\n") then print ( "Package `" ^ name ^ "` already installed.\n")
else ( print ( "Package `" ^ name ^ "` downloaded.\n") else ( print ( "Package `" ^ name ^ "` downloaded.\n")
; resolveDependencies pkg ver ; resolveDependencies pkg ver (*
; (if runHooks then ; (if runHooks then
(SmackLib.build (SmackLib.build
(!Configure.smackHome) (!Configure.smackHome)
Expand All @@ -87,7 +89,7 @@ struct
(!Configure.smackHome) (!Configure.smackHome)
(!Configure.platform,!Configure.compilers) (!Configure.platform,!Configure.compilers)
(pkg,ver)) else ()) (pkg,ver)) else ())
) *))
end end


(** Uninstall a package with a given name and version. (** Uninstall a package with a given name and version.
Expand Down Expand Up @@ -132,9 +134,11 @@ struct
val res = VersionIndex.search name val res = VersionIndex.search name
val _ = if length res = 0 then print "No packages found.\n" else () val _ = if length res = 0 then print "No packages found.\n" else ()
val _ = List.app val _ = List.app
(fn (n,v,p) => (fn (n,dict) =>
print (n ^ " " ^ SemVer.toString v ^ " (from " ^ SemVerDict.app
Protocol.toString p ^ ")\n")) res (fn (v, p) =>
print (n ^ " " ^ SemVer.toString v ^ " (from " ^
Protocol.toString p ^ ")\n")) dict) res
in in
() ()
end end
Expand Down Expand Up @@ -335,6 +339,8 @@ struct
end handle (SmackExn s) => end handle (SmackExn s) =>
(TextIO.output (TextIO.stdErr, s ^ "\n"); OS.Process.failure) (TextIO.output (TextIO.stdErr, s ^ "\n"); OS.Process.failure)
| (Fail s) => | (Fail s) =>
(TextIO.output (TextIO.stdErr, s ^ "\n"); OS.Process.failure)
| (Spec.SpecError s) =>
(TextIO.output (TextIO.stdErr, s ^ "\n"); OS.Process.failure) (TextIO.output (TextIO.stdErr, s ^ "\n"); OS.Process.failure)
| exn => | exn =>
(TextIO.output (TextIO.stdErr, "UNEXPECTED ERROR: " (TextIO.output (TextIO.stdErr, "UNEXPECTED ERROR: "
Expand Down
16 changes: 12 additions & 4 deletions src/semver.sml
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
signature SEMVER = signature SEMVER =
sig sig
eqtype semver (* v0.2.4beta, v1.2.3, etc... *) eqtype semver (* v0.2.4beta, v1.2.3, etc... *)
type t = semver
type constraint (* v1, v1.2, v2.3.6, v3.1.6, etc... *) type constraint (* v1, v1.2, v2.3.6, v3.1.6, etc... *)


exception InvalidVersion exception InvalidVersion
Expand Down Expand Up @@ -40,6 +41,7 @@ end
structure SemVer:> SEMVER = structure SemVer:> SEMVER =
struct struct
type semver = int * int * int * string option type semver = int * int * int * string option
type t = semver
type constraint = int * int option * int option * string option type constraint = int * int option * int option * string option


exception InvalidVersion exception InvalidVersion
Expand All @@ -53,12 +55,18 @@ struct


fun fromString' s = fun fromString' s =
let let
val s' = if String.sub (s,0) = #"v" fun fail () = raise Fail ("`" ^ s ^ "` not a valid semantic version")
then String.extract (s, 1, NONE)
else s val s' =
case String.tokens Char.isSpace s of
[ s ] =>
if String.sub (s,0) = #"v"
then String.extract (s, 1, NONE)
else s
| _ => fail ()

val f = String.fields (fn #"." => true | _ => false) s' val f = String.fields (fn #"." => true | _ => false) s'


fun fail () = raise Fail ("`" ^ s ^ "` not a valid semantic version")
fun vtoi i = fun vtoi i =
case Int.fromString i of case Int.fromString i of
NONE => fail () NONE => fail ()
Expand Down
2 changes: 1 addition & 1 deletion src/smackage-path.sml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct
then raise Metadata ("Spec file not found: " ^ specFile) else then raise Metadata ("Spec file not found: " ^ specFile) else
if not (OS.FileSys.access (specFile, [ OS.FileSys.A_READ ])) if not (OS.FileSys.access (specFile, [ OS.FileSys.A_READ ]))
then raise Metadata "Spec file exists but can't be read" then raise Metadata "Spec file exists but can't be read"
else Spec.fromFile specFile else Spec.fromFile specFile
handle (Spec.SpecError s) => raise Fail ("Spec error: " ^ s) handle (Spec.SpecError s) => raise Fail ("Spec error: " ^ s)
end end


Expand Down
21 changes: 14 additions & 7 deletions src/smacklib.sml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sig
** was already there *) ** was already there *)
val download : string -> string * SemVer.semver * Protocol.protocol -> bool val download : string -> string * SemVer.semver * Protocol.protocol -> bool


(*
(** Build a previously downloaded package by invoking a command (** Build a previously downloaded package by invoking a command
specified as 'build:' in the spec file. *) specified as 'build:' in the spec file. *)
val build : string -> (string * string list) -> val build : string -> (string * string list) ->
Expand All @@ -13,6 +14,7 @@ sig
specified as 'install:' in the spec file. *) specified as 'install:' in the spec file. *)
val install : string -> (string * string list) -> val install : string -> (string * string list) ->
(string * SemVer.semver) -> unit; (string * SemVer.semver) -> unit;
*)


(** Returns a list of installed versions *) (** Returns a list of installed versions *)
(* XXX should probably be sorted, relies on the filesystem for this now *) (* XXX should probably be sorted, relies on the filesystem for this now *)
Expand Down Expand Up @@ -45,6 +47,7 @@ struct
; SmackagePath.createVersionLinks smackage_root (pkg,ver) ; SmackagePath.createVersionLinks smackage_root (pkg,ver)
; false) ; false)


(*
fun build smackage_root host (pkg,ver) = fun build smackage_root host (pkg,ver) =
let let
val pkgDir = (smackage_root // "lib" // pkg // "v"^SemVer.toString ver) val pkgDir = (smackage_root // "lib" // pkg // "v"^SemVer.toString ver)
Expand All @@ -68,6 +71,7 @@ struct
end handle (Spec.SpecError _) => () (* Silently fail if there is no spec. *) end handle (Spec.SpecError _) => () (* Silently fail if there is no spec. *)
fun uninstall smackage_root (pkg,ver) = raise Fail "Not implemented" fun uninstall smackage_root (pkg,ver) = raise Fail "Not implemented"
*)


fun versions smackage_root pkg = fun versions smackage_root pkg =
let let
Expand All @@ -87,11 +91,14 @@ struct
end end


fun info smackage_root (pkg,ver) = fun info smackage_root (pkg,ver) =
Spec.fromFile let
( smackage_root val file =
// "lib" ( smackage_root
// pkg // "lib"
// ("v" ^ SemVer.toString ver) // pkg
// (pkg ^ ".smackspec")) // ("v" ^ SemVer.toString ver)
handle (Spec.SpecError s) => raise Fail ("Spec error: " ^ s) // (pkg ^ ".smackspec"))
in
Spec.fromFile file
end handle (Spec.SpecError s) => raise Fail ("Spec error: " ^ s)
end end
Loading

0 comments on commit 50e816a

Please sign in to comment.