~ubuntu-branches/ubuntu/trusty/ocaml-config-file/trusty

« back to all changes in this revision

Viewing changes to config_file_parser.ml4

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-07-23 13:30:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110723133006-1pr1s355qg2h0uyi
Tags: upstream-1.0
Import upstream version 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*********************************************************************************)
 
2
(*                Config_file                                                    *)
 
3
(*                                                                               *)
 
4
(*    Copyright (C) 2011 Institut National de Recherche en Informatique          *)
 
5
(*    et en Automatique. All rights reserved.                                    *)
 
6
(*                                                                               *)
 
7
(*    This program is free software; you can redistribute it and/or modify       *)
 
8
(*    it under the terms of the GNU Library General Public License as            *)
 
9
(*    published by the Free Software Foundation; either version 2 of the         *)
 
10
(*    License, or any later version.                                             *)
 
11
(*                                                                               *)
 
12
(*    This program is distributed in the hope that it will be useful,            *)
 
13
(*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *)
 
14
(*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *)
 
15
(*    GNU Library General Public License for more details.                       *)
 
16
(*                                                                               *)
 
17
(*    You should have received a copy of the GNU Library General Public          *)
 
18
(*    License along with this program; if not, write to the Free Software        *)
 
19
(*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                   *)
 
20
(*    02111-1307  USA                                                            *)
 
21
(*                                                                               *)
 
22
(*    Contact: Maxence.Guesdon@inria.fr                                          *)
 
23
(*                                                                               *)
 
24
(*                                                                               *)
 
25
(*********************************************************************************)
 
26
 
 
27
(* This file is used to generate the code of the module Config_file.Raw.Parse. *)
 
28
 
 
29
module Parse = struct
 
30
  let lexer = Genlex.make_lexer ["="; "{"; "}"; "["; "]"; ";"; "("; ")"; ","]
 
31
 
 
32
(* parsers: *)
 
33
  let rec file l = parser
 
34
    | [< id = ident; 'Genlex.Kwd "="; v = value ; result = file ((id, v) :: l) >] -> result
 
35
    | [< >] -> List.rev l
 
36
  and value = parser
 
37
    | [< 'Genlex.Kwd "{"; v = file []; 'Genlex.Kwd "}" >] -> Section v
 
38
    | [< 'Genlex.Ident s >] -> String s
 
39
    | [< 'Genlex.String s >] -> String s
 
40
    | [< 'Genlex.Int i >] -> Int i
 
41
    | [< 'Genlex.Float f >] -> Float f
 
42
    | [< 'Genlex.Char c >] -> String (String.make 1 c)
 
43
    | [< 'Genlex.Kwd "["; v = list [] >] -> List v
 
44
    | [< 'Genlex.Kwd "("; v = list [] >] -> Tuple v
 
45
  and ident = parser
 
46
    | [< 'Genlex.Ident s >] -> s
 
47
    | [< 'Genlex.String s >] -> s
 
48
  and list l = parser
 
49
    | [< 'Genlex.Kwd ";"; result = list l >] -> result
 
50
    | [< 'Genlex.Kwd ","; result = list l >] -> result
 
51
    | [< v = value; result = list (v :: l) >] -> result
 
52
    | [< 'Genlex.Kwd "]" >] -> List.rev l
 
53
    | [< 'Genlex.Kwd ")" >] -> List.rev l
 
54
end