{"thread":{"id":"31564","subject":"[PATCHv2] Add userdiff patterns for Ada","startedAt":"2012-09-17T12:42:20Z","lastAt":"2012-09-17T12:42:20Z","messageCount":1,"participants":["Adrian Johnson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"199223","messageId":"50571AAC.5070607@redneon.com","threadId":"31564","inReplyTo":null,"subject":"[PATCHv2] Add userdiff patterns for Ada","fromName":"Adrian Johnson","fromEmail":"ajohnson@redneon.com","sentAt":"2012-09-17T12:42:20Z","receivedAt":"2012-09-17T12:42:20Z","isPatch":false,"sender":{"key":"ajohnson@redneon.com","avatar":"https://avatars.githubusercontent.com/u/3437729?v=4"},"body":"Add Ada xfuncname and wordRegex patterns to the list of builtin\npatterns.\n\nSigned-off-by: Adrian Johnson <ajohnson@redneon.com>\n---\nOn 17/09/12 14:29, Junio C Hamano wrote:\n> You could add test vectors to check if the built-in xfuncname\n> catches beginning of functions in Ada correctly if you wanted to,\n> but I think observing what appears on @@ lines in t4034 test vector\n> would be a sufficient test.\n\nI've added additional Ada code to the t4034 test to test xfuncname.\n\n Documentation/gitattributes.txt |  2 ++\n t/t4018-diff-funcname.sh        |  2 +-\n t/t4034-diff-words.sh           |  1 +\n t/t4034/ada/expect              | 56 ++++++++++++++++++++++++++++++++++++++\n t/t4034/ada/post                | 59 +++++++++++++++++++++++++++++++++++++++++\n t/t4034/ada/pre                 | 59 +++++++++++++++++++++++++++++++++++++++++\n userdiff.c                      |  9 +++++++\n 7 files changed, 187 insertions(+), 1 deletion(-)\n create mode 100644 t/t4034/ada/expect\n create mode 100644 t/t4034/ada/post\n create mode 100644 t/t4034/ada/pre\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex 462b79c..99ed04d 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -511,6 +511,8 @@ configuration file (you still need to enable this with the\n attribute mechanism, via `.gitattributes`).  The following built in\n patterns are available:\n \n+- `ada` suitable for source code in the Ada language.\n+\n - `bibtex` suitable for files with BibTeX coded references.\n \n - `cpp` suitable for source code in the C and C++ languages.\ndiff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh\nindex 4bd2a1c..082d3e8 100755\n--- a/t/t4018-diff-funcname.sh\n+++ b/t/t4018-diff-funcname.sh\n@@ -105,7 +105,7 @@ test_expect_funcname () {\n \tgrep \"^@@.*@@ $1\" diff\n }\n \n-for p in bibtex cpp csharp fortran html java matlab objc pascal perl php python ruby tex\n+for p in ada bibtex cpp csharp fortran html java matlab objc pascal perl php python ruby tex\n do\n \ttest_expect_success \"builtin $p pattern compiles\" '\n \t\techo \"*.java diff=$p\" >.gitattributes &&\ndiff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh\nindex 30d42cb..40ab333 100755\n--- a/t/t4034-diff-words.sh\n+++ b/t/t4034-diff-words.sh\n@@ -298,6 +298,7 @@ test_expect_success 'unset default driver' '\n \ttest_unconfig diff.wordregex\n '\n \n+test_language_driver ada\n test_language_driver bibtex\n test_language_driver cpp\n test_language_driver csharp\ndiff --git a/t/t4034/ada/expect b/t/t4034/ada/expect\nnew file mode 100644\nindex 0000000..b193519\n--- /dev/null\n+++ b/t/t4034/ada/expect\n@@ -0,0 +1,56 @@\n+<BOLD>diff --git a/pre b/post<RESET>\n+<BOLD>index 6874c06..851f9e8 100644<RESET>\n+<BOLD>--- a/pre<RESET>\n+<BOLD>+++ b/post<RESET>\n+<CYAN>@@ -4,7 +4,7 @@<RESET> <RESET><MAGENTA>package body Beer is<RESET>\n+\n+   package Text_IO renames Ada.Text_IO;<RESET>\n+\n+   type Bottle_Num is range 0 .. <RED>99<RESET><GREEN>98<RESET>;\n+\n+   package Bottle_Num_IO is new Text_IO.Integer_IO(Bottle_Num);<RESET>\n+   use Bottle_Num_IO;<RESET>\n+<CYAN>@@ -13,7 +13,7 @@<RESET> <RESET><MAGENTA>function Take_Beer (Beer : Bottle_Num) return Bottle_Num is<RESET>\n+   begin<RESET>\n+      -- Add two lines to ensure function<RESET>\n+      -- name appears in the hunk header.<RESET>\n+      return Beer - <RED>1<RESET><GREEN>2<RESET>;\n+   end Take_Beer;<RESET>\n+\n+   procedure Main is<RESET>\n+<CYAN>@@ -27,7 +27,7 @@<RESET> <RESET><MAGENTA>procedure Main is<RESET>\n+\t Put(\" bottles of beer on the wall \");<RESET>\n+\t Put(Bottles);<RESET>\n+\t Put_Line(\" bottles of beer\");<RESET>\n+\t Bottles := <RED>Take_Beer<RESET><GREEN>Take_Two_Beers<RESET>(Bottles);\n+\t Put(\"Take one down, pass it around, \");<RESET>\n+\t Put(Bottles);<RESET>\n+\t Put_Line(\" bottles of beer on the wall.\");<RESET>\n+<CYAN>@@ -41,18 +41,18 @@<RESET> <RESET><MAGENTA>procedure Word_Diff is<RESET>\n+   -- Test wordDiff regex with Ada operators<RESET>\n+   begin<RESET>\n+\n+1 1e-10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>'\n+<RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>**<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>(<RED>b<RESET><GREEN>y<RESET>)\n+<RED>a<RESET><GREEN>x<RESET>:=<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>/= <RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET><<RED>b a<RESET><GREEN>y x<RESET><=<RED>b a<RESET><GREEN>y x<RESET>><RED>b a<RESET><GREEN>y x<RESET>>=<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>,<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>=><RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET>..<RED>b<RESET>\n+<RED>a<RESET><GREEN>y<RESET>\n+<GREEN>x<RESET><><RED>b<RESET><GREEN>y<RESET>\n+\n+   end Word_Diff;<RESET>\n+\ndiff --git a/t/t4034/ada/post b/t/t4034/ada/post\nnew file mode 100644\nindex 0000000..851f9e8\n--- /dev/null\n+++ b/t/t4034/ada/post\n@@ -0,0 +1,59 @@\n+with Ada.Text_IO;\n+\n+package body Beer is\n+\n+   package Text_IO renames Ada.Text_IO;\n+\n+   type Bottle_Num is range 0 .. 98;\n+\n+   package Bottle_Num_IO is new Text_IO.Integer_IO(Bottle_Num);\n+   use Bottle_Num_IO;\n+\n+   function Take_Beer (Beer : Bottle_Num) return Bottle_Num is\n+   begin\n+      -- Add two lines to ensure function\n+      -- name appears in the hunk header.\n+      return Beer - 2;\n+   end Take_Beer;\n+\n+   procedure Main is\n+      procedure Put_Line (Item: String) renames Text_IO.Put_Line;\n+      procedure Put (Item: String) renames Text_IO.Put;\n+      Bottles : Bottle_Num;\n+   begin\n+      Bottles := Bottle_Num'Last;\n+      while Bottles > Bottle_Num'First loop\n+\t Put(Bottles);\n+\t Put(\" bottles of beer on the wall \");\n+\t Put(Bottles);\n+\t Put_Line(\" bottles of beer\");\n+\t Bottles := Take_Two_Beers(Bottles);\n+\t Put(\"Take one down, pass it around, \");\n+\t Put(Bottles);\n+\t Put_Line(\" bottles of beer on the wall.\");\n+      end loop;\n+      Put_Line(\"Go to the store, buy some more,\");\n+      Put_Line(\"99 bottles of beer on the wall.\");\n+   end Main;\n+\n+\n+   procedure Word_Diff is\n+   -- Test wordDiff regex with Ada operators\n+   begin\n+\n+1 1e-10 16#FE12#E2 3.141_592 'y'\n+x+y x-y\n+x*y x/y\n+x**y\n+x(y)\n+x:=y\n+x=y x/= y\n+x<y x<=y x>y x>=y\n+x,y\n+x=>y\n+x..y\n+x<>y\n+\n+   end Word_Diff;\n+\n+end Beer;\ndiff --git a/t/t4034/ada/pre b/t/t4034/ada/pre\nnew file mode 100644\nindex 0000000..6874c06\n--- /dev/null\n+++ b/t/t4034/ada/pre\n@@ -0,0 +1,59 @@\n+with Ada.Text_IO;\n+\n+package body Beer is\n+\n+   package Text_IO renames Ada.Text_IO;\n+\n+   type Bottle_Num is range 0 .. 99;\n+\n+   package Bottle_Num_IO is new Text_IO.Integer_IO(Bottle_Num);\n+   use Bottle_Num_IO;\n+\n+   function Take_Beer (Beer : Bottle_Num) return Bottle_Num is\n+   begin\n+      -- Add two lines to ensure function\n+      -- name appears in the hunk header.\n+      return Beer - 1;\n+   end Take_Beer;\n+\n+   procedure Main is\n+      procedure Put_Line (Item: String) renames Text_IO.Put_Line;\n+      procedure Put (Item: String) renames Text_IO.Put;\n+      Bottles : Bottle_Num;\n+   begin\n+      Bottles := Bottle_Num'Last;\n+      while Bottles > Bottle_Num'First loop\n+\t Put(Bottles);\n+\t Put(\" bottles of beer on the wall \");\n+\t Put(Bottles);\n+\t Put_Line(\" bottles of beer\");\n+\t Bottles := Take_Beer(Bottles);\n+\t Put(\"Take one down, pass it around, \");\n+\t Put(Bottles);\n+\t Put_Line(\" bottles of beer on the wall.\");\n+      end loop;\n+      Put_Line(\"Go to the store, buy some more,\");\n+      Put_Line(\"99 bottles of beer on the wall.\");\n+   end Main;\n+\n+\n+   procedure Word_Diff is\n+   -- Test wordDiff regex with Ada operators\n+   begin\n+\n+1 1e-10 16#FE12#E2 3.141_592 'x'\n+a+b a-b\n+a*b a/b\n+a**b\n+a(b)\n+a:=b\n+a=b a/= b\n+a<b a<=b a>b a>=b\n+a,b\n+a=>b\n+a..b\n+a<>b\n+\n+   end Word_Diff;\n+\n+end Beer;\ndiff --git a/userdiff.c b/userdiff.c\nindex 1e7184f..ed958ef 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -14,6 +14,15 @@ static int drivers_alloc;\n \t{ name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \\\n \t  word_regex \"|[^[:space:]]|[\\xc0-\\xff][\\x80-\\xbf]+\" }\n static struct userdiff_driver builtin_drivers[] = {\n+IPATTERN(\"ada\",\n+\t \"!^(.*[ \\t])?(is new|renames|is separate)([ \\t].*)?$\\n\"\n+\t \"!^[ \\t]*with[ \\t].*$\\n\"\n+\t \"^[ \\t]*((procedure|function)[ \\t]+.*)$\\n\"\n+\t \"^[ \\t]*((package|protected|task)[ \\t]+.*)$\",\n+\t /* -- */\n+\t \"[a-zA-Z][a-zA-Z0-9_]*\"\n+\t \"|[0-9][-+0-9#_.eE]\"\n+\t \"|=>|\\\\.\\\\.|\\\\*\\\\*|:=|/=|>=|<=|<<|>>|<>\"),\n IPATTERN(\"fortran\",\n \t \"!^([C*]|[ \\t]*!)\\n\"\n \t \"!^[ \\t]*MODULE[ \\t]+PROCEDURE[ \\t]\\n\"\n-- \n1.7.12.465.g03a9b82\n"}]}