eolian: parser cleanup - structs no longer have to lookahead, making our grammar effectively LL(1)

This commit is contained in:
Daniel Kolesa 2014-07-15 17:06:18 +01:00
parent 58f47426a4
commit d0e0576f0b
1 changed files with 15 additions and 19 deletions

View File

@ -275,7 +275,6 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern)
static Eolian_Type * static Eolian_Type *
parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon) parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
{ {
Eina_Bool has_struct = EINA_FALSE;
Eolian_Type *def; Eolian_Type *def;
const char *ctype; const char *ctype;
const char *sname = NULL; const char *sname = NULL;
@ -328,42 +327,39 @@ parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
return parse_struct(ls, NULL, EINA_FALSE); return parse_struct(ls, NULL, EINA_FALSE);
} }
check(ls, TOK_VALUE); check(ls, TOK_VALUE);
if (eo_lexer_get_c_type(ls->t.kw))
eo_lexer_syntax_error(ls, "invalid struct name");
sname = eina_stringshare_add(ls->t.value); sname = eina_stringshare_add(ls->t.value);
if (eo_lexer_lookahead(ls) == '{') eo_lexer_get(ls);
{ if (ls->t.token == '{')
if (eo_lexer_get_c_type(ls->t.kw)) return parse_struct(ls, sname, is_extern);
eo_lexer_syntax_error(ls, "invalid struct name");
eo_lexer_get(ls);
return parse_struct(ls, sname, is_extern);
}
} }
else else
{ {
check(ls, TOK_VALUE); check(ls, TOK_VALUE);
if (eo_lexer_get_c_type(ls->t.kw))
eo_lexer_syntax_error(ls, "invalid struct name");
sname = eina_stringshare_add(ls->t.value); sname = eina_stringshare_add(ls->t.value);
eo_lexer_get(ls);
} }
has_struct = EINA_TRUE; def = push_type(ls);
break; def->type = EOLIAN_TYPE_REGULAR_STRUCT;
def->name = sname;
goto parse_ptr;
case KW_func: case KW_func:
return parse_function_type(ls); return parse_function_type(ls);
default: default:
break; break;
} }
def = push_type(ls); def = push_type(ls);
if (ls->t.kw == KW_void && !has_struct) if (ls->t.kw == KW_void)
def->type = EOLIAN_TYPE_VOID; def->type = EOLIAN_TYPE_VOID;
else else
{ {
def->type = has_struct ? EOLIAN_TYPE_REGULAR_STRUCT : EOLIAN_TYPE_REGULAR; def->type = EOLIAN_TYPE_REGULAR;
def->is_const = EINA_FALSE;
check(ls, TOK_VALUE); check(ls, TOK_VALUE);
ctype = eo_lexer_get_c_type(ls->t.kw); ctype = eo_lexer_get_c_type(ls->t.kw);
if (ctype && has_struct) def->name = eina_stringshare_add(ctype ? ctype : ls->t.value);
{
eina_stringshare_del(sname);
eo_lexer_syntax_error(ls, "invalid struct name");
}
def->name = sname ? sname : eina_stringshare_add(ctype ? ctype : ls->t.value);
} }
eo_lexer_get(ls); eo_lexer_get(ls);
parse_ptr: parse_ptr: