@@ -32,6 +32,7 @@ typedef enum {
3232 K_UNION ,
3333 K_ALIAS ,
3434 K_PROPERTY ,
35+ K_ENUMERATOR ,
3536 COUNT_KIND
3637} typeSpecKind ;
3738
@@ -43,7 +44,8 @@ static kindDefinition TypeSpecKinds[COUNT_KIND] = {
4344 { true, 'm' , "model" , "models" },
4445 { true, 'u' , "union" , "unions" },
4546 { true, 'a' , "alias" , "aliases" },
46- { true, 'p' , "property" , "properties" }
47+ { true, 'p' , "property" , "properties" },
48+ { true, 'e' , "enumerator" , "enumerators (values inside an enumeration)" , .version = 1 },
4749};
4850
4951typedef enum eTokenType {
@@ -388,8 +390,12 @@ static void parseNamespace(tokenInfo *const token)
388390 vStringDelete (name );
389391}
390392
391- static void parseEnum (tokenInfo * const token )
393+ static void parseEnum (tokenInfo * const parentToken )
392394{
395+ tokenInfo * token = newToken ();
396+ copyToken (token , parentToken );
397+ setScope (token , parentToken -> scope );
398+
393399 readToken (token );
394400
395401 if (token -> type == TOKEN_IDENTIFIER )
@@ -399,7 +405,36 @@ static void parseEnum(tokenInfo *const token)
399405
400406 if (token -> type == TOKEN_OPEN_CURLY )
401407 {
402- enterScope (token , enumIndex );
408+ /* Parse enum body */
409+ while (token -> type != TOKEN_CLOSE_CURLY && token -> type != TOKEN_EOF )
410+ {
411+ if (token -> type == TOKEN_IDENTIFIER )
412+ {
413+ /* Create tag for enumerator */
414+ setScope (token , enumIndex );
415+ makeTypeSpecTag (token , K_ENUMERATOR );
416+ readToken (token );
417+
418+ /* Skip value assignment if any */
419+ if (token -> type == TOKEN_EQUAL_SIGN )
420+ {
421+ readToken (token );
422+ /* Skip the value */
423+ while (token -> type != TOKEN_COMMA &&
424+ token -> type != TOKEN_CLOSE_CURLY &&
425+ token -> type != TOKEN_EOF )
426+ {
427+ readToken (token );
428+ }
429+ }
430+
431+ /* Skip comma if present */
432+ if (token -> type == TOKEN_COMMA )
433+ readToken (token );
434+ }
435+ else
436+ readToken (token );
437+ }
403438 }
404439 }
405440}
@@ -678,5 +713,7 @@ extern parserDefinition* TypeSpecParser (void)
678713 def -> keywordCount = ARRAY_SIZE (TypeSpecKeywordTable );
679714 def -> defaultScopeSeparator = SCOPE_SEPARATOR ;
680715 def -> useCork = CORK_QUEUE ;
716+ def -> versionCurrent = 1 ;
717+ def -> versionAge = 1 ;
681718 return def ;
682719}
0 commit comments