github.com/keysonzzz/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgGoSource/kmgGoParser/skip.go (about) 1 package kmgGoParser 2 3 import ( 4 "github.com/bronze1man/kmg/kmgGoSource/kmgGoReader" 5 // "fmt" 6 ) 7 8 // 此处暂时仅跳过该部分 9 func (gofile *File) readGoType(r *kmgGoReader.Reader) { 10 r.MustReadMatch([]byte("type")) 11 r.ReadAllSpace() 12 b := r.ReadByte() 13 if b == '(' { 14 for { 15 r.ReadAllSpace() 16 b = r.ReadByte() 17 if b == ')' { 18 return 19 } 20 r.UnreadByte() 21 name := readIdentifier(r) 22 r.ReadAllSpace() 23 typ := gofile.readType(r) 24 gofile.NamedTypeList = append(gofile.NamedTypeList, &NamedType{ 25 PackagePath: gofile.PackagePath, 26 Name: string(name), 27 underType: typ, 28 }) 29 } 30 return 31 } else { 32 r.UnreadByte() 33 name := readIdentifier(r) 34 r.ReadAllSpace() 35 typ := gofile.readType(r) 36 gofile.NamedTypeList = append(gofile.NamedTypeList, &NamedType{ 37 PackagePath: gofile.PackagePath, 38 Name: string(name), 39 underType: typ, 40 }) 41 return 42 } 43 } 44 45 // 正确跳过该部分. 46 func (gofile *File) readGoVar(r *kmgGoReader.Reader) { 47 r.MustReadMatch([]byte("var")) 48 r.ReadAllSpace() 49 b := r.ReadByte() 50 if b == '(' { 51 readMatchSmallParantheses(r) 52 return 53 } 54 r.UnreadByte() 55 readIdentifier(r) 56 r.ReadAllSpace() 57 b = r.ReadByte() 58 if b == '=' { 59 r.ReadAllSpace() 60 } 61 for { 62 if b == '"' || b == '`' { 63 r.UnreadByte() 64 MustReadGoString(r) 65 } 66 if b == '\'' { 67 r.UnreadByte() 68 mustReadGoChar(r) 69 } 70 if b == '\n' { 71 return 72 } 73 if b == '{' { //里面可以字面写东西. 74 readMatchBigParantheses(r) 75 //TODO 正确跳过该部分 76 /* 77 简单解决下列情况 78 var UnreadRuneErrorTests = []struct { 79 name string 80 f func(*Reader) 81 }{ 82 {"Read", func(r *Reader) { r.Read([]byte{0}) }}, 83 {"ReadByte", func(r *Reader) { r.ReadByte() }}, 84 {"UnreadRune", func(r *Reader) { r.UnreadRune() }}, 85 {"Seek", func(r *Reader) { r.Seek(0, 1) }}, 86 {"WriteTo", func(r *Reader) { r.WriteTo(&Buffer{}) }}, 87 } 88 89 */ 90 } 91 if b == '(' { //里面可以调用函数 92 readMatchSmallParantheses(r) 93 } 94 if r.IsEof() { 95 return 96 } 97 b = r.ReadByte() 98 } 99 } 100 101 // 正确跳过该部分. 102 func (gofile *File) readGoConst(r *kmgGoReader.Reader) { 103 r.MustReadMatch([]byte("const")) 104 r.ReadAllSpace() 105 b := r.ReadByte() 106 if b == '(' { 107 readMatchSmallParantheses(r) 108 return 109 } 110 for { 111 if b == '"' || b == '`' { 112 r.UnreadByte() 113 MustReadGoString(r) 114 } 115 if b == '\'' { 116 r.UnreadByte() 117 mustReadGoChar(r) 118 } 119 if b == '\n' { 120 return 121 } 122 b = r.ReadByte() 123 } 124 }