@@ -1701,13 +1701,12 @@ class _MathStyle(enum.Enum):
1701
1701
liminf sin cos exp limsup sinh cosh gcd ln sup cot hom log tan
1702
1702
coth inf max tanh""" .split ())
1703
1703
1704
- _ambi_delim = set (r"""
1704
+ _ambi_delims = set (r"""
1705
1705
| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
1706
1706
\Downarrow \Updownarrow . \vert \Vert""" .split ())
1707
-
1708
- _left_delim = set (r"( [ \{ < \lfloor \langle \lceil" .split ())
1709
-
1710
- _right_delim = set (r") ] \} > \rfloor \rangle \rceil" .split ())
1707
+ _left_delims = set (r"( [ \{ < \lfloor \langle \lceil" .split ())
1708
+ _right_delims = set (r") ] \} > \rfloor \rangle \rceil" .split ())
1709
+ _delims = _left_delims | _right_delims | _ambi_delims
1711
1710
1712
1711
def __init__ (self ):
1713
1712
p = types .SimpleNamespace ()
@@ -1742,9 +1741,7 @@ def set_names_and_parse_actions():
1742
1741
Optional (r"\math" + oneOf (self ._fontnames )("font" )) + "{" )
1743
1742
p .end_group = Literal ("}" )
1744
1743
1745
- p .ambi_delim = oneOf (self ._ambi_delim )
1746
- p .left_delim = oneOf (self ._left_delim )
1747
- p .right_delim = oneOf (self ._right_delim )
1744
+ p .delim = oneOf (self ._delims )
1748
1745
1749
1746
set_names_and_parse_actions () # for root definitions.
1750
1747
@@ -1799,8 +1796,8 @@ def set_names_and_parse_actions():
1799
1796
1800
1797
p .genfrac <<= cmd (
1801
1798
r"\genfrac" ,
1802
- "{" + Optional (p .ambi_delim | p . left_delim )("ldelim" ) + "}"
1803
- + "{" + Optional (p .ambi_delim | p . right_delim )("rdelim" ) + "}"
1799
+ "{" + Optional (p .delim )("ldelim" ) + "}"
1800
+ + "{" + Optional (p .delim )("rdelim" ) + "}"
1804
1801
+ "{" + p .float_literal ("rulesize" ) + "}"
1805
1802
+ p .optional_group ("style" )
1806
1803
+ p .required_group ("num" )
@@ -1861,13 +1858,9 @@ def set_names_and_parse_actions():
1861
1858
)
1862
1859
1863
1860
p .auto_delim <<= (
1864
- r"\left"
1865
- - ((p .left_delim | p .ambi_delim )("left" )
1866
- | Error ("Expected a delimiter" ))
1861
+ r"\left" - (p .delim ("left" ) | Error ("Expected a delimiter" ))
1867
1862
+ ZeroOrMore (p .simple | p .auto_delim )("mid" )
1868
- + r"\right"
1869
- - ((p .right_delim | p .ambi_delim )("right" )
1870
- | Error ("Expected a delimiter" ))
1863
+ + r"\right" - (p .delim ("right" ) | Error ("Expected a delimiter" ))
1871
1864
)
1872
1865
1873
1866
# Leaf definitions.
@@ -2001,7 +1994,7 @@ def symbol(self, s, loc, toks):
2001
1994
# Binary operators at start of string should not be spaced
2002
1995
if (c in self ._binary_operators and
2003
1996
(len (s [:loc ].split ()) == 0 or prev_char == '{' or
2004
- prev_char in self ._left_delim )):
1997
+ prev_char in self ._left_delims )):
2005
1998
return [char ]
2006
1999
else :
2007
2000
return [Hlist ([self ._make_space (0.2 ),
@@ -2106,8 +2099,7 @@ def operatorname(self, s, loc, toks):
2106
2099
if isinstance (name , ParseResults ):
2107
2100
next_char_loc += len ('operatorname{}' )
2108
2101
next_char = next ((c for c in s [next_char_loc :] if c != ' ' ), '' )
2109
- delimiters = self ._left_delim | self ._ambi_delim | self ._right_delim
2110
- delimiters |= {'^' , '_' }
2102
+ delimiters = self ._delims | {'^' , '_' }
2111
2103
if (next_char not in delimiters and
2112
2104
name not in self ._overunder_functions ):
2113
2105
# Add thin space except when followed by parenthesis, bracket, etc.
@@ -2502,4 +2494,7 @@ def _auto_sized_delimiter(self, front, middle, back):
2502
2494
2503
2495
def auto_delim (self , s , loc , toks ):
2504
2496
return self ._auto_sized_delimiter (
2505
- toks ["left" ], toks ["mid" ].asList (), toks ["right" ])
2497
+ toks ["left" ],
2498
+ # if "mid" in toks ... can be removed when requiring pyparsing 3.
2499
+ toks ["mid" ].asList () if "mid" in toks else [],
2500
+ toks ["right" ])
0 commit comments