From: Florian Forster Date: Sun, 11 Feb 2007 16:53:28 +0000 (+0100) Subject: Adjustments of the language, added copyright notice and license information, ... X-Git-Tag: liboconfig-0.1.0^0 X-Git-Url: https://git.octo.it/?p=liboconfig.git;a=commitdiff_plain;h=d7ead7bd0d32daa0b8ca55213b18ba7e327648f0 Adjustments of the language, added copyright notice and license information, ... --- diff --git a/src/parser.y b/src/parser.y index 7f048d0..6d1de2d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,3 +1,21 @@ +/** + * oconfig - src/parser.y + * Copyright (C) 2007 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + %{ #include #include @@ -5,7 +23,13 @@ #include "aux_types.h" static char *unquote (const char *orig); -static void dump_ci (oconfig_item_t *ci, int shift); +static int yyerror (const char *s); + +/* Lexer variables */ +extern int yylineno; +extern char *yytext; + +extern oconfig_item_t *ci_root; %} %start entire_file @@ -151,15 +175,19 @@ statement_list: entire_file: statement_list { - $$.children = $1.statement; - $$.children_num = $1.statement_num; + ci_root = malloc (sizeof (oconfig_item_t)); + memset (ci_root, '\0', sizeof (oconfig_item_t)); + ci_root->children = $1.statement; + ci_root->children_num = $1.statement_num; } ; %% -#if 0 -#include "scanner.c" -#endif +static int yyerror (const char *s) +{ + fprintf (stderr, "Error in line %i near `%s': %s\n", yylineno, yytext, s); + return (-1); +} /* int yyerror */ static char *unquote (const char *orig) { @@ -190,30 +218,3 @@ static char *unquote (const char *orig) return (ret); } /* char *unquote */ - -static void dump_ci (oconfig_item_t *ci, int shift) -{ - int i; - - if (shift > 0) - printf ("%*s", shift, ""); - - printf ("%s", ci->key); - for (i = 0; i < ci->values_num; i++) - { - oconfig_value_t cv = ci->values[i]; - - if (cv.type == OCONFIG_TYPE_STRING) - printf (" `%s'", cv.value.string); - else if (cv.type == OCONFIG_TYPE_NUMBER) - printf (" %lf", cv.value.number); - else if (cv.type == OCONFIG_TYPE_BOOLEAN) - printf (" %s", cv.value.boolean ? "true" : "false"); - else - printf ("", cv.type); - } - printf ("\n"); - - for (i = 0; i < ci->children_num; i++) - dump_ci (ci->children + i, shift + 1); -} diff --git a/src/scanner.l b/src/scanner.l index 1205508..aa111a2 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -1,3 +1,21 @@ +/** + * oconfig - src/scanner.l + * Copyright (C) 2007 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + %{ #include #include "oconfig.h" @@ -5,9 +23,8 @@ #include "parser.h" %} WHITE_SPACE [\ \t\b] -ALNUM [A-Za-z0-9_] -QUOTED_STRING \"([^\"]+|\\.)*\" -UNQUOTED_STRING {ALNUM}+ +QUOTED_STRING \"([^\\"]+|\\.)*\" +UNQUOTED_STRING [0-9A-Za-z_]+ HEX_NUMBER 0[xX][0-9a-fA-F]+ OCT_NUMBER 0[0-7]+ DEC_NUMBER [\+\-]?[0-9]+ @@ -16,20 +33,25 @@ NUMBER ({FLOAT_NUMBER}|{HEX_NUMBER}|{OCT_NUMBER}|{DEC_NUMBER}) BOOL_TRUE (true|yes|on) BOOL_FALSE (false|no|off) COMMENT #.* +PORT (6(5(5(3[0-5]|[0-2][0-9])|[0-4][0-9][0-9])|[0-4][0-9][0-9][0-9])|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9]?[0-9]?[0-9]?) +IP_BYTE (2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]) +IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})? %% -{WHITE_SPACE} | -{COMMENT} {/* nothing */} +{WHITE_SPACE} | +{COMMENT} {/* ignore */} \n {return (EOL);} "/" {return (SLASH);} "<" {return (OPENBRAC);} ">" {return (CLOSEBRAC);} -{NUMBER} {yylval.number = strtod (yytext, NULL); return (NUMBER);} {BOOL_TRUE} {yylval.boolean = 1; return (TRUE);} {BOOL_FALSE} {yylval.boolean = 0; return (FALSE);} +{IPV4_ADDR} {yylval.string = yytext; return (UNQUOTED_STRING);} + +{NUMBER} {yylval.number = strtod (yytext, NULL); return (NUMBER);} + {QUOTED_STRING} {yylval.string = yytext; return (QUOTED_STRING);} {UNQUOTED_STRING} {yylval.string = yytext; return (UNQUOTED_STRING);} - %%