comments

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package comments extracts and parses comments from a package.

Index

Constants

View Source
const DefaultMarkerPrefix = "+"

DefaultMarkerPrefix that is commonly used by comment markers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comments

type Comments struct {
	// contains filtered or unexported fields
}

Comments for a particular package.

func In

func In(p *packages.Package) Comments

In returns all comments in a particular package.

func (Comments) Before

func (c Comments) Before(o types.Object) string

Before returns the comments before the supplied Object, if any. A comment is deemed to be 'before' (rather than 'for') an Object if it ends exactly one blank line above where the Object (including its comment, if any) begins.

func (Comments) For

func (c Comments) For(o types.Object) string

For returns the comments for the supplied Object, if any.

type Markers

type Markers map[string][]string

Markers are comments that begin with a special character (typically DefaultMarkerPrefix). Comment markers that contain '=' are considered to be key=value pairs, represented as one map key with a slice of multiple values.

func ParseMarkers

func ParseMarkers(comment string) Markers

ParseMarkers parses comment markers from the supplied comment using the DefaultMarkerPrefix.

func ParseMarkersWithPrefix

func ParseMarkersWithPrefix(prefix, comment string) Markers

ParseMarkersWithPrefix parses comment markers from the supplied comment. Any line that begins with the supplied prefix is considered a comment marker. For example using marker prefix '+' the following comments:

+key:value1 +key:value2

Would be parsed as Markers{"key": []string{"value1", "value2"}}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL