Skip to content

Commit

Permalink
Parsing enumeration literals
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Jun 8, 2014
1 parent 0f8ab9a commit b2f7034
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/parse.c
Expand Up @@ -1679,6 +1679,41 @@ static type_t p_physical_type_definition(range_t r)
return t;
}

static tree_t p_enumeration_literal(void)
{
// identifier | character_literal

BEGIN("enumeration literal");

tree_t t = tree_new(T_ENUM_LIT);
tree_set_ident(t, p_identifier());
tree_set_loc(t, CURRENT_LOC);

return t;
}

static type_t p_enumeration_type_definition(void)
{
// ( enumeration_literal { , enumeration_literal } )

BEGIN("enumeration type definition");

type_t t = type_new(T_ENUM);

consume(tLPAREN);

unsigned pos = 0;
do {
tree_t lit = p_enumeration_literal();
tree_set_pos(lit, pos++);
type_enum_add_literal(t, lit);
} while (optional(tCOMMA));

consume(tRPAREN);

return t;
}

static type_t p_scalar_type_definition(void)
{
// enumeration_type_definition | integer_type_definition
Expand Down Expand Up @@ -1706,6 +1741,9 @@ static type_t p_scalar_type_definition(void)
}
}

case tLPAREN:
return p_enumeration_type_definition();

default:
expect(tRANGE);
return type_new(T_NONE);
Expand Down Expand Up @@ -1816,6 +1854,7 @@ static type_t p_type_definition(void)

switch (peek()) {
case tRANGE:
case tLPAREN:
return p_scalar_type_definition();

case tACCESS:
Expand Down
2 changes: 1 addition & 1 deletion test/test_parse.c
Expand Up @@ -1867,8 +1867,8 @@ int main(void)
tcase_add_test(tc_core, test_literal);
tcase_add_test(tc_core, test_extended);
tcase_add_test(tc_core, test_package);
#if 0
tcase_add_test(tc_core, test_enum);
#if 0
tcase_add_test(tc_core, test_qual);
tcase_add_test(tc_core, test_func);
tcase_add_test(tc_core, test_array);
Expand Down

0 comments on commit b2f7034

Please sign in to comment.