[SVN] Patch to fix C macro parsing

Sam Vaughan samvaughan at mac.com
Thu Jan 11 05:47:42 UTC 2007


The following patch fixes the C macro parsing regular expression,  
which currently requires macros to have arguments and doesn't know  
about varargs.  I've pasted it inline for the benefit of the  
archives, and attached a diff that won't get munged by Apple Mail.

If someone could review and check this in that'd be great.

Thanks,

Sam

- - - - - - - -

Two changes to the meta.preprocessor.macro.c parsing:

- Made macro arguments optional to correctly match basic macros, e.g:

     #define SPINAL_TAP_VOLUME 11

- Permitted a trailing ellipsis to match macros with varargs, e.g:

     #define ERR_IF(condition, function, format, args...)   \
     if (condition)                                         \
     {                                                      \
         fprintf(stderr, "%s:%d in %s(): " format,          \
                 __FILE__, __LINE__, __FUNCTION__, ##args); \
         perror(" with " #function "() failed");            \
     }

- - - - - - - -

Index: Syntaxes/C.plist
===================================================================
--- Syntaxes/C.plist	(revision 6438)
+++ Syntaxes/C.plist	(working copy)
@@ -200,12 +200,17 @@
		<dict>
			<key>begin</key>
			<string>(?x)
-				^\s*\#\s*(define)\s+             # define
+				^\s*\#\s*(define)\s+                   # define
				((?<id>[a-zA-Z_][a-zA-Z0-9_]*))  # macro name
-				(\()(
-					\s* \g<id> \s*              # first argument
-					(, \s* \g<id> \s*)*         # additional arguments
-				)(\))
+				(?:                                    # and optionally:
+				    (\()                               # an open parenthesis
+				        (
+				            \s* \g<id> \s*       # first argument
+				            (, \s* \g<id> \s*)*  # additional arguments
+				            (?:\.\.\.)?                # varargs ellipsis?
+				        )
+				    (\))                               # a close parenthesis
+				)?
			</string>
			<key>beginCaptures</key>
			<dict>

- - - - - - - -

-------------- next part --------------
A non-text attachment was scrubbed...
Name: meta.preprocessor.macro.c.diff.gz
Type: application/x-gzip
Size: 421 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate-dev/attachments/20070111/fa11f435/attachment.gz>


More information about the textmate-dev mailing list