summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-29 16:10:40 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-29 16:10:40 +0100
commit5cdf202ee4c81afcd5a18749a09eab9724a76402 (patch)
tree19f1ca61d715402e4245abd926c6b6eb1af8d1a4
parent8a6e542fefcd0d4dc3c876c1da51f18e2b0e8f44 (diff)
eolian: more advanced comment parsing (properly skip asterisks etc)
-rw-r--r--src/lib/eolian/eo_lexer.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c
index 7b79d23cad..32be9f90fa 100644
--- a/src/lib/eolian/eo_lexer.c
+++ b/src/lib/eolian/eo_lexer.c
@@ -158,21 +158,52 @@ static void next_line(Eo_Lexer *ls)
158 ls->icolumn = ls->column = 0; 158 ls->icolumn = ls->column = 0;
159} 159}
160 160
161static void skip_ws(Eo_Lexer *ls)
162{
163 while (isspace(ls->current) && !is_newline(ls->current))
164 next_char(ls);
165}
166
161/* go to next line and strip leading whitespace */ 167/* go to next line and strip leading whitespace */
162static void next_line_ws(Eo_Lexer *ls) 168static void next_line_ws(Eo_Lexer *ls)
163{ 169{
164 next_line(ls); 170 next_line(ls);
165 while (isspace(ls->current) && !is_newline(ls->current)) 171 skip_ws(ls);
166 next_char(ls); 172}
173
174static Eina_Bool
175should_skip_star(Eo_Lexer *ls, int ccol, Eina_Bool *term)
176{
177 Eina_Bool had_star = EINA_FALSE;
178 if (ls->column == ccol && ls->current == '*')
179 {
180 had_star = EINA_TRUE;
181 next_char(ls);
182 if (ls->current == '/')
183 {
184 next_char(ls);
185 *term = EINA_TRUE;
186 return EINA_FALSE;
187 }
188 skip_ws(ls);
189 }
190 return had_star;
167} 191}
168 192
169static void 193static void
170read_long_comment(Eo_Lexer *ls, Eo_Token *tok) 194read_long_comment(Eo_Lexer *ls, Eo_Token *tok, int ccol)
171{ 195{
196 Eina_Bool had_star = EINA_FALSE, had_nl = EINA_FALSE;
172 eina_strbuf_reset(ls->buff); 197 eina_strbuf_reset(ls->buff);
173 198
174 if (is_newline(ls->current)) 199 if (is_newline(ls->current))
175 next_line_ws(ls); 200 {
201 Eina_Bool term = EINA_FALSE;
202 had_nl = EINA_TRUE;
203 next_line_ws(ls);
204 had_star = should_skip_star(ls, ccol, &term);
205 if (term) goto cend;
206 }
176 207
177 for (;;) 208 for (;;)
178 { 209 {
@@ -192,6 +223,23 @@ read_long_comment(Eo_Lexer *ls, Eo_Token *tok)
192 { 223 {
193 eina_strbuf_append_char(ls->buff, '\n'); 224 eina_strbuf_append_char(ls->buff, '\n');
194 next_line_ws(ls); 225 next_line_ws(ls);
226 if (!had_nl)
227 {
228 Eina_Bool term = EINA_FALSE;
229 had_nl = EINA_TRUE;
230 had_star = should_skip_star(ls, ccol, &term);
231 if (term) break;
232 }
233 else if (had_star && ls->column == ccol && ls->current == '*')
234 {
235 next_char(ls);
236 if (ls->current == '/')
237 {
238 next_char(ls);
239 break;
240 }
241 skip_ws(ls);
242 }
195 } 243 }
196 else 244 else
197 { 245 {
@@ -199,6 +247,7 @@ read_long_comment(Eo_Lexer *ls, Eo_Token *tok)
199 next_char(ls); 247 next_char(ls);
200 } 248 }
201 } 249 }
250cend:
202 eina_strbuf_trim(ls->buff); 251 eina_strbuf_trim(ls->buff);
203 if (tok) tok->value.s = eina_stringshare_add(eina_strbuf_string_get(ls->buff)); 252 if (tok) tok->value.s = eina_stringshare_add(eina_strbuf_string_get(ls->buff));
204} 253}
@@ -472,10 +521,11 @@ lex(Eo_Lexer *ls, Eo_Token *tok)
472 next_char(ls); 521 next_char(ls);
473 if (ls->current == '*') 522 if (ls->current == '*')
474 { 523 {
524 int ccol = ls->column;
475 next_char(ls); 525 next_char(ls);
476 if ((doc = (ls->current == '@'))) 526 if ((doc = (ls->current == '@')))
477 next_char(ls); 527 next_char(ls);
478 read_long_comment(ls, doc ? tok : NULL); 528 read_long_comment(ls, doc ? tok : NULL, ccol);
479 if (doc) 529 if (doc)
480 return TOK_COMMENT; 530 return TOK_COMMENT;
481 else 531 else