github.com/bakjos/protoreflect@v1.9.2/desc/protoparse/ast/source_pos.go (about) 1 package ast 2 3 import "fmt" 4 5 // SourcePos identifies a location in a proto source file. 6 type SourcePos struct { 7 Filename string 8 Line, Col int 9 Offset int 10 } 11 12 func (pos SourcePos) String() string { 13 if pos.Line <= 0 || pos.Col <= 0 { 14 return pos.Filename 15 } 16 return fmt.Sprintf("%s:%d:%d", pos.Filename, pos.Line, pos.Col) 17 } 18 19 // PosRange is a range of positions in a source file that indicates 20 // the span of some region of source, such as a single token or 21 // a sub-tree of the AST. 22 type PosRange struct { 23 Start, End SourcePos 24 } 25 26 // Comment represents a single comment in a source file. It indicates 27 // the position of the comment and its contents. 28 type Comment struct { 29 // The location of the comment in the source file. 30 PosRange 31 // Any whitespace between the prior lexical element (either a token 32 // or other comment) and this comment. 33 LeadingWhitespace string 34 // The text of the comment, including any "//" or "/*" and "*/" 35 // symbols at the start and end. Single-line comments will include 36 // the trailing newline rune in Text. 37 Text string 38 }