git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] userdiff: add built-in pattern for CSS

From
Junio C Hamano <gitster@pobox.com>
Date
May 20, 2016, 22:37 UTC
Message-ID
<xmqqshxcbbkp.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160520132829.7937-1-william.duclot@ensimag.grenoble-inp.fr>
William Duclot <william.duclot@ensimag.grenoble-inp.fr> writes:
Show 12 quoted lines
> 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.

In other words, if "div#foo" changed to "span#bar", word-diff would say that "div changed to span, # didn't change and foo changed to bar".

Which makes sense to me.

The above is not a request to change anything; just me thinking aloud to see if I agree with the reasoning.

Show 16 quoted lines
> 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 */
> +),
Style:
	/*
         * This regex comes from ...
         * ...
         * but they are not handled with this regex.
         */
I wonder if IPATTERN() may make it easier to express the above.

Also, a-zA-F (twice seen in "identifiers" section) looks somewhat suspicious. a-fA-F or a-zA-Z I would understand, and I suspect this is a misspelled form of the latter.

Previous: William DuclotNext: William Duclot
Message 2 of 21 in “userdiff: add built-in pattern for CSS”
  1. userdiff: add built-in pattern for CSSWilliam Duclot, May 20, 2016
  2. Junio C HamanoMay 20, 2016
  3. userdiff: add built-in pattern for CSSWilliam Duclot, May 24, 2016
  4. Junio C HamanoMay 24, 2016
  5. William DuclotMay 24, 2016
  6. Junio C HamanoMay 24, 2016
  7. Johannes SixtMay 26, 2016
  8. William DuclotMay 27, 2016
  9. userdiff: add built-in pattern for CSSWilliam Duclot, Jun 2, 2016
  10. Junio C HamanoJun 2, 2016
  11. Johannes SixtJun 3, 2016
  12. Matthieu MoyJun 3, 2016
  13. Johannes SixtJun 3, 2016
  14. William DuclotJun 3, 2016
  15. Junio C HamanoJun 3, 2016
  16. William DuclotJun 6, 2016
  17. Junio C HamanoJun 6, 2016
  18. William DuclotJun 6, 2016
  19. Junio C HamanoJun 6, 2016
  20. userdiff: add built-in pattern for CSSWilliam Duclot, Jun 3, 2016
  21. Johannes SixtJun 3, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.