MCPcopy Create free account
hub / github.com/nodejs/node / check

Method check

tools/gyp/pylib/packaging/_tokenizer.py:113–132  ·  view source on GitHub ↗

Check whether the next token has the provided name. By default, if the check succeeds, the token *must* be read before another check. If `peek` is set to `True`, the token is not loaded and would need to be checked again.

(self, name: str, *, peek: bool = False)

Source from the content-addressed store, hash-verified

111 self.read()
112
113 def check(self, name: str, *, peek: bool = False) -> bool:
114 """Check whether the next token has the provided name.
115
116 By default, if the check succeeds, the token *must* be read before
117 another check. If `peek` is set to `True`, the token is not loaded and
118 would need to be checked again.
119 """
120 assert (
121 self.next_token is None
122 ), f"Cannot check for {name!r}, already have {self.next_token!r}"
123 assert name in self.rules, f"Unknown token name: {name!r}"
124
125 expression = self.rules[name]
126
127 match = expression.match(self.source, self.position)
128 if match is None:
129 return False
130 if not peek:
131 self.next_token = Token(name, match[0], self.position)
132 return True
133
134 def expect(self, name: str, *, expected: str) -> Token:
135 """Expect a certain token name next, failing with a syntax error otherwise.

Callers 12

consumeMethod · 0.95
expectMethod · 0.95
enclosing_tokensMethod · 0.95
_parse_extrasFunction · 0.45
_parse_extras_listFunction · 0.45
_parse_version_manyFunction · 0.45
_parse_markerFunction · 0.45
_parse_marker_atomFunction · 0.45
_parse_marker_varFunction · 0.45
_parse_marker_opFunction · 0.45

Calls 2

TokenClass · 0.70
matchMethod · 0.65

Tested by

no test coverage detected