]> git.eshelyaron.com Git - emacs.git/commitdiff
Support Go language in 'etags'
authorlu4nx <lx@shellcodes.org>
Sat, 30 Jan 2016 12:56:43 +0000 (14:56 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 30 Jan 2016 12:56:43 +0000 (14:56 +0200)
* lib-src/etags.c <Ruby_help>: Fix documentation of Ruby tags.
<Go_help>: New help.
<Go_suffixes>: New variable.
(Go_functions): New function.
<lang_names>: Add entry for Go.  (Bug#22370)

* doc/emacs/maintaining.texi (Tag Syntax): Document Go support.
* doc/man/etags.1: Mention Go support.

* etc/NEWS: Mention Go support.

* test/etags/go-src/test.go:
* test/etags/go-src/test1.go: New test files.
* test/etags/Makefile (GOSRC): New variable.
(SRCS): Add $(GOSRC).
* test/etags/ETAGS.good_1:
* test/etags/ETAGS.good_2:
* test/etags/ETAGS.good_3:
* test/etags/ETAGS.good_4:
* test/etags/ETAGS.good_5:
* test/etags/ETAGS.good_6:
* test/etags/CTAGS.good: Adapt to addition of Go tests.

14 files changed:
doc/emacs/maintaining.texi
doc/man/etags.1
etc/NEWS
lib-src/etags.c
test/etags/CTAGS.good
test/etags/ETAGS.good_1
test/etags/ETAGS.good_2
test/etags/ETAGS.good_3
test/etags/ETAGS.good_4
test/etags/ETAGS.good_5
test/etags/ETAGS.good_6
test/etags/Makefile
test/etags/go-src/test.go [new file with mode: 0644]
test/etags/go-src/test1.go [new file with mode: 0644]

index 7039de63e538a9790105181e7a94adfa474b792a..3f1a9c07e91ff7c6e995819ff0a01dc2787dc6b6 100644 (file)
@@ -2217,6 +2217,9 @@ in the file.
 @item
 In Fortran code, functions, subroutines and block data are tags.
 
+@item
+In Go code, packages, functions, and types are tags.
+
 @item
 In HTML input files, the tags are the @code{title} and the @code{h1},
 @code{h2}, @code{h3} headers.  Also, tags are @code{name=} in anchors
index d34063f23cd78ee95faba1d8a22dd5acb6602e15..fc247f758a30b6ac859d6000cc6f4330e0c60b9e 100644 (file)
@@ -50,7 +50,7 @@ format understood by
 .BR vi ( 1 )\c
 \&.  Both forms of the program understand
 the syntax of C, Objective C, C++, Java, Fortran, Ada, Cobol, Erlang,
-Forth, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Pascal, Perl,
+Forth, Go, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Pascal, Perl,
 Ruby, PHP, PostScript, Python, Prolog, Scheme and
 most assembler\-like syntaxes.
 Both forms read the files specified on the command line, and write a tag
index 78dce166b43c0644464f9fbe9b808be255f69275..d0415a22f9564d57b247795db65a6b2c272cce69 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1833,6 +1833,10 @@ qualified names by hand.
 Names of modules, classes, methods, functions, and constants are
 tagged.  Overloaded operators are also tagged.
 
++++
+*** New language Go
+Names of packages, functions, and types are tagged.
+
 +++
 *** Improved support for Lua
 
index adc08a2367817967532dc3244d1716ff3bb228c8..bdfced5bc9c145faa84ecf9e8a377c9aac76ee45 100644 (file)
@@ -354,6 +354,7 @@ static void Cstar_entries (FILE *);
 static void Erlang_functions (FILE *);
 static void Forth_words (FILE *);
 static void Fortran_functions (FILE *);
+static void Go_functions (FILE *);
 static void HTML_labels (FILE *);
 static void Lisp_functions (FILE *);
 static void Lua_functions (FILE *);
@@ -641,6 +642,10 @@ static const char *Fortran_suffixes [] =
 static const char Fortran_help [] =
 "In Fortran code, functions, subroutines and block data are tags.";
 
+static const char *Go_suffixes [] = {"go", NULL};
+static const char Go_help [] =
+  "In Go code, functions, interfaces and packages are tags.";
+
 static const char *HTML_suffixes [] =
   { "htm", "html", "shtml", NULL };
 static const char HTML_help [] =
@@ -727,7 +732,7 @@ static const char *Ruby_suffixes [] =
   { "rb", "ruby", NULL };
 static const char Ruby_help [] =
   "In Ruby code, 'def' or 'class' or 'module' at the beginning of\n\
-a line generate a tag.";
+a line generate a tag.  Constants also generate a tag.";
 
 /* Can't do the `SCM' or `scm' prefix with a version number. */
 static const char *Scheme_suffixes [] =
@@ -794,6 +799,7 @@ static language lang_names [] =
   { "erlang",    Erlang_help,    Erlang_functions,  Erlang_suffixes    },
   { "forth",     Forth_help,     Forth_words,       Forth_suffixes     },
   { "fortran",   Fortran_help,   Fortran_functions, Fortran_suffixes   },
+  { "go",        Go_help,        Go_functions,      Go_suffixes        },
   { "html",      HTML_help,      HTML_labels,       HTML_suffixes      },
   { "java",      Cjava_help,     Cjava_entries,     Cjava_suffixes     },
   { "lisp",      Lisp_help,      Lisp_functions,    Lisp_suffixes      },
@@ -4207,6 +4213,73 @@ Fortran_functions (FILE *inf)
     }
 }
 
