]> git.proxmox.com Git - libgit2.git/blame - src/userdiff.h
Add PHP and Javascript diff drivers
[libgit2.git] / src / userdiff.h
CommitLineData
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
16typedef 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 */
45static git_diff_driver_definition builtin_defs[] = {
46
47IPATTERN("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
57IPATTERN("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
71PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
72 "[^<>= \t]+"),
73
74PATTERNS("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
83PATTERNS("objc",
84 /* Negate C statements that can look like functions */
85 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
86 /* Objective-C methods */
87 "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
88 /* C functions */
89 "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n"
90 /* Objective-C class/protocol definitions */
91 "^(@(implementation|interface|protocol)[ \t].*)$",
92 /* -- */
93 "[a-zA-Z_][a-zA-Z0-9_]*"
94 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
95 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
96
3b19d2fd
RB
97PATTERNS("pascal",
98 "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface|"
99 "implementation|initialization|finalization)[ \t]*.*)$"
100 "\n"
101 "^(.*=[ \t]*(class|record).*)$",
102 /* -- */
103 "[a-zA-Z_][a-zA-Z0-9_]*"
104 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
105 "|<>|<=|>=|:=|\\.\\."),
106
c7c260a5
RB
107PATTERNS("perl",
108 "^package .*\n"
109 "^sub [[:alnum:]_':]+[ \t]*"
110 "(\\([^)]*\\)[ \t]*)?" /* prototype */
111 /*
112 * Attributes. A regex can't count nested parentheses,
113 * so just slurp up whatever we see, taking care not
114 * to accept lines like "sub foo; # defined elsewhere".
115 *
116 * An attribute could contain a semicolon, but at that
117 * point it seems reasonable enough to give up.
118 */
119 "(:[^;#]*)?"
120 "(\\{[ \t]*)?" /* brace can come here or on the next line */
121 "(#.*)?$\n" /* comment */
122 "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*"
123 "(\\{[ \t]*)?" /* brace can come here or on the next line */
124 "(#.*)?$\n"
125 "^=head[0-9] .*", /* POD */
126 /* -- */
127 "[[:alpha:]_'][[:alnum:]_']*"
128 "|0[xb]?[0-9a-fA-F_]*"
129 /* taking care not to interpret 3..5 as (3.)(.5) */
130 "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
131 "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
132 "|&&=|\\|\\|=|//=|\\*\\*="
133 "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
134 "|[-+*/%.^&<>=!|]="
135 "|=~|!~"
136 "|<<|<>|<=>|>>"),
137
138PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
139 /* -- */
140 "[a-zA-Z_][a-zA-Z0-9_]*"
141 "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
142 "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
143
144PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
145 /* -- */
146 "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
147 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
148 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
149
150PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
151 "[={}\"]|[^={}\" \t]+"),
152
153PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
154 "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"),
155
156PATTERNS("cpp",
157 /* Jump targets or access declarations */
158 "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:.*$\n"
159 /* C/++ functions/methods at top level */
160 "^([A-Za-z_][A-Za-z_0-9]*([ \t*]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"
161 /* compound type at top level */
162 "^((struct|class|enum)[^;]*)$",
163 /* -- */
164 "[a-zA-Z_][a-zA-Z0-9_]*"
165 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
166 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
3b19d2fd
RB
167
168PATTERNS("csharp",
169 /* Keywords */
170 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
171 /* Methods and constructors */
172 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
173 /* Properties */
174 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
175 /* Type definitions */
176 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n"
177 /* Namespace */
178 "^[ \t]*(namespace[ \t]+.*)$",
179 /* -- */
180 "[a-zA-Z_][a-zA-Z0-9_]*"
181 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
182 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
7cc001ce
RB
183
184PATTERNS("php",
185 "^[ \t]*((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*)$",
186 /* -- */
187 "[a-zA-Z_][a-zA-Z0-9_]*"
188 "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
189 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
190
191PATTERNS("javascript",
192 "^[ \t]*(\(?function[ \t].*)$\n"
193 "^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\(].*)$\n"
194 "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\(].*)$",
195 /* -- */
196 "[a-zA-Z_][a-zA-Z0-9_]*"
197 "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
198 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
c7c260a5
RB
199};
200
201#undef IPATTERN
202#undef PATTERNS
203#undef WORD_DEFAULT
204
205#endif
206