diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2010-11-11 19:15:28 -0800 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2010-11-11 19:15:28 -0800 |
commit | 91eb09a12a040795a2aca06de050b4507af93790 (patch) | |
tree | ec99bf559a02e8e31cd1dbeac6e08ac4ead0202f /src/cparse/cparse.ypp | |
parent | 0f5de703f7641cf583b907c047df98b1014d5653 (diff) | |
download | vyatta-cfg-91eb09a12a040795a2aca06de050b4507af93790.tar.gz vyatta-cfg-91eb09a12a040795a2aca06de050b4507af93790.zip |
continue config parser work
* add parser to package build.
* add prefix, error handling, etc.
* fix handling of empty and 1-char values in lex.
* add API function.
Diffstat (limited to 'src/cparse/cparse.ypp')
-rw-r--r-- | src/cparse/cparse.ypp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/cparse/cparse.ypp b/src/cparse/cparse.ypp index eef3d13..eb2ab12 100644 --- a/src/cparse/cparse.ypp +++ b/src/cparse/cparse.ypp @@ -1,16 +1,22 @@ -/* bison -v -t --defines=cparse.h -o cparse.cpp cparse.ypp */ %{ -#include <stdio.h> +#include <cstdio> + +#include "cparse.hpp" #include "cparse_def.h" +// stuff from lex extern "C" { -int yylex(); +extern int cparse_lineno; +extern char *cparse_text; +int cparse_lex(); +void cparse_set_in(FILE *fin); } -void -yyerror(const char *s) +static void +cparse_error(const char *s) { - printf("%s\n", s); + printf("Invalid config file (%s): error at line %d, text [%s]\n", + s, cparse_lineno, cparse_text); } int level = 0; @@ -19,7 +25,7 @@ char *ncomment = NULL; char *nname = NULL; char *nval = NULL; -void +static void print_node() { int i = 0; @@ -47,6 +53,7 @@ print_node() %token COMMENT %token LEFTB %token RIGHTB +%token SYNTAX_ERROR %% @@ -93,8 +100,9 @@ comment: COMMENT %% int -main() +cparse::parse_file(FILE *fin) { - return yyparse(); + cparse_set_in(fin); + return cparse_parse(); } |