More operators for C++. Forgot about new/delete and some other less used

such as ->*.
This commit is contained in:
Armin Ronacher 2010-03-02 13:10:44 +01:00
parent 91322038e2
commit a6c625f25c
2 changed files with 80 additions and 54 deletions

View File

@ -33,9 +33,10 @@ _visibility_re = re.compile(r'\b(public|private|protected)\b')
_operator_re = re.compile(r'''(?x)
\[\s*\]
| \(\s*\)
| [!<>=/*%+-|&^]=?
| [!<>=/*%+|&^-]=?
| \+\+ | --
| <<=? | >>=? | ~ | && | \| | \|\|
| (<<|>>)=? | ~ | && | \| | \|\|
| ->\*? | \,
''')
_id_shortwords = {
@ -87,9 +88,17 @@ _id_shortwords = {
'operator|=': 'or-assign-operator',
'operator<<=': 'lshift-assign-operator',
'operator>>=': 'rshift-assign-operator',
'operator^=': 'xor-assign-operator',
'operator,': 'comma-operator',
'operator->': 'pointer-operator',
'operator->*': 'pointer-by-pointer-operator',
'operator~': 'inv-operator',
'operator++': 'inc-operator',
'operator--': 'dec-operator'
'operator--': 'dec-operator',
'operator new': 'new-operator',
'operator new[]': 'new-array-operator',
'operator delete': 'delete-operator',
'operator delete[]': 'delete-array-operator'
}
@ -491,11 +500,24 @@ class DefinitionParser(object):
return self.last_match.group()
def _parse_operator(self):
self.skip_ws()
# thank god, a regular operator definition
if self.match(_operator_re):
return NameDefExpr('operator' +
_whitespace_re.sub('', self.matched_text))
# new/delete operator?
for allocop in 'new', 'delete':
if not self.skip_word(allocop):
continue
self.skip_ws()
if self.skip_string('['):
self.skip_ws()
if not self.skip_string(']'):
self.fail('expected "]" for ' + allocop)
allocop += '[]'
return NameDefExpr('operator ' + allocop)
# oh well, looks like a cast operator definition.
# In that case, eat another type.
type = self._parse_type()

View File

@ -19,7 +19,6 @@ def parse(name, string):
def test_type_definitions():
"""Tests the type definition parsing"""
rv = parse('member_object', ' const std::string & name = 42')
assert unicode(rv) == 'const std::string& name = 42'
@ -40,3 +39,8 @@ def test_type_definitions():
assert unicode(parse('type_object', x)) == x
assert unicode(parse('type_object', 'long long int foo')) == 'long long foo'
def test_operators():
x = parse('function', 'void operator new [ ] ()')
assert unicode(x) == 'void operator new[]()'