function ParseDefinition(TokenStream $it) { $root = new ASTRoot(); while ($it->hasMore() && $it->expectAny([SyntaxMap::Annotation, SyntaxMap::Keyword], 0)) { $annotations = ParseAnnotations($it); $token = $it->val(); switch (strtolower($token->value)) { case "type": $type = ParseType($it); $type->annotations = $annotations; $root->types->add($type); break; case "entity": $entity = ParseEntity($it); $entity->annotations = $annotations; $root->entities->add($entity); break; case "const": $const = ParseConstant($it); $const->annotations = $annotations; $root->constants->add($const); break; case "enum": $enum = ParseEnum($it); $enum->annotations = $annotations; $root->enums->add($enum); break; default: throw ParserException::unexpectedKeyword($token); } } return $root; }