@@ -418,6 +418,8 @@ def locatedExpr(expr: ParserElement) -> ParserElement:
418418 )
419419
420420
421+ # define special default value to permit None as a significant value for
422+ # ignore_expr
421423_NO_IGNORE_EXPR_GIVEN = NoMatch ()
422424
423425
@@ -498,11 +500,13 @@ def nested_expr(
498500 """
499501 if ignoreExpr != ignore_expr :
500502 ignoreExpr = ignore_expr if ignoreExpr is _NO_IGNORE_EXPR_GIVEN else ignoreExpr
503+
501504 if ignoreExpr is _NO_IGNORE_EXPR_GIVEN :
502505 ignoreExpr = quoted_string ()
503506
504507 if opener == closer :
505508 raise ValueError ("opening and closing strings cannot be the same" )
509+
506510 if content is None :
507511 if isinstance (opener , str_type ) and isinstance (closer , str_type ):
508512 opener = typing .cast (str , opener )
@@ -519,8 +523,11 @@ def nested_expr(
519523 )
520524 )
521525 else :
522- content = empty .copy () + CharsNotIn (
523- opener + closer + ParserElement .DEFAULT_WHITE_CHARS
526+ content = Combine (
527+ Empty ()
528+ + CharsNotIn (
529+ opener + closer + ParserElement .DEFAULT_WHITE_CHARS
530+ )
524531 )
525532 else :
526533 if ignoreExpr is not None :
@@ -544,10 +551,12 @@ def nested_expr(
544551 raise ValueError (
545552 "opening and closing arguments must be strings if no content expression is given"
546553 )
547- if ParserElement .DEFAULT_WHITE_CHARS :
548- content .set_parse_action (
549- lambda t : t [0 ].strip (ParserElement .DEFAULT_WHITE_CHARS )
550- )
554+
555+ # for these internally-created context expressions, simulate whitespace-skipping
556+ if ParserElement .DEFAULT_WHITE_CHARS :
557+ content .set_parse_action (
558+ lambda t : t [0 ].strip (ParserElement .DEFAULT_WHITE_CHARS )
559+ )
551560
552561 ret = Forward ()
553562 if ignoreExpr is not None :
@@ -556,7 +565,9 @@ def nested_expr(
556565 )
557566 else :
558567 ret <<= Group (Suppress (opener ) + ZeroOrMore (ret | content ) + Suppress (closer ))
568+
559569 ret .set_name (f"nested { opener } { closer } expression" )
570+
560571 # don't override error message from content expressions
561572 ret .errmsg = None
562573 return ret
@@ -621,7 +632,7 @@ def _makeTags(tagStr, xml, suppress_LT=Suppress("<"), suppress_GT=Suppress(">"))
621632
622633
623634def make_html_tags (
624- tag_str : Union [str , ParserElement ]
635+ tag_str : Union [str , ParserElement ],
625636) -> tuple [ParserElement , ParserElement ]:
626637 """Helper to construct opening and closing tag expressions for HTML,
627638 given a tag name. Matches tags in either upper or lower case,
@@ -648,7 +659,7 @@ def make_html_tags(
648659
649660
650661def make_xml_tags (
651- tag_str : Union [str , ParserElement ]
662+ tag_str : Union [str , ParserElement ],
652663) -> tuple [ParserElement , ParserElement ]:
653664 """Helper to construct opening and closing tag expressions for XML,
654665 given a tag name. Matches tags only in the given upper/lower case.
0 commit comments