diff options
author | lu4nx <lx@shellcodes.org> | 2016-01-30 14:56:43 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2016-01-30 14:56:43 +0200 |
commit | 40a85fba441aa69d47ef9efd645df3411e43ae21 (patch) | |
tree | 036fafebce750bb4083bbef7edf3ac0910c903c3 /lib-src | |
parent | 25b79d7bc71079cd6ebb2700623e7e3b76b03287 (diff) |
Support Go language in 'etags'
* 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.
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/etags.c | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c index adc08a2367..bdfced5bc9 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 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 }, @@ -4209,6 +4215,73 @@ Fortran_functions (FILE *inf) /* + * 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); + } + } +} + + +/* * Ada parsing * Original code by * Philippe Waroquiers (1998) |