Re: [PATCH] userdiff: add builtin diff driver for TypeScript language
- From
Matthew Hughes <matthewhughes934@gmail.com>
- Date
- Jul 16, 2024, 12:21 UTC
- Message-ID
- <20240716122112.zqauqgxmng2tk2j6@archP14s>
- In-Reply-To
- <pull.1746.git.git.1721061218993.gitgitgadget@gmail.com>
On Mon, Jul 15, 2024 at 04:33:38PM +0000, Matthew Hughes via GitGitGadget wrote:
Show 26 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index c4ebb9ff734..7247d351cde 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -333,6 +333,17 @@ PATTERNS("scheme",
> "|([^][)(}{[ \t])+"),
> PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
> "\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
> +PATTERNS("typescript",
> + "^[\t ]*((class|constructor|public|private|protected|function|interface)[ \t].*)$\n"
> + // arrow funcs
> + "^[\t ]*((const|let|var)?[^()]*)=[\t ]*\\([^()]*\\)[\t ]*.*=>.*$",
> + /* -- */
> + "[a-zA-Z_][a-zA-Z0-9_]*"
> + // numeric constants
> + "|[-+0-9.e]+|0[xX]?[0-9a-fA-F]"
> + // operators
> + "|[-+*/<>%&^|=!]"
> + "|--|\\+\\+|//=?|<<=?|>>?=?"),
> { .name = "default", .binary = -1 },
> };
> #undef PATTERNS
>
> base-commit: a7dae3bdc8b516d36f630b12bb01e853a667e0d9
> --
> gitgitgadgetThis needs some updates. For the arrow function, definitions can cover multiple lines e.g.:
const bar = (
name: string
) => console.log(name)The funcname pattern should also consider the `export` keyword, since both of the following are valid:
export const bar = (
name: string
) => console.log(name) export function foo() {}Some docs: https://www.typescriptlang.org/docs/handbook/modules/reference.html#module-syntax