@@ -495,7 +495,7 @@ def __init__(self, savelist: bool = False) -> None:
495495# used when checking for left-recursion
496496self ._may_return_empty :bool = False
497497self .keepTabs :bool = False
498- self .ignoreExprs :list [ParserElement ]= list ()
498+ self .ignoreExprs :set [ParserElement ]= set ()
499499self .debug :bool = False
500500self .streamlined :bool = False
501501# optimize exception handling for subclasses that don't advance parse index
@@ -603,7 +603,7 @@ def copy(self) -> ParserElement:
603603 """
604604cpy = copy .copy (self )
605605cpy .parseAction = self .parseAction [:]
606- cpy .ignoreExprs = self .ignoreExprs [:]
606+ cpy .ignoreExprs = self .ignoreExprs . copy ()
607607if self .copyDefaultWhiteChars :
608608cpy .whiteChars = set (ParserElement .DEFAULT_WHITE_CHARS )
609609return cpy
@@ -878,7 +878,7 @@ def _skipIgnorables(self, instring: str, loc: int) -> int:
878878for ignore_fn in ignore_expr_fns :
879879try :
880880while 1 :
881- loc ,dummy = ignore_fn (instring ,loc )
881+ loc ,_ = ignore_fn (instring ,loc )
882882exprsFound = True
883883except ParseException :
884884pass
@@ -1997,11 +1997,8 @@ def ignore(self, other: ParserElement) -> ParserElement:
19971997if isinstance (other ,str_type ):
19981998other = Suppress (other )
19991999
2000- if isinstance (other ,Suppress ):
2001- if other not in self .ignoreExprs :
2002- self .ignoreExprs .append (other )
2003- else :
2004- self .ignoreExprs .append (Suppress (other .copy ()))
2000+ if other is not self :
2001+ self .ignoreExprs .add (other )
20052002return self
20062003
20072004def set_debug_actions (
@@ -4357,15 +4354,10 @@ def ignore(self, other) -> ParserElement:
43574354 matching; may be called repeatedly, to define multiple comment or other
43584355 ignorable patterns.
43594356 """
4360- if isinstance (other ,Suppress ):
4361- if other not in self .ignoreExprs :
4362- super ().ignore (other )
4363- for e in self .exprs :
4364- e .ignore (self .ignoreExprs [- 1 ])
4365- else :
4366- super ().ignore (other )
4367- for e in self .exprs :
4368- e .ignore (self .ignoreExprs [- 1 ])
4357+ super ().ignore (other )
4358+ for e in self .exprs :
4359+ if other not in e .ignoreExprs :
4360+ e .ignore (other )
43694361return self
43704362
43714363def _generateDefaultName (self )-> str :
@@ -5142,7 +5134,7 @@ def __init__(self, expr: Union[ParserElement, str], savelist: bool = False) -> N
51425134self .skipWhitespace = expr .skipWhitespace
51435135self .saveAsList = expr .saveAsList
51445136self .callPreparse = expr .callPreparse
5145- self .ignoreExprs . extend ( expr .ignoreExprs )
5137+ self .ignoreExprs |= expr .ignoreExprs
51465138
51475139def recurse (self )-> list [ParserElement ]:
51485140return [self .expr ]if self .expr is not None else []
@@ -5196,10 +5188,9 @@ def ignore(self, other) -> ParserElement:
51965188 matching; may be called repeatedly, to define multiple comment or other
51975189 ignorable patterns.
51985190 """
5199- if not isinstance (other ,Suppress )or other not in self .ignoreExprs :
5200- super ().ignore (other )
5201- if self .expr is not None :
5202- self .expr .ignore (self .ignoreExprs [- 1 ])
5191+ super ().ignore (other )
5192+ if self .expr is not None :
5193+ self .expr .ignore (other )
52035194
52045195return self
52055196
@@ -6189,7 +6180,7 @@ def __lshift__(self, other) -> Forward:
61896180 )
61906181self .skipWhitespace = self .expr .skipWhitespace
61916182self .saveAsList = self .expr .saveAsList
6192- self .ignoreExprs . extend ( self .expr .ignoreExprs )
6183+ self .ignoreExprs |= self .expr .ignoreExprs
61936184self .lshift_line = traceback .extract_stack (limit = 2 )[- 2 ]# type: ignore[assignment]
61946185return self
61956186
@@ -6480,7 +6471,8 @@ def ignore(self, other) -> ParserElement:
64806471if self .adjacent :
64816472ParserElement .ignore (self ,other )
64826473else :
6483- super ().ignore (other )
6474+ if other is not self :
6475+ super ().ignore (other )
64846476return self
64856477
64866478def postParse (self ,instring ,loc ,tokenlist ):