Documentation
¶
Overview ¶
Package parser implements a parser for Go annotations. The results of parsing are AST representations of annotations that include location information.
Index ¶
- type AggregateNode
- type Annotation
- type BinaryOperatorNode
- type Element
- type ExpressionNode
- type Identifier
- type InvokeComplexNode
- type InvokeImagNode
- type InvokeRealNode
- type LiteralNode
- type ParenthesizedExpressionNode
- type ParseError
- type PrefixOperatorNode
- type RefNode
- type Type
- type TypedExpressionNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateNode ¶
type AggregateNode struct { Contents []Element // contains filtered or unexported fields }
AggregateNode is an expression node that represents an aggregate value, which could be a slice/array, a map, or a struct value.
func (AggregateNode) Pos ¶
func (n AggregateNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type Annotation ¶
type Annotation struct { Type Identifier Value ExpressionNode Pos scanner.Position }
Annotation is a fully parsed annotation. It identifies the annotation type and has an optional value. If the value is not present, it is assumed to be "true" for annotations whose underlying type is bool or an empty struct. If the named annotation type is neither a bool nor a struct, a value must be supplied.
func ParseAnnotations ¶
func ParseAnnotations(filename string, r io.Reader) ([]Annotation, error)
ParseAnnotations parses annotations from the given reader. The given file name is used to display locations in errors. If an error is returned, it will be of type *ParseError.
The contents of the reader should be zero or more annotation values, separated by newlines or semicolons. A single value may span multiple lines but uses the same rule as for Go expressions spanning multiple lines (e.g. a line break is only allowed after certain characters, such as '(' and ',').
type BinaryOperatorNode ¶
type BinaryOperatorNode struct {
Left, Right ExpressionNode
Operator string
OperatorPos scanner.Position
}
BinaryOperatorNode is an expression node that represents an binary operator and its two arguments. These include arithmetic operations (including bitwise ones), logical and comparison operations, and string concatenation.
func (BinaryOperatorNode) Pos ¶
func (n BinaryOperatorNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type Element ¶
type Element struct { Key ExpressionNode HasKey bool Value ExpressionNode }
Element is an AST node for a component of an aggregate value. Aggregates that represent arrays or slices will not have keys. Aggregates that represent structs may or may not have keys. Aggregates that represent maps must have keys.
type ExpressionNode ¶
ExpressionNode is a node in the AST for constant expressions (including arithmetic operations) and aggregate values (e.g. maps, slices, arrays, and structs).
type Identifier ¶
Identifier is an AST node that refers to an identifier, possibly qualified with a package name/alias.
func (Identifier) String ¶
func (id Identifier) String() string
String implements the fmt.Stringer interface, returning the identifier as a string. If the identifier includes a package qualifier, it is included in the returned string.
type InvokeComplexNode ¶
type InvokeComplexNode struct {
RealArg, ImagArg ExpressionNode
// contains filtered or unexported fields
}
InvokeComplexNode is an expression node that represents the invocation of the built-in function complex, which takes two values and assembles a complex number from them. The expression complex(X, Y) is the same as X + Yi if X and Y are numeric literals.
func (InvokeComplexNode) Pos ¶
func (n InvokeComplexNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type InvokeImagNode ¶
type InvokeImagNode struct { Argument ExpressionNode // contains filtered or unexported fields }
InvokeImagNode is an expression node that represents the invocation of the built-in function imag, which takes a complex number and returns the imaginary portion.
func (InvokeImagNode) Pos ¶
func (n InvokeImagNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type InvokeRealNode ¶
type InvokeRealNode struct { Argument ExpressionNode // contains filtered or unexported fields }
InvokeRealNode is an expression node that represents the invocation of the built-in function real, which takes a complex number and returns the real portion.
func (InvokeRealNode) Pos ¶
func (n InvokeRealNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type LiteralNode ¶
type LiteralNode struct { Val constant.Value // nil if literal nil // If Val is an int, original literal could have been a numeric literal // or a rune literal. This allows for distinguishing between the two. IsRune bool // contains filtered or unexported fields }
LiteralNode is an expression node that represents a literal value, such as a number, boolean, or string.
func (LiteralNode) Pos ¶
func (n LiteralNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type ParenthesizedExpressionNode ¶
type ParenthesizedExpressionNode struct { Contents ExpressionNode // contains filtered or unexported fields }
ParenthesizedExpressionNode is an expression node that represents an expression surrounded by parentheses.
func (ParenthesizedExpressionNode) Pos ¶
func (n ParenthesizedExpressionNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseError is an error type that includes position information about where the error was encountered in source.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error implements the error interface. The message includes location information.
func (*ParseError) Pos ¶
func (e *ParseError) Pos() scanner.Position
Pos returns the position in source where the underlying error was encountered.
func (*ParseError) Underlying ¶
func (e *ParseError) Underlying() error
Underlying returns the underlying error.
type PrefixOperatorNode ¶
type PrefixOperatorNode struct { Operator string Value ExpressionNode // contains filtered or unexported fields }
PrefixOperatorNode is an expression node that represents a prefix operator. This includes logical not (!), bitwise not (^), and unary minus (-).
func (PrefixOperatorNode) Pos ¶
func (n PrefixOperatorNode) Pos() scanner.Position
Pos returns the position of this node in the source.
type RefNode ¶
type RefNode struct {
Ident Identifier
}
RefNode is an expression node that is a reference to an identifier, which is expected to resolve to a constant or function name.
type Type ¶
type Type interface { Name() Identifier Elem() Type Key() Type Len() ExpressionNode IsSlice() bool IsMap() bool IsArray() bool IsNamed() bool IsPointer() bool IsEmptyStruct() bool IsEmptyInterface() bool Pos() scanner.Position }
Type is an AST node that represents a type reference. Type references in annotations are limited. Unlike full Go syntax, annotations cannot reference channel types or anonymous structs or interfaces other than the empty struct and empty interface.
type TypedExpressionNode ¶
type TypedExpressionNode struct { Type Type Value ExpressionNode }
TypedExpressionNode is an expression node that represents a type conversion. It consists of the target type and an expression that is the value.
func (TypedExpressionNode) Pos ¶
func (n TypedExpressionNode) Pos() scanner.Position
Pos returns the position of this node in the source.