summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-07-02 23:39:35 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-07-02 23:39:44 +0100
commit7d46c921cb828b289005228123cbfc6ed463b912 (patch)
tree532b3f858c585168c2a96ba8783788a9d7eb9f17
parent09a079cb106c11d1f187717b825b133b68f2c46d (diff)
eolian: column information in error messages
-rw-r--r--src/lib/eolian/eo_lexer.c49
-rw-r--r--src/lib/eolian/eo_lexer.h1
-rw-r--r--src/lib/eolian/eo_parser.c6
3 files changed, 49 insertions, 7 deletions
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c
index 7cdbeef0d7..d68e4e477e 100644
--- a/src/lib/eolian/eo_lexer.c
+++ b/src/lib/eolian/eo_lexer.c
@@ -8,12 +8,38 @@
8 8
9int _eo_lexer_log_dom = -1; 9int _eo_lexer_log_dom = -1;
10 10
11static void next_char(Eo_Lexer *ls) 11static int
12get_nbytes(int c)
12{ 13{
14 if (c < 192) return 1;
15 if (c < 224) return 2;
16 if (c < 240) return 3;
17 return 4;
18}
19
20static int lastbytes = 0;
21
22static void
23next_char(Eo_Lexer *ls)
24{
25 int nb;
26
13 if (ls->stream == ls->stream_end) 27 if (ls->stream == ls->stream_end)
14 ls->current = '\0'; 28 ls->current = '\0';
15 else 29 else
16 ls->current = *(ls->stream++); 30 ls->current = *(ls->stream++);
31
32 nb = lastbytes;
33 if (!nb) nb = get_nbytes(ls->current);
34
35 if (nb == 1)
36 {
37 nb = 0;
38 ++ls->column;
39 }
40 else --nb;
41
42 lastbytes = nb;
17} 43}
18 44
19#define KW(x) #x 45#define KW(x) #x
@@ -103,6 +129,7 @@ static void next_line(Eo_Lexer *ls)
103 next_char(ls); 129 next_char(ls);
104 if (++ls->line_number >= INT_MAX) 130 if (++ls->line_number >= INT_MAX)
105 eo_lexer_syntax_error(ls, "chunk has too many lines"); 131 eo_lexer_syntax_error(ls, "chunk has too many lines");
132 ls->column = 0;
106} 133}
107 134
108/* go to next line and strip leading whitespace */ 135/* go to next line and strip leading whitespace */
@@ -192,6 +219,7 @@ lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars)
192 || ls->current == '@' 219 || ls->current == '@'
193 || strchr(chars, ls->current))) 220 || strchr(chars, ls->current)))
194 { 221 {
222 int col = ls->column;
195 Eina_Bool at_kw = (ls->current == '@'); 223 Eina_Bool at_kw = (ls->current == '@');
196 const char *str; 224 const char *str;
197 eina_strbuf_reset(ls->buff); 225 eina_strbuf_reset(ls->buff);
@@ -205,6 +233,7 @@ lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars)
205 str = eina_strbuf_string_get(ls->buff); 233 str = eina_strbuf_string_get(ls->buff);
206 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, 234 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map,
207 str); 235 str);
236 ls->column = col;
208 if (at_kw && *kwid == 0) 237 if (at_kw && *kwid == 0)
209 eo_lexer_syntax_error(ls, "invalid keyword"); 238 eo_lexer_syntax_error(ls, "invalid keyword");
210 *value = str; 239 *value = str;
@@ -223,9 +252,12 @@ lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars)
223static int 252static int
224lex_balanced(Eo_Lexer *ls, const char **value, int *kwid, char beg, char end) 253lex_balanced(Eo_Lexer *ls, const char **value, int *kwid, char beg, char end)
225{ 254{
226 int depth = 0; 255 int depth = 0, col;
227 const char *str; 256 const char *str;
228 eina_strbuf_reset(ls->buff); 257 eina_strbuf_reset(ls->buff);
258 while (isspace(ls->current))
259 next_char(ls);
260 col = ls->column;
229 while (ls->current) 261 while (ls->current)
230 { 262 {
231 if (ls->current == beg) 263 if (ls->current == beg)
@@ -243,14 +275,19 @@ lex_balanced(Eo_Lexer *ls, const char **value, int *kwid, char beg, char end)
243 str = eina_strbuf_string_get(ls->buff); 275 str = eina_strbuf_string_get(ls->buff);
244 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, str); 276 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, str);
245 *value = str; 277 *value = str;
278 ls->column = col;
246 return TOK_VALUE; 279 return TOK_VALUE;
247} 280}
248 281
249static int 282static int
250lex_until(Eo_Lexer *ls, const char **value, int *kwid, char end) 283lex_until(Eo_Lexer *ls, const char **value, int *kwid, char end)
251{ 284{
285 int col;
252 const char *str; 286 const char *str;
253 eina_strbuf_reset(ls->buff); 287 eina_strbuf_reset(ls->buff);
288 while (isspace(ls->current))
289 next_char(ls);
290 col = ls->column;
254 while (ls->current) 291 while (ls->current)
255 { 292 {
256 if (ls->current == end) 293 if (ls->current == end)
@@ -262,6 +299,7 @@ lex_until(Eo_Lexer *ls, const char **value, int *kwid, char end)
262 str = eina_strbuf_string_get(ls->buff); 299 str = eina_strbuf_string_get(ls->buff);
263 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, str); 300 *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, str);
264 *value = str; 301 *value = str;
302 ls->column = col;
265 return TOK_VALUE; 303 return TOK_VALUE;
266} 304}
267 305
@@ -278,6 +316,7 @@ eo_lexer_set_input(Eo_Lexer *ls, const char *source)
278 ls->stream_end = ls->stream + eina_file_size_get(f); 316 ls->stream_end = ls->stream + eina_file_size_get(f);
279 ls->source = eina_stringshare_add(source); 317 ls->source = eina_stringshare_add(source);
280 ls->line_number = 1; 318 ls->line_number = 1;
319 ls->column = 0;
281 next_char(ls); 320 next_char(ls);
282} 321}
283 322
@@ -380,11 +419,11 @@ eo_lexer_lex_error(Eo_Lexer *ls, const char *msg, int token)
380 { 419 {
381 char buf[256]; 420 char buf[256];
382 txt_token(ls, token, buf); 421 txt_token(ls, token, buf);
383 throw(ls, "%s:%d: %s near '%s'\n", ls->source, ls->line_number, msg, 422 throw(ls, "%s:%d:%d: %s near '%s'\n", ls->source, ls->line_number,
384 buf); 423 ls->column, msg, buf);
385 } 424 }
386 else 425 else
387 throw(ls, "%s:%d: %s\n", ls->source, ls->line_number, msg); 426 throw(ls, "%s:%d:%d: %s\n", ls->source, ls->line_number, ls->column, msg);
388} 427}
389 428
390void 429void
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index de47dc3fdd..d4a2ee2fbb 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -72,6 +72,7 @@ typedef struct _Eo_Node
72typedef struct _Eo_Lexer 72typedef struct _Eo_Lexer
73{ 73{
74 int current; 74 int current;
75 int column;
75 int line_number; 76 int line_number;
76 Eo_Token t, lookahead; 77 Eo_Token t, lookahead;
77 Eina_Strbuf *buff; 78 Eina_Strbuf *buff;
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 4fe98818a3..b16ef18b8c 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -149,11 +149,12 @@ static Eo_Type_Def *parse_type_void(Eo_Lexer *ls);
149static Eo_Type_Def * 149static Eo_Type_Def *
150parse_type(Eo_Lexer *ls) 150parse_type(Eo_Lexer *ls)
151{ 151{
152 int line = ls->line_number; 152 int line = ls->line_number, column = ls->column;
153 Eo_Type_Def *ret = parse_type_void(ls); 153 Eo_Type_Def *ret = parse_type_void(ls);
154 if (ret->type == EOLIAN_TYPE_VOID) 154 if (ret->type == EOLIAN_TYPE_VOID)
155 { 155 {
156 ls->line_number = line; 156 ls->line_number = line;
157 ls->column = column;
157 eo_lexer_syntax_error(ls, "non-void type expected"); 158 eo_lexer_syntax_error(ls, "non-void type expected");
158 } 159 }
159 return ret; 160 return ret;
@@ -203,7 +204,7 @@ parse_type_void(Eo_Lexer *ls)
203 } 204 }
204 case KW_own: 205 case KW_own:
205 { 206 {
206 int sline = ls->line_number, line; 207 int sline = ls->line_number, column = ls->column, line;
207 eo_lexer_get(ls); 208 eo_lexer_get(ls);
208 line = ls->line_number; 209 line = ls->line_number;
209 check_next(ls, '('); 210 check_next(ls, '(');
@@ -211,6 +212,7 @@ parse_type_void(Eo_Lexer *ls)
211 if (def->type != EOLIAN_TYPE_POINTER) 212 if (def->type != EOLIAN_TYPE_POINTER)
212 { 213 {
213 ls->line_number = sline; 214 ls->line_number = sline;
215 ls->column = column;
214 eo_lexer_syntax_error(ls, "pointer type expected"); 216 eo_lexer_syntax_error(ls, "pointer type expected");
215 } 217 }
216 def->is_own = EINA_TRUE; 218 def->is_own = EINA_TRUE;