All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergius Nyah <sergiusnyah@gmail.com>
To: christian.couder@gmail.com, pk@pks.im
Cc: git@vger.kernel.org, Sergius Nyah <sergiusnyah@gmail.com>
Subject: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
Date: Tue, 27 Feb 2024 17:02:52 +0100	[thread overview]
Message-ID: <20240227160253.104011-2-sergiusnyah@gmail.com> (raw)
In-Reply-To: <20240227160253.104011-1-sergiusnyah@gmail.com>

This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
---
 userdiff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"
-#include "attr.h"
+#include "attr.h" 
 #include "strbuf.h"
 
 static struct userdiff_driver *drivers;
@@ -183,6 +183,19 @@ PATTERNS("java",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+     /* 
+	  * Looks for lines that start with optional whitespace, followed 
+	  * by 'function'* and any characters (for function declarations), 
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	  * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+	  */ 
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+     /* This pattern matches JavaScript identifiers */
+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
@@ -192,7 +205,7 @@ PATTERNS("kotlin",
 	 /* integers and floats */
 	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
 	 /* floating point numbers beginning with decimal point */
-	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
+	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
 	 /* unary and binary operators */
 	 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
 PATTERNS("markdown",
-- 
2.43.2
:wq



  reply	other threads:[~2024-02-27 16:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 19:55 [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject Sergius Nyah
2024-01-10 11:33 ` Christian Couder
     [not found]   ` <CANAnif90Bqp2pWCn_71t-Fss6wspo+==vMdYsX+Wt5m=4Ocpng@mail.gmail.com>
     [not found]     ` <CAP8UFD0ELy2WegVYdxi_O5UpHS4MyOPp4tuAQK+XvvNmABc2ZA@mail.gmail.com>
     [not found]       ` <CAP8UFD3e=Zv2wkx5tswCz05Vwn3vD68Vw-TD6SoENWK+norYsw@mail.gmail.com>
2024-01-11 14:23         ` Fwd: " Sergius Nyah
2024-01-11 15:11           ` Christian Couder
2024-01-11 15:42             ` Sergius Nyah
2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:19                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:19                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:21                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:21                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:25                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:25                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 16:02                 ` Sergius Nyah [this message]
2024-02-27 19:06                   ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Ghanshyam Thakkar
2024-02-27 21:05                     ` Sergius Nyah
2024-02-27 16:02                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-28 15:00               ` [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript Sergius Nyah
2024-02-28 18:19                 ` Junio C Hamano
2024-02-29 10:11                   ` [GSOC][PATCH] userdiff: " Sergius Nyah
2024-02-29 12:01                     ` Ghanshyam Thakkar
2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
2024-03-02 10:28                     ` Christian Couder
2024-03-02 10:54                       ` Christian Couder
2024-03-02 17:13                       ` Junio C Hamano
2024-03-04  9:04                     ` Patrick Steinhardt
2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
2024-03-12 13:14                         ` [GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver Sergius Nyah
2024-03-12 13:14                         ` [GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments Sergius Nyah
2024-03-19 10:10                       ` [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver Sergius Nyah
2024-03-19 21:02                         ` Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240227160253.104011-2-sergiusnyah@gmail.com \
    --to=sergiusnyah@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pk@pks.im \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.