summaryrefslogtreecommitdiffabout
path: root/src/meta1-lex.l
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-26 12:18:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-06-26 18:23:42 (GMT)
commit440771ca0056eb20396e24f03d349a75ee1c9d22 (patch) (side-by-side diff)
tree3ec58a85e96d21a855ad3dcefaa8adc51039fc38 /src/meta1-lex.l
parent4c1959a4848c30206de3be4b16bdf04b650daae8 (diff)
downloadgrecs-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/meta1-lex.l') (more/less context) (ignore whitespace changes)
-rw-r--r--src/meta1-lex.l27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/meta1-lex.l b/src/meta1-lex.l
index cb2931d..04eddb5 100644
--- a/src/meta1-lex.l
+++ b/src/meta1-lex.l
@@ -23,6 +23,7 @@
# include <config.h>
#endif
#include "grecs.h"
+#include "grecs-locus.h"
#include "meta1-gram.h"
#include <ctype.h>
}
@@ -30,6 +31,15 @@
%{
static int yywrap(void);
static void meta1_line_add_unescape_hex(const char *text, size_t len);
+
+#define YY_USER_ACTION do { \
+ if (YYSTATE == 0) { \
+ yylloc.beg = grecs_current_locus_point; \
+ yylloc.beg.col++; \
+ } \
+ grecs_current_locus_point.col += yyleng; \
+ yylloc.end = grecs_current_locus_point; \
+ } while (0);
%}
%x COMMENT STR
@@ -39,10 +49,10 @@ X [0-9a-fA-F]
"/*" BEGIN (COMMENT);
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
-<COMMENT>\n ++grecs_current_locus.line;
+<COMMENT>\n grecs_locus_point_advance_line(grecs_current_locus_point);
<COMMENT>"*"+"/" BEGIN (INITIAL);
/* End-of-line comments */
-#.*\n { grecs_current_locus.line++; }
+#.*\n { grecs_locus_point_advance_line(grecs_current_locus_point); }
#.* /* end-of-file comment */;
/* Number */
0[xX]{X}+ |
@@ -54,8 +64,7 @@ X [0-9a-fA-F]
/* Identifiers (unquoted strings) */
[a-zA-Z0-9_\./:\*-]+ { grecs_line_begin();
grecs_line_add(yytext, yyleng);
- yylval.ident.locus = grecs_current_locus;
- yylval.ident.string = grecs_line_finish();
+ yylval.string = grecs_line_finish();
return META1_IDENT; }
/* Quoted strings */
\"[^\\"\n]*\" { grecs_line_begin();
@@ -78,16 +87,16 @@ X [0-9a-fA-F]
yylval.string = grecs_line_finish();
return META1_STRING; }
<STR>[^\\"\n]*\n { BEGIN(INITIAL);
- grecs_error(&grecs_current_locus, 0,
+ grecs_error(&yylloc, 0,
_("newline in a string"));
- grecs_line_add (yytext, yyleng - 1);
- yylval.string = grecs_line_finish ();
+ grecs_line_add(yytext, yyleng - 1);
+ yylval.string = grecs_line_finish();
return META1_STRING; }
/* Other tokens */
[ \t\f][ \t\f]* ;
-\n { grecs_current_locus.line++; }
+\n { grecs_locus_point_advance_line(grecs_current_locus_point); }
[,;{}=] return yytext[0];
-. { grecs_error(&grecs_current_locus, 0,
+. { grecs_error(&yylloc, 0,
(isascii(yytext[0]) && isprint(yytext[0])) ?
_("stray character %c") :
_("stray character \\%03o"),

Return to:

Send suggestions and report system problems to the System administrator.