first commit

This commit is contained in:
pena 2022-01-17 18:10:12 +01:00
commit e1c6aeeeed
42 changed files with 1305 additions and 0 deletions

4
example/dune Normal file
View file

@ -0,0 +1,4 @@
(executable
(name main)
(modules main)
(libraries fpath scfg))

34
example/main.ml Normal file
View file

@ -0,0 +1,34 @@
(* run on the `main.scfg` file in this directory *)
let () =
if Array.length Sys.argv <> 2 then begin
Format.eprintf "usage: %s <scfg file>@\n" Sys.argv.(0);
exit 1
end
(* parsing file path *)
let filepath =
match Fpath.of_string Sys.argv.(1) with
| Error (`Msg e) ->
Format.eprintf "error: %s@\n" e;
exit 1
| Ok path -> path
(* parsing the file *)
let config =
match Scfg.Parse.from_file filepath with
| Error (`Msg e) ->
Format.eprintf "error: %s@\n" e;
exit 1
| Ok config -> config
(* printing the file *)
let () = Format.printf "```scfg@\n%a@\n```@\n" Scfg.Pp.config config
(* querying the file *)
let () =
match Scfg.Query.get_dir "train" config with
| None -> Format.printf "No train found.@\n"
| Some train -> (
match Scfg.Query.get_param 0 train with
| Error _e -> Format.printf "Train has no name.@\n"
| Ok name -> Format.printf "The first train is `%s`.@\n" name )

7
example/main.scfg Normal file
View file

@ -0,0 +1,7 @@
train A-Train {
bla bla bla
}
train "John Col Train" {
tut tut tut
}