I am trying to more or less reproduce for Python the if0 syntax highlighting of C-like files in Vim where code surrounded by #if 0 and #endif are grayed out (highlighted as Comment).
Instead of preprocessor directives, I would like to gray out Python code blocks starting with if 0: or if False:.
Inspired by this question, I came up with the following code which almost works:
syn region pyIfFalse start=/^\(\s*\)if \%(0\+\|False\):\n\+\z(\1\s\+\)\S/ skip=/^\%(\z1\S\|^$\)/ end=/^\z1\@!.*/me=s-1
hi def link pyIfFalse Comment
This results in the following
if 0: # grayed out (there is a space at the beginning)
pass
if 0: # not grayed out
pass
If I replace all if by ef (in the example and in the pattern), both blocks will be grayed out, meaning that the problem must be with the keyword if.
Following this question, one can redefine if as a keyword contained but then it would not be highlighted in regular text so it does not seem like a satisfying solution.
What is quite surprising to me is that the highlighting works for the first block but not the second, with the only difference being a space before the if.