summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2023-03-29 01:33:00 -0500
committerptmcg <ptmcg@austin.rr.com>2023-03-29 01:33:00 -0500
commit05d894d2a6120b47a2afe6ea1ed6c749fdcef8e9 (patch)
tree5a0f33b4ce0cc5ef47dd3e2e40e32c3191141a0f
parent14067a94ca42810f2416b73fc544a1380dcc9846 (diff)
downloadpyparsing-git-05d894d2a6120b47a2afe6ea1ed6c749fdcef8e9.tar.gz
Small perf optimization for `expr | ""` mapping to `Optional(expr)`
-rw-r--r--pyparsing/core.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py
index ae7dcb6..03371ab 100644
--- a/pyparsing/core.py
+++ b/pyparsing/core.py
@@ -1552,6 +1552,9 @@ class ParserElement(ABC):
return _PendingSkip(self, must_skip=True)
if isinstance(other, str_type):
+ # `expr | ""` is equivalent to `Opt(expr)`
+ if other == "":
+ return Opt(self)
other = self._literalStringClass(other)
if not isinstance(other, ParserElement):
return NotImplemented