Re: [PATCH v2] userdiff: support Bash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Johannes Sixt <j6t@xxxxxxxx> writes:

>> diff --git a/t/t4018/bash-missing-parentheses b/t/t4018/bash-missing-parentheses
>> new file mode 100644
>> index 0000000000..d112761300
>> --- /dev/null
>> +++ b/t/t4018/bash-missing-parentheses
>> @@ -0,0 +1,4 @@
>> +functionRIGHT { # non-match
>> +    :
>> +    echo 'ChangeMe'
>> +}
>
> To check for a non-match, you write the test like this:
>
> 	function RIGHT () {
> 	}
> 	# the following must not be picked up:
> 	functionWrong {
> 		:
> 		ChangeMe
> 	}
>
> That is, you present a positive match, and then expect that the
> subsequent negative match is not picked up.

All good suggestions, but I especially appreciate this one ;-).

>> diff --git a/userdiff.c b/userdiff.c
>> index fde02f225b..8830019f05 100644
>> --- a/userdiff.c
>> +++ b/userdiff.c
>> @@ -23,6 +23,28 @@ IPATTERN("ada",
>>  	 "[a-zA-Z][a-zA-Z0-9_]*"
>>  	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
>>  	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
>> +PATTERNS("bash",
>> +	 /* Optional leading indentation */
>> +	 "^[ \t]*"
>> +	 /* Start of function definition */
>> +	 "("
>
> The purpose of this outer-most pair of parentheses is actually to mark
> the captured text, not so much "the function definition".

This, too (I called it "here comes the whole thing" in my suggested
version ).

>> +	 /* Start of POSIX/Bashism grouping */
>> +	 "("
>
> You could omit the comment if you indent the parts that are inside the
> parentheses:
>
> 	"("
> 		"..."
> 	"|"
> 		"..."
> 	")"
>

An excellent readability suggestion.

Thanks for a review.  Especially the parts that mine didn't touch
(i.e. the proposed log message).

> (But perhaps don't indent between the outer-most parentheses; it would
> get us too far to the right. But judge yourself.)
>
>> +	 /* POSIX identifier with mandatory parentheses */
>> +	 "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
>> +	 /* Bashism identifier with optional parentheses */
>> +	 "|(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
>> +	 /* End of POSIX/Bashism grouping */
>> +	 ")"
>> +	 /* Optional whitespace */
>> +	 "[ \t]*"
>> +	 /* Compound command starting with `{`, `(`, `((` or `[[` */
>> +	 "(\\{|\\(\\(?|\\[\\[)"
>> +	 /* End of function definition */
>> +	 ")",
>> +	 /* -- */
>> +	 /* Characters not in the default $IFS value */
>> +	 "[^ \t]+"),



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux