// Parse a class definition. // // class-declaration: // 'class' identifier [':'] class-body // 'class' identifier [':' type] class-body // 'class' identifier [':' extension] class-body // // NOTE: The parser currently allows the omission of the ':' because it // looks weird when the kind is not given explicitly omitted. // // TODO: We could use '=' notation in bodies to create new derived types. Decl& Parser::class_declaration() { Match_token_pred end_kind(*this, lbrace_tok); require(class_tok); Name& name = identifier(); // Match the metatype. Type* kind; if (match_if(colon_tok)) { if (match_if(extension_tok)) return extension_declaration(name, &cxt.get_type_type()); if (next_token_is(lbrace_tok)) kind = &cxt.get_type_type(); else kind = &unparsed_type(end_kind); } else { kind = &cxt.get_type_type(); } // Point of declaration. Decl& decl = start_class_declaration(name, *kind); Enter_scope scope(cxt, cxt.saved_scope(decl)); // Match the class body. Def& def = class_body(); return finish_class_definition(decl, def); };
// Parse a class definition. // // class-declaration: // 'class' identifier [':'] class-body // 'class' identifier [':' type] class-body // // NOTE: The parser currently allows the omission of the ':' because it // looks weird when the kind is not given explicitly omitted. // // TODO: We could use '=' notation in bodies to create new derived types. Decl& Parser::class_declaration() { Match_token_pred end_kind(*this, tk::lbrace_tok); require(tk::class_tok); Name& name = identifier(); // Point of declaration. Decl& decl = start_class_declaration(name); Enter_scope scope(cxt, cxt.saved_scope(decl)); // Match the class body. Def& def = class_body(); return finish_class_definition(decl, def); };