-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_cudf_parse_822.ml
50 lines (40 loc) · 1.76 KB
/
main_cudf_parse_822.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(*****************************************************************************)
(* libCUDF - CUDF (Common Upgrade Description Format) manipulation library *)
(* Copyright (C) 2009-2012 Stefano Zacchiroli <zack@upsilon.cc> *)
(* *)
(* This library is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Lesser General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version. A special linking *)
(* exception to the GNU Lesser General Public License applies to this *)
(* library, see the COPYING file for more information. *)
(*****************************************************************************)
open Printf
open Cudf_types
let file_arg = ref ""
let arg_spec = [
]
let usage_msg = "Usage: cudf-parse-822 FILE"
let die_usage () = Arg.usage arg_spec usage_msg ; exit (-2)
let pp_822 =
let pp_stanza stanza =
List.iter (fun (k, (_loc, v)) -> printf "%s: %s\n%!" k v) stanza;
print_newline ()
in
List.iter pp_stanza
let pp_lpos { Lexing.pos_fname = _fname;
pos_lnum = lnum; pos_bol = bol; pos_cnum = cnum } =
sprintf "%d:%d" lnum (cnum - bol)
let main () =
Arg.parse arg_spec ((:=) file_arg) usage_msg;
if !file_arg = "" then
die_usage ();
let ic = open_in !file_arg in
let lexbuf = Lexing.from_channel ic in
try
let stanzas = Cudf_822_parser.doc_822 Cudf_822_lexer.token_822 lexbuf in
pp_822 stanzas
with Parse_error_822 (msg, (startpos, endpos)) ->
failwith (sprintf "Parse error on file %s:%s--%s" !file_arg
(pp_lpos startpos) (pp_lpos endpos))
let _ = main ()