diff options
Diffstat (limited to 'src/bind-gram.y')
-rw-r--r-- | src/bind-gram.y | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/src/bind-gram.y b/src/bind-gram.y index c751ae1..e353a54 100644 --- a/src/bind-gram.y +++ b/src/bind-gram.y @@ -19,7 +19,8 @@ # include <config.h> #endif #include <grecs.h> -#include <grecs-gram.h> +#include <grecs-locus.h> +#include <bind-gram.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> @@ -30,17 +31,16 @@ int yyerror(char *s); static struct grecs_node *parse_tree; extern int yy_flex_debug; -extern int grecs_bind_new_source(const char *name); +extern int grecs_bind_new_source(const char *name, grecs_locus_t *loc); extern void grecs_bind_close_sources(void); static struct grecs_value *stmtlist_to_value(struct grecs_node *node); %} +%error-verbose +%locations + %union { - struct { - grecs_locus_t locus; - char *string; - } ident; char *string; grecs_value_t svalue, *pvalue; struct grecs_list *list; @@ -49,8 +49,7 @@ static struct grecs_value *stmtlist_to_value(struct grecs_node *node); struct { struct grecs_node *head, *tail; } node_list; } -%token <ident> BIND_IDENT BIND_CONTROLS -%token <string> BIND_STRING +%token <string> BIND_STRING BIND_IDENT BIND_CONTROLS %type <string> string %type <svalue> value ctlsub %type <pvalue> vallist tag @@ -62,8 +61,7 @@ static struct grecs_value *stmtlist_to_value(struct grecs_node *node); input : maybe_stmtlist { - parse_tree = grecs_node_create(grecs_node_root, - &grecs_current_locus); + parse_tree = grecs_node_create(grecs_node_root, &@1); parse_tree->v.texttab = grecs_text_table(); grecs_node_bind(parse_tree, $1, 1); } @@ -102,38 +100,44 @@ stmt : simple simple : BIND_IDENT vallist ';' { - if (strcmp($1.string, "include") == 0 && + if (strcmp($1, "include") == 0 && $2->type == GRECS_TYPE_STRING) { - grecs_bind_new_source($2->v.string); + grecs_bind_new_source($2->v.string, &@1); $$ = NULL; } else { - $$ = grecs_node_create(grecs_node_stmt, &$1.locus); - $$->ident = $1.string; + $$ = grecs_node_create_points(grecs_node_stmt, + @1.beg, @2.end); + $$->ident = $1; + $$->idloc = @1; $$->v.value = $2; } } | string ';' { - $$ = grecs_node_create(grecs_node_stmt, - &grecs_current_locus); + $$ = grecs_node_create(grecs_node_stmt, &@1); $$->ident = $1; + $$->idloc = @1; $$->v.value = NULL; } | '!' string ';' { - $$ = grecs_node_create(grecs_node_stmt, - &grecs_current_locus); - $$->ident = grecs_strdup("!"); - $$->v.value = grecs_malloc(sizeof($$->v.value[0])); - $$->v.value->type = GRECS_TYPE_STRING; - $$->v.value->v.string = $2; + $$ = grecs_node_create_points(grecs_node_stmt, + @1.beg, @2.end); + $$->ident = grecs_strdup("!"); + $$->idloc = @1; + $$->v.value = grecs_malloc(sizeof($$->v.value[0])); + $$->v.value->type = GRECS_TYPE_STRING; + $$->v.value->locus = @2; + $$->v.value->v.string = $2; } ; block : BIND_IDENT tag '{' maybe_stmtlist '}' ';' { - $$ = grecs_node_create(grecs_node_block, &$1.locus); - $$->ident = $1.string; + $$ = grecs_node_create_points(grecs_node_block, + @1.beg, @5.end); + $$->ident = $1; + $$->idloc = @1; $$->v.value = $2; grecs_node_bind($$, $4, 1); } @@ -151,8 +155,10 @@ block : BIND_IDENT tag '{' maybe_stmtlist '}' ';' (127.0.0.1, 127.0.0.2), keys, (rndc-key)) */ { - $$ = grecs_node_create(grecs_node_stmt, &$1.locus); - $$->ident = $1.string; + $$ = grecs_node_create_points(grecs_node_stmt, + @1.beg, @4.end); + $$->ident = $1; + $$->idloc = @1; $$->v.value = grecs_value_ptr_from_static(&$3); } ; @@ -176,6 +182,7 @@ vallist : vlist $$ = grecs_malloc(sizeof($$[0])); $$->type = GRECS_TYPE_ARRAY; + $$->locus = @1; $$->v.arg.c = n; $$->v.arg.v = grecs_calloc(n, sizeof($$->v.arg.v[0])); @@ -201,20 +208,19 @@ vlist : value value : string { $$.type = GRECS_TYPE_STRING; + $$.locus = @1; $$.v.string = $1; } ; string : BIND_STRING | BIND_IDENT - { - $$ = $1.string; - } ; ctlsub : ctllist ';' { $$.type = GRECS_TYPE_LIST; + $$.locus = @1; $$.v.list = $1; } ; @@ -240,7 +246,7 @@ ctllist : value int yyerror(char *s) { - grecs_error(&grecs_current_locus, 0, "%s", s); + grecs_error(&yylloc, 0, "%s", s); return 0; } @@ -249,7 +255,7 @@ grecs_bind_parser(const char *name, int traceflags) { int rc; - if (grecs_bind_new_source(name)) + if (grecs_bind_new_source(name, NULL)) return NULL; yy_flex_debug = traceflags & GRECS_TRACE_LEX; yydebug = traceflags & GRECS_TRACE_GRAM; |