-
Notifications
You must be signed in to change notification settings - Fork 1
/
directive.ml
34 lines (30 loc) · 944 Bytes
/
directive.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
open Spotlib.Spot
open List
module Re = Ppx_orakuda.Regexp.Re_pcre
open Re.Infix
open Re.Literal
let parse s = case s
|> ( {m|^\s*#(.*)$|m} ==> fun r ->
let lexbuf = Lexing.from_string r#_1 in
Some (Exn.catch Parse.expression lexbuf)
)
|> default (fun () -> None)
let interpret db e conf pspec = match e with
| [%expr packages] ->
let open Data.DB in
flip iter db.packs (fun (n,v) ->
match v with
| None -> !!% "%s@." n
| Some v -> !!% "%s.%s@." n v);
conf, pspec
| [%expr all] -> conf, Query.PackageSpec.All_but []
| [%expr vanilla] -> conf, Query.PackageSpec.Vanilla []
| [%expr none] -> conf, Query.PackageSpec.Just []
| [%expr quit] ->
!!% "Bye@.";
exit 0
| [%expr show_v true] -> { Conf.show_v = true }, pspec
| [%expr show_v false] -> { Conf.show_v = false }, pspec
| _ ->
!!% "illegal directive@.";
conf, pspec