I was wondering how they'd specify a language with semantic indents in an EBNF grammar. Apparently they don't do that at all - they seem to use "virtual" INDENT and DEDENT tokens that act like brackets. I suppose there is an instruction written in prose somewhere how to convert the actual python into the python-with-invisible-brackets that is defined here.
Very clever!
The algorithm for generating those tokens is explained in the Lexical Analysis reference[0], and a quick look at the cpython source shows the logic is implemented in Parser/tokenizer.c[1].