MCPcopy Index your code
hub / github.com/RustPython/RustPython / _process_tokens

Function _process_tokens

Lib/tabnanny.py:282–334  ·  view source on GitHub ↗
(tokens)

Source from the content-addressed store, hash-verified

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

Callers 1

process_tokensFunction · 0.85

Calls 8

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

Tested by

no test coverage detected