type Position … // add returns the position at the end of s, assuming it starts at p. func (p Position) add(s string) Position { … } type Expr … type Comment … type Comments … // Comment returns the receiver. This isn't useful by itself, but // a [Comments] struct is embedded into all the expression // implementation types, and this gives each of those a Comment // method to satisfy the Expr interface. func (c *Comments) Comment() *Comments { … } type FileSyntax … func (x *FileSyntax) Span() (start, end Position) { … } // addLine adds a line containing the given tokens to the file. // // If the first token of the hint matches the first token of the // line, the new line is added at the end of the block containing hint, // extracting hint into a new block if it is not yet in one. // // If the hint is non-nil buts its first token does not match, // the new line is added after the block containing hint // (or hint itself, if not in a block). // // If no hint is provided, addLine appends the line to the end of // the last block with a matching first token, // or to the end of the file if no such block exists. func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { … } func (x *FileSyntax) updateLine(line *Line, tokens ...string) { … } // markRemoved modifies line so that it (and its end-of-line comment, if any) // will be dropped by (*FileSyntax).Cleanup. func (line *Line) markRemoved() { … } // Cleanup cleans up the file syntax x after any edit operations. // To avoid quadratic behavior, (*Line).markRemoved marks the line as dead // by setting line.Token = nil but does not remove it from the slice // in which it appears. After edits have all been indicated, // calling Cleanup cleans out the dead lines. func (x *FileSyntax) Cleanup() { … } func commentsAdd(x, y []Comment) []Comment { … } func stringsAdd(x, y []string) []string { … } type CommentBlock … func (x *CommentBlock) Span() (start, end Position) { … } type Line … func (x *Line) Span() (start, end Position) { … } type LineBlock … func (x *LineBlock) Span() (start, end Position) { … } type LParen … func (x *LParen) Span() (start, end Position) { … } type RParen … func (x *RParen) Span() (start, end Position) { … } type input … func newInput(filename string, data []byte) *input { … } // parse parses the input file. func parse(file string, data []byte) (f *FileSyntax, err error) { … } // Error is called to report an error. // Error does not return: it panics. func (in *input) Error(s string) { … } // eof reports whether the input has reached end of file. func (in *input) eof() bool { … } // peekRune returns the next rune in the input without consuming it. func (in *input) peekRune() int { … } // peekPrefix reports whether the remaining input begins with the given prefix. func (in *input) peekPrefix(prefix string) bool { … } // readRune consumes and returns the next rune in the input. func (in *input) readRune() int { … } type token … type tokenKind … const _EOF … const _EOLCOMMENT … const _IDENT … const _STRING … const _COMMENT … func (k tokenKind) isComment() bool { … } // isEOL returns whether a token terminates a line. func (k tokenKind) isEOL() bool { … } // startToken marks the beginning of the next input token. // It must be followed by a call to endToken, once the token's text has // been consumed using readRune. func (in *input) startToken() { … } // endToken marks the end of an input token. // It records the actual token string in tok.text. // A single trailing newline (LF or CRLF) will be removed from comment tokens. func (in *input) endToken(kind tokenKind) { … } // peek returns the kind of the next token returned by lex. func (in *input) peek() tokenKind { … } // lex is called from the parser to obtain the next input token. func (in *input) lex() token { … } // readToken lexes the next token from the text and stores it in in.token. func (in *input) readToken() { … } // isIdent reports whether c is an identifier rune. // We treat most printable runes as identifier runes, except for a handful of // ASCII punctuation characters. func isIdent(c int) bool { … } // order walks the expression adding it and its subexpressions to the // preorder and postorder lists. func (in *input) order(x Expr) { … } // assignComments attaches comments to nearby syntax. func (in *input) assignComments() { … } // reverseComments reverses the []Comment list. func reverseComments(list []Comment) { … } func (in *input) parseFile() { … } func (in *input) parseStmt() { … } func (in *input) parseLineBlock(start Position, token []string, lparen token) *LineBlock { … } func (in *input) parseLine() *Line { … } var slashSlash … var moduleStr … // ModulePath returns the module path from the gomod file text. // If it cannot find a module path, it returns an empty string. // It is tolerant of unrelated problems in the go.mod file. func ModulePath(mod []byte) string { … }