+/**
+ * oconfig - src/parser.y
+ * Copyright (C) 2007 Florian octo Forster <octo at verplant.org>
+ *
+ * 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 <stdlib.h>
#include <string.h>
#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
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)
{
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 ("<unknown type %i>", cv.type);
- }
- printf ("\n");
-
- for (i = 0; i < ci->children_num; i++)
- dump_ci (ci->children + i, shift + 1);
-}
+/**
+ * oconfig - src/scanner.l
+ * Copyright (C) 2007 Florian octo Forster <octo at verplant.org>
+ *
+ * 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 <stdlib.h>
#include "oconfig.h"
#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]+
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);}
-
%%