@@ -6,35 +6,81 @@ static struct userdiff_driver *drivers;
66static int ndrivers ;
77static int drivers_alloc ;
88
9- #define FUNCNAME (name , pattern ) \
10- { name, NULL, -1, { pattern, REG_EXTENDED } }
9+ #define PATTERNS (name , pattern , wordregex ) \
10+ { name, NULL, -1, { pattern, REG_EXTENDED }, wordregex }
1111static struct userdiff_driver builtin_drivers [] = {
12- FUNCNAME ("html" , "^[ \t]*(<[Hh][1-6][ \t].*>.*)$" ),
13- FUNCNAME ("java" ,
12+ PATTERNS ("html" , "^[ \t]*(<[Hh][1-6][ \t].*>.*)$" ,
13+ "[^<>= \t]+|[^[:space:]]|[\x80-\xff]+" ),
14+ PATTERNS ("java" ,
1415 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
15- "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$" ),
16- FUNCNAME ("objc" ,
16+ "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$" ,
17+ "[a-zA-Z_][a-zA-Z0-9_]*"
18+ "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
19+ "|[-+*/<>%&^|=!]="
20+ "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"
21+ "|[^[:space:]]|[\x80-\xff]+" ),
22+ PATTERNS ("objc" ,
1723 /* Negate C statements that can look like functions */
1824 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
1925 /* Objective-C methods */
2026 "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
2127 /* C functions */
2228 "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$\n"
2329 /* Objective-C class/protocol definitions */
24- "^(@(implementation|interface|protocol)[ \t].*)$" ),
25- FUNCNAME ("pascal" ,
30+ "^(@(implementation|interface|protocol)[ \t].*)$" ,
31+ /* -- */
32+ "[a-zA-Z_][a-zA-Z0-9_]*"
33+ "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
34+ "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
35+ "|[^[:space:]]|[\x80-\xff]+" ),
36+ PATTERNS ("pascal" ,
2637 "^((procedure|function|constructor|destructor|interface|"
2738 "implementation|initialization|finalization)[ \t]*.*)$"
2839 "\n"
29- "^(.*=[ \t]*(class|record).*)$" ),
30- FUNCNAME ("php" , "^[\t ]*((function|class).*)" ),
31- FUNCNAME ("python" , "^[ \t]*((class|def)[ \t].*)$" ),
32- FUNCNAME ("ruby" , "^[ \t]*((class|module|def)[ \t].*)$" ),
33- FUNCNAME ("bibtex" , "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$" ),
34- FUNCNAME ("tex" , "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$" ),
40+ "^(.*=[ \t]*(class|record).*)$" ,
41+ /* -- */
42+ "[a-zA-Z_][a-zA-Z0-9_]*"
43+ "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
44+ "|<>|<=|>=|:=|\\.\\."
45+ "|[^[:space:]]|[\x80-\xff]+" ),
46+ PATTERNS ("php" , "^[\t ]*((function|class).*)" ,
47+ /* -- */
48+ "[a-zA-Z_][a-zA-Z0-9_]*"
49+ "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
50+ "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"
51+ "|[^[:space:]]|[\x80-\xff]+" ),
52+ PATTERNS ("python" , "^[ \t]*((class|def)[ \t].*)$" ,
53+ /* -- */
54+ "[a-zA-Z_][a-zA-Z0-9_]*"
55+ "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
56+ "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"
57+ "|[^[:space:]|[\x80-\xff]+" ),
58+ /* -- */
59+ PATTERNS ("ruby" , "^[ \t]*((class|module|def)[ \t].*)$" ,
60+ /* -- */
61+ "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
62+ "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
63+ "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"
64+ "|[^[:space:]|[\x80-\xff]+" ),
65+ PATTERNS ("bibtex" , "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$" ,
66+ "[={}\"]|[^={}\" \t]+" ),
67+ PATTERNS ("tex" , "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$" ,
68+ "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+|[^[:space:]]" ),
69+ PATTERNS ("cpp" ,
70+ /* Jump targets or access declarations */
71+ "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:.*$\n"
72+ /* C/++ functions/methods at top level */
73+ "^([A-Za-z_][A-Za-z_0-9]*([ \t]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"
74+ /* compound type at top level */
75+ "^((struct|class|enum)[^;]*)$" ,
76+ /* -- */
77+ "[a-zA-Z_][a-zA-Z0-9_]*"
78+ "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
79+ "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
80+ "|[^[:space:]]|[\x80-\xff]+" ),
3581{ "default" , NULL , -1 , { NULL , 0 } },
3682};
37- #undef FUNCNAME
83+ #undef PATTERNS
3884
3985static struct userdiff_driver driver_true = {
4086 "diff=true" ,
@@ -134,6 +180,8 @@ int userdiff_config(const char *k, const char *v)
134180 return parse_string (& drv -> external , k , v );
135181 if ((drv = parse_driver (k , v , "textconv" )))
136182 return parse_string (& drv -> textconv , k , v );
183+ if ((drv = parse_driver (k , v , "wordregex" )))
184+ return parse_string (& drv -> word_regex , k , v );
137185
138186 return 0 ;
139187}
0 commit comments