all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#22370: [PATCH] Initial support for Go Language in 'etags'
@ 2016-01-14  5:27 lu4nx
  2016-01-14 16:05 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: lu4nx @ 2016-01-14  5:27 UTC (permalink / raw)
  To: 22370; +Cc: lu4nx

* lib-src/etags.c <Go_suffixes>: New variable.
(lang_names): Add an entry for Go
(Go_functions): Add new function.
* test/manual/etags/ETAGS.good_6: Add TAGS content for Go
* test/manual/etags/Makefile:
(GOSRC): Add new variable.
(SRCS): Add an entry for Go.
---
 lib-src/etags.c                   | 73 +++++++++++++++++++++++++++++++++++++++
 test/manual/etags/ETAGS.good_6    | 15 ++++++++
 test/manual/etags/Makefile        |  3 +-
 test/manual/etags/go-src/test.go  | 11 ++++++
 test/manual/etags/go-src/test1.go | 34 ++++++++++++++++++
 5 files changed, 135 insertions(+), 1 deletion(-)
 create mode 100644 test/manual/etags/go-src/test.go
 create mode 100644 test/manual/etags/go-src/test1.go

diff --git a/lib-src/etags.c b/lib-src/etags.c
index 2192627..5320686 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -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.";
+
 static const char *HTML_suffixes [] =
   { "htm", "html", "shtml", NULL };
 static const char HTML_help [] =
@@ -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      },
@@ -4210,6 +4216,73 @@ Fortran_functions (FILE *inf)
 
 \f
 /*
+ * Go language support
+ * Idea 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 similar to 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
  * Original code by
  * Philippe Waroquiers (1998)
diff --git a/test/manual/etags/ETAGS.good_6 b/test/manual/etags/ETAGS.good_6
index 39522db..3c53a8b 100644
--- a/test/manual/etags/ETAGS.good_6
+++ b/test/manual/etags/ETAGS.good_6
@@ -5406,3 +5406,18 @@ tex-src/nonewline.tex,0
 php-src/sendmail.php,0
 \f
 a-src/empty.zz,0
+\f
+test.go,48
+package main\x7f1,0
+func say(\x7f5,28
+func main(\x7f9,72
+\f
+test1.go,172
+package main\x7f1,0
+type plus \x7f5,28
+type str \x7f9,65
+type intNumber \x7f13,99
+func (s str) PrintAdd(\x7f17,136
+func (n intNumber) PrintAdd(\x7f21,189
+func test(\x7f25,248
+func main(\x7f29,285
diff --git a/test/manual/etags/Makefile b/test/manual/etags/Makefile
index 4d9f358..81ee7a7 100644
--- a/test/manual/etags/Makefile
+++ b/test/manual/etags/Makefile
@@ -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,7 +28,7 @@ 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}\
+     ${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
diff --git a/test/manual/etags/go-src/test.go b/test/manual/etags/go-src/test.go
new file mode 100644
index 0000000..6aea26e
--- /dev/null
+++ b/test/manual/etags/go-src/test.go
@@ -0,0 +1,11 @@
+package main
+
+import "fmt"
+
+func say(msg string) {
+	fmt.Println(msg)
+}
+
+func main() {
+	say("Hello, Emacs!")
+}
diff --git a/test/manual/etags/go-src/test1.go b/test/manual/etags/go-src/test1.go
new file mode 100644
index 0000000..6d1efaa
--- /dev/null
+++ b/test/manual/etags/go-src/test1.go
@@ -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)
+}
-- 
2.5.0








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

* bug#22370: [PATCH] Initial support for Go Language in 'etags'
  2016-01-14  5:27 bug#22370: [PATCH] Initial support for Go Language in 'etags' lu4nx
@ 2016-01-14 16:05 ` Eli Zaretskii
  2016-01-14 16:15   ` lux
  2016-01-30 12:58   ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Eli Zaretskii @ 2016-01-14 16:05 UTC (permalink / raw)
  To: lu4nx; +Cc: 22370, lx

> From: lu4nx <lx@shellcodes.org>
> Date: Thu, 14 Jan 2016 13:27:48 +0800
> Cc: lu4nx <lx@shellcodes.org>
> 
> * lib-src/etags.c <Go_suffixes>: New variable.
> (lang_names): Add an entry for Go
> (Go_functions): Add new function.

Thanks.

> * test/manual/etags/ETAGS.good_6: Add TAGS content for Go

Why only ETAGS.good_6?  What about other ETAGS.good_N files, and the
CTAGS file?

I will look into pushing this to emacs-25 in a few days, if no one
beats me to it.





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

* bug#22370: [PATCH] Initial support for Go Language in 'etags'
  2016-01-14 16:05 ` Eli Zaretskii
@ 2016-01-14 16:15   ` lux
  2016-01-30 12:58   ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: lux @ 2016-01-14 16:15 UTC (permalink / raw)
  To: 22370

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

在 2016年01月15日 00:05, Eli Zaretskii 写道:
> Why only ETAGS.good_6?  What about other ETAGS.good_N files, and the
> CTAGS file?
I'm not familiar  ETAGS.good_N files and CTAGS file,
I run `make check` is failed:

/Makefile:61: recipe for target 'ediff_1' failed//
//make[1]: *** [ediff_1] Error 1//
//make[1]: Leaving directory '/opt/emacs/emacs-25/test/manual/etags'//
//Makefile:52: recipe for target 'check' failed//
//make: *** [check] Error 2/

So I don't update other ETAGS.good_N files.

Thanks.

[-- Attachment #2: Type: text/html, Size: 967 bytes --]

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

* bug#22370: [PATCH] Initial support for Go Language in 'etags'
  2016-01-14 16:05 ` Eli Zaretskii
  2016-01-14 16:15   ` lux
@ 2016-01-30 12:58   ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2016-01-30 12:58 UTC (permalink / raw)
  To: lx; +Cc: 22370-done

> Date: Thu, 14 Jan 2016 18:05:38 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: 22370@debbugs.gnu.org, lx@shellcodes.org
> 
> I will look into pushing this to emacs-25 in a few days, if no one
> beats me to it.

Done.





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

end of thread, other threads:[~2016-01-30 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-14  5:27 bug#22370: [PATCH] Initial support for Go Language in 'etags' lu4nx
2016-01-14 16:05 ` Eli Zaretskii
2016-01-14 16:15   ` lux
2016-01-30 12:58   ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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.