func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern interface{}) (token.Pos, token.Pos, error)
MatchBefore attempts to match a pattern in the line before the supplied pos. It uses the FileSet and the ReadFile to work out the contents of the line that end is part of, and then matches the pattern against the content of the start of that line up to the supplied position. The pattern may be either a simple string, []byte or a *regexp.Regexp. MatchBefore returns the range of the line that matched the pattern, and invalid positions if there was no match, or an error if the line could not be found.
Identifier is the type for an identifier in an Note argument list.
type Identifier string
Note is a parsed note from an expect comment. It knows the position of the start of the comment, and the name and arguments that make up the note.
type Note struct { Pos token.Pos // The position at which the note identifier appears Name string // the name associated with the note Args []interface{} // the arguments for the note }
func Extract(fset *token.FileSet, file *ast.File) ([]*Note, error)
Extract collects all the notes present in an AST. Each comment whose text starts with @ is parsed as a comma-separated sequence of notes. See the package documentation for details about the syntax of those notes.
func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error)
Parse collects all the notes present in a file. If content is nil, the filename specified is read and parsed, otherwise the content is used and the filename is used for positions and error messages. Each comment whose text starts with @ is parsed as a comma-separated sequence of notes. See the package documentation for details about the syntax of those notes.
ReadFile is the type of a function that can provide file contents for a given filename. This is used in MatchBefore to look up the content of the file in order to find the line to match the pattern against.
type ReadFile func(filename string) ([]byte, error)