| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
{ |
| 12 |
|
| 13 |
open Lexing |
| 14 |
open Format |
| 15 |
|
| 16 |
let string_buffer = Buffer.create 1024 |
| 17 |
|
| 18 |
} |
| 19 |
|
| 20 |
let space = [' ' '\010' '\013' '\009' '\012'] |
| 21 |
let char = ['A'-'Z' 'a'-'z' '_' '0'-'9'] |
| 22 |
let ident = (char | '.')+ |
| 23 |
let ignore = space | ('#' [^ '\n']*) |
| 24 |
|
| 25 |
rule prefs m = parse |
| 26 |
|ignore* (ident as id) ignore* '=' { let conf = str_list [] lexbuf in |
| 27 |
prefs (Util.String.Map.add id conf m) lexbuf } |
| 28 |
| _ { let c = lexeme_start lexbuf in |
| 29 |
eprintf "coqiderc: invalid character (%d)\n@." c; |
| 30 |
prefs m lexbuf } |
| 31 |
| eof { m } |
| 32 |
|
| 33 |
and str_list l = parse |
| 34 |
| ignore* '"' { Buffer.reset string_buffer; |
| 35 |
Buffer.add_char string_buffer '"'; |
| 36 |
string lexbuf; |
| 37 |
let s = Buffer.contents string_buffer in |
| 38 |
str_list ((Scanf.sscanf s "%S" (fun s -> s))::l) lexbuf } |
| 39 |
|ignore+ { List.rev l} |
| 40 |
|
| 41 |
and string = parse |
| 42 |
| '"' { Buffer.add_char string_buffer '"' } |
| 43 |
| '\\' '"' | _ |
| 44 |
{ Buffer.add_string string_buffer (lexeme lexbuf); string lexbuf } |
| 45 |
| eof { eprintf "coqiderc: unterminated string\n@." } |
| 46 |
|
| 47 |
{ |
| 48 |
|
| 49 |
let load_file f = |
| 50 |
let c = open_in f in |
| 51 |
let lb = from_channel c in |
| 52 |
let m = prefs Util.String.Map.empty lb in |
| 53 |
close_in c; |
| 54 |
m |
| 55 |
|
| 56 |
let print_file f m = |
| 57 |
let c = open_out f in |
| 58 |
let fmt = formatter_of_out_channel c in |
| 59 |
let rec print_list fmt = function |
| 60 |
| [] -> () |
| 61 |
| s :: sl -> fprintf fmt "%S@ %a" s print_list sl |
| 62 |
in |
| 63 |
Util.String.Map.iter |
| 64 |
(fun k s -> fprintf fmt "@[<hov 2>%s = %a@]@\n" k print_list s) m; |
| 65 |
fprintf fmt "@."; |
| 66 |
close_out c |
| 67 |
|
| 68 |
} |