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

Method _parseStatement

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

Source from the content-addressed store, hash-verified

153 // compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt
154 // | funcdef | classdef | decorated | async_stmt
155 private _parseStatement(): StatementNode | undefined {
156 // Handle the errant condition of a dedent token here to provide
157 // better recovery.
158 if (this._consumeTokenIfType(TokenType.Dedent)) {
159 this._addError('Unindent not expected', this._peekToken());
160 }
161
162 switch (this._peekKeywordType()) {
163 case KeywordType.If:
164 return this._parseIfStatement();
165
166 case KeywordType.While:
167 return this._parseWhileStatement();
168
169 case KeywordType.For:
170 return this._parseForStatement();
171
172 case KeywordType.Try:
173 return this._parseTryStatement();
174
175 case KeywordType.With:
176 return this._parseWithStatement();
177
178 case KeywordType.Def:
179 return this._parseFunctionDef();
180
181 case KeywordType.Class:
182 return this._parseClassDef();
183
184 case KeywordType.Async:
185 return this._parseAsyncStatement();
186 }
187
188 if (this._peekOperatorType() === OperatorType.MatrixMultiply) {
189 return this._parseDecorated();
190 }
191
192 return this._parseSimpleStatement();
193 }
194
195 // async_stmt: 'async' (funcdef | with_stmt | for_stmt)
196 private _parseAsyncStatement(): StatementNode | undefined {

Callers 2

parseSourceFileMethod · 0.95
_parseSuiteMethod · 0.95

Calls 15

_consumeTokenIfTypeMethod · 0.95
_addErrorMethod · 0.95
_peekTokenMethod · 0.95
_peekKeywordTypeMethod · 0.95
_parseIfStatementMethod · 0.95
_parseWhileStatementMethod · 0.95
_parseForStatementMethod · 0.95
_parseTryStatementMethod · 0.95
_parseWithStatementMethod · 0.95
_parseFunctionDefMethod · 0.95
_parseClassDefMethod · 0.95
_parseAsyncStatementMethod · 0.95

Tested by

no test coverage detected