def indentedBlock(blockStatementExpr, indentStack, indent=True):
def checkPeerIndent(s,l,t):<EOL><INDENT>if l >= len(s): return<EOL>curCol = col(l,s)<EOL>if curCol != indentStack[-<NUM_LIT:1>]:<EOL><INDENT>if curCol > indentStack[-<NUM_LIT:1>]:<EOL><INDENT>raise ParseFatalException(s,l,"<STR_LIT>")<EOL><DEDENT>raise ParseException(s,l,"<STR_LIT>")<EOL><DEDENT><DEDENT>def checkSubIndent(s,l,t):<EOL><INDENT>curCol = col(l,s)<EOL>if curCol > indentStack[-<NUM_LIT:1>]:<EOL><INDENT>indentStack.append( curCol )<EOL><DEDENT>else:<EOL><INDENT>raise ParseException(s,l,"<STR_LIT>")<EOL><DEDENT><DEDENT>def checkUnindent(s,l,t):<EOL><INDENT>if l >= len(s): return<EOL>curCol = col(l,s)<EOL>if not(indentStack and curCol < indentStack[-<NUM_LIT:1>] and curCol <= indentStack[-<NUM_LIT:2>]):<EOL><INDENT>raise ParseException(s,l,"<STR_LIT>")<EOL><DEDENT>indentStack.pop()<EOL><DEDENT>NL = OneOrMore(LineEnd().setWhitespaceChars("<STR_LIT>").suppress())<EOL>INDENT = Empty() + Empty().setParseAction(checkSubIndent)<EOL>PEER   = Empty().setParseAction(checkPeerIndent)<EOL>UNDENT = Empty().setParseAction(checkUnindent)<EOL>if indent:<EOL><INDENT>smExpr = Group( Optional(NL) +<EOL>INDENT + (OneOrMore( PEER + Group(blockStatementExpr) + Optional(NL) )) + UNDENT)<EOL><DEDENT>else:<EOL><INDENT>smExpr = Group( Optional(NL) +<EOL>(OneOrMore( PEER + Group(blockStatementExpr) + Optional(NL) )) )<EOL><DEDENT>blockStatementExpr.ignore(_bslash + LineEnd())<EOL>return smExpr<EOL>
Helper method for defining space-delimited indentation blocks, such as
       those used to define block statements in Python source code.

       Parameters:
        - blockStatementExpr - expression defining syntax of statement that
            is repeated within the indented block
        - indentStack - list created by caller to manage indentation stack
            (multiple statementWithIndentedBlock expressions within a single grammar
            should share a common indentStack)
        - indent - boolean indicating whether block must be indented beyond the
            the current level; set to False for block of left-most statements
            (default=True)

       A valid block must contain at least one C{blockStatement}.