]>
Commit | Line | Data |
---|---|---|
c7c260a5 RB |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | #ifndef INCLUDE_userdiff_h__ | |
8 | #define INCLUDE_userdiff_h__ | |
9 | ||
10 | /* | |
11 | * This file isolates the built in diff driver function name patterns. | |
12 | * Most of these patterns are taken from Git (with permission from the | |
13 | * original authors for relicensing to libgit2). | |
14 | */ | |
15 | ||
16 | typedef struct { | |
17 | const char *name; | |
18 | const char *fns; | |
19 | const char *words; | |
20 | int flags; | |
21 | } git_diff_driver_definition; | |
22 | ||
23 | #define WORD_DEFAULT "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" | |
24 | ||
25 | /* | |
26 | * These builtin driver definition macros have same signature as in core | |
27 | * git userdiff.c so that the data can be extracted verbatim | |
28 | */ | |
29 | #define PATTERNS(NAME, FN_PATS, WORD_PAT) \ | |
30 | { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 } | |
31 | #define IPATTERN(NAME, FN_PATS, WORD_PAT) \ | |
32 | { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, REG_ICASE } | |
33 | ||
34 | /* | |
35 | * The table of diff driver patterns | |
36 | * | |
37 | * Function name patterns are a list of newline separated patterns that | |
38 | * match a function declaration (i.e. the line you want in the hunk header), | |
39 | * or a negative pattern prefixed with a '!' to reject a pattern (such as | |
40 | * rejecting goto labels in C code). | |
41 | * | |
42 | * Word boundary patterns are just a simple pattern that will be OR'ed with | |
43 | * the default value above (i.e. whitespace or non-ASCII characters). | |
44 | */ | |
45 | static git_diff_driver_definition builtin_defs[] = { | |
46 | ||
47 | IPATTERN("ada", | |
48 | "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n" | |
49 | "!^[ \t]*with[ \t].*$\n" | |
50 | "^[ \t]*((procedure|function)[ \t]+.*)$\n" | |
51 | "^[ \t]*((package|protected|task)[ \t]+.*)$", | |
52 | /* -- */ | |
53 | "[a-zA-Z][a-zA-Z0-9_]*" | |
54 | "|[0-9][-+0-9#_.eE]" | |
55 | "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"), | |
56 | ||
57 | IPATTERN("fortran", | |
58 | "!^([C*]|[ \t]*!)\n" | |
59 | "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n" | |
60 | "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA" | |
61 | "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$", | |
62 | /* -- */ | |
63 | "[a-zA-Z][a-zA-Z0-9_]*" | |
64 | "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\." | |
65 | /* numbers and format statements like 2E14.4, or ES12.6, 9X. | |
66 | * Don't worry about format statements without leading digits since | |
67 | * they would have been matched above as a variable anyway. */ | |
68 | "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?" | |
69 | "|//|\\*\\*|::|[/<>=]="), | |
70 | ||
71 | PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$", | |
72 | "[^<>= \t]+"), | |
73 | ||
74 | PATTERNS("java", | |
75 | "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n" | |
76 | "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$", | |
77 | /* -- */ | |
78 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
79 | "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" | |
80 | "|[-+*/<>%&^|=!]=" | |
81 | "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), | |
82 | ||
41159877 RB |
83 | PATTERNS("matlab", |
84 | "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$", | |
85 | "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"), | |
86 | ||
c7c260a5 RB |
87 | PATTERNS("objc", |
88 | /* Negate C statements that can look like functions */ | |
89 | "!^[ \t]*(do|for|if|else|return|switch|while)\n" | |
90 | /* Objective-C methods */ | |
91 | "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n" | |
92 | /* C functions */ | |
93 | "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n" | |
94 | /* Objective-C class/protocol definitions */ | |
95 | "^(@(implementation|interface|protocol)[ \t].*)$", | |
96 | /* -- */ | |
97 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
98 | "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" | |
99 | "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), | |
100 | ||
3b19d2fd RB |
101 | PATTERNS("pascal", |
102 | "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface|" | |
103 | "implementation|initialization|finalization)[ \t]*.*)$" | |
104 | "\n" | |
105 | "^(.*=[ \t]*(class|record).*)$", | |
106 | /* -- */ | |
107 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
108 | "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+" | |
109 | "|<>|<=|>=|:=|\\.\\."), | |
110 | ||
c7c260a5 RB |
111 | PATTERNS("perl", |
112 | "^package .*\n" | |
113 | "^sub [[:alnum:]_':]+[ \t]*" | |
114 | "(\\([^)]*\\)[ \t]*)?" /* prototype */ | |
115 | /* | |
116 | * Attributes. A regex can't count nested parentheses, | |
117 | * so just slurp up whatever we see, taking care not | |
118 | * to accept lines like "sub foo; # defined elsewhere". | |
119 | * | |
120 | * An attribute could contain a semicolon, but at that | |
121 | * point it seems reasonable enough to give up. | |
122 | */ | |
123 | "(:[^;#]*)?" | |
124 | "(\\{[ \t]*)?" /* brace can come here or on the next line */ | |
125 | "(#.*)?$\n" /* comment */ | |
126 | "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*" | |
127 | "(\\{[ \t]*)?" /* brace can come here or on the next line */ | |
128 | "(#.*)?$\n" | |
129 | "^=head[0-9] .*", /* POD */ | |
130 | /* -- */ | |
131 | "[[:alpha:]_'][[:alnum:]_']*" | |
132 | "|0[xb]?[0-9a-fA-F_]*" | |
133 | /* taking care not to interpret 3..5 as (3.)(.5) */ | |
134 | "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?" | |
135 | "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::" | |
136 | "|&&=|\\|\\|=|//=|\\*\\*=" | |
137 | "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?" | |
138 | "|[-+*/%.^&<>=!|]=" | |
139 | "|=~|!~" | |
140 | "|<<|<>|<=>|>>"), | |
141 | ||
142 | PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$", | |
143 | /* -- */ | |
144 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
145 | "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?" | |
146 | "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"), | |
147 | ||
148 | PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$", | |
149 | /* -- */ | |
150 | "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" | |
151 | "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." | |
152 | "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), | |
153 | ||
154 | PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$", | |
155 | "[={}\"]|[^={}\" \t]+"), | |
156 | ||
157 | PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$", | |
158 | "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"), | |
159 | ||
160 | PATTERNS("cpp", | |
161 | /* Jump targets or access declarations */ | |
76b4e3d4 JK |
162 | "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])\n" |
163 | /* functions/methods, variables, and compounds at top level */ | |
164 | "^((::[[:space:]]*)?[A-Za-z_].*)$", | |
c7c260a5 RB |
165 | /* -- */ |
166 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
76b4e3d4 JK |
167 | "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lLuU]*" |
168 | "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*"), | |
3b19d2fd RB |
169 | |
170 | PATTERNS("csharp", | |
171 | /* Keywords */ | |
172 | "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n" | |
173 | /* Methods and constructors */ | |
174 | "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n" | |
175 | /* Properties */ | |
176 | "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n" | |
177 | /* Type definitions */ | |
178 | "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n" | |
179 | /* Namespace */ | |
180 | "^[ \t]*(namespace[ \t]+.*)$", | |
181 | /* -- */ | |
182 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
183 | "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" | |
184 | "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), | |
7cc001ce RB |
185 | |
186 | PATTERNS("php", | |
daebb598 | 187 | "^[ \t]*(((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*))$", |
7cc001ce RB |
188 | /* -- */ |
189 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
190 | "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" | |
191 | "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), | |
192 | ||
193 | PATTERNS("javascript", | |
e9d5e5f3 RB |
194 | "^[ \t]*(function[ \t][a-zA-Z_][^\\{]*)\n" |
195 | "^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\\(][^\\{]*)\n" | |
196 | "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\\(][^\\{]*)", | |
7cc001ce RB |
197 | /* -- */ |
198 | "[a-zA-Z_][a-zA-Z0-9_]*" | |
199 | "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" | |
200 | "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), | |
c7c260a5 RB |
201 | }; |
202 | ||
203 | #undef IPATTERN | |
204 | #undef PATTERNS | |
205 | #undef WORD_DEFAULT | |
206 | ||
207 | #endif | |
208 |