Armin Ronacher committed 075a95f

Added support for non-name template arguments. This fixes #696

Comments (0)

Files changed (2)


                         r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S)
 _visibility_re = re.compile(r'\b(public|private|protected)\b')
 _array_def_re = re.compile(r'\[\s*(.+?)?\s*\]')
+_template_arg_re = re.compile(r'[^,>]+')
 _operator_re = re.compile(r'''(?x)
     |   \(\s*\)
         return u'%s<%s>' % (self.typename, u', '.join(map(unicode, self.args)))
+class ConstantTemplateArgExpr(PrimaryDefExpr):
+    def __init__(self, arg):
+        self.arg = arg
+    def get_id(self):
+        return self.arg.replace(u' ', u'-')
+    def __unicode__(self):
+        return unicode(self.arg)
 class WrappingDefExpr(DefExpr):
     def __init__(self, typename):
         return CastOpDefExpr(type)
     def _parse_name(self):
+        return self._parse_name_or_template_arg(False)
+    def _parse_name_or_template_arg(self, in_template):
         if not self.match(_identifier_re):
-  'expected name')
+            if not in_template:
+      'expected name')
+            if not self.match(_template_arg_re):
+      'expected name or constant template argument')
+            return ConstantTemplateArgExpr(self.matched_text.strip())
         identifier = self.matched_text
         # strictly speaking, operators are not regular identifiers
         rv = ModifierDefExpr(NameDefExpr(typename), modifiers)
         return self._attach_crefptr(rv, is_const)
-    def _parse_type_expr(self):
-        typename = self._parse_name()
+    def _parse_type_expr(self, in_template=False):
+        typename = self._parse_name_or_template_arg(in_template)
         if not self.skip_string('<'):
             return typename
                (result and not self.skip_string('::')) or \
-            result.append(self._parse_type_expr())
+            result.append(self._parse_type_expr(in_template))
         if not result:
   'expected type')


     rv = parse('member_object', '  const  std::string  &  name leftover')
     assert unicode(rv) == 'const std::string& name'
+    x = 'void operator()(const boost::array<VertexID, 2>& v) const'
+    assert unicode(parse('function', x)) == x
     rv = parse('member_object', 'const std::vector< unsigned int, long> &name')
     assert unicode(rv) == 'const std::vector<unsigned int, long>& name'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.