Commits

Georg Brandl committed cf606e8

Recognize methods in the ObjC lexer (#638).

  • Participants
  • Parent commits 50cee44

Comments (0)

Files changed (3)

 
 - Several fixes to the reStructuredText lexer (#636).
 
+- Recognize methods in the ObjC lexer (#638).
+
 - Fix Lua "class" highlighting: it does not have classes (#665).
 
 - Fix degenerate regex in Scala lexer (#671).

File pygments/lexers/compiled.py

              bygroups(using(this), Name.Function,
                       using(this), Text, Punctuation),
              'function'),
+            # methods
+            (r'^([-+])(\s*)'                         # method marker
+             r'(\(.*?\))?(\s*)'                      # return type
+             r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)',        # begin of method name
+             bygroups(Keyword, Text, using(this),
+                      Text, Name.Function),
+             'method'),
             # function declarations
             (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))'    # return arguments
              r'([a-zA-Z$_][a-zA-Z0-9$_]*)'           # method name
             ('{', Punctuation, '#push'),
             ('}', Punctuation, '#pop'),
         ],
+        'method': [
+            include('whitespace'),
+            (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this),
+                                                              Name.Variable)),
+            (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function),
+            (';', Punctuation, '#pop'),
+            ('{', Punctuation, 'function'),
+            ('', Text, '#pop'),
+        ],
         'string': [
             (r'"', String, '#pop'),
             (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),

File tests/examplefiles/objc_example.m

 #import "Somefile.h"
 
+@implementation ABC
+
+- (id)a:(B)b {
+    return 1;
+}
+
+@end
+
+@implementation ABC
+
+- (void)xyz;
+
+@end
+
 NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
     @"quattuor", @"four", @"quinque", @"five", @"sex", @"six", nil];