1 /* -*- fundamental -*- */
2 /*
3  * libxlu_cfg_l.y - xl configuration file parsing: parser
4  *
5  * Copyright (C) 2010      Citrix Ltd.
6  * Author Ian Jackson <ian.jackson@eu.citrix.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; version 2.1 only. with the special
11  * exception on linking described in file LICENSE.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  */
18 
19 %{
20 #define ctx_scanner ctx->scanner
21 #include "libxlu_cfg_i.h"
22 #include "libxlu_cfg_l.h"
23 %}
24 
25 %union {
26   char *string;
27   XLU_ConfigValue *value;
28 }
29 
30 %locations
31 %pure-parser
32 %defines
33 %error-verbose
34 %name-prefix "xlu__cfg_yy"
35 %parse-param { CfgParseContext *ctx }
36 %lex-param { ctx_scanner }
37 
38 %token <string>                IDENT STRING NUMBER NEWLINE
39 %type <string>            atom
40 %destructor { free($$); } atom IDENT STRING NUMBER
41 %token OP_ADD "+="
42 
43 %type <value>                             value valuelist values
44 %destructor { xlu__cfg_value_free($$); }  value valuelist values
45 
46 %%
47 
48 file:  stmts
49  |     stmts assignment
50 
51 stmts:  /* empty */
52  |      stmts stmt
53 
54 stmt:   assignment endstmt
55  |      endstmt
56  |      error NEWLINE
57 
58 assignment: IDENT '=' value { xlu__cfg_set_store(ctx,$1,XLU_OP_ASSIGNMENT,$3,@3.first_line); }
59  |          IDENT "+=" value { xlu__cfg_set_store(ctx,$1,XLU_OP_ADDITION,$3,@3.first_line); }
60 
61 endstmt: NEWLINE
62  |      ';'
63 
64 value:  atom                         { $$= xlu__cfg_string_mk(ctx,$1,&@1); }
65  |      '[' nlok valuelist ']'       { $$= $3; }
66 
67 atom:   STRING                   { $$= $1; }
68  |      NUMBER                   { $$= $1; }
69 
70 valuelist: /* empty */           { $$= xlu__cfg_list_mk(ctx,NULL,&yylloc); }
71  |      values                  { $$= $1; }
72  |      values ',' nlok         { $$= $1; }
73 
74 values: value nlok                  { $$= xlu__cfg_list_mk(ctx,$1,&@1); }
75  |      values ',' nlok value nlok  { xlu__cfg_list_append(ctx,$1,$4); $$= $1; }
76 
77 nlok:
78         /* nothing */
79  |      nlok NEWLINE
80