parser

package
v0.0.0-...-81a9ded Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

parser contains the glue code for different parsers (e.g. go ast and go doc) and custom things like annotations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoAnnotationError

func IsNoAnnotationError(err error) bool

Types

type Annotation

type Annotation struct {
	Doc    string
	Text   string
	Name   string
	Values map[string]interface{}
}

An Annotation is actually an @-prefixed-named json object one-liner

func ParseAnnotation

func ParseAnnotation(line string) (Annotation, error)

ParseAnnotation is a simple minimal parser which evaluates a single line as an Annotation. If the given line is not an annotation at all, *NoAnnotationError is returned. An annotation always starts with an @ followed by a char sequence with optional opening and closing braces.

Examples

*not valid: @
*not valid: @()
*valid: @a
*valid: @a.b.c() // some comment or text )
*invalid: @a.b.c("hello") ) // this is wrong syntax

func ParseAnnotations

func ParseAnnotations(text string) ([]Annotation, error)

ParseAnnotations tries to parse all annotations from the given text and only returns ParserErrors

type AnnotationParserError

type AnnotationParserError struct {
	Text    string
	Details string
}

An AnnotationParserError means that an annotation has been found but could not be parsed

func (*AnnotationParserError) Error

func (a *AnnotationParserError) Error() string

type File

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

A File contains all imports and macros together

func ParseFile

func ParseFile(parent *Package, fname string) (*File, error)

func (*File) Filename

func (f *File) Filename() string

func (*File) Node

func (f *File) Node() *ast.File

func (*File) Parent

func (f *File) Parent() *Package

func (*File) ResolveIdentifierImportName

func (f *File) ResolveIdentifierImportName(name string) string

func (*File) ResolveImportName

func (f *File) ResolveImportName(name string) string

func (*File) String

func (f *File) String() string

type NoAnnotationError

type NoAnnotationError struct {
	Text string
}

A NoAnnotationError means that Text did not contain any annotation

func (NoAnnotationError) Error

func (a NoAnnotationError) Error() string

type Package

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

func ParsePackage

func ParsePackage(parent *Package, dirname string) (*Package, error)

func (*Package) Doc

func (p *Package) Doc() *doc.Package

func (*Package) FileSet

func (p *Package) FileSet() *token.FileSet

func (*Package) Files

func (p *Package) Files() []*File

func (*Package) FuncDoc

func (p *Package) FuncDoc(name string) *doc.Func

func (*Package) ImportPath

func (p *Package) ImportPath() string

func (*Package) ModName

func (p *Package) ModName() string

func (*Package) Name

func (p *Package) Name() string

func (*Package) Nodes

func (p *Package) Nodes() []*ast.File

func (*Package) Packages

func (p *Package) Packages() []*Package

func (*Package) Parent

func (p *Package) Parent() *Package

func (*Package) TypeDoc

func (p *Package) TypeDoc(name string) *doc.Type

func (*Package) VisitDoc

func (p *Package) VisitDoc(f func(pkg *doc.Package) error) error

func (*Package) VisitFiles

func (p *Package) VisitFiles(f func(file *File) error) error

func (*Package) VisitPackages

func (p *Package) VisitPackages(f func(pkg *Package) error) error

Jump to

Keyboard shortcuts

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