LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package ast declares the types used to represent syntax trees for Go | 5 // Package ast declares the types used to represent syntax trees for Go |
6 // packages. | 6 // packages. |
7 // | 7 // |
8 package ast | 8 package ast |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 func stripTrailingWhitespace(s string) string { | 82 func stripTrailingWhitespace(s string) string { |
83 i := len(s) | 83 i := len(s) |
84 for i > 0 && isWhitespace(s[i-1]) { | 84 for i > 0 && isWhitespace(s[i-1]) { |
85 i-- | 85 i-- |
86 } | 86 } |
87 return s[0:i] | 87 return s[0:i] |
88 } | 88 } |
89 | 89 |
90 // Text returns the text of the comment. | 90 // Text returns the text of the comment. |
91 // Comment markers (//, /*, and */), leading and trailing empty lines are | 91 // Comment markers (//, /*, and */), the first space of a line comment, and |
92 // removed, multiple empty lines are reduced to one, and trailing space on | 92 // leading and trailing empty lines are removed. Multiple empty lines are |
93 // lines is trimmed. Unless the result is empty, it is newline-terminated. | 93 // reduced to one, and trailing space on lines is trimmed. Unless the result |
| 94 // is empty, it is newline-terminated. |
94 // | 95 // |
95 func (g *CommentGroup) Text() string { | 96 func (g *CommentGroup) Text() string { |
96 if g == nil { | 97 if g == nil { |
97 return "" | 98 return "" |
98 } | 99 } |
99 comments := make([]string, len(g.List)) | 100 comments := make([]string, len(g.List)) |
100 for i, c := range g.List { | 101 for i, c := range g.List { |
101 comments[i] = string(c.Text) | 102 comments[i] = string(c.Text) |
102 } | 103 } |
103 | 104 |
104 lines := make([]string, 0, 10) // most comments are less than 10 lines | 105 lines := make([]string, 0, 10) // most comments are less than 10 lines |
105 for _, c := range comments { | 106 for _, c := range comments { |
106 // Remove comment markers. | 107 // Remove comment markers. |
107 // The parser has given us exactly the comment text. | 108 // The parser has given us exactly the comment text. |
108 switch c[1] { | 109 switch c[1] { |
109 case '/': | 110 case '/': |
110 //-style comment (no newline at the end) | 111 //-style comment (no newline at the end) |
111 c = c[2:] | 112 c = c[2:] |
| 113 // strip first space - required for Example tests |
| 114 if len(c) > 0 && c[0] == ' ' { |
| 115 c = c[1:] |
| 116 } |
112 case '*': | 117 case '*': |
113 /*-style comment */ | 118 /*-style comment */ |
114 c = c[2 : len(c)-2] | 119 c = c[2 : len(c)-2] |
115 } | 120 } |
116 | 121 |
117 // Split on newlines. | 122 // Split on newlines. |
118 cl := strings.Split(c, "\n") | 123 cl := strings.Split(c, "\n") |
119 | 124 |
120 // Walk lines, stripping trailing white space and adding to list
. | 125 // Walk lines, stripping trailing white space and adding to list
. |
121 for _, l := range cl { | 126 for _, l := range cl { |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 // | 983 // |
979 type Package struct { | 984 type Package struct { |
980 Name string // package name | 985 Name string // package name |
981 Scope *Scope // package scope across all files | 986 Scope *Scope // package scope across all files |
982 Imports map[string]*Object // map of package id -> package object | 987 Imports map[string]*Object // map of package id -> package object |
983 Files map[string]*File // Go source files by filename | 988 Files map[string]*File // Go source files by filename |
984 } | 989 } |
985 | 990 |
986 func (p *Package) Pos() token.Pos { return token.NoPos } | 991 func (p *Package) Pos() token.Pos { return token.NoPos } |
987 func (p *Package) End() token.Pos { return token.NoPos } | 992 func (p *Package) End() token.Pos { return token.NoPos } |
LEFT | RIGHT |