Commits

Tomas Heran committed 0458d46

- Added support for packages
- Function declaration tags have search pattern associated with them, so
that the they are always found despite source modification (line
numbers won't match).
- Some debugging stuff

Comments (0)

Files changed (1)

 
 // Date: 2009-11-12
 // Updated: 2010-08-21
+// Updated: 2010-11-21 Tomas Heran <tomas.heran@gmail.com>
 
 //
 // usage: gotags filename [ filename... ] > tags
 	"go/parser"
 	"os"
 	"sort"
+	//"reflect"
 )
 
 var (
 )
 
 func output_tag(name *ast.Ident, kind byte) {
-	tags.Push(fmt.Sprintf("%s\t%s\t%d;\"\t%c",
-		name.Name(), name.Position.Filename, name.Position.Line, kind))
+	switch kind {
+	case PKG:
+		//fmt.Printf("!_DEBUG\t%#v - %c\n", name, kind)
+		tags.Push(fmt.Sprintf("%s\t%s\t/\\m^\\s*package.*%s/;\"\t%c",
+			name.Name, name.NamePos.Filename, name.Name, kind))
+	case FUNC:
+		tags.Push(fmt.Sprintf("%s\t%s\t/\\m^\\s*func.*%s(.*{/;\"\t%c",
+			name.Name, name.NamePos.Filename, name.Name, kind))
+	default:
+		//fmt.Printf("!_DEBUG\t%#v - %c\n", name, kind)
+		tags.Push(fmt.Sprintf("%s\t%s\t%d;\"\t%c",
+			name.Name, name.NamePos.Filename, name.NamePos.Line, kind))
+	}
 }
 
 func main() {
 	}
 }
 
-const FUNC, TYPE, VAR = 'f', 't', 'v'
+const FUNC, TYPE, VAR, PKG = 'f', 't', 'v', 'p'
 
 func parse_files() {
 	for i, m := 1, len(os.Args); i < m; i++ {
 			println("error parsing file", os.Args[i], ok.String())
 			panic(nil)
 		}
-
+		output_tag(tree.Name, PKG);
 		for _, node := range tree.Decls {
 			switch n := node.(type) {
 			case *ast.FuncDecl:
 }
 
 func do_gen_decl(node *ast.GenDecl) {
+	//fmt.Printf("!_DEBUG\tGenDecl\t%+v\n", node)
 	for _, v := range node.Specs {
 		switch n := v.(type) {
 		case *ast.TypeSpec:
+			//fmt.Printf("!_DEBUG\tTypeSpec(%+v)\t%+v\n", n.Type, n)
 			output_tag(n.Name, TYPE)
 
 		case *ast.ValueSpec:
+			//fmt.Printf("!_DEBUG\tValueSpec(%s)\t%+v\n", n.Type, n)
 			for _, vv := range n.Names {
 				output_tag(vv, VAR)
 			}
+		default:
+			//fmt.Printf("!_DEBUG\tSPEC:%s\t%+v\n", reflect.Typeof(n), n)
 		}
 	}
 }