def nestedExpr(opener="<STR_LIT:(>", closer="<STR_LIT:)>", content=None, ignoreExpr=quotedString.copy()):
if opener == closer:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if content is None:<EOL><INDENT>if isinstance(opener,basestring) and isinstance(closer,basestring):<EOL><INDENT>if len(opener) == <NUM_LIT:1> and len(closer)==<NUM_LIT:1>:<EOL><INDENT>if ignoreExpr is not None:<EOL><INDENT>content = (Combine(OneOrMore(~ignoreExpr +<EOL>CharsNotIn(opener+closer+ParserElement.DEFAULT_WHITE_CHARS,exact=<NUM_LIT:1>))<EOL>).setParseAction(lambda t:t[<NUM_LIT:0>].strip()))<EOL><DEDENT>else:<EOL><INDENT>content = (empty.copy()+CharsNotIn(opener+closer+ParserElement.DEFAULT_WHITE_CHARS<EOL>).setParseAction(lambda t:t[<NUM_LIT:0>].strip()))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ignoreExpr is not None:<EOL><INDENT>content = (Combine(OneOrMore(~ignoreExpr +<EOL>~Literal(opener) + ~Literal(closer) +<EOL>CharsNotIn(ParserElement.DEFAULT_WHITE_CHARS,exact=<NUM_LIT:1>))<EOL>).setParseAction(lambda t:t[<NUM_LIT:0>].strip()))<EOL><DEDENT>else:<EOL><INDENT>content = (Combine(OneOrMore(~Literal(opener) + ~Literal(closer) +<EOL>CharsNotIn(ParserElement.DEFAULT_WHITE_CHARS,exact=<NUM_LIT:1>))<EOL>).setParseAction(lambda t:t[<NUM_LIT:0>].strip()))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>ret = Forward()<EOL>if ignoreExpr is not None:<EOL><INDENT>ret <<= Group( Suppress(opener) + ZeroOrMore( ignoreExpr | ret | content ) + Suppress(closer) )<EOL><DEDENT>else:<EOL><INDENT>ret <<= Group( Suppress(opener) + ZeroOrMore( ret | content )  + Suppress(closer) )<EOL><DEDENT>ret.setName('<STR_LIT>' % (opener,closer))<EOL>return ret<EOL>
Helper method for defining nested lists enclosed in opening and
    closing delimiters ("(" and ")" are the default).

    Parameters:
     - opener - opening character for a nested list
       (default= ``"("``); can also be a pyparsing expression
     - closer - closing character for a nested list
       (default= ``")"``); can also be a pyparsing expression
     - content - expression for items within the nested lists
       (default= ``None``)
     - ignoreExpr - expression for ignoring opening and closing
       delimiters (default= :class:`quotedString`)

    If an expression is not provided for the content argument, the
    nested expression will capture all whitespace-delimited content
    between delimiters as a list of separate values.

    Use the ``ignoreExpr`` argument to define expressions that may
    contain opening or closing characters that should not be treated as
    opening or closing characters for nesting, such as quotedString or
    a comment expression.  Specify multiple expressions using an
    :class:`Or` or :class:`MatchFirst`. The default is
    :class:`quotedString`, but if no expressions are to be ignored, then
    pass ``None`` for this argument.

    Example::

        data_type = oneOf("void int short long char float double")
        decl_data_type = Combine(data_type + Optional(Word('*')))
        ident = Word(alphas+'_', alphanums+'_')
        number = pyparsing_common.number
        arg = Group(decl_data_type + ident)
        LPAR,RPAR = map(Suppress, "()")

        code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment))

        c_function = (decl_data_type("type")
                      + ident("name")
                      + LPAR + Optional(delimitedList(arg), [])("args") + RPAR
                      + code_body("body"))
        c_function.ignore(cStyleComment)

        source_code = '''
            int is_odd(int x) {
                return (x%2);
            }

            int dec_to_hex(char hchar) {
                if (hchar >= '0' && hchar <= '9') {
                    return (ord(hchar)-ord('0'));
                } else {
                    return (10+ord(hchar)-ord('A'));
                }
            }
        '''
        for func in c_function.searchString(source_code):
            print("%(name)s (%(type)s) args: %(args)s" % func)


    prints::

        is_odd (int) args: [['int', 'x']]
        dec_to_hex (int) args: [['char', 'hchar']]