scanner

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BackslashEscape indicates characters can be escaped by a backslash.
	BackslashEscape = "backslash"
	// NoEscape indicates characters cannot be escaped.
	NoEscape = "none"
	// DoubleEscape indicates that strings can be escaped with double characters.
	DoubleEscape = "double"
)
View Source
var LanguagesConfig map[string]*Config

LanguagesConfig is a map of language names to their configuration. Keys are language names defined in the linguist library.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Text      string
	Line      int
	Multiline bool
}

Comment is a generic Comment implementation.

func (*Comment) String

func (c *Comment) String() string

String implements fmt.Stringer.String.

type CommentScanner

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

CommentScanner is a generic code comment scanner.

func FromBytes added in v0.2.0

func FromBytes(fileName string, rawContents []byte, charset string) (*CommentScanner, error)

FromBytes returns an appropriate CommentScanner for the given contents. The language is auto-detected and a relevant configuration is used to initialize the scanner.

func FromFile added in v0.1.0

func FromFile(f *os.File, charset string) (*CommentScanner, error)

FromFile returns an appropriate CommentScanner for the given file. The language is auto-detected and a relevant configuration is used to initialize the scanner.

func New

func New(r io.Reader, c *Config) *CommentScanner

New returns a new CommentScanner that scans code returned by r with the given Config.

func (*CommentScanner) Config added in v0.1.0

func (s *CommentScanner) Config() *Config

Config returns the scanners configuration.

func (*CommentScanner) Err

func (s *CommentScanner) Err() error

Err returns an error if one occurred.

func (*CommentScanner) Next

func (s *CommentScanner) Next() *Comment

Next returns the next Comment.

func (*CommentScanner) Scan

func (s *CommentScanner) Scan() bool

Scan implements a simple state machine to parse comments out of generic code.

type Config

type Config struct {
	LineCommentStart []string               `yaml:"line_comment_start,omitempty"`
	MultilineComment MultilineCommentConfig `yaml:"multiline_comment,omitempty"`
	Strings          []StringConfig         `yaml:"strings,omitempty"`
}

Config is configuration for a language comment scanner.

type MultilineCommentConfig added in v0.6.0

type MultilineCommentConfig struct {
	Start       string `yaml:"start,omitempty"`
	End         string `yaml:"end,omitempty"`
	AtLineStart bool   `yaml:"at_line_start,omitempty"`
}

MultilineCommentConfig describes multi-line comments.

type StringConfig added in v0.6.0

type StringConfig struct {
	Start  string `yaml:"start,omitempty"`
	End    string `yaml:"end,omitempty"`
	Escape string `yaml:"escape,omitempty"`
}

StringConfig is config describing types of string.

Jump to

Keyboard shortcuts

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