eolian: validate eo/legacy prefix to be [a-z_][a-z0-9_]*

This commit is contained in:
Daniel Kolesa 2016-03-07 15:01:13 +00:00
parent 2ae2790604
commit bf2c0c3405
1 changed files with 26 additions and 2 deletions

View File

@ -1642,6 +1642,30 @@ parse_events(Eo_Lexer *ls)
check_match(ls, '}', '{', line, col);
}
static void
_validate_pfx(Eo_Lexer *ls)
{
char ebuf[PATH_MAX];
check(ls, TOK_VALUE);
const char *str = ls->t.value.s;
if ((*str != '_') && ((*str < 'a') || (*str > 'z')))
goto error;
for (++str; *str; ++str)
{
if (*str == '_')
continue;
if ((*str >= 'a') && (*str <= 'z'))
continue;
if ((*str >= '0') && (*str <= '9'))
continue;
goto error;
}
return;
error:
snprintf(ebuf, sizeof(ebuf), "invalid prefix '%s'", ls->t.value.s);
eo_lexer_syntax_error(ls, ebuf);
}
static void
parse_class_body(Eo_Lexer *ls, Eolian_Class_Type type)
{
@ -1663,7 +1687,7 @@ parse_class_body(Eo_Lexer *ls, Eolian_Class_Type type)
CASE_LOCK(ls, legacy_prefix, "legacy prefix definition")
eo_lexer_get(ls);
check_next(ls, ':');
check(ls, TOK_VALUE);
_validate_pfx(ls);
ls->tmp.kls->legacy_prefix = eina_stringshare_ref(ls->t.value.s);
eo_lexer_get(ls);
check_next(ls, ';');
@ -1672,7 +1696,7 @@ parse_class_body(Eo_Lexer *ls, Eolian_Class_Type type)
CASE_LOCK(ls, eo_prefix, "eo prefix definition")
eo_lexer_get(ls);
check_next(ls, ':');
check(ls, TOK_VALUE);
_validate_pfx(ls);
ls->tmp.kls->eo_prefix = eina_stringshare_ref(ls->t.value.s);
eo_lexer_get(ls);
check_next(ls, ';');