head 1.13; access; symbols FSL_1_7_0:1.13 CFG_0_9_11:1.13 FSL_1_6_1:1.12 CFG_0_9_10:1.12 FSL_1_6_0:1.12 FSL_1_6b2:1.12 CFG_0_9_9:1.12 FSL_1_6b1:1.12 CFG_0_9_8:1.12 CFG_0_9_7:1.11 CFG_0_9_6:1.11 CFG_0_9_5:1.9 CFG_0_9_4:1.8 FSL_1_5_0:1.7 FSL_1_5a3:1.7 CFG_0_9_3:1.7 FSL_1_5a2:1.7 FSL_1_5a1:1.7 FSL_1_4_0:1.7 FSL_1_4b1:1.7 CFG_0_9_2:1.7 CFG_0_9_1:1.7 FSL_1_4a1:1.7 FSL_1_3_0:1.7 FSL_1_3b1:1.7 FSL_1_2_1:1.7 FSL_1_2_0:1.7 FSL_1_1_0:1.7 FSL_1_1b1:1.7 FSL_1_0_8:1.7 FSL_1_0_7:1.7 FSL_1_0_6:1.3 FSL_1_0_5:1.3 FSL_1_0_4:1.3 FSL_1_0_3:1.3 FSL_1_0_2:1.3 FSL_1_0_1:1.3 FSL_1_0_0:1.3 FSL_0_9_0:1.3 CFG_0_9_0:1.3 FSL_0_1_12:1.3 FSL_0_1_11:1.3 FSL_0_1_10:1.3 FSL_0_1_9:1.3 FSL_0_1_8:1.3 FSL_0_1_7:1.3 FSL_0_1_6:1.3 FSL_0_1_5:1.3 FSL_0_1_1:1.3; locks; strict; comment @ * @; 1.13 date 2006.08.10.19.35.57; author rse; state Exp; branches; next 1.12; commitid Isy241gp4yykKkIr; 1.12 date 2004.12.31.19.16.25; author rse; state Exp; branches; next 1.11; 1.11 date 2004.12.04.12.48.40; author rse; state Exp; branches; next 1.10; 1.10 date 2004.11.28.14.17.52; author rse; state Exp; branches; next 1.9; 1.9 date 2004.11.20.12.54.07; author rse; state Exp; branches; next 1.8; 1.8 date 2004.07.17.07.37.55; author rse; state Exp; branches; next 1.7; 1.7 date 2003.01.06.11.17.43; author rse; state Exp; branches; next 1.6; 1.6 date 2003.01.06.11.08.26; author rse; state Exp; branches; next 1.5; 1.5 date 2002.11.18.09.51.29; author rse; state Exp; branches; next 1.4; 1.4 date 2002.11.10.12.12.23; author rse; state Exp; branches; next 1.3; 1.3 date 2002.07.10.12.00.23; author rse; state Exp; branches; next 1.2; 1.2 date 2002.07.04.14.51.21; author rse; state Exp; branches; next 1.1; 1.1 date 2002.07.03.13.25.34; author rse; state Exp; branches; next ; desc @@ 1.13 log @cleanup source tree for status as of 2006 @ text @%{ /* ** OSSP cfg - Configuration Parsing ** Copyright (c) 2002-2006 Ralf S. Engelschall ** Copyright (c) 2002-2006 The OSSP Project (http://www.ossp.org/) ** ** This file is part of OSSP cfg, a configuration parsing ** library which can be found at http://www.ossp.org/pkg/lib/cfg/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** cfg_syn_parse.y: context free grammar specification for GNU Bison ** ** ATTENTION: This requires GNU Bison 1.875 or newer! */ #include #include #include "cfg.h" #include "cfg_global.h" #include "cfg_syn.h" /* make sure yyparse() accepts a context pointer and passes through its inlined scanner context to yylex() */ #define CTX ((cfg_syn_ctx_t *)ctx) #define YYPARSE_PARAM ctx #define YYLEX_PARAM CTX->yyscan /* provide an explicit prototype for the yylex() function but use "void *" instead of correct type because at this point in the generation process we have the types still not available */ extern int yylex(/*YYSTYPE*/ void *lvalp, /*YYLTYPE*/ void *llocp, cfg_syn_ctx_t *ctx); /* generate verbose error messages and remember them inside the context */ #undef yyerror #define yyerror(msg) \ cfg_syn_error(CTX, CFG_ERR_SYN, &yylloc, "%s", msg) /* scanner state transition */ extern void cfg_syn_scan_push(cfg_syn_ctx_t *, const char *state); extern void cfg_syn_scan_pop (cfg_syn_ctx_t *); %} /* parser options */ %error-verbose %pure_parser %locations %defines /* the YYSTYPE: parser token value */ %union { char *cpString; cfg_node_t *npNode; } /* assign YYSTYPE elements to parser rules */ %type sequence %type directives %type directive %type tokens %type token %type string /* list of scanner tokens */ %token T_SEP %token T_OPEN %token T_CLOSE %token T_STRING /* operator association */ %right T_SEP %right T_OPEN %right T_CLOSE /* grammar start rule (technically redundant but explicit to be sure) */ %start configuration %% configuration : sequence { CTX->node = $1; } ; sequence : directives { cfg_node_t *n; cfg_node_create(CTX->cfg, &n); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_SEQ); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_CHILD1, $1); $$ = n; } ; directives : /* empty */ { $$ = NULL; } | directive { $$ = $1; } | directive T_SEP directives { cfg_node_set(CTX->cfg, $1, CFG_NODE_ATTR_RBROTH, $3); $$ = $1; } ; directive : tokens { cfg_node_t *n; cfg_node_create(CTX->cfg, &n); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_DIR); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_CHILD1, $1); $$ = n; } ; tokens : token { $$ = $1; } | token tokens { cfg_node_set(CTX->cfg, $1, CFG_NODE_ATTR_RBROTH, $2); $$ = $1; } ; token : T_OPEN sequence T_CLOSE { $$ = $2; } | string { $$ = $1; } ; string : T_STRING { cfg_node_t *n; cfg_node_create(CTX->cfg, &n); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_ARG); cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TOKEN|CFG_ATTR_GIFT, $1); $$ = n; } ; %% @ 1.12 log @Adjust copyright messages for new year 2005. @ text @d4 2 a5 3 ** Copyright (c) 2002-2005 Ralf S. Engelschall ** Copyright (c) 2002-2005 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2005 Cable & Wireless (http://www.cw.com/) @ 1.11 log @Plug remaining memory leaks by introducing the usual LOAN/GIFT/COPY argument passing semantics to cfg_node_{set,get} and using this to directly pass the allocated tokens from the scanner through the parser into the node tree. @ text @d4 3 a6 3 ** Copyright (c) 2002-2004 Ralf S. Engelschall ** Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2004 Cable & Wireless (http://www.cw.com/) @ 1.10 log @Fix annotational error reporting in scanner/parser. @ text @d164 1 a164 1 cfg_node_set(CTX->cfg, n, CFG_NODE_ATTR_TOKEN, $1); @ 1.9 log @- Fixed cfg_test program by correctly passing the used number of bytes in the buffer instead of the size of the buffer. - Accept zero-length strings for parsing. - Correctly handle end-of-file during plain text token scanning. @ text @d56 1 a56 1 cfg_syn_error(CTX, CFG_ERR_SYN, &yylloc, msg) @ 1.8 log @Adjust copyright messages for new year 2004. @ text @d60 2 a61 1 extern void cfg_syn_scan_pop(cfg_syn_ctx_t *); @ 1.7 log @update copyright messages for new year @ text @d4 3 a6 3 ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2002-2003 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.6 log @upgrade to the latest Flex & Bison combo @ text @d4 3 a6 3 ** Copyright (c) 1999-2002 Ralf S. Engelschall ** Copyright (c) 1999-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.5 log @add Dmalloc support @ text @d31 1 a31 1 ** ATTENTION: This requires GNU Bison 1.30 or newer! a56 1 #define YYERROR_VERBOSE d64 1 @ 1.4 log @remove trailing whitespaces @ text @d38 1 @ 1.3 log @Mega-change: full API overhauling. @ text @d46 2 a47 2 /* provide an explicit prototype for the yylex() function but use "void *" instead of correct type because at this point in the d49 1 a49 1 extern int yylex(/*YYSTYPE*/ void *lvalp, d93 1 a93 1 /* grammar start rule d116 1 a116 1 : /* empty */ { d119 2 a120 2 | directive { $$ = $1; d122 1 a122 1 | directive T_SEP directives { d138 3 a140 3 tokens : token { $$ = $1; d142 1 a142 1 | token tokens { d149 2 a150 2 : T_OPEN sequence T_CLOSE { $$ = $2; d153 1 a153 1 $$ = $1; d163 1 a163 1 $$ = n; @ 1.2 log @Flush today's work: the library is now able to parse a .cfg file into an internal node tree and export this again in textual .cfg file format (including indented blocks). @ text @d108 3 a110 3 cfg_node_create(&n); cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_SEQ); cfg_node_set(n, CFG_NODE_ATTR_CHILD1, $1); d123 1 a123 1 cfg_node_set($1, CFG_NODE_ATTR_RBROTH, $3); d131 3 a133 3 cfg_node_create(&n); cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_DIR); cfg_node_set(n, CFG_NODE_ATTR_CHILD1, $1); d143 1 a143 1 cfg_node_set($1, CFG_NODE_ATTR_RBROTH, $2); d160 3 a162 3 cfg_node_create(&n); cfg_node_set(n, CFG_NODE_ATTR_TYPE, CFG_NODE_TYPE_TOK); cfg_node_set(n, CFG_NODE_ATTR_TOKEN, $1); @ 1.1 log @Add this first cut for the forthcoming OSSP cfg library to CVS. This is work in progress and still not ready for use anywhere. @ text @d111 1 d134 1 @