1 | /* $Id: conf_tab.y 13 2011-04-20 15:41:43Z mmamonski $ */ |
---|
2 | /* |
---|
3 | * |
---|
4 | * PSNC DRMAA 2.0 utilities library |
---|
5 | * Copyright (C) 2012 Poznan Supercomputing and Networking Center |
---|
6 | * |
---|
7 | * This program is free software: you can redistribute it and/or modify |
---|
8 | * it under the terms of the GNU General Public License as published by |
---|
9 | * the Free Software Foundation, either version 3 of the License, or |
---|
10 | * (at your option) 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 General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | */ |
---|
20 | |
---|
21 | %{ |
---|
22 | #ifdef HAVE_MALLOC_H |
---|
23 | # include <malloc.h> |
---|
24 | #endif |
---|
25 | #include <drmaa_utils/conf_impl.h> |
---|
26 | #include <drmaa_utils/conf_tab.h> |
---|
27 | %} |
---|
28 | |
---|
29 | %pure-parser |
---|
30 | %locations |
---|
31 | %name-prefix="fsd_conf_" |
---|
32 | %parse-param { fsd_conf_parser_t *parser } |
---|
33 | %parse-param { fsd_conf_lexer_t *lexer } |
---|
34 | %lex-param { fsd_conf_lexer_t *lexer } |
---|
35 | |
---|
36 | |
---|
37 | %union { |
---|
38 | int integer; |
---|
39 | char *string; |
---|
40 | fsd_conf_option_t *option; |
---|
41 | fsd_conf_dict_t *dictionary; |
---|
42 | fsd_conf_pair_t pair; |
---|
43 | } |
---|
44 | |
---|
45 | %type<option> value |
---|
46 | %destructor { fsd_conf_option_destroy($$); } value |
---|
47 | %type<dictionary> start conf dict dict_body pair_list |
---|
48 | %destructor { fsd_conf_dict_destroy($$); } conf dict dict_body pair_list |
---|
49 | %type<pair> pair |
---|
50 | %token<integer> INTEGER |
---|
51 | %token<string> STRING |
---|
52 | %destructor { free($$); } STRING |
---|
53 | %token LEXER_ERROR |
---|
54 | |
---|
55 | |
---|
56 | %% |
---|
57 | |
---|
58 | start |
---|
59 | : conf { parser->result = $1; $$ = NULL; } |
---|
60 | ; |
---|
61 | |
---|
62 | conf |
---|
63 | : dict |
---|
64 | | dict_body |
---|
65 | ; |
---|
66 | |
---|
67 | dict |
---|
68 | : '{' dict_body '}' { $$ = $2; } |
---|
69 | ; |
---|
70 | |
---|
71 | dict_body |
---|
72 | : pair_list { $$ = $1; } |
---|
73 | | pair_list ',' { $$ = $1; } |
---|
74 | | { |
---|
75 | $$ = fsd_conf_dict_create_noraise(); |
---|
76 | if( $$ == NULL ) YYABORT; |
---|
77 | } |
---|
78 | ; |
---|
79 | |
---|
80 | pair_list |
---|
81 | : pair |
---|
82 | { |
---|
83 | fsd_conf_dict_t *dict = NULL; |
---|
84 | int rc; |
---|
85 | dict = fsd_conf_dict_create_noraise(); |
---|
86 | if( dict == NULL ) |
---|
87 | YYABORT; |
---|
88 | rc = fsd_conf_dict_set_noraise( dict, $1.key, $1.value ); |
---|
89 | if( rc ) |
---|
90 | { |
---|
91 | fsd_conf_dict_destroy( dict ); |
---|
92 | YYABORT; |
---|
93 | } |
---|
94 | $$ = dict; |
---|
95 | } |
---|
96 | | pair_list ',' pair |
---|
97 | { |
---|
98 | int rc; |
---|
99 | rc = fsd_conf_dict_set_noraise( $1, $3.key, $3.value ); |
---|
100 | if( rc ) |
---|
101 | YYABORT; |
---|
102 | $$ = $1; /* explicit no op */ |
---|
103 | } |
---|
104 | ; |
---|
105 | |
---|
106 | pair |
---|
107 | : STRING ':' value { $$.key = $1; $$.value = $3; } |
---|
108 | ; |
---|
109 | |
---|
110 | value |
---|
111 | : INTEGER |
---|
112 | { |
---|
113 | fsd_conf_option_t *o; |
---|
114 | o = fsd_conf_option_create_noraise( FSD_CONF_INTEGER, &$1 ); |
---|
115 | if( o ) |
---|
116 | $$ = o; |
---|
117 | else |
---|
118 | YYABORT; |
---|
119 | } |
---|
120 | | STRING |
---|
121 | { |
---|
122 | fsd_conf_option_t *o; |
---|
123 | o = fsd_conf_option_create_noraise( FSD_CONF_STRING, $1 ); |
---|
124 | if( o ) |
---|
125 | $$ = o; |
---|
126 | else |
---|
127 | YYABORT; |
---|
128 | } |
---|
129 | | dict |
---|
130 | { |
---|
131 | fsd_conf_option_t *o; |
---|
132 | o = fsd_conf_option_create_noraise( FSD_CONF_DICT, $1 ); |
---|
133 | if( o ) |
---|
134 | $$ = o; |
---|
135 | else |
---|
136 | YYABORT; |
---|
137 | } |
---|
138 | ; |
---|
139 | |
---|
140 | %% |
---|