parser: don't use %locations byacc doesn't support this feature. We print the line/col of the last scanned token instead. This is slightly less in case of *parser* errors (not syntax errors), but I couldn't make it point to another line, and this are pretty cryptic anyways. So it's good enough. Also might be a bit faster, but haven't checked. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/src/xkbcomp/parser-priv.h b/src/xkbcomp/parser-priv.h
index f0d1f22..05e725e 100644
--- a/src/xkbcomp/parser-priv.h
+++ b/src/xkbcomp/parser-priv.h
@@ -33,13 +33,13 @@ struct parser_param;
#include "parser.h"
int
-scanner_error(YYLTYPE *yylloc, struct scanner *scanner, const char *msg);
+scanner_error(struct scanner *scanner, const char *msg);
void
-scanner_warn(YYLTYPE *yylloc, struct scanner *s, const char *msg);
+scanner_warn(struct scanner *s, const char *msg);
int
-_xkbcommon_lex(YYSTYPE *yylval, YYLTYPE *yylloc, struct scanner *scanner);
+_xkbcommon_lex(YYSTYPE *yylval, struct scanner *scanner);
XkbFile *
parse(struct xkb_context *ctx, void *scanner, const char *map);
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 4f69545..8b3ca5b 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -37,16 +37,15 @@ struct parser_param {
};
static void
-_xkbcommon_error(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
+_xkbcommon_error(struct parser_param *param, const char *msg)
{
- scanner_error(loc, param->scanner, msg);
+ scanner_error(param->scanner, msg);
}
#define scanner param->scanner
%}
%pure-parser
-%locations
%lex-param { struct scanner *scanner }
%parse-param { struct parser_param *param }
diff --git a/src/xkbcomp/scanner-utils.h b/src/xkbcomp/scanner-utils.h
index 74870ea..04783ac 100644
--- a/src/xkbcomp/scanner-utils.h
+++ b/src/xkbcomp/scanner-utils.h
@@ -52,6 +52,8 @@ struct scanner {
char buf[1024];
size_t buf_pos;
int line, column;
+ /* The line/column of the start of the current token. */
+ int token_line, token_column;
const char *file_name;
struct xkb_context *ctx;
};
@@ -64,6 +66,7 @@ scanner_init(struct scanner *s, struct xkb_context *ctx,
s->len = len;
s->pos = 0;
s->line = s->column = 1;
+ s->token_line = s->token_column = 1;
s->file_name = file_name;
s->ctx = ctx;
}
diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c
index fa63e10..aef9a62 100644
--- a/src/xkbcomp/scanner.c
+++ b/src/xkbcomp/scanner.c
@@ -26,24 +26,23 @@
#include "scanner-utils.h"
static void
-scanner_log(enum xkb_log_level level, YYLTYPE *yylloc, struct scanner *s,
- const char *msg)
+scanner_log(enum xkb_log_level level, struct scanner *s, const char *msg)
{
xkb_log_cond_level(s->ctx, level, "%s:%d:%d: %s\n", s->file_name,
- yylloc->first_line, yylloc->first_column, msg);
+ s->token_line, s->token_column, msg);
}
int
-scanner_error(YYLTYPE *yylloc, struct scanner *s, const char *msg)
+scanner_error(struct scanner *s, const char *msg)
{
- scanner_log(XKB_LOG_LEVEL_ERROR, yylloc, s, msg);
+ scanner_log(XKB_LOG_LEVEL_ERROR, s, msg);
return ERROR_TOK;
}
void
-scanner_warn(YYLTYPE *yylloc, struct scanner *s, const char *msg)
+scanner_warn(struct scanner *s, const char *msg)
{
- scanner_log(XKB_LOG_LEVEL_WARNING, yylloc, s, msg);
+ scanner_log(XKB_LOG_LEVEL_WARNING, s, msg);
}
static bool
@@ -80,7 +79,7 @@ number(struct scanner *s, int64_t *out, int *out_tok)
}
int
-_xkbcommon_lex(YYSTYPE *yylval, YYLTYPE *yylloc, struct scanner *s)
+_xkbcommon_lex(YYSTYPE *yylval, struct scanner *s)
{
int tok;
@@ -98,8 +97,8 @@ skip_more_whitespace_and_comments:
if (eof(s)) return END_OF_FILE;
/* New token. */
- yylloc->first_line = yylloc->last_line = s->line;
- yylloc->first_column = yylloc->last_column = s->column;
+ s->token_line = s->line;
+ s->token_column = s->column;
s->buf_pos = 0;
/* String literal. */
@@ -117,8 +116,7 @@ skip_more_whitespace_and_comments:
else if (chr(s, 'e')) buf_append(s, '\033');
else if (oct(s, &o)) buf_append(s, (char) o);
else {
- scanner_warn(yylloc, s,
- "unknown escape sequence in string literal");
+ scanner_warn(s, "unknown escape sequence in string literal");
/* Ignore. */
}
} else {
@@ -126,10 +124,10 @@ skip_more_whitespace_and_comments:
}
}
if (!buf_append(s, '\0') || !chr(s, '\"'))
- return scanner_error(yylloc, s, "unterminated string literal");
+ return scanner_error(s, "unterminated string literal");
yylval->str = strdup(s->buf);
if (!yylval->str)
- return scanner_error(yylloc, s, "scanner out of memory");
+ return scanner_error(s, "scanner out of memory");
return STRING;
}
@@ -138,7 +136,7 @@ skip_more_whitespace_and_comments:
while (isgraph(peek(s)) && peek(s) != '>')
buf_append(s, next(s));
if (!buf_append(s, '\0') || !chr(s, '>'))
- return scanner_error(yylloc, s, "unterminated key name literal");
+ return scanner_error(s, "unterminated key name literal");
/* Empty key name literals are allowed. */
yylval->sval = xkb_atom_intern(s->ctx, s->buf, s->buf_pos - 1);
return KEYNAME;
@@ -167,7 +165,7 @@ skip_more_whitespace_and_comments:
while (isalnum(peek(s)) || peek(s) == '_')
buf_append(s, next(s));
if (!buf_append(s, '\0'))
- return scanner_error(yylloc, s, "identifier too long");
+ return scanner_error(s, "identifier too long");
/* Keyword. */
tok = keyword_to_token(s->buf);
@@ -175,18 +173,18 @@ skip_more_whitespace_and_comments:
yylval->str = strdup(s->buf);
if (!yylval->str)
- return scanner_error(yylloc, s, "scanner out of memory");
+ return scanner_error(s, "scanner out of memory");
return IDENT;
}
/* Number literal (hexadecimal / decimal / float). */
if (number(s, &yylval->num, &tok)) {
if (tok == ERROR_TOK)
- return scanner_error(yylloc, s, "malformed number literal");
+ return scanner_error(s, "malformed number literal");
return tok;
}
- return scanner_error(yylloc, s, "unrecognized token");
+ return scanner_error(s, "unrecognized token");
}
XkbFile *