aboutsummaryrefslogtreecommitdiff
path: root/src/meta1lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/meta1lex.l')
-rw-r--r--src/meta1lex.l55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/meta1lex.l b/src/meta1lex.l
index 4eca9e2..7faaf41 100644
--- a/src/meta1lex.l
+++ b/src/meta1lex.l
@@ -1,10 +1,10 @@
/* MeTA1 configuration lexer for GNU Pies. -*- c -*- */
%top {
/* MeTA1 configuration lexer for GNU Pies.
- Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff
+ Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
GNU Pies 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; either version 3, or (at your option)
any later version.
@@ -23,35 +23,46 @@
# include <config.h>
#endif
}
%{
#include "pies.h"
+#include "grecs-locus.h"
#include "meta1gram.h"
#include "meta1lex.h"
-grecs_locus_t meta1_locus;
-size_t meta1_error_count;
+static struct grecs_locus_point meta1_locus_point;
struct obstack meta1_stk;
int meta1_stk_init;
char *meta1_queue_dir;
-
#define yylval meta1lval
+
+#define YY_USER_ACTION do \
+ { \
+ if (YYSTATE == 0) \
+ { \
+ meta1lloc.beg = meta1_locus_point; \
+ meta1lloc.beg.col++; \
+ } \
+ meta1_locus_point.col += yyleng; \
+ meta1lloc.end = meta1_locus_point; \
+ } \
+ while (0);
%}
%x COMMENT STR
X [0-9a-fA-F]
%%
/* C-style comments */
"/*" BEGIN (COMMENT);
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
-<COMMENT>\n ++meta1_locus.line;
+<COMMENT>\n grecs_locus_point_advance_line(meta1_locus_point);
<COMMENT>"*"+"/" BEGIN (INITIAL);
/* End-of-line comments */
-#.*\n { meta1_locus.line++; }
+#.*\n grecs_locus_point_advance_line(meta1_locus_point);
#.* /* end-of-file comment */;
/* Number */
0[xX]{X}+ |
0[0-7]+ |
[1-9][0-9]+ { meta1_line_begin ();
meta1_line_add (yytext, yyleng);
@@ -79,24 +90,24 @@ X [0-9a-fA-F]
<STR>[^\\"\n]*\" { BEGIN (INITIAL);
if (yyleng > 1)
meta1_line_add (yytext, yyleng - 1);
yylval.string = meta1_line_finish ();
return META1_STRING; }
<STR>[^\\"\n]*\n { BEGIN (INITIAL);
- meta1_parse_error (_("newline in a string"));
+ grecs_error (&meta1lloc, 0, _("newline in a string"));
meta1_line_add (yytext, yyleng - 1);
yylval.string = meta1_line_finish ();
return META1_STRING; }
/* Other tokens */
[ \t\f][ \t\f]* ;
-\n { meta1_locus.line++; }
+\n grecs_locus_point_advance_line(meta1_locus_point);
[,;{}=] return yytext[0];
. { if (isascii (yytext[0]) && isprint (yytext[0]))
- meta1_parse_error (_("stray character %c"), yytext[0]);
+ grecs_error (&meta1lloc, 0, _("stray character %c"), yytext[0]);
else
- meta1_parse_error (_("stray character \\%03o"),
+ grecs_error (&meta1lloc, 0, _("stray character \\%03o"),
(unsigned char) yytext[0]); }
%%
int
yywrap ()
{
@@ -132,13 +143,13 @@ unescape_to_line (int c)
if (c == 'v')
t = '\v';
else
{
t = unescape_char (c);
if (t == c && t != '\\' && t != '\"')
- meta1_parse_error (_("unknown escape sequence '\\%c'"), c);
+ grecs_error (&meta1lloc, 0, _("unknown escape sequence '\\%c'"), c);
}
obstack_1grow (&meta1_stk, t);
}
void
meta1_line_add_unescape_last (const char *text, size_t len)
@@ -179,26 +190,12 @@ meta1_string (const char *str, size_t len)
meta1_line_begin ();
meta1_line_add (str, len);
return meta1_line_finish ();
}
void
-meta1_parse_error (const char *fmt, ...)
-{
- va_list ap;
-
- logmsg_printf (LOG_ERR, "%s:%lu: ", meta1_locus.file,
- (unsigned long) meta1_locus.line);
- va_start (ap, fmt);
- logmsg_vprintf (LOG_ERR, fmt, ap);
- va_end (ap);
- logmsg_printf (LOG_ERR, "\n");
- meta1_error_count++;
-}
-
-void
meta1_lexer_set_debug ()
{
char *p = getenv ("META1_DEBUG_LEX");
yy_flex_debug = p && (*p - '0') > 0;
}
@@ -214,21 +211,23 @@ meta1_config_parse (const char *name)
if (!fp)
{
logmsg (LOG_ERR,
_("%s: cannot open file: %s"), name, strerror (errno));
return 1;
}
- meta1_locus.file = meta1_string (name, strlen (name));
- meta1_locus.line = 1;
+ meta1_locus_point.file = meta1_string (name, strlen (name));
+ meta1_locus_point.line = 1;
+ meta1_locus_point.col = 0;
meta1_lexer_set_debug ();
meta1_parser_set_debug ();
yyrestart (fp);
+ grecs_error_count = 0;
rc = meta1parse ();
fclose (fp);
- if (meta1_error_count)
+ if (grecs_error_count)
rc = 1;
return rc;
}

Return to:

Send suggestions and report system problems to the System administrator.