+\f
+/*
+ * Go language support
+ * Original code by Xi Lu <lx@shellcodes.org> (2016)
+ */
+static void
+Go_functions(FILE *inf)
+{
+  char *cp, *name;
+
+  LOOP_ON_INPUT_LINES(inf, lb, cp)
+    {
+      cp = skip_spaces (cp);
+
+      if (LOOKING_AT (cp, "package"))
+       {
+         name = cp;
+         while (!notinname (*cp) && *cp != '\0')
+           cp++;
+         make_tag (name, cp - name, false, lb.buffer,
+                   cp - lb.buffer + 1, lineno, linecharno);
+       }
+      else if (LOOKING_AT (cp, "func"))
+       {
+         /* Go implementation of interface, such as:
+            func (n *Integer) Add(m Integer) ...
+            skip `(n *Integer)` part.
+         */
+         if (*cp == '(')
+           {
+             while (*cp != ')')
+               cp++;
+             cp = skip_spaces (cp+1);
+           }
+
+         if (*cp)
+           {
+             name = cp;
+
+             while (!notinname (*cp))
+               cp++;
+
+             make_tag (name, cp - name, true, lb.buffer,
+                       cp - lb.buffer + 1, lineno, linecharno);
+           }
+       }
+      else if (members && LOOKING_AT (cp, "type"))
+       {
+         name = cp;
+
+         /* Ignore the likes of the following:
+            type (
+                   A
+            )
+          */
+         if (*cp == '(')
+           return;
+
+         while (!notinname (*cp) && *cp != '\0')
+           cp++;
+
+         make_tag (name, cp - name, false, lb.buffer,
+                   cp - lb.buffer + 1, lineno, linecharno);
+       }
+    }
+}
+
 \f
 /*
  * Ada parsing
index 86eb9f85cf3180e352f90d0b63b55bc651e46a5b..846725ef71384ad4619f5ed578db900c857c653f 100644 (file)
@@ -947,6 +947,10 @@ MoveLayerAfter     lua-src/allegro.lua     /^function MoveLayerAfter (this_one)$/
 MoveLayerBefore        lua-src/allegro.lua     /^function MoveLayerBefore (this_one)$/
 MoveLayerBottom        lua-src/allegro.lua     /^function MoveLayerBottom ()$/
 MoveLayerTop   lua-src/allegro.lua     /^function MoveLayerTop ()$/
+Mtest.go       go-src/test.go  1
+Mtest.go       go-src/test.go  /^func main() {$/
+Mtest1.go      go-src/test1.go 1
+Mtest1.go      go-src/test1.go /^func main() {$/
 Mx.cc  cp-src/x.cc     /^main(int argc, char *argv[])$/
 NAME   y-src/cccp.c    8
 NATNUMP        c-src/emacs/src/lisp.h  /^NATNUMP (Lisp_Object x)$/
@@ -1077,6 +1081,8 @@ Pkg1_Proc2/p      ada-src/waroquiers.ada  /^  procedure Pkg1_Proc2 (I : Integer);$/
 Pkg1_Proc2/p   ada-src/waroquiers.ada  /^  procedure Pkg1_Proc2 (I : Integer) is$/
 PostControls   pyt-src/server.py       /^    def PostControls(self):$/
 Pre_Call_State/t       ada-src/2ataspri.ads    /^   type Pre_Call_State is new System.Address;$/
+PrintAdd       go-src/test1.go /^func (s str) PrintAdd() {$/
+PrintAdd       go-src/test1.go /^func (n intNumber) PrintAdd() {$/
 Private        objc-src/Subprocess.m   /^@interface Subprocess(Private)$/
 Private_T/b    ada-src/etags-test-for.ada      /^    task body Private_T is$/
 Private_T/b    ada-src/waroquiers.ada  /^    task body Private_T is$/
@@ -3135,6 +3141,7 @@ instance_method_question? ruby-src/test.rb        /^        def instance_method_questio
 instr  y-src/parse.y   80
 instr  parse.y 80
 instruct       c-src/etags.c   2527
+intNumber      go-src/test1.go 13
 integer        c-src/emacs/src/lisp.h  2127
 integer        cccp.y  113
 integer        y-src/cccp.y    112
@@ -3738,6 +3745,7 @@ plain_C_suffixes  c-src/etags.c   643
 plainc c-src/etags.c   2934
 plist  c-src/emacs/src/lisp.h  697
 plus   cp-src/functions.cpp    /^void Date::plus ( int days , int month , int year /
+plus   go-src/test1.go 5
 plusvalseq     prol-src/natded.prolog  /^plusvalseq([]) --> [].$/
 pointer        c-src/emacs/src/lisp.h  2125
 poll_for_input c-src/emacs/src/keyboard.c      /^poll_for_input (struct atimer *timer)$/
@@ -3950,6 +3958,7 @@ save_getcjmp      c-src/emacs/src/keyboard.c      /^save_getcjmp (sys_jmp_buf temp)$/
 save_type      c-src/emacs/src/lisp.h  /^save_type (struct Lisp_Save_Value *v, int n)$/
 savenstr       c-src/etags.c   /^savenstr (const char *cp, int len)$/
 savestr        c-src/etags.c   /^savestr (const char *cp)$/
+say    go-src/test.go  /^func say(msg string) {$/
 scan_separators        c-src/etags.c   /^scan_separators (char *name)$/
 scolonseen     c-src/etags.c   2447
 scratch        c-src/sysdep.h  56
@@ -4075,6 +4084,7 @@ step      cp-src/clheir.hpp       /^    virtual void step(void) { }$/
 step_everybody cp-src/clheir.cpp       /^void step_everybody(void)$/
 stop_polling   c-src/emacs/src/keyboard.c      /^stop_polling (void)$/
 store_user_signal_events       c-src/emacs/src/keyboard.c      /^store_user_signal_events (void)$/
+str    go-src/test1.go 9
 strcaseeq      c-src/etags.c   /^#define strcaseeq(s,t)        (assert ((s)!=NULL && (t)!=/
 streq  c-src/etags.c   /^#define streq(s,t)    (assert ((s)!=NULL || (t)!=NULL/
 string_intervals       c-src/emacs/src/lisp.h  /^string_intervals (Lisp_Object s)$/
@@ -4217,6 +4227,7 @@ terminateInput    objc-src/Subprocess.m   /^- terminateInput$/
 test   c-src/emacs/src/lisp.h  1871
 test   cp-src/c.C      86
 test   erl-src/gs_dialog.erl   /^test() ->$/
+test   go-src/test1.go /^func test(p plus) {$/
 test   php-src/ptest.php       /^test $/
 test.me22b     lua-src/test.lua        /^   local function test.me22b (one)$/
 test.me_22a    lua-src/test.lua        /^   function test.me_22a(one, two)$/
index 44ac091066b0a1a9c8eb1db51398dd39fb3841ed..c7b122111c4b4b0d252461d7dd684fbf3b18aeaa 100644 (file)
@@ -2283,6 +2283,18 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,119
+package main\7f1,0
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index 8a93e3b0656f3db4b393e0108b44117fa273cc74..8d0f33824a4d19b264e3d4fd144fdba8be525125 100644 (file)
@@ -2852,6 +2852,18 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,119
+package main\7f1,0
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index e575b40ab0d981dfad9fc2c06312c1e699f0707c..060389c6232f6ea6f4acd061d8505c0892035193 100644 (file)
@@ -2600,6 +2600,21 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,172
+package main\7f1,0
+type plus \7f5,28
+type str \7f9,65
+type intNumber \7f13,99
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index 282580605179ac12b60a99fb57047930ce070d54..40404f9fc6e473ac517d0d39874e4b0d52b929eb 100644 (file)
@@ -2447,6 +2447,18 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,119
+package main\7f1,0
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index 35bb353c7671a37f213723e0f045f79071b992a2..432819d3b32cd3c586ab2fa4dc09f8f1a0169136 100644 (file)
@@ -3333,6 +3333,21 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,172
+package main\7f1,0
+type plus \7f5,28
+type str \7f9,65
+type intNumber \7f13,99
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index 8add300784fb8b90ec68c261157a5f69db2fe836..4ad5d76db271c714ad7e3998f84a01e8a2485e6f 100644 (file)
@@ -3333,6 +3333,21 @@ constant (a-forth-constant\7f(a-forth-constant\ 138,628
 code assemby-code-word \7f43,685
 : a-forth-word \7f50,870
 \f
+go-src/test.go,48
+package main\7f1,0
+func say(\7f5,28
+func main(\7f9,72
+\f
+go-src/test1.go,172
+package main\7f1,0
+type plus \7f5,28
+type str \7f9,65
+type intNumber \7f13,99
+func (s str) PrintAdd(\7f17,136
+func (n intNumber) PrintAdd(\7f21,189
+func test(\7f25,248
+func main(\7f29,285
+\f
 html-src/softwarelibero.html,200
 Cos'è il software libero?\7f4,38
 Licenze d'uso di un programma\7flicenze\ 165,2500
index 00d5b9f52b215be1a30bf268c0e0dd9359e30db1..21a77eb0c5daef0f8ad1b440e8c0fc3992d9f1fc 100644 (file)
@@ -11,6 +11,7 @@ ELSRC=$(addprefix ./el-src/,TAGTEST.EL emacs/lisp/progmodes/etags.el)
 ERLSRC=$(addprefix ./erl-src/,gs_dialog.erl)
 FORTHSRC=$(addprefix ./forth-src/,test-forth.fth)
 FSRC=$(addprefix ./f-src/,entry.for entry.strange_suffix entry.strange)
+GOSRC=$(addprefix ./go-src/,test.go test1.go)
 HTMLSRC=$(addprefix ./html-src/,softwarelibero.html index.shtml algrthms.html software.html)
 #JAVASRC=$(addprefix ./java-src/, )
 LUASRC=$(addprefix ./lua-src/,allegro.lua test.lua)
@@ -27,9 +28,9 @@ RBSRC=$(addprefix ./ruby-src/,test.rb test1.ruby)
 TEXSRC=$(addprefix ./tex-src/,testenv.tex gzip.texi texinfo.tex nonewline.tex)
 YSRC=$(addprefix ./y-src/,parse.y parse.c atest.y cccp.c cccp.y)
 SRCS=${ADASRC} ${ASRC} ${CSRC} ${CPSRC} ${ELSRC} ${ERLSRC} ${FSRC}\
-     ${FORTHSRC} ${HTMLSRC} ${JAVASRC} ${LUASRC} ${MAKESRC} ${OBJCSRC}\
-     ${OBJCPPSRC} ${PASSRC} ${PHPSRC} ${PERLSRC} ${PSSRC} ${PROLSRC} ${PYTSRC}\
-     ${RBSRC} ${TEXSRC} ${YSRC}
+     ${FORTHSRC} ${GOSRC} ${HTMLSRC} ${JAVASRC} ${LUASRC} ${MAKESRC}\
+     ${OBJCSRC} ${OBJCPPSRC} ${PASSRC} ${PHPSRC} ${PERLSRC} ${PSSRC}\
+     ${PROLSRC} ${PYTSRC} ${RBSRC} ${TEXSRC} ${YSRC}
 NONSRCS=./f-src/entry.strange ./erl-src/lists.erl ./cp-src/clheir.hpp.gz
 
 ETAGS_PROG=../../lib-src/etags
diff --git a/test/etags/go-src/test.go b/test/etags/go-src/test.go
new file mode 100644 (file)
index 0000000..6aea26e
--- /dev/null
@@ -0,0 +1,11 @@
+package main
+
+import "fmt"
+
+func say(msg string) {
+       fmt.Println(msg)
+}
+
+func main() {
+       say("Hello, Emacs!")
+}
diff --git a/test/etags/go-src/test1.go b/test/etags/go-src/test1.go
new file mode 100644 (file)
index 0000000..6d1efaa
--- /dev/null
@@ -0,0 +1,34 @@
+package main
+
+import "fmt"
+
+type plus interface {
+       PrintAdd()
+}
+
+type str struct {
+       a, b string
+}
+
+type intNumber struct {
+       a, b int
+}
+
+func (s str) PrintAdd() {
+       fmt.Println(s.a + s.b)
+}
+
+func (n intNumber) PrintAdd() {
+       fmt.Println(n.a + n.b)
+}
+
+func test(p plus) {
+       p.PrintAdd()
+}
+
+func main() {
+       s := str{a: "Hello,", b: "Emacs!"}
+       number := intNumber{a: 1, b: 2}
+       test(number)
+       test(s)
+}