MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / process_tokens

Function process_tokens

tools/python-3.11.9-amd64/Lib/tabnanny.py:275–327  ·  view source on GitHub ↗
(tokens)

Source from the content-addressed store, hash-verified

273 return prefix + " " + ', '.join(firsts)
274
275def process_tokens(tokens):
276 INDENT = tokenize.INDENT
277 DEDENT = tokenize.DEDENT
278 NEWLINE = tokenize.NEWLINE
279 JUNK = tokenize.COMMENT, tokenize.NL
280 indents = [Whitespace("")]
281 check_equal = 0
282
283 for (type, token, start, end, line) in tokens:
284 if type == NEWLINE:
285 # a program statement, or ENDMARKER, will eventually follow,
286 # after some (possibly empty) run of tokens of the form
287 # (NL | COMMENT)* (INDENT | DEDENT+)?
288 # If an INDENT appears, setting check_equal is wrong, and will
289 # be undone when we see the INDENT.
290 check_equal = 1
291
292 elif type == INDENT:
293 check_equal = 0
294 thisguy = Whitespace(token)
295 if not indents[-1].less(thisguy):
296 witness = indents[-1].not_less_witness(thisguy)
297 msg = "indent not greater e.g. " + format_witnesses(witness)
298 raise NannyNag(start[0], msg, line)
299 indents.append(thisguy)
300
301 elif type == DEDENT:
302 # there's nothing we need to check here! what's important is
303 # that when the run of DEDENTs ends, the indentation of the
304 # program statement (or ENDMARKER) that triggered the run is
305 # equal to what's left at the top of the indents stack
306
307 # Ouch! This assert triggers if the last line of the source
308 # is indented *and* lacks a newline -- then DEDENTs pop out
309 # of thin air.
310 # assert check_equal # else no earlier NEWLINE, or an earlier INDENT
311 check_equal = 1
312
313 del indents[-1]
314
315 elif check_equal and type not in JUNK:
316 # this is the first "real token" following a NEWLINE, so it
317 # must be the first token of the next program statement, or an
318 # ENDMARKER; the "line" argument exposes the leading whitespace
319 # for this statement; in the case of ENDMARKER, line is an empty
320 # string, so will properly match the empty string with which the
321 # "indents" stack was seeded
322 check_equal = 0
323 thisguy = Whitespace(line)
324 if not indents[-1].equal(thisguy):
325 witness = indents[-1].not_equal_witness(thisguy)
326 msg = "indent not equal e.g. " + format_witnesses(witness)
327 raise NannyNag(start[0], msg, line)
328
329
330if __name__ == '__main__':

Callers 1

checkFunction · 0.85

Calls 8

WhitespaceClass · 0.85
format_witnessesFunction · 0.85
NannyNagClass · 0.85
lessMethod · 0.80
not_less_witnessMethod · 0.80
not_equal_witnessMethod · 0.80
appendMethod · 0.45
equalMethod · 0.45

Tested by

no test coverage detected