annotations

package
v0.0.0-...-6c909a5 Latest Latest
Warning

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

Go to latest
Published: May 24, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package annotations provides utilities to work with SGo annotation files.

Packa

Index

Constants

This section is empty.

Variables

View Source
var EOF error = errors.New("unexpected end of file")

EOF represents an unexpected end of file while parsing a .sgoann source.

Functions

This section is empty.

Types

type Annotation

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

An Annotation holds SGo type annotations for a Go package or identifier, and its children. If its Cursor is empty, it refers to a Go package. From there, use Lookup to get annotations to its declared identifiers, and from those to their subidentifiers (struct fields, etc.).

func NewAnnotation

func NewAnnotation(anns map[string]string) *Annotation

NewAnnotation returns an Annotation for a map from

func Parse

func Parse(src string) (*Annotation, error)

Parse parses source in .sgoann format and returns an Annotation you can navigate as you walk through a Go AST for a package.

The source must conform to this grammar:

List -> Item*
Item -> Name Def /[\n;]*/
Name -> Ident | Receiver
Receiver -> "(" "*" Ident ")"
Ident -> (Go identifier)
Def -> Type | "{" List "}"
Type -> /[^{][^\n;]*/

func (*Annotation) Cursor

func (a *Annotation) Cursor() string

Cursor returns the cursor, or path, from the package's Annotation to the receiver Annotation, separated by '.'.

func (*Annotation) Lookup

func (a *Annotation) Lookup(name string) *Annotation

Lookup finds a child Annotation of the receiver with the given identifier.

func (*Annotation) String

func (a *Annotation) String() string

String implements fmt.Stringer for Annotation.

func (*Annotation) Type

func (a *Annotation) Type() (string, bool)

Type returns the SGo type annotation for package or identifier referred to by Cursor, if it exists.

type Token

type Token struct {
	Lexeme  rune
	Line    int
	Col     int
	Size    int
	BytePos int
	RunePos int
}

A Token is a .sgoann token from a source.

type Tokenizer

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

A Tokenizer produces Tokens from a .sgoann source.

func NewTokenizer

func NewTokenizer(src string) *Tokenizer

NewTokenizer returns a Tokenizer for the given .sgoann source.

func (*Tokenizer) Next

func (t *Tokenizer) Next() (Token, error)

Next consumes and returns the next Token.

func (*Tokenizer) Peek

func (t *Tokenizer) Peek() (Token, error)

Peek returns the next Token without consuming it.

func (*Tokenizer) SkipWhite

func (t *Tokenizer) SkipWhite()

SkipWhite skips until the next non-whitespace character.

func (*Tokenizer) SkipWhiteUntilLine

func (t *Tokenizer) SkipWhiteUntilLine()

SkipWhite until the next new line or non-whitespace character.

type UTF8Error

type UTF8Error struct {
	Line int
	Col  int
}

UTF8Error is a UTF-8 encoding error at the given position.

func NewUTF8Error

func NewUTF8Error(line, col int) UTF8Error

NewUTF8Error returns a UTF8Error.

func (UTF8Error) Error

func (err UTF8Error) Error() string

Error implements the error interface.

type UnexpectedTokenError

type UnexpectedTokenError struct {
	Token Token
}

UnexpectedTokenError reports an unexpected token while parsing a .sgoann source.

func NewUnexpectedTokenError

func NewUnexpectedTokenError(tk Token) UnexpectedTokenError

NewUnexpectedTokenError returns an UnexpectedTokenError.

func (UnexpectedTokenError) Error

func (err UnexpectedTokenError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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