Blame src/userdiff.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_userdiff_h__
Packit Service 20376f
#define INCLUDE_userdiff_h__
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * This file isolates the built in diff driver function name patterns.
Packit Service 20376f
 * Most of these patterns are taken from Git (with permission from the
Packit Service 20376f
 * original authors for relicensing to libgit2).
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
typedef struct {
Packit Service 20376f
	const char *name;
Packit Service 20376f
	const char *fns;
Packit Service 20376f
	const char *words;
Packit Service 20376f
	int flags;
Packit Service 20376f
} git_diff_driver_definition;
Packit Service 20376f
Packit Service 20376f
#define WORD_DEFAULT "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+"
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * These builtin driver definition macros have same signature as in core
Packit Service 20376f
 * git userdiff.c so that the data can be extracted verbatim
Packit Service 20376f
 */
Packit Service 20376f
#define PATTERNS(NAME, FN_PATS, WORD_PAT) \
Packit Service 20376f
	{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 }
Packit Service 20376f
#define IPATTERN(NAME, FN_PATS, WORD_PAT) \
Packit Service 20376f
	{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, REG_ICASE }
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * The table of diff driver patterns
Packit Service 20376f
 *
Packit Service 20376f
 * Function name patterns are a list of newline separated patterns that
Packit Service 20376f
 * match a function declaration (i.e. the line you want in the hunk header),
Packit Service 20376f
 * or a negative pattern prefixed with a '!' to reject a pattern (such as
Packit Service 20376f
 * rejecting goto labels in C code).
Packit Service 20376f
 *
Packit Service 20376f
 * Word boundary patterns are just a simple pattern that will be OR'ed with
Packit Service 20376f
 * the default value above (i.e. whitespace or non-ASCII characters).
Packit Service 20376f
 */
