MCPcopy
hub / github.com/microsoft/pyright / _parseDecorated

Method _parseDecorated

server/src/parser/parser.ts:731–761  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

729 // decorators: decorator+
730 // decorated: decorators (classdef | funcdef | async_funcdef)
731 private _parseDecorated(): StatementNode | undefined {
732 let decoratorList: DecoratorNode[] = [];
733
734 while (true) {
735 if (this._peekOperatorType() === OperatorType.MatrixMultiply) {
736 decoratorList.push(this._parseDecorator());
737 } else {
738 break;
739 }
740 }
741
742 let nextToken = this._peekToken() as KeywordToken;
743 if (nextToken.type === TokenType.Keyword) {
744 if (nextToken.keywordType === KeywordType.Async) {
745 this._getNextToken();
746
747 if (this._peekKeywordType() !== KeywordType.Def) {
748 this._addError('Expected function definition after "async"', this._peekToken());
749 return undefined;
750 }
751 return this._parseFunctionDef(nextToken, decoratorList);
752 } else if (nextToken.keywordType === KeywordType.Def) {
753 return this._parseFunctionDef(undefined, decoratorList);
754 } else if (nextToken.keywordType === KeywordType.Class) {
755 return this._parseClassDef(decoratorList);
756 }
757 }
758
759 this._addError('Expected function or class declaration after decorator', this._peekToken());
760 return undefined;
761 }
762
763 // decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
764 private _parseDecorator(): DecoratorNode {

Callers 1

_parseStatementMethod · 0.95

Calls 8

_peekOperatorTypeMethod · 0.95
_parseDecoratorMethod · 0.95
_peekTokenMethod · 0.95
_getNextTokenMethod · 0.95
_peekKeywordTypeMethod · 0.95
_addErrorMethod · 0.95
_parseFunctionDefMethod · 0.95
_parseClassDefMethod · 0.95

Tested by

no test coverage detected