userdiff: add built-in pattern for CSS
CSS is widely used, motivating it being included as a built-in pattern. It must be noted that the word_regex for CSS (i.e. the regex defining what is a word in the language) does not consider '.' and '#' characters (in CSS selectors) to be part of the word. This behavior is documented by the test t/t4018/css-rule. The logic behind this behavior is the following: identifiers in CSS selectors are identifiers in a HTML/XML document. Therefore, the '.'/'#' character are not part of the identifier, but an indicator of the nature of the identifier in HTML/XML (class or id). Diffing ".class1" and ".class2" must show that the class name is changed, but we still are selecting a class. Logic behind the "pattern" regex is: 1. reject lines ending with a colon/semicolon (properties) 2. if a line begins with a name in column 1, pick the whole line Credits to Johannes Sixt (j6t@kdbg.org) for the pattern regex and most of the tests. Signed-off-by: William Duclot <william.duclot@ensimag.grenoble-inp.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4b0891ffe4
commit
0719f3eecd
12
userdiff.c
12
userdiff.c
@ -148,6 +148,18 @@ PATTERNS("csharp",
|
||||
"[a-zA-Z_][a-zA-Z0-9_]*"
|
||||
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
|
||||
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
|
||||
IPATTERN("css",
|
||||
"![:;][[:space:]]*$\n"
|
||||
"^[_a-z0-9].*$",
|
||||
/* -- */
|
||||
/*
|
||||
* This regex comes from W3C CSS specs. Should theoretically also
|
||||
* allow ISO 10646 characters U+00A0 and higher,
|
||||
* but they are not handled in this regex.
|
||||
*/
|
||||
"-?[_a-zA-Z][-_a-zA-Z0-9]*" /* identifiers */
|
||||
"|-?[0-9]+|\\#[0-9a-fA-F]+" /* numbers */
|
||||
),
|
||||
{ "default", NULL, -1, { NULL, 0 } },
|
||||
};
|
||||
#undef PATTERNS
|
||||
|
Reference in New Issue
Block a user