Clarify licensing for Debian.
[virt-df.git] / lib / diskimage_lvm2_parser.mly
1 /* 'df' command for virtual domains.  -*- text -*-
2    (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version,
9    with the OCaml linking exception described in ../COPYING.LIB.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19  */
20
21 /* Parser for LVM2 metadata.
22    ocamlyacc tutorial:
23    http://plus.kaist.ac.kr/~shoh/ocaml/ocamllex-ocamlyacc/ocamlyacc-tutorial/
24  */
25
26 %{
27   open Diskimage_lvm2_metadata
28 %}
29
30 %token LBRACE RBRACE                    /* { } */
31 %token LSQUARE RSQUARE                  /* [ ] */
32 %token EQ                               /* = */
33 %token COMMA                            /* , */
34 %token <string> STRING                  /* "string" */
35 %token <Int63.t> INT                    /* an integer */
36 %token <float> FLOAT                    /* a float */
37 %token <string> IDENT                   /* a naked keyword/identifier */
38 %token EOF                              /* end of file */
39
40 %start input
41 %type <Diskimage_lvm2_metadata.metadata> input
42
43 %%
44
45 input   : lines EOF     { List.rev $1 }
46         ;
47
48 lines   : /* empty */   { [] }
49         | lines line    { $2 :: $1 }
50         ;
51
52 line    : /* empty */   /* These dummy entries get removed after parsing. */
53                         { ("", String "") }
54         | IDENT EQ value
55                         { ($1, $3) }
56         | IDENT LBRACE lines RBRACE
57                         { ($1, Metadata (List.rev $3)) }
58         ;
59
60 value   : STRING        { String $1 }
61         | INT           { Int $1 }
62         | FLOAT         { Float $1 }
63         | LSQUARE list RSQUARE
64                         { List (List.rev $2) }
65         ;
66
67 list    : /* empty */   { [] }
68         | value         { [$1] }
69         | list COMMA value
70                         { $3 :: $1 }
71         ;