Packit Service 20376f
static git_diff_driver_definition builtin_defs[] = {
Packit Service 20376f
Packit Service 20376f
IPATTERN("ada",
Packit Service 20376f
	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
Packit Service 20376f
	 "!^[ \t]*with[ \t].*$\n"
Packit Service 20376f
	 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
Packit Service 20376f
	 "^[ \t]*((package|protected|task)[ \t]+.*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
Packit Service 20376f
	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
Packit Service 20376f
Packit Service 20376f
IPATTERN("fortran",
Packit Service 20376f
	 "!^([C*]|[ \t]*!)\n"
Packit Service 20376f
	 "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
Packit Service 20376f
	 "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
Packit Service 20376f
		"|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|\\.([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])\\."
Packit Service 20376f
	 /* numbers and format statements like 2E14.4, or ES12.6, 9X.
Packit Service 20376f
	  * Don't worry about format statements without leading digits since
Packit Service 20376f
	  * they would have been matched above as a variable anyway. */
Packit Service 20376f
	 "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
Packit Service 20376f
	 "|//|\\*\\*|::|[/<>=]="),
Packit Service 20376f
Packit Service 20376f
PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
Packit Service 20376f
	 "[^<>= \t]+"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("java",
Packit Service 20376f
	 "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
Packit Service 20376f
	 "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]="
Packit Service 20376f
	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("matlab",
Packit Service 20376f
	 "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("objc",
Packit Service 20376f
	 /* Negate C statements that can look like functions */
Packit Service 20376f
	 "!^[ \t]*(do|for|if|else|return|switch|while)\n"
Packit Service 20376f
	 /* Objective-C methods */
Packit Service 20376f
	 "^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
Packit Service 20376f
	 /* C functions */
Packit Service 20376f
	 "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n"
Packit Service 20376f
	 /* Objective-C class/protocol definitions */
Packit Service 20376f
	 "^(@(implementation|interface|protocol)[ \t].*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("pascal",
Packit Service 20376f
	 "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface|"
Packit Service 20376f
		"implementation|initialization|finalization)[ \t]*.*)$"
Packit Service 20376f
	 "\n"
Packit Service 20376f
	 "^(.*=[ \t]*(class|record).*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
Packit Service 20376f
	 "|<>|<=|>=|:=|\\.\\."),
Packit Service 20376f
Packit Service 20376f
PATTERNS("perl",
Packit Service 20376f
	 "^package .*\n"
Packit Service 20376f
	 "^sub [[:alnum:]_':]+[ \t]*"
Packit Service 20376f
		"(\\([^)]*\\)[ \t]*)?" /* prototype */
Packit Service 20376f
		/*
Packit Service 20376f
		 * Attributes.  A regex can't count nested parentheses,
Packit Service 20376f
		 * so just slurp up whatever we see, taking care not
Packit Service 20376f
		 * to accept lines like "sub foo; # defined elsewhere".
Packit Service 20376f
		 *
Packit Service 20376f
		 * An attribute could contain a semicolon, but at that
Packit Service 20376f
		 * point it seems reasonable enough to give up.
Packit Service 20376f
		 */
Packit Service 20376f
		"(:[^;#]*)?"
Packit Service 20376f
		"(\\{[ \t]*)?" /* brace can come here or on the next line */
Packit Service 20376f
		"(#.*)?$\n" /* comment */
Packit Service 20376f
	 "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*"
Packit Service 20376f
		"(\\{[ \t]*)?" /* brace can come here or on the next line */
Packit Service 20376f
		"(#.*)?$\n"
Packit Service 20376f
	 "^=head[0-9] .*",	/* POD */
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[[:alpha:]_'][[:alnum:]_']*"
Packit Service 20376f
	 "|0[xb]?[0-9a-fA-F_]*"
Packit Service 20376f
	 /* taking care not to interpret 3..5 as (3.)(.5) */
Packit Service 20376f
	 "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
Packit Service 20376f
	 "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
Packit Service 20376f
	 "|&&=|\\|\\|=|//=|\\*\\*="
Packit Service 20376f
	 "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
Packit Service 20376f
	 "|[-+*/%.^&<>=!|]="
Packit Service 20376f
	 "|=~|!~"
Packit Service 20376f
	 "|<<|<>|<=>|>>"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
Packit Service 20376f
	 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
Packit Service 20376f
	 "[={}\"]|[^={}\" \t]+"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
Packit Service 20376f
	 "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("cpp",
Packit Service 20376f
	 /* Jump targets or access declarations */
Packit Service 20376f
	 "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])\n"
Packit Service 20376f
	 /* functions/methods, variables, and compounds at top level */
Packit Service 20376f
	 "^((::[[:space:]]*)?[A-Za-z_].*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lLuU]*"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("csharp",
Packit Service 20376f
	 /* Keywords */
Packit Service 20376f
	 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
Packit Service 20376f
	 /* Methods and constructors */
Packit Service 20376f
	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
Packit Service 20376f
	 /* Properties */
Packit Service 20376f
	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
Packit Service 20376f
	 /* Type definitions */
Packit Service 20376f
	 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n"
Packit Service 20376f
	 /* Namespace */
Packit Service 20376f
	 "^[ \t]*(namespace[ \t]+.*)$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("php",
Packit Service 20376f
	 "^[ \t]*(((public|private|protected|static|final)[ \t]+)*((class|function)[ \t].*))$",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
Packit Service 20376f
Packit Service 20376f
PATTERNS("javascript",
Packit Service 20376f
	 "([a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z0-9_$]+)*[ \t]*=[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
Packit Service 20376f
	 "([a-zA-Z_$][a-zA-Z0-9_$]*[ \t]*:[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
Packit Service 20376f
	 "[^a-zA-Z0-9_\\$](function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)",
Packit Service 20376f
	 /* -- */
Packit Service 20376f
	 "[a-zA-Z_][a-zA-Z0-9_]*"
Packit Service 20376f
	 "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
Packit Service 20376f
	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#undef IPATTERN
Packit Service 20376f
#undef PATTERNS
Packit Service 20376f
#undef WORD_DEFAULT
Packit Service 20376f
Packit Service 20376f
#endif
Packit Service 20376f