From: William Duclot <william.duclot@ensimag.grenoble-inp.fr>
To: git@vger.kernel.org
Cc: simon.rabourg@ensimag.grenoble-inp.fr,
francois.beutin@ensimag.grenoble-inp.fr,
antoine.queru@ensimag.grenoble-inp.fr,
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Subject: [PATCH] userdiff: add built-in pattern for CSS
Date: Fri, 20 May 2016 15:28:29 +0200 [thread overview]
Message-ID: <20160520132829.7937-1-william.duclot@ensimag.grenoble-inp.fr> (raw)
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.
Signed-off-by: William Duclot <william.duclot@ensimag.grenoble-inp.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
Documentation/gitattributes.txt | 2 ++
t/t4018-diff-funcname.sh | 1 +
t/t4018/css-rule | 4 ++++
t/t4034-diff-words.sh | 1 +
t/t4034/css/expect | 16 ++++++++++++++++
t/t4034/css/post | 9 +++++++++
t/t4034/css/pre | 9 +++++++++
userdiff.c | 8 ++++++++
8 files changed, 50 insertions(+)
create mode 100644 t/t4018/css-rule
create mode 100644 t/t4034/css/expect
create mode 100644 t/t4034/css/post
create mode 100644 t/t4034/css/pre
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index e3b1de8..81f60ad 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -525,6 +525,8 @@ patterns are available:
- `csharp` suitable for source code in the C# language.
+- `css` suitable for source code in the CSS language.
+
- `fortran` suitable for source code in the Fortran language.
- `fountain` suitable for Fountain documents.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 67373dc..1795ffc 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -30,6 +30,7 @@ diffpatterns="
bibtex
cpp
csharp
+ css
fortran
fountain
html
diff --git a/t/t4018/css-rule b/t/t4018/css-rule
new file mode 100644
index 0000000..84ed754
--- /dev/null
+++ b/t/t4018/css-rule
@@ -0,0 +1,4 @@
+RIGHT label.control-label {
+ margin-top: 10px!important;
+ border : 10px ChangeMe #C6C6C6;
+}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f2f55fc..912df91 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -302,6 +302,7 @@ test_language_driver ada
test_language_driver bibtex
test_language_driver cpp
test_language_driver csharp
+test_language_driver css
test_language_driver fortran
test_language_driver html
test_language_driver java
diff --git a/t/t4034/css/expect b/t/t4034/css/expect
new file mode 100644
index 0000000..b025d88
--- /dev/null
+++ b/t/t4034/css/expect
@@ -0,0 +1,16 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 735f301..bdf6a90 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,9 +1,9 @@<RESET>
+.<RED>class-form<RESET><GREEN>other-form<RESET> label.control-label {
+ margin-top: <RED>10<RESET><GREEN>15<RESET>px!important;
+ border : 10px <RED>dashed<RESET><GREEN>dotted<RESET> #C6C6C6;
+}<RESET>
+<RED>#CCCCCC<RESET>
+<RED>padding-bottom<RESET><GREEN>#CCCCCB<RESET>
+<GREEN>margin-left<RESET>
+150<RED>px<RESET><GREEN>em<RESET>
+10px
+<RED>!important<RESET>
+<RED>div<RESET><GREEN>li<RESET>.class#id
diff --git a/t/t4034/css/post b/t/t4034/css/post
new file mode 100644
index 0000000..bdf6a90
--- /dev/null
+++ b/t/t4034/css/post
@@ -0,0 +1,9 @@
+.other-form label.control-label {
+ margin-top: 15px!important;
+ border : 10px dotted #C6C6C6;
+}
+#CCCCCB
+margin-left
+150em
+10px
+li.class#id
diff --git a/t/t4034/css/pre b/t/t4034/css/pre
new file mode 100644
index 0000000..735f301
--- /dev/null
+++ b/t/t4034/css/pre
@@ -0,0 +1,9 @@
+.class-form label.control-label {
+ margin-top: 10px!important;
+ border : 10px dashed #C6C6C6;
+}
+#CCCCCC
+padding-bottom
+150px
+10px!important
+div.class#id
diff --git a/userdiff.c b/userdiff.c
index 6bf2505..0f9cfbe 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -148,6 +148,14 @@ PATTERNS("csharp",
"[a-zA-Z_][a-zA-Z0-9_]*"
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
+PATTERNS("css",
+ "^([^,{}]+)((,[^}]*\\{)|([ \t]*\\{))$",
+ /* -- */
+ /* This regex comes from W3C CSS specs. Should theoretically also allow ISO 10646 characters U+00A0 and higher,
+ * this not handled in this regex. */
+ "-?[_a-zA-F][-_a-zA-F0-9]*" /* identifiers */
+ "|-?[0-9]+|\\#[0-9a-fA-F]+" /* numbers */
+),
{ "default", NULL, -1, { NULL, 0 } },
};
#undef PATTERNS
--
2.8.2.403.gdf0b511.dirty
next reply other threads:[~2016-05-20 13:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 13:28 William Duclot [this message]
2016-05-20 22:37 ` [PATCH] userdiff: add built-in pattern for CSS Junio C Hamano
2016-05-24 14:25 ` William Duclot
2016-05-24 19:06 ` Junio C Hamano
2016-05-24 22:12 ` William Duclot
2016-05-24 22:18 ` Junio C Hamano
2016-05-26 21:11 ` Johannes Sixt
2016-05-27 7:48 ` William Duclot
2016-06-02 22:48 ` William Duclot
2016-06-02 23:07 ` Junio C Hamano
2016-06-03 5:52 ` Johannes Sixt
2016-06-03 6:41 ` Matthieu Moy
2016-06-03 6:56 ` Johannes Sixt
2016-06-03 9:45 ` William Duclot
2016-06-03 15:50 ` Junio C Hamano
2016-06-06 7:28 ` William Duclot
2016-06-06 18:00 ` Junio C Hamano
2016-06-06 20:45 ` William Duclot
2016-06-06 20:55 ` Junio C Hamano
2016-06-03 12:32 ` William Duclot
2016-06-03 21:31 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160520132829.7937-1-william.duclot@ensimag.grenoble-inp.fr \
--to=william.duclot@ensimag.grenoble-inp.fr \
--cc=antoine.queru@ensimag.grenoble-inp.fr \
--cc=francois.beutin@ensimag.grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=matthieu.moy@grenoble-inp.fr \
--cc=simon.rabourg@ensimag.grenoble-inp.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).