MCPcopy Index your code
hub / github.com/python/cpython / _match

Method _match

Parser/asdl.py:378–395  ·  view source on GitHub ↗

The 'match' primitive of RD parsers. * Verifies that the current token is of the given kind (kind can be a tuple, in which the kind must match one of its members). * Returns the value of the current token * Reads in the next token

(self, kind)

Source from the content-addressed store, hash-verified

376 _id_kinds = (TokenKind.ConstructorId, TokenKind.TypeId)
377
378 def _match(self, kind):
379 """The 'match' primitive of RD parsers.
380
381 * Verifies that the current token is of the given kind (kind can
382 be a tuple, in which the kind must match one of its members).
383 * Returns the value of the current token
384 * Reads in the next token
385 """
386 if (isinstance(kind, tuple) and self.cur_token.kind in kind or
387 self.cur_token.kind == kind
388 ):
389 value = self.cur_token.value
390 self._advance()
391 return value
392 else:
393 raise ASDLSyntaxError(
394 'Unmatched {} (found {})'.format(kind, self.cur_token.kind),
395 self.cur_token.lineno)
396
397 def _at_keyword(self, keyword):
398 return (self.cur_token.kind == TokenKind.TypeId and

Callers 4

_parse_moduleMethod · 0.95
_parse_definitionsMethod · 0.95
_parse_typeMethod · 0.95
_parse_fieldsMethod · 0.95

Calls 3

_advanceMethod · 0.95
ASDLSyntaxErrorClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected