Re: [PATCH v3] userdiff: support Bash
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Oct 22, 2020, 06:08 UTC
- Message-ID
- <0d9f9ad1-2ba7-567e-97a1-a96f0b7cd4be@kdbg.org>
- In-Reply-To
- <6c6b5ed2166ec2c308c53bf87c78b422fdc5084f.camel@engmark.name>
Am 22.10.20 um 01:45 schrieb Victor Engmark:
Show 10 quoted lines
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt > index 2d0a03715b..5e8a973449 100644 > --- a/Documentation/gitattributes.txt > +++ b/Documentation/gitattributes.txt > @@ -802,6 +802,9 @@ patterns are available: > > - `ada` suitable for source code in the Ada language. > > +- `bash` suitable for source code in the Bourne-Again SHell language. > + Covers a superset of POSIX function definitions.
OK. POSIX *shell* function definitions would have been even better, but I think I can live with this version.
Show 8 quoted lines
> diff --git a/t/t4018/bash-bashism-style-compact b/t/t4018/bash-bashism-style-compact
> new file mode 100644
> index 0000000000..1ca3126f61
> --- /dev/null
> +++ b/t/t4018/bash-bashism-style-compact
> @@ -0,0 +1,6 @@
> +function RIGHT {
> + function InvalidSyntax{Nicely done!
> + : > + echo 'ChangeMe' > + } > +}
Show 12 quoted lines
> diff --git a/t/t4018/bash-nested-functions b/t/t4018/bash-nested-functions
> new file mode 100644
> index 0000000000..2c9237ead4
> --- /dev/null
> +++ b/t/t4018/bash-nested-functions
> @@ -0,0 +1,6 @@
> +outer() {
> + RIGHT() {
> + :
> + echo 'ChangeMe'
> + }
> +}That's another very good addition!
Show 33 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index fde02f225b..eb698eaca7 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -23,6 +23,27 @@ 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 captured text */
> + "("
> + "("
> + /* 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]+))"
> + ")"
> + /* Optional whitespace */
> + "[ \t]*"
> + /* Compound command starting with `{`, `(`, `((` or `[[` */
> + "(\\{|\\(\\(?|\\[\\[)"
> + /* End of captured text */
> + ")",
> + /* -- */
> + /* Characters not in the default $IFS value */
> + "[^ \t]+"),
> PATTERNS("dts",
> "!;\n"
> "!=\n"
> This is very well done. Thank you!
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes