diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-26 15:18:29 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-06-26 21:23:42 +0300 |
commit | 440771ca0056eb20396e24f03d349a75ee1c9d22 (patch) | |
tree | 3ec58a85e96d21a855ad3dcefaa8adc51039fc38 /src/grecs-gram.y | |
parent | 4c1959a4848c30206de3be4b16bdf04b650daae8 (diff) | |
download | grecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.gz grecs-440771ca0056eb20396e24f03d349a75ee1c9d22.tar.bz2 |
Keep track of columns in the node and value locations. Improve error diagnostics.
* src/grecs.h (grecs_locus_point): New struct.
(grecs_locus_point_advance_line): New macro.
(grecs_locus_t): Redesign.
(grecs_value) <locus>: New member.
(grecs_node) <idloc>: New member.
(grecs_print_diag_fun): Change signature.
(grecs_warning,grecs_error): Change signature.
(grecs_parse_line_directive)
(grecs_parse_line_directive_cpp)
(grecs_string_convert): Change signature.
(grecs_current_locus): Remove.
(grecs_current_locus_point): New extern.
* src/grecs-locus.h: New file.
* src/Make.am (noinst_HEADERS): Add grecs-locus.h.
* src/join.c (reset_locus): Rewrite.
* src/lookup.c: Initialize new members of grecs_value and grecs_node.
(split_cfg_path): Return wrdse error code.
(grecs_node_from_path_locus): Take two grecs_locus_t arguments.
Make sure all created nodes have their locus members
properly initialized.
* src/parser.c (grecs_parse): Initialize grecs_current_locus_point.
* src/tree.c (grecs_node_create_points): New function.
(string_to_bool,string_to_host,string_to_sockaddr)
(grecs_string_convert): Change signatures. Be more precise in
what locus to report.
* src/diag.c (default_print_diag): Use YY_LOCATION_PRINT to
output locus.
(grecs_print_diag_fun): Change signature.
(grecs_warning,grecs_error): Change signature.
* src/format.c (grecs_format_locus): Rewrite.
(grecs_format_node): Be more precise in what locus is being
output.
* src/bind-gram.y: Keep track of locations. Turn on error-verbose mode.
* src/grecs-gram.y: Likewise.
* src/meta1-gram.y: Likewise.
* src/bind-lex.l: Keep track of locations.
* src/git-parser.c: Likewise.
* src/grecs-lex.l: Likewise.
* src/meta1-lex.l: Likewise.
* src/path-parser.c: Likewise.
* src/preproc.c: Likewise.
* tests/gcf1.conf: Untabify.
* tests/format01.at: Reflect changes in the output.
* tests/join.at: Likewise.
* tests/set.at: Likewise.
* tests/locus-bind.at: New testcase.
* tests/locus-git.at: New testcase.
* tests/locus-meta1.at: New testcase.
* tests/locus00.at: New testcase.
* tests/locus01.at: New testcase.
* tests/locus02.at: New testcase.
* tests/path-locus.at: New testcase.
Diffstat (limited to 'src/grecs-gram.y')
-rw-r--r-- | src/grecs-gram.y | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/grecs-gram.y b/src/grecs-gram.y index bbe3d5e..92de6b2 100644 --- a/src/grecs-gram.y +++ b/src/grecs-gram.y @@ -19,6 +19,7 @@ # include <config.h> #endif #include <grecs.h> +#include <grecs-locus.h> #include <grecs-gram.h> #include <stdlib.h> #include <stdarg.h> @@ -31,11 +32,10 @@ int yyerror(char *s); static struct grecs_node *parse_tree; %} +%error-verbose +%locations + %union { - struct { - grecs_locus_t locus; - char *string; - } ident; char *string; grecs_value_t svalue, *pvalue; struct grecs_list *list; @@ -44,8 +44,7 @@ static struct grecs_node *parse_tree; struct { struct grecs_node *head, *tail; } node_list; } -%token <ident> IDENT -%token <string> STRING QSTRING MSTRING +%token <string> STRING QSTRING MSTRING IDENT %type <string> string slist %type <list> slist0 %type <svalue> value @@ -58,8 +57,7 @@ static struct grecs_node *parse_tree; 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); } @@ -92,25 +90,27 @@ stmt : simple simple : IDENT vallist ';' { - $$ = 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; } | IDENT ';' { - $$ = grecs_node_create(grecs_node_stmt, - &$1.locus); - $$->ident = $1.string; + $$ = grecs_node_create(grecs_node_stmt, &@1); + $$->ident = $1; + $$->idloc = @1; $$->v.value = NULL; } ; block : IDENT tag '{' stmtlist '}' opt_sc { - $$ = 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.head, 1); } @@ -135,6 +135,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])); @@ -160,25 +161,25 @@ vlist : value value : string { $$.type = GRECS_TYPE_STRING; + $$.locus = @1; $$.v.string = $1; } | list { $$.type = GRECS_TYPE_LIST; + $$.locus = @1; $$.v.list = $1; } | MSTRING { $$.type = GRECS_TYPE_STRING; + $$.locus = @1; $$.v.string = $1; } ; string : STRING | IDENT - { - $$ = $1.string; - } | slist ; @@ -244,7 +245,7 @@ opt_sc : /* empty */ int yyerror(char *s) { - grecs_error(&grecs_current_locus, 0, "%s", s); + grecs_error(&yylloc, 0, "%s", s); return 0; } |