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 42 %type <value> value valuelist values 43 %destructor { xlu__cfg_value_free($$); } value valuelist values 44 45 %% 46 47 file: stmts 48 | stmts assignment 49 50 stmts: /* empty */ 51 | stmts stmt 52 53 stmt: assignment endstmt 54 | endstmt 55 | error NEWLINE 56 57 assignment: IDENT '=' value { xlu__cfg_set_store(ctx,$1,$3,@3.first_line); } 58 59 endstmt: NEWLINE 60 | ';' 61 62 value: atom { $$= xlu__cfg_string_mk(ctx,$1,&@1); } 63 | '[' nlok valuelist ']' { $$= $3; } 64 65 atom: STRING { $$= $1; } 66 | NUMBER { $$= $1; } 67 68 valuelist: /* empty */ { $$= xlu__cfg_list_mk(ctx,NULL,&yylloc); } 69 | values { $$= $1; } 70 | values ',' nlok { $$= $1; } 71 72 values: value nlok { $$= xlu__cfg_list_mk(ctx,$1,&@1); } 73 | values ',' nlok value nlok { xlu__cfg_list_append(ctx,$1,$4); $$= $1; } 74 75 nlok: 76 /* nothing */ 77 | nlok NEWLINE 78