Documentation ¶
Overview ¶
Package annotations provides utilities to work with SGo annotation files.
Packa
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
A Tokenizer produces Tokens from a .sgoann source.
func NewTokenizer ¶
NewTokenizer returns a Tokenizer for the given .sgoann source.
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 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.