Skip to contentSkip to conversation

userdiff: update Ada patterns

PATCH Superseded Adrian Johnson 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 userdiff: update Ada patterns

- Allow extra space in "is new" and "is separate"
- Fix bug in word regex for numbers

---
 t/t4034/ada/expect | 2 +-
 userdiff.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
t/t4034/ada/expect +1 -1
index be2376e..a682d28 100644
@@ -4,7 +4,7 @@
 <BOLD>+++ b/post<RESET>
 <CYAN>@@ -1,13 +1,13 @@<RESET>
 Ada.Text_IO.Put_Line("Hello World<RED>!<RESET><GREEN>?<RESET>");
-1 1e<RED>-<RESET>10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
+1 <RED>1e-10<RESET><GREEN>1e10<RESET> 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
 <RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET>
 <RED>a<RESET><GREEN>y<RESET>
 <GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET>
userdiff.c +2 -2
index ea43a03..e8915bf 100644
@@ -15,13 +15,13 @@ static int drivers_alloc;
 	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
 static struct userdiff_driver builtin_drivers[] = {
 IPATTERN("ada",
-	 "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n"
+	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
 	 "!^[ \t]*with[ \t].*$\n"
 	 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
 	 "^[ \t]*((package|protected|task)[ \t]+.*)$",
 	 /* -- */
 	 "[a-zA-Z][a-zA-Z0-9_]*"
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+0-9#_.eE]+"
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
Signature · 1 line
1.8.3.2
#1 lore raw

userdiff.c static int drivers_alloc; · line 18

Quoted 4 lines · Adrian Johnson

- Allow extra space in "is new" and "is separate"
[...]

userdiff.c +1 -1
-	 "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n"
+	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"

I do not know anything about Ada syntax, but this change looks obviously sensible.

userdiff.c static int drivers_alloc; · line 24

Quoted 3 lines

- Fix bug in word regex for numbers

userdiff.c +1 -1
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+0-9#_.eE]+"

This makes "E" or "_" a number. Is that right?

I think the intent of the original was "starts with a digit, and then has one or more of these other things after it". You do not describe the bug, but I guess it would be that it does not match obvious things like "5". Should it be "zero or more" instead, like:

[0-9][-+0-9#_.eE]*

? Also, should -/+ be hoisted to the front?

[-+]?[0-9][0-9#_.eE]*

Again, I am just guessing, as I am not familiar enough with Ada.

-Peff

#2 lore raw
Quoted 7 lines · Jeff King

userdiff.c static int drivers_alloc; · line 24

Quoted 3 lines · Adrian Johnson

- Fix bug in word regex for numbers

userdiff.c +1 -1
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+0-9#_.eE]+"

This makes "E" or "_" a number. Is that right?

Quoted 6 lines

I think the intent of the original was "starts with a digit, and then has one or more of these other things after it". You do not describe the bug, but I guess it would be that it does not match obvious things like "5". Should it be "zero or more" instead, like:

[0-9][-+0-9#_.eE]*

Yes, the original was missing the '*' at the end.

I changed it to be similar to the number regexes used by the other builtin patterns which are of the form '[-+0-9#_.eE]+'.

Quoted 4 lines

? Also, should -/+ be hoisted to the front?

[-+]?[0-9][0-9#_.eE]*

The other builtins don't do this. But it is probably better to have [-+]?[0-9] at the front.

Quoted 1 line

Again, I am just guessing, as I am not familiar enough with Ada.

Ada numbers have the form:

- integers and reals eg 123, 1.23, 1e-2 ('.' can not be first)
- a '_' may be used between digits to improve readability eg 123_456
- base n (2 <= n <= 16) is of the form n#digits# eg 16#FFEF#
- base n numbers can include a radix point and/or an exponent eg 16#FF12.8#e-2
- Ada is case insensitive

After having another look I noticed it was missing the hex characters. The new number regex I am proposing is:

[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?

I kept exponents containing a +/- sign separate from the digits to prevent things like '1+2' from matching. I'll send an updated patch.

Quoted 7 lines

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

PATCH v2 1/1 userdiff: update Ada patterns

In reply to Jeff King

- Allow extra space in "is new" and "is separate"
- Fix bug in word regex for numbers

---
 t/t4034/ada/expect | 2 +-
 userdiff.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
t/t4034/ada/expect +1 -1
index be2376e..a682d28 100644
@@ -4,7 +4,7 @@
 <BOLD>+++ b/post<RESET>
 <CYAN>@@ -1,13 +1,13 @@<RESET>
 Ada.Text_IO.Put_Line("Hello World<RED>!<RESET><GREEN>?<RESET>");
-1 1e<RED>-<RESET>10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
+1 <RED>1e-10<RESET><GREEN>1e10<RESET> 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
 <RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET>
 <RED>a<RESET><GREEN>y<RESET>
 <GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET>
userdiff.c +2 -2
index ea43a03..10b61ec 100644
@@ -15,13 +15,13 @@ static int drivers_alloc;
 	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
 static struct userdiff_driver builtin_drivers[] = {
 IPATTERN("ada",
-	 "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n"
+	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
 	 "!^[ \t]*with[ \t].*$\n"
 	 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
 	 "^[ \t]*((package|protected|task)[ \t]+.*)$",
 	 /* -- */
 	 "[a-zA-Z][a-zA-Z0-9_]*"
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
Signature · 1 line
1.8.3.2
#4 lore raw
Quoted 29 lines · Adrian Johnson

- Allow extra space in "is new" and "is separate"
- Fix bug in word regex for numbers

---
 t/t4034/ada/expect | 2 +-
 userdiff.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
t/t4034/ada/expect +1 -1
index be2376e..a682d28 100644
@@ -4,7 +4,7 @@
 <BOLD>+++ b/post<RESET>
 <CYAN>@@ -1,13 +1,13 @@<RESET>
 Ada.Text_IO.Put_Line("Hello World<RED>!<RESET><GREEN>?<RESET>");
-1 1e<RED>-<RESET>10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
+1 <RED>1e-10<RESET><GREEN>1e10<RESET> 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
 <RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET>
 <RED>a<RESET><GREEN>y<RESET>
 <GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET>
userdiff.c +0 -0
index ea43a03..10b61ec 100644
@@ -15,13 +15,13 @@ static int drivers_alloc;
 	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
 static struct userdiff_driver builtin_drivers[] = {

userdiff.c static int drivers_alloc; · line 24

Quoted 10 lines
userdiff.c +2 -2
 IPATTERN("ada",
-	 "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n"
+	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
 	 "!^[ \t]*with[ \t].*$\n"
 	 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
 	 "^[ \t]*((package|protected|task)[ \t]+.*)$",
 	 /* -- */
 	 "[a-zA-Z][a-zA-Z0-9_]*"
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"

This would match a lot wider than what I read you said you wanted to match in your previous message. Does "-04##4_3_2Ee-9" count as a number, for example, or can we just ignore such syntactically incorrect sequence?

Quoted 3 lines
userdiff.c +0 -0
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"
#5 lore raw
Quoted 38 lines · Junio C Hamano
Quoted 36 lines · Adrian Johnson

- Allow extra space in "is new" and "is separate"
- Fix bug in word regex for numbers

---
 t/t4034/ada/expect | 2 +-
 userdiff.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
t/t4034/ada/expect +1 -1
index be2376e..a682d28 100644
@@ -4,7 +4,7 @@
 <BOLD>+++ b/post<RESET>
 <CYAN>@@ -1,13 +1,13 @@<RESET>
 Ada.Text_IO.Put_Line("Hello World<RED>!<RESET><GREEN>?<RESET>");
-1 1e<RED>-<RESET>10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
+1 <RED>1e-10<RESET><GREEN>1e10<RESET> 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'
 <RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET>
 <RED>a<RESET><GREEN>y<RESET>
 <GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET>
userdiff.c +1 -1
index ea43a03..10b61ec 100644
@@ -15,13 +15,13 @@ static int drivers_alloc;
 	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
 static struct userdiff_driver builtin_drivers[] = {
 IPATTERN("ada",
-	 "!^(.*[ \t])?(is new|renames|is separate)([ \t].*)?$\n"
+	 "!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
 	 "!^[ \t]*with[ \t].*$\n"
 	 "^[ \t]*((procedure|function)[ \t]+.*)$\n"
 	 "^[ \t]*((package|protected|task)[ \t]+.*)$",
 	 /* -- */
Quoted 8 lines

userdiff.c static int drivers_alloc; · line 24

Quoted 3 lines
userdiff.c +1 -1
 	 "[a-zA-Z][a-zA-Z0-9_]*"
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"

This would match a lot wider than what I read you said you wanted to match in your previous message. Does "-04##4_3_2Ee-9" count as a number, for example, or can we just ignore such syntactically incorrect sequence?

Maybe I am misunderstanding the purpose of the word diff regexes. I thought the purpose of the word regex is to split lines into words, not determine what is syntactically correct.

For example decimal number regex for pascal is: [-+0-9.e]+ and for cpp: [-+0-9.e]+[fFlL]?

These will obviously match stuff that is not a number.

Quoted 9 lines

userdiff.c static int drivers_alloc; · line 27

Quoted 4 lines
userdiff.c +0 -0
 	 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
 IPATTERN("fortran",
 	 "!^([C*]|[ \t]*!)\n"

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 11 lines · Adrian Johnson
Quoted 7 lines

userdiff.c static int drivers_alloc; · line 24

Quoted 2 lines
userdiff.c +1 -1
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"

This would match a lot wider than what I read you said you wanted to match in your previous message. Does "-04##4_3_2Ee-9" count as a number, for example, or can we just ignore such syntactically incorrect sequence?

Maybe I am misunderstanding the purpose of the word diff regexes. I thought the purpose of the word regex is to split lines into words, not determine what is syntactically correct.

I agree that the purpose is former---So you could have just said "the latter" ;-).

Any other nitpick, anybody? Otherwise I'll queue this version.

#7 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Adrian Johnson
Quoted 7 lines

userdiff.c static int drivers_alloc; · line 24

Quoted 2 lines
userdiff.c +1 -1
-	 "|[0-9][-+0-9#_.eE]"
+	 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"

This would match a lot wider than what I read you said you wanted to match in your previous message. Does "-04##4_3_2Ee-9" count as a number, for example, or can we just ignore such syntactically incorrect sequence?

Quoted 8 lines
Quoted 3 lines

Maybe I am misunderstanding the purpose of the word diff regexes. I thought the purpose of the word regex is to split lines into words, not determine what is syntactically correct.

I agree that the purpose is former---So you could have just said "the latter" ;-).

Any other nitpick, anybody? Otherwise I'll queue this version.

No nitpick here, I had the same thought as Adrian while reading the thread (and if somebody comes up with a real case where the output looks bad, we can iterate on it).

-Peff