git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] userdiff: update Ada patterns
@ 2014-02-03 18:33 George Spelvin
  2014-02-03 20:05 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: George Spelvin @ 2014-02-03 18:33 UTC (permalink / raw)
  To: ajohnson; +Cc: git, linux

Looking at the grammar at http://www.adahome.com/rm95/rm9x-P.html
and http://www.adaic.org/resources/add_content/standards/05rm/html/RM-2-4.html
I see the following restrictions apply:

- A number must begin and end with a digit.  There must be at least one
  digit on either side of each underscore and decimal point.
- There may be at most one decimal point in a number.
- The base must be between 2 and 16, inclusive.

[-+]?(
        [0-9](_?[0-9])*([.][0-9](_?[0-9])*)?|
        ([2-9]|1[0-6])#[0-9a-fA-F](_?[0-9a-fA-F])*([.][0-9a-fA-F](_?[0-9a-fA-F])*)?#
)([eE][+-]?[0-9](_?[0-9])*)?

If you want a slightly smaller version, we can drop the "only one decimal
point" rule and get

[-+]?(
        [0-9]([._]?[0-9])*|
        ([2-9]|1[0-6])#[0-9a-fA-F]([._]?[0-9a-fA-F])*#
)([eE][+-]?[0-9](_?[0-9])*)?

Ideally, for a based number, the range of acceptable digits would
depend on the base.  Which is possible for a finite-state machine since
the number of bases is finite, but laeds to a bit of a state explosion.
Here's an approximation that separates bases 2-9 and 10-16:

[-+]?(
        [0-9](_?[0-9])*([.][0-9](_?[0-9])*)?|
        [2-9]#[0-8](_?[0-8])*([.][0-8](_?[0-8])*)?#|
        1[0-6]#[0-9a-fA-F](_?[0-9a-fA-F])*([.][0-9a-fA-F](_?[0-9a-fA-F])*)?#
)([eE][+-]?[0-9](_?[0-9])*)?

because I think that this is overdoing it:

[-+]?(
        [0-9](_?[0-9])*([.][0-9](_?[0-9])*)?|
        2#[0-1](_?[0-1])*([.][0-1](_?[0-1])*)?#|
        3#[0-2](_?[0-2])*([.][0-2](_?[0-2])*)?#|
        4#[0-3](_?[0-3])*([.][0-3](_?[0-3])*)?#|
        5#[0-4](_?[0-4])*([.][0-4](_?[0-4])*)?#|
        6#[0-5](_?[0-5])*([.][0-5](_?[0-5])*)?#|
        7#[0-5](_?[0-5])*([.][0-5](_?[0-5])*)?#|
        8#[0-7](_?[0-7])*([.][0-7](_?[0-7])*)?#|
        9#[0-8](_?[0-8])*([.][0-8](_?[0-8])*)?#|
        10#[0-9](_?[0-9])*([.][0-9](_?[0-9])*)?#|
        11#[0-9aA](_?[0-9aA])*([.][0-9aA](_?[0-9aA])*)?#|
        12#[0-9abAB](_?[0-9abAB])*([.][0-9abAB](_?[0-9abAB])*)?#|
        13#[0-9a-cA-C](_?[0-9a-cA-C])*([.][0-9a-cA-C](_?[0-9a-cA-C])*)?#|
        14#[0-9a-dA-D](_?[0-9a-dA-D])*([.][0-9a-dA-D](_?[0-9a-dA-D])*)?#|
        15#[0-9a-eA-E](_?[0-9a-eA-E])*([.][0-9a-eA-E](_?[0-9a-eA-E])*)?#|
        16#[0-9a-fA-F](_?[0-9a-fA-F])*([.][0-9a-fA-F](_?[0-9a-fA-F])*)?#|
)([eE][+-]?[0-9](_?[0-9])*)?

Another point is that Ada doesn't actually include leading + or -
signs in the syntax for "number", but rather makes them unary operators.
This means that spaces are allowed, and whether you want to include them
in the "number" pattern is a judgement call.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] userdiff: update Ada patterns
@ 2014-02-02 10:51 Adrian Johnson
  2014-02-02 23:35 ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Adrian Johnson @ 2014-02-02 10:51 UTC (permalink / raw)
  To: git

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

Signed-off-by: Adrian Johnson <ajohnson@redneon.com>
---
 t/t4034/ada/expect | 2 +-
 userdiff.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t4034/ada/expect b/t/t4034/ada/expect
index be2376e..a682d28 100644
--- a/t/t4034/ada/expect
+++ b/t/t4034/ada/expect
@@ -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>
diff --git a/userdiff.c b/userdiff.c
index ea43a03..e8915bf 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -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"
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-05 17:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-03 18:33 [PATCH v2] userdiff: update Ada patterns George Spelvin
2014-02-03 20:05 ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2014-02-02 10:51 [PATCH] " Adrian Johnson
2014-02-02 23:35 ` Jeff King
2014-02-03 11:33   ` [PATCH v2] " Adrian Johnson
2014-02-03 20:00     ` Junio C Hamano
2014-02-05 10:44       ` Adrian Johnson
2014-02-05 17:17         ` Junio C Hamano
2014-02-05 17:28           ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).