Documentation ¶
Overview ¶
Package ast defines types for modeling the AST (Abstract Syntax Tree) for the protocol buffers source language.
All nodes of the tree implement the Node interface. Leaf nodes in the tree implement TerminalNode and all others implement CompositeNode. The root of the tree for a proto source file is a *FileNode.
Comments are not represented as nodes in the tree. Instead, they are attached to all terminal nodes in the tree. So, when lexing, comments are accumulated until the next non-comment token is found. The AST model in this package thus provides access to all comments in the file, regardless of location (unlike the SourceCodeInfo present in descriptor protos, which are lossy). The comments associated with a a non-leaf/non-token node (i.e. a CompositeNode) come from the first and last nodes in its sub-tree.
Creation of AST nodes should use the factory functions in this package instead of struct literals. Some factory functions accept optional arguments, which means the arguments can be nil. If nil values are provided for other (non-optional) arguments, the resulting node may be invalid and cause panics later in the program.
This package defines numerous interfaces. However, user code should not attempt to implement any of them. Most consumers of an AST will not work correctly if they encounter concrete implementations other than the ones defined in this package.
Index ¶
- func AsInt32(n IntValueNode, min, max int32) (int32, bool)
- func Print(w io.Writer, node Node) error
- func Walk(root Node, v VisitFunc)
- type ArrayLiteralNode
- type BoolLiteralNodedeprecated
- type Comment
- type CompactOptionsNode
- func (n *CompactOptionsNode) Children() []Node
- func (n *CompactOptionsNode) End() *SourcePos
- func (e *CompactOptionsNode) GetElements() []*OptionNode
- func (n *CompactOptionsNode) LeadingComments() []Comment
- func (n *CompactOptionsNode) Start() *SourcePos
- func (n *CompactOptionsNode) TrailingComments() []Comment
- type CompositeNode
- type CompoundIdentNode
- func (n *CompoundIdentNode) AsIdentifier() Identifier
- func (n *CompoundIdentNode) Children() []Node
- func (n *CompoundIdentNode) End() *SourcePos
- func (n *CompoundIdentNode) LeadingComments() []Comment
- func (n *CompoundIdentNode) Start() *SourcePos
- func (n *CompoundIdentNode) TrailingComments() []Comment
- func (n *CompoundIdentNode) Value() interface{}
- type CompoundStringLiteralNode
- func (n *CompoundStringLiteralNode) AsString() string
- func (n *CompoundStringLiteralNode) Children() []Node
- func (n *CompoundStringLiteralNode) End() *SourcePos
- func (n *CompoundStringLiteralNode) LeadingComments() []Comment
- func (n *CompoundStringLiteralNode) Start() *SourcePos
- func (n *CompoundStringLiteralNode) TrailingComments() []Comment
- func (n *CompoundStringLiteralNode) Value() interface{}
- type EmptyDeclNode
- type EnumElement
- type EnumNode
- type EnumValueDeclNode
- type EnumValueNode
- func (n *EnumValueNode) Children() []Node
- func (n *EnumValueNode) End() *SourcePos
- func (e *EnumValueNode) GetName() Node
- func (e *EnumValueNode) GetNumber() Node
- func (n *EnumValueNode) LeadingComments() []Comment
- func (n *EnumValueNode) Start() *SourcePos
- func (n *EnumValueNode) TrailingComments() []Comment
- type ExtendElement
- type ExtendNode
- type ExtensionRangeNode
- type FieldDeclNode
- type FieldLabel
- type FieldNode
- func (n *FieldNode) Children() []Node
- func (n *FieldNode) End() *SourcePos
- func (n *FieldNode) FieldExtendee() Node
- func (n *FieldNode) FieldLabel() Node
- func (n *FieldNode) FieldName() Node
- func (n *FieldNode) FieldTag() Node
- func (n *FieldNode) FieldType() Node
- func (n *FieldNode) GetGroupKeyword() Node
- func (n *FieldNode) GetOptions() *CompactOptionsNode
- func (n *FieldNode) LeadingComments() []Comment
- func (n *FieldNode) Start() *SourcePos
- func (n *FieldNode) TrailingComments() []Comment
- type FieldReferenceNode
- func (n *FieldReferenceNode) Children() []Node
- func (n *FieldReferenceNode) End() *SourcePos
- func (a *FieldReferenceNode) IsAnyTypeReference() bool
- func (a *FieldReferenceNode) IsExtension() bool
- func (n *FieldReferenceNode) LeadingComments() []Comment
- func (n *FieldReferenceNode) Start() *SourcePos
- func (n *FieldReferenceNode) TrailingComments() []Comment
- func (a *FieldReferenceNode) Value() string
- type FileDeclNode
- type FileElement
- type FileNode
- type FloatLiteralNode
- func (n *FloatLiteralNode) AsFloat() float64
- func (n *FloatLiteralNode) End() *SourcePos
- func (n *FloatLiteralNode) LeadingComments() []Comment
- func (n *FloatLiteralNode) LeadingWhitespace() string
- func (n *FloatLiteralNode) PopLeadingComment() Comment
- func (n *FloatLiteralNode) PushTrailingComment(c Comment)
- func (n *FloatLiteralNode) RawText() string
- func (n *FloatLiteralNode) Start() *SourcePos
- func (n *FloatLiteralNode) TrailingComments() []Comment
- func (n *FloatLiteralNode) Value() interface{}
- type FloatValueNode
- type GroupNode
- func (n *GroupNode) Children() []Node
- func (n *GroupNode) End() *SourcePos
- func (n *GroupNode) FieldExtendee() Node
- func (n *GroupNode) FieldLabel() Node
- func (n *GroupNode) FieldName() Node
- func (n *GroupNode) FieldTag() Node
- func (n *GroupNode) FieldType() Node
- func (n *GroupNode) GetGroupKeyword() Node
- func (n *GroupNode) GetOptions() *CompactOptionsNode
- func (n *GroupNode) LeadingComments() []Comment
- func (n *GroupNode) MessageName() Node
- func (n *GroupNode) Start() *SourcePos
- func (n *GroupNode) TrailingComments() []Comment
- type IdentNode
- func (n *IdentNode) AsIdentifier() Identifier
- func (n *IdentNode) End() *SourcePos
- func (n *IdentNode) LeadingComments() []Comment
- func (n *IdentNode) LeadingWhitespace() string
- func (n *IdentNode) PopLeadingComment() Comment
- func (n *IdentNode) PushTrailingComment(c Comment)
- func (n *IdentNode) RawText() string
- func (n *IdentNode) Start() *SourcePos
- func (n *IdentNode) ToKeyword() *KeywordNode
- func (n *IdentNode) TrailingComments() []Comment
- func (n *IdentNode) Value() interface{}
- type IdentValueNode
- type Identifier
- type ImportNode
- type IntValueNode
- type KeywordNode
- type MapFieldNode
- func (n *MapFieldNode) Children() []Node
- func (n *MapFieldNode) End() *SourcePos
- func (n *MapFieldNode) FieldExtendee() Node
- func (n *MapFieldNode) FieldLabel() Node
- func (n *MapFieldNode) FieldName() Node
- func (n *MapFieldNode) FieldTag() Node
- func (n *MapFieldNode) FieldType() Node
- func (n *MapFieldNode) GetGroupKeyword() Node
- func (n *MapFieldNode) GetOptions() *CompactOptionsNode
- func (n *MapFieldNode) KeyField() *SyntheticMapField
- func (n *MapFieldNode) LeadingComments() []Comment
- func (n *MapFieldNode) MessageName() Node
- func (n *MapFieldNode) Start() *SourcePos
- func (n *MapFieldNode) TrailingComments() []Comment
- func (n *MapFieldNode) ValueField() *SyntheticMapField
- type MapTypeNode
- type MessageBody
- type MessageDeclNode
- type MessageElement
- type MessageFieldNode
- type MessageLiteralNode
- func (n *MessageLiteralNode) Children() []Node
- func (n *MessageLiteralNode) End() *SourcePos
- func (n *MessageLiteralNode) LeadingComments() []Comment
- func (n *MessageLiteralNode) Start() *SourcePos
- func (n *MessageLiteralNode) TrailingComments() []Comment
- func (n *MessageLiteralNode) Value() interface{}
- type MessageNode
- type NegativeIntLiteralNode
- func (n *NegativeIntLiteralNode) AsInt64() (int64, bool)
- func (n *NegativeIntLiteralNode) AsUint64() (uint64, bool)
- func (n *NegativeIntLiteralNode) Children() []Node
- func (n *NegativeIntLiteralNode) End() *SourcePos
- func (n *NegativeIntLiteralNode) LeadingComments() []Comment
- func (n *NegativeIntLiteralNode) Start() *SourcePos
- func (n *NegativeIntLiteralNode) TrailingComments() []Comment
- func (n *NegativeIntLiteralNode) Value() interface{}
- type NoSourceNode
- func (n NoSourceNode) End() *SourcePos
- func (n NoSourceNode) FieldExtendee() Node
- func (n NoSourceNode) FieldLabel() Node
- func (n NoSourceNode) FieldName() Node
- func (n NoSourceNode) FieldTag() Node
- func (n NoSourceNode) FieldType() Node
- func (n NoSourceNode) GetGroupKeyword() Node
- func (n NoSourceNode) GetInputType() Node
- func (n NoSourceNode) GetName() Node
- func (n NoSourceNode) GetNumber() Node
- func (n NoSourceNode) GetOptions() *CompactOptionsNode
- func (n NoSourceNode) GetOutputType() Node
- func (n NoSourceNode) GetSyntax() Node
- func (n NoSourceNode) GetValue() ValueNode
- func (n NoSourceNode) LeadingComments() []Comment
- func (n NoSourceNode) MessageName() Node
- func (n NoSourceNode) RangeEnd() Node
- func (n NoSourceNode) RangeStart() Node
- func (n NoSourceNode) Start() *SourcePos
- func (n NoSourceNode) TrailingComments() []Comment
- func (n NoSourceNode) Value() interface{}
- type Node
- type OneOfDeclNode
- type OneOfElement
- type OneOfNode
- type OptionDeclNode
- type OptionNameNode
- type OptionNode
- type PackageNode
- type PosRange
- type PositiveUintLiteralNodedeprecated
- func (n *PositiveUintLiteralNode) AsInt64() (int64, bool)
- func (n *PositiveUintLiteralNode) AsUint64() (uint64, bool)
- func (n *PositiveUintLiteralNode) Children() []Node
- func (n *PositiveUintLiteralNode) End() *SourcePos
- func (n *PositiveUintLiteralNode) LeadingComments() []Comment
- func (n *PositiveUintLiteralNode) Start() *SourcePos
- func (n *PositiveUintLiteralNode) TrailingComments() []Comment
- func (n *PositiveUintLiteralNode) Value() interface{}
- type RPCDeclNode
- type RPCElement
- type RPCNode
- type RPCTypeNode
- type RangeDeclNode
- type RangeNode
- func (n *RangeNode) Children() []Node
- func (n *RangeNode) End() *SourcePos
- func (n *RangeNode) EndValue() interface{}
- func (n *RangeNode) EndValueAsInt32(min, max int32) (int32, bool)
- func (n *RangeNode) LeadingComments() []Comment
- func (n *RangeNode) RangeEnd() Node
- func (n *RangeNode) RangeStart() Node
- func (n *RangeNode) Start() *SourcePos
- func (n *RangeNode) StartValue() interface{}
- func (n *RangeNode) StartValueAsInt32(min, max int32) (int32, bool)
- func (n *RangeNode) TrailingComments() []Comment
- type ReservedNode
- type RuneNode
- func (n *RuneNode) End() *SourcePos
- func (n *RuneNode) LeadingComments() []Comment
- func (n *RuneNode) LeadingWhitespace() string
- func (n *RuneNode) PopLeadingComment() Comment
- func (n *RuneNode) PushTrailingComment(c Comment)
- func (n *RuneNode) RawText() string
- func (n *RuneNode) Start() *SourcePos
- func (n *RuneNode) TrailingComments() []Comment
- type ServiceElement
- type ServiceNode
- type SignedFloatLiteralNode
- func (n *SignedFloatLiteralNode) AsFloat() float64
- func (n *SignedFloatLiteralNode) Children() []Node
- func (n *SignedFloatLiteralNode) End() *SourcePos
- func (n *SignedFloatLiteralNode) LeadingComments() []Comment
- func (n *SignedFloatLiteralNode) Start() *SourcePos
- func (n *SignedFloatLiteralNode) TrailingComments() []Comment
- func (n *SignedFloatLiteralNode) Value() interface{}
- type SourcePos
- type SpecialFloatLiteralNode
- type StringLiteralNode
- func (n *StringLiteralNode) AsString() string
- func (n *StringLiteralNode) End() *SourcePos
- func (n *StringLiteralNode) LeadingComments() []Comment
- func (n *StringLiteralNode) LeadingWhitespace() string
- func (n *StringLiteralNode) PopLeadingComment() Comment
- func (n *StringLiteralNode) PushTrailingComment(c Comment)
- func (n *StringLiteralNode) RawText() string
- func (n *StringLiteralNode) Start() *SourcePos
- func (n *StringLiteralNode) TrailingComments() []Comment
- func (n *StringLiteralNode) Value() interface{}
- type StringValueNode
- type SyntaxNode
- type SyntheticMapField
- func (n *SyntheticMapField) End() *SourcePos
- func (n *SyntheticMapField) FieldExtendee() Node
- func (n *SyntheticMapField) FieldLabel() Node
- func (n *SyntheticMapField) FieldName() Node
- func (n *SyntheticMapField) FieldTag() Node
- func (n *SyntheticMapField) FieldType() Node
- func (n *SyntheticMapField) GetGroupKeyword() Node
- func (n *SyntheticMapField) GetOptions() *CompactOptionsNode
- func (n *SyntheticMapField) LeadingComments() []Comment
- func (n *SyntheticMapField) Start() *SourcePos
- func (n *SyntheticMapField) TrailingComments() []Comment
- type SyntheticOneOf
- type TerminalNode
- type TokenInfo
- type UintLiteralNode
- func (n *UintLiteralNode) AsFloat() float64
- func (n *UintLiteralNode) AsInt64() (int64, bool)
- func (n *UintLiteralNode) AsUint64() (uint64, bool)
- func (n *UintLiteralNode) End() *SourcePos
- func (n *UintLiteralNode) LeadingComments() []Comment
- func (n *UintLiteralNode) LeadingWhitespace() string
- func (n *UintLiteralNode) PopLeadingComment() Comment
- func (n *UintLiteralNode) PushTrailingComment(c Comment)
- func (n *UintLiteralNode) RawText() string
- func (n *UintLiteralNode) Start() *SourcePos
- func (n *UintLiteralNode) TrailingComments() []Comment
- func (n *UintLiteralNode) Value() interface{}
- type ValueNode
- type VisitFunc
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsInt32 ¶
func AsInt32(n IntValueNode, min, max int32) (int32, bool)
AsInt32 range checks the given int value and returns its value is in the range or 0, false if it is outside the range.
func Print ¶
Print prints the given AST node to the given output. This operation basically walks the AST and, for each TerminalNode, prints the node's leading comments, leading whitespace, the node's raw text, and then any trailing comments. If the given node is a *FileNode, it will then also print the file's FinalComments and FinalWhitespace.
Types ¶
type ArrayLiteralNode ¶
type ArrayLiteralNode struct { OpenBracket *RuneNode Elements []ValueNode // Commas represent the separating ',' characters between elements. The // length of this slice must be exactly len(Elements)-1, with each item // in Elements having a corresponding item in this slice *except the last* // (since a trailing comma is not allowed). Commas []*RuneNode CloseBracket *RuneNode // contains filtered or unexported fields }
ArrayLiteralNode represents an array literal, which is only allowed inside of a MessageLiteralNode, to indicate values for a repeated field. Example:
["foo", "bar", "baz"]
func NewArrayLiteralNode ¶
func NewArrayLiteralNode(openBracket *RuneNode, vals []ValueNode, commas []*RuneNode, closeBracket *RuneNode) *ArrayLiteralNode
NewArrayLiteralNode creates a new *ArrayLiteralNode. The openBracket and closeBracket args must be non-nil and represent the "[" and "]" runes that surround the array values. The given commas arg must have a length that is one less than the length of the vals arg. However, vals may be empty, in which case commas must also be empty.
func (*ArrayLiteralNode) LeadingComments ¶
func (n *ArrayLiteralNode) LeadingComments() []Comment
func (*ArrayLiteralNode) TrailingComments ¶
func (n *ArrayLiteralNode) TrailingComments() []Comment
func (*ArrayLiteralNode) Value ¶
func (n *ArrayLiteralNode) Value() interface{}
type BoolLiteralNode
deprecated
type BoolLiteralNode struct { *KeywordNode Val bool }
BoolLiteralNode represents a boolean literal.
Deprecated: The AST uses IdentNode for boolean literals, where the identifier value is "true" or "false". This is required because an identifier "true" is not necessarily a boolean value as it could also be an enum value named "true" (ditto for "false").
func NewBoolLiteralNode ¶
func NewBoolLiteralNode(name *KeywordNode) *BoolLiteralNode
NewBoolLiteralNode returns a new *BoolLiteralNode for the given keyword, which must be "true" or "false".
func (*BoolLiteralNode) Value ¶
func (n *BoolLiteralNode) Value() interface{}
type Comment ¶
type Comment struct { // The location of the comment in the source file. PosRange // Any whitespace between the prior lexical element (either a token // or other comment) and this comment. LeadingWhitespace string // The text of the comment, including any "//" or "/*" and "*/" // symbols at the start and end. Single-line comments will include // the trailing newline rune in Text. Text string }
Comment represents a single comment in a source file. It indicates the position of the comment and its contents.
type CompactOptionsNode ¶
type CompactOptionsNode struct { OpenBracket *RuneNode Options []*OptionNode // Commas represent the separating ',' characters between options. The // length of this slice must be exactly len(Options)-1, with each item // in Options having a corresponding item in this slice *except the last* // (since a trailing comma is not allowed). Commas []*RuneNode CloseBracket *RuneNode // contains filtered or unexported fields }
CompactOptionsNode represents a compact options declaration, as used with fields, enum values, and extension ranges. Example:
[deprecated = true, json_name = "foo_bar"]
func NewCompactOptionsNode ¶
func NewCompactOptionsNode(openBracket *RuneNode, opts []*OptionNode, commas []*RuneNode, closeBracket *RuneNode) *CompactOptionsNode
NewCompactOptionsNode creates a *CompactOptionsNode. All args must be non-nil. The commas arg must have a length that is one less than the length of opts. The opts arg must not be empty.
func (*CompactOptionsNode) GetElements ¶
func (e *CompactOptionsNode) GetElements() []*OptionNode
func (*CompactOptionsNode) LeadingComments ¶
func (n *CompactOptionsNode) LeadingComments() []Comment
func (*CompactOptionsNode) TrailingComments ¶
func (n *CompactOptionsNode) TrailingComments() []Comment
type CompositeNode ¶
type CompositeNode interface { Node // All AST nodes that are immediate children of this one. Children() []Node }
CompositeNode represents any non-terminal node in the tree. These are interior or root nodes and have child nodes.
type CompoundIdentNode ¶
type CompoundIdentNode struct { // Optional leading dot, indicating that the identifier is fully qualified. LeadingDot *RuneNode Components []*IdentNode // Dots[0] is the dot after Components[0]. The length of Dots is always // one less than the length of Components. Dots []*RuneNode // The text value of the identifier, with all components and dots // concatenated. Val string // contains filtered or unexported fields }
CompoundIdentNode represents a qualified identifier. A qualified identifier has at least one dot and possibly multiple identifier names (all separated by dots). If the identifier has a leading dot, then it is a *fully* qualified identifier. Example:
.com.foobar.Baz
func NewCompoundIdentNode ¶
func NewCompoundIdentNode(leadingDot *RuneNode, components []*IdentNode, dots []*RuneNode) *CompoundIdentNode
NewCompoundIdentNode creates a *CompoundIdentNode. The leadingDot may be nil. The dots arg must have a length that is one less than the length of components. The components arg must not be empty.
func (*CompoundIdentNode) AsIdentifier ¶
func (n *CompoundIdentNode) AsIdentifier() Identifier
func (*CompoundIdentNode) LeadingComments ¶
func (n *CompoundIdentNode) LeadingComments() []Comment
func (*CompoundIdentNode) TrailingComments ¶
func (n *CompoundIdentNode) TrailingComments() []Comment
func (*CompoundIdentNode) Value ¶
func (n *CompoundIdentNode) Value() interface{}
type CompoundStringLiteralNode ¶
type CompoundStringLiteralNode struct { Val string // contains filtered or unexported fields }
CompoundStringLiteralNode represents a compound string literal, which is the concatenaton of adjacent string literals. Example:
"this " "is" " all one " "string"
func NewCompoundLiteralStringNode ¶
func NewCompoundLiteralStringNode(components ...*StringLiteralNode) *CompoundStringLiteralNode
NewCompoundLiteralStringNode creates a new *CompoundStringLiteralNode that consists of the given string components. The components argument may not be empty.
func (*CompoundStringLiteralNode) AsString ¶
func (n *CompoundStringLiteralNode) AsString() string
func (*CompoundStringLiteralNode) LeadingComments ¶
func (n *CompoundStringLiteralNode) LeadingComments() []Comment
func (*CompoundStringLiteralNode) TrailingComments ¶
func (n *CompoundStringLiteralNode) TrailingComments() []Comment
func (*CompoundStringLiteralNode) Value ¶
func (n *CompoundStringLiteralNode) Value() interface{}
type EmptyDeclNode ¶
type EmptyDeclNode struct { Semicolon *RuneNode // contains filtered or unexported fields }
EmptyDeclNode represents an empty declaration in protobuf source. These amount to extra semicolons, with no actual content preceding the semicolon.
func NewEmptyDeclNode ¶
func NewEmptyDeclNode(semicolon *RuneNode) *EmptyDeclNode
NewEmptyDeclNode creates a new *EmptyDeclNode. The one argument must be non-nil.
func (*EmptyDeclNode) LeadingComments ¶
func (n *EmptyDeclNode) LeadingComments() []Comment
func (*EmptyDeclNode) TrailingComments ¶
func (n *EmptyDeclNode) TrailingComments() []Comment
type EnumElement ¶
type EnumElement interface { Node // contains filtered or unexported methods }
EnumElement is an interface implemented by all AST nodes that can appear in the body of an enum declaration.
type EnumNode ¶
type EnumNode struct { Keyword *KeywordNode Name *IdentNode OpenBrace *RuneNode Decls []EnumElement CloseBrace *RuneNode // contains filtered or unexported fields }
EnumNode represents an enum declaration. Example:
enum Foo { BAR = 0; BAZ = 1 }
func NewEnumNode ¶
func NewEnumNode(keyword *KeywordNode, name *IdentNode, openBrace *RuneNode, decls []EnumElement, closeBrace *RuneNode) *EnumNode
NewEnumNode creates a new *EnumNode. All arguments must be non-nil. While it is technically allowed for decls to be nil or empty, the resulting node will not be a valid enum, which must have at least one value.
- keyword: The token corresponding to the "enum" keyword.
- name: The token corresponding to the enum's name.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the enum body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*EnumNode) LeadingComments ¶
func (n *EnumNode) LeadingComments() []Comment
func (*EnumNode) TrailingComments ¶
func (n *EnumNode) TrailingComments() []Comment
type EnumValueDeclNode ¶
EnumValueDeclNode is a placeholder interface for AST nodes that represent enum values. This allows NoSourceNode to be used in place of *EnumValueNode for some usages.
type EnumValueNode ¶
type EnumValueNode struct { Name *IdentNode Equals *RuneNode Number IntValueNode Options *CompactOptionsNode Semicolon *RuneNode // contains filtered or unexported fields }
EnumNode represents an enum declaration. Example:
UNSET = 0 [deprecated = true];
func NewEnumValueNode ¶
func NewEnumValueNode(name *IdentNode, equals *RuneNode, number IntValueNode, opts *CompactOptionsNode, semicolon *RuneNode) *EnumValueNode
NewEnumValueNode creates a new *EnumValueNode. All arguments must be non-nil except opts which is only non-nil if the declaration included options.
- name: The token corresponding to the enum value's name.
- equals: The token corresponding to the '=' rune after the name.
- number: The token corresponding to the enum value's number.
- opts: Optional set of enum value options.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*EnumValueNode) GetName ¶
func (e *EnumValueNode) GetName() Node
func (*EnumValueNode) GetNumber ¶
func (e *EnumValueNode) GetNumber() Node
func (*EnumValueNode) LeadingComments ¶
func (n *EnumValueNode) LeadingComments() []Comment
func (*EnumValueNode) TrailingComments ¶
func (n *EnumValueNode) TrailingComments() []Comment
type ExtendElement ¶
type ExtendElement interface { Node // contains filtered or unexported methods }
ExtendElement is an interface implemented by all AST nodes that can appear in the body of an extends declaration.
type ExtendNode ¶
type ExtendNode struct { Keyword *KeywordNode Extendee IdentValueNode OpenBrace *RuneNode Decls []ExtendElement CloseBrace *RuneNode // contains filtered or unexported fields }
ExtendNode represents a declaration of extension fields. Example:
extend google.protobuf.FieldOptions { bool redacted = 33333; }
func NewExtendNode ¶
func NewExtendNode(keyword *KeywordNode, extendee IdentValueNode, openBrace *RuneNode, decls []ExtendElement, closeBrace *RuneNode) *ExtendNode
NewExtendNode creates a new *ExtendNode. All arguments must be non-nil.
- keyword: The token corresponding to the "extend" keyword.
- extendee: The token corresponding to the name of the extended message.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the message body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*ExtendNode) LeadingComments ¶
func (n *ExtendNode) LeadingComments() []Comment
func (*ExtendNode) TrailingComments ¶
func (n *ExtendNode) TrailingComments() []Comment
type ExtensionRangeNode ¶
type ExtensionRangeNode struct { Keyword *KeywordNode Ranges []*RangeNode // Commas represent the separating ',' characters between ranges. The // length of this slice must be exactly len(Ranges)-1, each item in Ranges // having a corresponding item in this slice *except the last* (since a // trailing comma is not allowed). Commas []*RuneNode Options *CompactOptionsNode Semicolon *RuneNode // contains filtered or unexported fields }
ExtensionRangeNode represents an extension range declaration in an extendable message. Example:
extensions 100 to max;
func NewExtensionRangeNode ¶
func NewExtensionRangeNode(keyword *KeywordNode, ranges []*RangeNode, commas []*RuneNode, opts *CompactOptionsNode, semicolon *RuneNode) *ExtensionRangeNode
NewExtensionRangeNode creates a new *ExtensionRangeNode. All args must be non-nil except opts, which may be nil.
- keyword: The token corresponding to the "extends" keyword.
- ranges: One or more range expressions.
- commas: Tokens that represent the "," runes that delimit the range expressions. The length of commas must be one less than the length of ranges.
- opts: The node corresponding to options that apply to each of the ranges.
- semicolon The token corresponding to the ";" rune that ends the declaration.
func (*ExtensionRangeNode) LeadingComments ¶
func (n *ExtensionRangeNode) LeadingComments() []Comment
func (*ExtensionRangeNode) TrailingComments ¶
func (n *ExtensionRangeNode) TrailingComments() []Comment
type FieldDeclNode ¶
type FieldDeclNode interface { Node FieldLabel() Node FieldName() Node FieldType() Node FieldTag() Node FieldExtendee() Node GetGroupKeyword() Node GetOptions() *CompactOptionsNode }
FieldDeclNode is a node in the AST that defines a field. This includes normal message fields as well as extensions. There are multiple types of AST nodes that declare fields:
- *FieldNode
- *GroupNode
- *MapFieldNode
- *SyntheticMapField
This also allows NoSourceNode to be used in place of one of the above for some usages.
type FieldLabel ¶
type FieldLabel struct { *KeywordNode Repeated bool Required bool }
FieldLabel represents the label of a field, which indicates its cardinality (i.e. whether it is optional, required, or repeated).
func (*FieldLabel) IsPresent ¶
func (f *FieldLabel) IsPresent() bool
IsPresent returns true if a label keyword was present in the declaration and false if it was absent.
type FieldNode ¶
type FieldNode struct { Label FieldLabel FldType IdentValueNode Name *IdentNode Equals *RuneNode Tag *UintLiteralNode Options *CompactOptionsNode Semicolon *RuneNode // This is an up-link to the containing *ExtendNode for fields // that are defined inside of "extend" blocks. Extendee *ExtendNode // contains filtered or unexported fields }
FieldNode represents a normal field declaration (not groups or maps). It can represent extension fields as well as non-extension fields (both inside of messages and inside of one-ofs). Example:
optional string foo = 1;
func NewFieldNode ¶
func NewFieldNode(label *KeywordNode, fieldType IdentValueNode, name *IdentNode, equals *RuneNode, tag *UintLiteralNode, opts *CompactOptionsNode, semicolon *RuneNode) *FieldNode
NewFieldNode creates a new *FieldNode. The label and options arguments may be nil but the others must be non-nil.
- label: The token corresponding to the label keyword if present ("optional", "required", or "repeated").
- fieldType: The token corresponding to the field's type.
- name: The token corresponding to the field's name.
- equals: The token corresponding to the '=' rune after the name.
- tag: The token corresponding to the field's tag number.
- opts: Optional set of field options.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*FieldNode) FieldExtendee ¶
func (*FieldNode) FieldLabel ¶
func (*FieldNode) GetGroupKeyword ¶
func (*FieldNode) GetOptions ¶
func (n *FieldNode) GetOptions() *CompactOptionsNode
func (*FieldNode) LeadingComments ¶
func (n *FieldNode) LeadingComments() []Comment
func (*FieldNode) TrailingComments ¶
func (n *FieldNode) TrailingComments() []Comment
type FieldReferenceNode ¶
type FieldReferenceNode struct { Open *RuneNode // only present for extension names and "any" type references // only present for "any" type references UrlPrefix IdentValueNode Slash *RuneNode Name IdentValueNode Close *RuneNode // only present for extension names and "any" type references // contains filtered or unexported fields }
FieldReferenceNode is a reference to a field name. It can indicate a regular field (simple unqualified name), an extension field (possibly-qualified name that is enclosed either in brackets or parentheses), or an "any" type reference (a type URL in the form "server.host/fully.qualified.Name" that is enclosed in brackets).
Extension names are used in options to refer to custom options (which are actually extensions), in which case the name is enclosed in parentheses "(" and ")". They can also be used to refer to extension fields of options.
Extension names are also used in message literals to set extension fields, in which case the name is enclosed in square brackets "[" and "]".
"Any" type references can only be used in message literals, and are not allowed in option names. They are always enclosed in square brackets. An "any" type reference is distinguished from an extension name by the presence of a slash, which must be present in an "any" type reference and must be absent in an extension name.
Examples:
foobar (foo.bar) [foo.bar] [type.googleapis.com/foo.bar]
func NewAnyTypeReferenceNode ¶
func NewAnyTypeReferenceNode(openSym *RuneNode, urlPrefix IdentValueNode, slashSym *RuneNode, name IdentValueNode, closeSym *RuneNode) *FieldReferenceNode
NewAnyTypeReferenceNode creates a new *FieldReferenceNode for an "any" type reference. All args must be non-nil. The openSym and closeSym runes should be "[" and "]". The slashSym run should be "/".
func NewExtensionFieldReferenceNode ¶
func NewExtensionFieldReferenceNode(openSym *RuneNode, name IdentValueNode, closeSym *RuneNode) *FieldReferenceNode
NewExtensionFieldReferenceNode creates a new *FieldReferenceNode for an extension field. All args must be non-nil. The openSym and closeSym runes should be "(" and ")" or "[" and "]".
func NewFieldReferenceNode ¶
func NewFieldReferenceNode(name *IdentNode) *FieldReferenceNode
NewFieldReferenceNode creates a new *FieldReferenceNode for a regular field. The name arg must not be nil.
func (*FieldReferenceNode) IsAnyTypeReference ¶
func (a *FieldReferenceNode) IsAnyTypeReference() bool
IsExtension reports if this is an extension name or not (e.g. enclosed in punctuation, such as parentheses or brackets).
func (*FieldReferenceNode) IsExtension ¶
func (a *FieldReferenceNode) IsExtension() bool
IsExtension reports if this is an extension name or not (e.g. enclosed in punctuation, such as parentheses or brackets).
func (*FieldReferenceNode) LeadingComments ¶
func (n *FieldReferenceNode) LeadingComments() []Comment
func (*FieldReferenceNode) TrailingComments ¶
func (n *FieldReferenceNode) TrailingComments() []Comment
func (*FieldReferenceNode) Value ¶
func (a *FieldReferenceNode) Value() string
type FileDeclNode ¶
FileDeclNode is a placeholder interface for AST nodes that represent files. This allows NoSourceNode to be used in place of *FileNode for some usages.
type FileElement ¶
type FileElement interface { Node // contains filtered or unexported methods }
FileElement is an interface implemented by all AST nodes that are allowed as top-level declarations in the file.
type FileNode ¶
type FileNode struct { Syntax *SyntaxNode // nil if file has no syntax declaration Decls []FileElement // Any comments that follow the last token in the file. FinalComments []Comment // Any whitespace at the end of the file (after the last token or // last comment in the file). FinalWhitespace string // contains filtered or unexported fields }
FileNode is the root of the AST hierarchy. It represents an entire protobuf source file.
func NewEmptyFileNode ¶
func NewFileNode ¶
func NewFileNode(syntax *SyntaxNode, decls []FileElement) *FileNode
NewFileNode creates a new *FileNode. The syntax parameter is optional. If it is absent, it means the file had no syntax declaration.
This function panics if the concrete type of any element of decls is not from this package.
func (*FileNode) LeadingComments ¶
func (n *FileNode) LeadingComments() []Comment
func (*FileNode) TrailingComments ¶
func (n *FileNode) TrailingComments() []Comment
type FloatLiteralNode ¶
type FloatLiteralNode struct { // Val is the numeric value indicated by the literal Val float64 // contains filtered or unexported fields }
FloatLiteralNode represents a floating point numeric literal.
func NewFloatLiteralNode ¶
func NewFloatLiteralNode(val float64, info TokenInfo) *FloatLiteralNode
NewFloatLiteralNode creates a new *FloatLiteralNode with the given val.
func (*FloatLiteralNode) AsFloat ¶
func (n *FloatLiteralNode) AsFloat() float64
func (*FloatLiteralNode) LeadingComments ¶
func (n *FloatLiteralNode) LeadingComments() []Comment
func (*FloatLiteralNode) LeadingWhitespace ¶
func (n *FloatLiteralNode) LeadingWhitespace() string
func (*FloatLiteralNode) PopLeadingComment ¶
func (n *FloatLiteralNode) PopLeadingComment() Comment
func (*FloatLiteralNode) PushTrailingComment ¶
func (n *FloatLiteralNode) PushTrailingComment(c Comment)
func (*FloatLiteralNode) TrailingComments ¶
func (n *FloatLiteralNode) TrailingComments() []Comment
func (*FloatLiteralNode) Value ¶
func (n *FloatLiteralNode) Value() interface{}
type FloatValueNode ¶
FloatValueNode is an AST node that represents a numeric literal with a floating point, in scientific notation, or too large to fit in an int64 or uint64.
type GroupNode ¶
type GroupNode struct { Label FieldLabel Keyword *KeywordNode Name *IdentNode Equals *RuneNode Tag *UintLiteralNode Options *CompactOptionsNode MessageBody // This is an up-link to the containing *ExtendNode for groups // that are defined inside of "extend" blocks. Extendee *ExtendNode // contains filtered or unexported fields }
GroupNode represents a group declaration, which doubles as a field and inline message declaration. It can represent extension fields as well as non-extension fields (both inside of messages and inside of one-ofs). Example:
optional group Key = 4 { optional uint64 id = 1; optional string name = 2; }
func NewGroupNode ¶
func NewGroupNode(label *KeywordNode, keyword *KeywordNode, name *IdentNode, equals *RuneNode, tag *UintLiteralNode, opts *CompactOptionsNode, openBrace *RuneNode, decls []MessageElement, closeBrace *RuneNode) *GroupNode
NewGroupNode creates a new *GroupNode. The label and options arguments may be nil but the others must be non-nil.
- label: The token corresponding to the label keyword if present ("optional", "required", or "repeated").
- keyword: The token corresponding to the "group" keyword.
- name: The token corresponding to the field's name.
- equals: The token corresponding to the '=' rune after the name.
- tag: The token corresponding to the field's tag number.
- opts: Optional set of field options.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the group body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*GroupNode) FieldExtendee ¶
func (*GroupNode) FieldLabel ¶
func (*GroupNode) GetGroupKeyword ¶
func (*GroupNode) GetOptions ¶
func (n *GroupNode) GetOptions() *CompactOptionsNode
func (*GroupNode) LeadingComments ¶
func (n *GroupNode) LeadingComments() []Comment
func (*GroupNode) MessageName ¶
func (*GroupNode) TrailingComments ¶
func (n *GroupNode) TrailingComments() []Comment
type IdentNode ¶
type IdentNode struct { Val string // contains filtered or unexported fields }
IdentNode represents a simple, unqualified identifier. These are used to name elements declared in a protobuf file or to refer to elements. Example:
foobar
func NewIdentNode ¶
NewIdentNode creates a new *IdentNode. The given val is the identifier text.
func (*IdentNode) AsIdentifier ¶
func (n *IdentNode) AsIdentifier() Identifier
func (*IdentNode) LeadingComments ¶
func (n *IdentNode) LeadingComments() []Comment
func (*IdentNode) LeadingWhitespace ¶
func (n *IdentNode) LeadingWhitespace() string
func (*IdentNode) PopLeadingComment ¶
func (n *IdentNode) PopLeadingComment() Comment
func (*IdentNode) PushTrailingComment ¶
func (n *IdentNode) PushTrailingComment(c Comment)
func (*IdentNode) ToKeyword ¶
func (n *IdentNode) ToKeyword() *KeywordNode
ToKeyword is used to convert identifiers to keywords. Since keywords are not reserved in the protobuf language, they are initially lexed as identifiers and then converted to keywords based on context.
func (*IdentNode) TrailingComments ¶
func (n *IdentNode) TrailingComments() []Comment
type IdentValueNode ¶
type IdentValueNode interface { ValueNode AsIdentifier() Identifier }
IdentValueNode is an AST node that represents an identifier.
type Identifier ¶
type Identifier string
Identifier is a possibly-qualified name. This is used to distinguish ValueNode values that are references/identifiers vs. those that are string literals.
type ImportNode ¶
type ImportNode struct { Keyword *KeywordNode // Optional; if present indicates this is a public import Public *KeywordNode // Optional; if present indicates this is a weak import Weak *KeywordNode Name StringValueNode Semicolon *RuneNode // contains filtered or unexported fields }
ImportNode represents an import statement. Example:
import "google/protobuf/empty.proto";
func NewImportNode ¶
func NewImportNode(keyword *KeywordNode, public *KeywordNode, weak *KeywordNode, name StringValueNode, semicolon *RuneNode) *ImportNode
NewImportNode creates a new *ImportNode. The public and weak arguments are optional and only one or the other (or neither) may be specified, not both. When public is non-nil, it indicates the "public" keyword in the import statement and means this is a public import. When weak is non-nil, it indicates the "weak" keyword in the import statement and means this is a weak import. When both are nil, this is a normal import. The other arguments must be non-nil:
- keyword: The token corresponding to the "import" keyword.
- public: The token corresponding to the optional "public" keyword.
- weak: The token corresponding to the optional "weak" keyword.
- name: The actual imported file name.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*ImportNode) LeadingComments ¶
func (n *ImportNode) LeadingComments() []Comment
func (*ImportNode) TrailingComments ¶
func (n *ImportNode) TrailingComments() []Comment
type IntValueNode ¶
IntValueNode is an AST node that represents an integer literal. If an integer literal is too large for an int64 (or uint64 for positive literals), it is represented instead by a FloatValueNode.
type KeywordNode ¶
type KeywordNode IdentNode
KeywordNode is an AST node that represents a keyword. Keywords are like identifiers, but they have special meaning in particular contexts. Example:
message
func NewKeywordNode ¶
func NewKeywordNode(val string, info TokenInfo) *KeywordNode
NewKeywordNode creates a new *KeywordNode. The given val is the keyword.
type MapFieldNode ¶
type MapFieldNode struct { MapType *MapTypeNode Name *IdentNode Equals *RuneNode Tag *UintLiteralNode Options *CompactOptionsNode Semicolon *RuneNode // contains filtered or unexported fields }
MapFieldNode represents a map field declaration. Example:
map<string,string> replacements = 3 [deprecated = true];
func NewMapFieldNode ¶
func NewMapFieldNode(mapType *MapTypeNode, name *IdentNode, equals *RuneNode, tag *UintLiteralNode, opts *CompactOptionsNode, semicolon *RuneNode) *MapFieldNode
NewMapFieldNode creates a new *MapFieldNode. All arguments must be non-nil except opts, which may be nil.
- mapType: The token corresponding to the map type.
- name: The token corresponding to the field's name.
- equals: The token corresponding to the '=' rune after the name.
- tag: The token corresponding to the field's tag number.
- opts: Optional set of field options.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*MapFieldNode) FieldExtendee ¶
func (n *MapFieldNode) FieldExtendee() Node
func (*MapFieldNode) FieldLabel ¶
func (n *MapFieldNode) FieldLabel() Node
func (*MapFieldNode) FieldName ¶
func (n *MapFieldNode) FieldName() Node
func (*MapFieldNode) FieldTag ¶
func (n *MapFieldNode) FieldTag() Node
func (*MapFieldNode) FieldType ¶
func (n *MapFieldNode) FieldType() Node
func (*MapFieldNode) GetGroupKeyword ¶
func (n *MapFieldNode) GetGroupKeyword() Node
func (*MapFieldNode) GetOptions ¶
func (n *MapFieldNode) GetOptions() *CompactOptionsNode
func (*MapFieldNode) KeyField ¶
func (n *MapFieldNode) KeyField() *SyntheticMapField
func (*MapFieldNode) LeadingComments ¶
func (n *MapFieldNode) LeadingComments() []Comment
func (*MapFieldNode) MessageName ¶
func (n *MapFieldNode) MessageName() Node
func (*MapFieldNode) TrailingComments ¶
func (n *MapFieldNode) TrailingComments() []Comment
func (*MapFieldNode) ValueField ¶
func (n *MapFieldNode) ValueField() *SyntheticMapField
type MapTypeNode ¶
type MapTypeNode struct { Keyword *KeywordNode OpenAngle *RuneNode KeyType *IdentNode Comma *RuneNode ValueType IdentValueNode CloseAngle *RuneNode // contains filtered or unexported fields }
MapTypeNode represents the type declaration for a map field. It defines both the key and value types for the map. Example:
map<string, Values>
func NewMapTypeNode ¶
func NewMapTypeNode(keyword *KeywordNode, openAngle *RuneNode, keyType *IdentNode, comma *RuneNode, valType IdentValueNode, closeAngle *RuneNode) *MapTypeNode
NewMapTypeNode creates a new *MapTypeNode. All arguments must be non-nil.
- keyword: The token corresponding to the "map" keyword.
- openAngle: The token corresponding to the "<" rune after the keyword.
- keyType: The token corresponding to the key type for the map.
- comma: The token corresponding to the "," rune between key and value types.
- valType: The token corresponding to the value type for the map.
- closeAngle: The token corresponding to the ">" rune that ends the declaration.
func (*MapTypeNode) LeadingComments ¶
func (n *MapTypeNode) LeadingComments() []Comment
func (*MapTypeNode) TrailingComments ¶
func (n *MapTypeNode) TrailingComments() []Comment
type MessageBody ¶
type MessageBody struct { OpenBrace *RuneNode Decls []MessageElement CloseBrace *RuneNode }
MessageBody represents the body of a message. It is used by both MessageNodes and GroupNodes.
type MessageDeclNode ¶
MessageDeclNode is a node in the AST that defines a message type. This includes normal message fields as well as implicit messages:
- *MessageNode
- *GroupNode (the group is a field and inline message type)
- *MapFieldNode (map fields implicitly define a MapEntry message type)
This also allows NoSourceNode to be used in place of one of the above for some usages.
type MessageElement ¶
type MessageElement interface { Node // contains filtered or unexported methods }
MessageElement is an interface implemented by all AST nodes that can appear in a message body.
type MessageFieldNode ¶
type MessageFieldNode struct { Name *FieldReferenceNode // Sep represents the ':' separator between the name and value. If // the value is a message literal (and thus starts with '<' or '{') // or an array literal (starting with '[') then the separator is // optional, and thus may be nil. Sep *RuneNode Val ValueNode // contains filtered or unexported fields }
MessageFieldNode represents a single field (name and value) inside of a message literal. Example:
foo:"bar"
func NewMessageFieldNode ¶
func NewMessageFieldNode(name *FieldReferenceNode, sep *RuneNode, val ValueNode) *MessageFieldNode
NewMessageFieldNode creates a new *MessageFieldNode. All args except sep must be non-nil.
func (*MessageFieldNode) LeadingComments ¶
func (n *MessageFieldNode) LeadingComments() []Comment
func (*MessageFieldNode) TrailingComments ¶
func (n *MessageFieldNode) TrailingComments() []Comment
type MessageLiteralNode ¶
type MessageLiteralNode struct { Open *RuneNode // should be '{' or '<' Elements []*MessageFieldNode // Separator characters between elements, which can be either ',' // or ';' if present. This slice must be exactly len(Elements) in // length, with each item in Elements having one corresponding item // in Seps. Separators in message literals are optional, so a given // item in this slice may be nil to indicate absence of a separator. Seps []*RuneNode Close *RuneNode // should be '}' or '>', depending on Open // contains filtered or unexported fields }
MessageLiteralNode represents a message literal, which is compatible with the protobuf text format and can be used for custom options with message types. Example:
{ foo:1 foo:2 foo:3 bar:<name:"abc" id:123> }
func NewMessageLiteralNode ¶
func NewMessageLiteralNode(openSym *RuneNode, vals []*MessageFieldNode, seps []*RuneNode, closeSym *RuneNode) *MessageLiteralNode
NewMessageLiteralNode creates a new *MessageLiteralNode. The openSym and closeSym runes must not be nil and should be "{" and "}" or "<" and ">".
Unlike separators (dots and commas) used for other AST nodes that represent a list of elements, the seps arg must be the SAME length as vals, and it may contain nil values to indicate absence of a separator (in fact, it could be all nils).
func (*MessageLiteralNode) LeadingComments ¶
func (n *MessageLiteralNode) LeadingComments() []Comment
func (*MessageLiteralNode) TrailingComments ¶
func (n *MessageLiteralNode) TrailingComments() []Comment
func (*MessageLiteralNode) Value ¶
func (n *MessageLiteralNode) Value() interface{}
type MessageNode ¶
type MessageNode struct { Keyword *KeywordNode Name *IdentNode MessageBody // contains filtered or unexported fields }
MessageNode represents a message declaration. Example:
message Foo { string name = 1; repeated string labels = 2; bytes extra = 3; }
func NewMessageNode ¶
func NewMessageNode(keyword *KeywordNode, name *IdentNode, openBrace *RuneNode, decls []MessageElement, closeBrace *RuneNode) *MessageNode
NewMessageNode creates a new *MessageNode. All arguments must be non-nil.
- keyword: The token corresponding to the "message" keyword.
- name: The token corresponding to the field's name.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the message body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*MessageNode) LeadingComments ¶
func (n *MessageNode) LeadingComments() []Comment
func (*MessageNode) MessageName ¶
func (n *MessageNode) MessageName() Node
func (*MessageNode) TrailingComments ¶
func (n *MessageNode) TrailingComments() []Comment
type NegativeIntLiteralNode ¶
type NegativeIntLiteralNode struct { Minus *RuneNode Uint *UintLiteralNode Val int64 // contains filtered or unexported fields }
NegativeIntLiteralNode represents an integer literal with a negative (-) sign.
func NewNegativeIntLiteralNode ¶
func NewNegativeIntLiteralNode(sign *RuneNode, i *UintLiteralNode) *NegativeIntLiteralNode
NewNegativeIntLiteralNode creates a new *NegativeIntLiteralNode. Both arguments must be non-nil.
func (*NegativeIntLiteralNode) AsInt64 ¶
func (n *NegativeIntLiteralNode) AsInt64() (int64, bool)
func (*NegativeIntLiteralNode) AsUint64 ¶
func (n *NegativeIntLiteralNode) AsUint64() (uint64, bool)
func (*NegativeIntLiteralNode) LeadingComments ¶
func (n *NegativeIntLiteralNode) LeadingComments() []Comment
func (*NegativeIntLiteralNode) TrailingComments ¶
func (n *NegativeIntLiteralNode) TrailingComments() []Comment
func (*NegativeIntLiteralNode) Value ¶
func (n *NegativeIntLiteralNode) Value() interface{}
type NoSourceNode ¶
type NoSourceNode struct {
// contains filtered or unexported fields
}
NoSourceNode is a placeholder AST node that implements numerous interfaces in this package. It can be used to represent an AST element for a file whose source is not available.
func NewNoSourceNode ¶
func NewNoSourceNode(filename string) NoSourceNode
NewNoSourceNode creates a new NoSourceNode for the given filename.
func (NoSourceNode) End ¶
func (n NoSourceNode) End() *SourcePos
func (NoSourceNode) FieldExtendee ¶
func (n NoSourceNode) FieldExtendee() Node
func (NoSourceNode) FieldLabel ¶
func (n NoSourceNode) FieldLabel() Node
func (NoSourceNode) FieldName ¶
func (n NoSourceNode) FieldName() Node
func (NoSourceNode) FieldTag ¶
func (n NoSourceNode) FieldTag() Node
func (NoSourceNode) FieldType ¶
func (n NoSourceNode) FieldType() Node
func (NoSourceNode) GetGroupKeyword ¶
func (n NoSourceNode) GetGroupKeyword() Node
func (NoSourceNode) GetInputType ¶
func (n NoSourceNode) GetInputType() Node
func (NoSourceNode) GetName ¶
func (n NoSourceNode) GetName() Node
func (NoSourceNode) GetNumber ¶
func (n NoSourceNode) GetNumber() Node
func (NoSourceNode) GetOptions ¶
func (n NoSourceNode) GetOptions() *CompactOptionsNode
func (NoSourceNode) GetOutputType ¶
func (n NoSourceNode) GetOutputType() Node
func (NoSourceNode) GetSyntax ¶
func (n NoSourceNode) GetSyntax() Node
func (NoSourceNode) GetValue ¶
func (n NoSourceNode) GetValue() ValueNode
func (NoSourceNode) LeadingComments ¶
func (n NoSourceNode) LeadingComments() []Comment
func (NoSourceNode) MessageName ¶
func (n NoSourceNode) MessageName() Node
func (NoSourceNode) RangeEnd ¶
func (n NoSourceNode) RangeEnd() Node
func (NoSourceNode) RangeStart ¶
func (n NoSourceNode) RangeStart() Node
func (NoSourceNode) Start ¶
func (n NoSourceNode) Start() *SourcePos
func (NoSourceNode) TrailingComments ¶
func (n NoSourceNode) TrailingComments() []Comment
func (NoSourceNode) Value ¶
func (n NoSourceNode) Value() interface{}
type Node ¶
type Node interface { Start() *SourcePos End() *SourcePos LeadingComments() []Comment TrailingComments() []Comment }
Node is the interface implemented by all nodes in the AST. It provides information about the span of this AST node in terms of location in the source file. It also provides information about all prior comments (attached as leading comments) and optional subsequent comments (attached as trailing comments).
type OneOfDeclNode ¶
OneOfDeclNode is a node in the AST that defines a oneof. There are multiple types of AST nodes that declare oneofs:
- *OneOfNode
- *SyntheticOneOf
This also allows NoSourceNode to be used in place of one of the above for some usages.
type OneOfElement ¶
type OneOfElement interface { Node // contains filtered or unexported methods }
OneOfElement is an interface implemented by all AST nodes that can appear in the body of a oneof declaration.
type OneOfNode ¶
type OneOfNode struct { Keyword *KeywordNode Name *IdentNode OpenBrace *RuneNode Decls []OneOfElement CloseBrace *RuneNode // contains filtered or unexported fields }
OneOfNode represents a one-of declaration. Example:
oneof query { string by_name = 2; Type by_type = 3; Address by_address = 4; Labels by_label = 5; }
func NewOneOfNode ¶
func NewOneOfNode(keyword *KeywordNode, name *IdentNode, openBrace *RuneNode, decls []OneOfElement, closeBrace *RuneNode) *OneOfNode
NewOneOfNode creates a new *OneOfNode. All arguments must be non-nil. While it is technically allowed for decls to be nil or empty, the resulting node will not be a valid oneof, which must have at least one field.
- keyword: The token corresponding to the "oneof" keyword.
- name: The token corresponding to the oneof's name.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the oneof body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*OneOfNode) LeadingComments ¶
func (n *OneOfNode) LeadingComments() []Comment
func (*OneOfNode) TrailingComments ¶
func (n *OneOfNode) TrailingComments() []Comment
type OptionDeclNode ¶
OptionDeclNode is a placeholder interface for AST nodes that represent options. This allows NoSourceNode to be used in place of *OptionNode for some usages.
type OptionNameNode ¶
type OptionNameNode struct { Parts []*FieldReferenceNode // Dots represent the separating '.' characters between name parts. The // length of this slice must be exactly len(Parts)-1, each item in Parts // having a corresponding item in this slice *except the last* (since a // trailing dot is not allowed). // // These do *not* include dots that are inside of an extension name. For // example: (foo.bar).baz.(bob) has three parts: // 1. (foo.bar) - an extension name // 2. baz - a regular field in foo.bar // 3. (bob) - an extension field in baz // Note that the dot in foo.bar will thus not be present in Dots but is // instead in Parts[0]. Dots []*RuneNode // contains filtered or unexported fields }
OptionNameNode represents an option name or even a traversal through message types to name a nested option field. Example:
(foo.bar).baz.(bob)
func NewOptionNameNode ¶
func NewOptionNameNode(parts []*FieldReferenceNode, dots []*RuneNode) *OptionNameNode
NewOptionNameNode creates a new *OptionNameNode. The dots arg must have a length that is one less than the length of parts. The parts arg must not be empty.
func (*OptionNameNode) LeadingComments ¶
func (n *OptionNameNode) LeadingComments() []Comment
func (*OptionNameNode) TrailingComments ¶
func (n *OptionNameNode) TrailingComments() []Comment
type OptionNode ¶
type OptionNode struct { Keyword *KeywordNode // absent for compact options Name *OptionNameNode Equals *RuneNode Val ValueNode Semicolon *RuneNode // absent for compact options // contains filtered or unexported fields }
OptionNode represents the declaration of a single option for an element. It is used both for normal option declarations (start with "option" keyword and end with semicolon) and for compact options found in fields, enum values, and extension ranges. Example:
option (custom.option) = "foo";
func NewCompactOptionNode ¶
func NewCompactOptionNode(name *OptionNameNode, equals *RuneNode, val ValueNode) *OptionNode
NewCompactOptionNode creates a new *OptionNode for a full compact declaration (as used in fields, enum values, and extension ranges). All arguments must be non-nil.
- name: The token corresponding to the name of the option.
- equals: The token corresponding to the "=" rune after the name.
- val: The token corresponding to the option value.
func NewOptionNode ¶
func NewOptionNode(keyword *KeywordNode, name *OptionNameNode, equals *RuneNode, val ValueNode, semicolon *RuneNode) *OptionNode
NewOptionNode creates a new *OptionNode for a full option declaration (as used in files, messages, oneofs, enums, services, and methods). All arguments must be non-nil. (Also see NewCompactOptionNode.)
- keyword: The token corresponding to the "option" keyword.
- name: The token corresponding to the name of the option.
- equals: The token corresponding to the "=" rune after the name.
- val: The token corresponding to the option value.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*OptionNode) GetName ¶
func (n *OptionNode) GetName() Node
func (*OptionNode) GetValue ¶
func (n *OptionNode) GetValue() ValueNode
func (*OptionNode) LeadingComments ¶
func (n *OptionNode) LeadingComments() []Comment
func (*OptionNode) TrailingComments ¶
func (n *OptionNode) TrailingComments() []Comment
type PackageNode ¶
type PackageNode struct { Keyword *KeywordNode Name IdentValueNode Semicolon *RuneNode // contains filtered or unexported fields }
PackageNode represents a package declaration. Example:
package foobar.com;
func NewPackageNode ¶
func NewPackageNode(keyword *KeywordNode, name IdentValueNode, semicolon *RuneNode) *PackageNode
NewPackageNode creates a new *PackageNode. All three arguments must be non-nil:
- keyword: The token corresponding to the "package" keyword.
- name: The package name declared for the file.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*PackageNode) LeadingComments ¶
func (n *PackageNode) LeadingComments() []Comment
func (*PackageNode) TrailingComments ¶
func (n *PackageNode) TrailingComments() []Comment
type PosRange ¶
type PosRange struct {
Start, End SourcePos
}
PosRange is a range of positions in a source file that indicates the span of some region of source, such as a single token or a sub-tree of the AST.
type PositiveUintLiteralNode
deprecated
type PositiveUintLiteralNode struct { Plus *RuneNode Uint *UintLiteralNode Val uint64 // contains filtered or unexported fields }
PositiveUintLiteralNode represents an integer literal with a positive (+) sign.
Deprecated: A valid AST will not contain a node of this type. The Protobuf language does not actually allow a numeric literal to have a leading "+" positive sign.
func NewPositiveUintLiteralNode
deprecated
func NewPositiveUintLiteralNode(sign *RuneNode, i *UintLiteralNode) *PositiveUintLiteralNode
NewPositiveUintLiteralNode creates a new *PositiveUintLiteralNode. Both arguments must be non-nil.
Deprecated: The ast.PositiveUintLiteralNode node type should not be used.
func (*PositiveUintLiteralNode) AsInt64 ¶
func (n *PositiveUintLiteralNode) AsInt64() (int64, bool)
func (*PositiveUintLiteralNode) AsUint64 ¶
func (n *PositiveUintLiteralNode) AsUint64() (uint64, bool)
func (*PositiveUintLiteralNode) LeadingComments ¶
func (n *PositiveUintLiteralNode) LeadingComments() []Comment
func (*PositiveUintLiteralNode) TrailingComments ¶
func (n *PositiveUintLiteralNode) TrailingComments() []Comment
func (*PositiveUintLiteralNode) Value ¶
func (n *PositiveUintLiteralNode) Value() interface{}
type RPCDeclNode ¶
RPCDeclNode is a placeholder interface for AST nodes that represent RPC declarations. This allows NoSourceNode to be used in place of *RPCNode for some usages.
type RPCElement ¶
type RPCElement interface { Node // contains filtered or unexported methods }
RPCElement is an interface implemented by all AST nodes that can appear in the body of an rpc declaration (aka method).
type RPCNode ¶
type RPCNode struct { Keyword *KeywordNode Name *IdentNode Input *RPCTypeNode Returns *KeywordNode Output *RPCTypeNode Semicolon *RuneNode OpenBrace *RuneNode Decls []RPCElement CloseBrace *RuneNode // contains filtered or unexported fields }
RPCNode represents an RPC declaration. Example:
rpc Foo (Bar) returns (Baz);
func NewRPCNode ¶
func NewRPCNode(keyword *KeywordNode, name *IdentNode, input *RPCTypeNode, returns *KeywordNode, output *RPCTypeNode, semicolon *RuneNode) *RPCNode
NewRPCNode creates a new *RPCNode with no body. All arguments must be non-nil.
- keyword: The token corresponding to the "rpc" keyword.
- name: The token corresponding to the RPC's name.
- input: The token corresponding to the RPC input message type.
- returns: The token corresponding to the "returns" keyword that precedes the output type.
- output: The token corresponding to the RPC output message type.
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func NewRPCNodeWithBody ¶
func NewRPCNodeWithBody(keyword *KeywordNode, name *IdentNode, input *RPCTypeNode, returns *KeywordNode, output *RPCTypeNode, openBrace *RuneNode, decls []RPCElement, closeBrace *RuneNode) *RPCNode
NewRPCNodeWithBody creates a new *RPCNode that includes a body (and possibly options). All arguments must be non-nil.
- keyword: The token corresponding to the "rpc" keyword.
- name: The token corresponding to the RPC's name.
- input: The token corresponding to the RPC input message type.
- returns: The token corresponding to the "returns" keyword that precedes the output type.
- output: The token corresponding to the RPC output message type.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the RPC body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*RPCNode) GetInputType ¶
func (*RPCNode) GetOutputType ¶
func (*RPCNode) LeadingComments ¶
func (n *RPCNode) LeadingComments() []Comment
func (*RPCNode) TrailingComments ¶
func (n *RPCNode) TrailingComments() []Comment
type RPCTypeNode ¶
type RPCTypeNode struct { OpenParen *RuneNode Stream *KeywordNode MessageType IdentValueNode CloseParen *RuneNode // contains filtered or unexported fields }
RPCTypeNode represents the declaration of a request or response type for an RPC. Example:
(stream foo.Bar)
func NewRPCTypeNode ¶
func NewRPCTypeNode(openParen *RuneNode, stream *KeywordNode, msgType IdentValueNode, closeParen *RuneNode) *RPCTypeNode
NewRPCTypeNode creates a new *RPCTypeNode. All arguments must be non-nil except stream, which may be nil.
- openParen: The token corresponding to the "(" rune that starts the declaration.
- stream: The token corresponding to the "stream" keyword or nil if not present.
- msgType: The token corresponding to the message type's name.
- closeParen: The token corresponding to the ")" rune that ends the declaration.
func (*RPCTypeNode) LeadingComments ¶
func (n *RPCTypeNode) LeadingComments() []Comment
func (*RPCTypeNode) TrailingComments ¶
func (n *RPCTypeNode) TrailingComments() []Comment
type RangeDeclNode ¶
RangeDeclNode is a placeholder interface for AST nodes that represent numeric values. This allows NoSourceNode to be used in place of *RangeNode for some usages.
type RangeNode ¶
type RangeNode struct { StartVal IntValueNode // if To is non-nil, then exactly one of EndVal or Max must also be non-nil To *KeywordNode // EndVal and Max are mutually exclusive EndVal IntValueNode Max *KeywordNode // contains filtered or unexported fields }
RangeNode represents a range expression, used in both extension ranges and reserved ranges. Example:
1000 to max
func NewRangeNode ¶
func NewRangeNode(start IntValueNode, to *KeywordNode, end IntValueNode, max *KeywordNode) *RangeNode
NewRangeNode creates a new *RangeNode. The start argument must be non-nil. The to argument represents the "to" keyword. If present (i.e. if it is non-nil), then so must be exactly one of end or max. If max is non-nil, it indicates a "100 to max" style range. But if end is non-nil, the end of the range is a literal, such as "100 to 200".
func (*RangeNode) EndValueAsInt32 ¶
func (*RangeNode) LeadingComments ¶
func (n *RangeNode) LeadingComments() []Comment
func (*RangeNode) RangeStart ¶
func (*RangeNode) StartValue ¶
func (n *RangeNode) StartValue() interface{}
func (*RangeNode) StartValueAsInt32 ¶
func (*RangeNode) TrailingComments ¶
func (n *RangeNode) TrailingComments() []Comment
type ReservedNode ¶
type ReservedNode struct { Keyword *KeywordNode // If non-empty, this node represents reserved ranges and Names will be empty. Ranges []*RangeNode // If non-empty, this node represents reserved names and Ranges will be empty. Names []StringValueNode // Commas represent the separating ',' characters between options. The // length of this slice must be exactly len(Ranges)-1 or len(Names)-1, depending // on whether this node represents reserved ranges or reserved names. Each item // in Ranges or Names has a corresponding item in this slice *except the last* // (since a trailing comma is not allowed). Commas []*RuneNode Semicolon *RuneNode // contains filtered or unexported fields }
ReservedNode represents reserved declaration, which can be used to reserve either names or numbers. Examples:
reserved 1, 10-12, 15; reserved "foo", "bar", "baz";
func NewReservedNamesNode ¶
func NewReservedNamesNode(keyword *KeywordNode, names []StringValueNode, commas []*RuneNode, semicolon *RuneNode) *ReservedNode
NewReservedNamesNode creates a new *ReservedNode that represents reserved names. All args must be non-nil.
- keyword: The token corresponding to the "reserved" keyword.
- names: One or more names.
- commas: Tokens that represent the "," runes that delimit the names. The length of commas must be one less than the length of names.
- semicolon The token corresponding to the ";" rune that ends the declaration.
func NewReservedRangesNode ¶
func NewReservedRangesNode(keyword *KeywordNode, ranges []*RangeNode, commas []*RuneNode, semicolon *RuneNode) *ReservedNode
NewReservedRangesNode creates a new *ReservedNode that represents reserved numeric ranges. All args must be non-nil.
- keyword: The token corresponding to the "reserved" keyword.
- ranges: One or more range expressions.
- commas: Tokens that represent the "," runes that delimit the range expressions. The length of commas must be one less than the length of ranges.
- semicolon The token corresponding to the ";" rune that ends the declaration.
func (*ReservedNode) LeadingComments ¶
func (n *ReservedNode) LeadingComments() []Comment
func (*ReservedNode) TrailingComments ¶
func (n *ReservedNode) TrailingComments() []Comment
type RuneNode ¶
type RuneNode struct { Rune rune // contains filtered or unexported fields }
RuneNode represents a single rune in protobuf source. Runes are typically collected into tokens, but some runes stand on their own, such as punctuation/symbols like commas, semicolons, equals signs, open and close symbols (braces, brackets, angles, and parentheses), and periods/dots.
func NewRuneNode ¶
NewRuneNode creates a new *RuneNode with the given properties.
func (*RuneNode) LeadingComments ¶
func (n *RuneNode) LeadingComments() []Comment
func (*RuneNode) LeadingWhitespace ¶
func (n *RuneNode) LeadingWhitespace() string
func (*RuneNode) PopLeadingComment ¶
func (n *RuneNode) PopLeadingComment() Comment
func (*RuneNode) PushTrailingComment ¶
func (n *RuneNode) PushTrailingComment(c Comment)
func (*RuneNode) TrailingComments ¶
func (n *RuneNode) TrailingComments() []Comment
type ServiceElement ¶
type ServiceElement interface { Node // contains filtered or unexported methods }
ServiceElement is an interface implemented by all AST nodes that can appear in the body of a service declaration.
type ServiceNode ¶
type ServiceNode struct { Keyword *KeywordNode Name *IdentNode OpenBrace *RuneNode Decls []ServiceElement CloseBrace *RuneNode // contains filtered or unexported fields }
ServiceNode represents a service declaration. Example:
service Foo { rpc Bar (Baz) returns (Bob); rpc Frobnitz (stream Parts) returns (Gyzmeaux); }
func NewServiceNode ¶
func NewServiceNode(keyword *KeywordNode, name *IdentNode, openBrace *RuneNode, decls []ServiceElement, closeBrace *RuneNode) *ServiceNode
NewServiceNode creates a new *ServiceNode. All arguments must be non-nil.
- keyword: The token corresponding to the "service" keyword.
- name: The token corresponding to the service's name.
- openBrace: The token corresponding to the "{" rune that starts the body.
- decls: All declarations inside the service body.
- closeBrace: The token corresponding to the "}" rune that ends the body.
func (*ServiceNode) LeadingComments ¶
func (n *ServiceNode) LeadingComments() []Comment
func (*ServiceNode) TrailingComments ¶
func (n *ServiceNode) TrailingComments() []Comment
type SignedFloatLiteralNode ¶
type SignedFloatLiteralNode struct { Sign *RuneNode Float FloatValueNode Val float64 // contains filtered or unexported fields }
SignedFloatLiteralNode represents a signed floating point number.
func NewSignedFloatLiteralNode ¶
func NewSignedFloatLiteralNode(sign *RuneNode, f FloatValueNode) *SignedFloatLiteralNode
NewSignedFloatLiteralNode creates a new *SignedFloatLiteralNode. Both arguments must be non-nil.
func (*SignedFloatLiteralNode) AsFloat ¶
func (n *SignedFloatLiteralNode) AsFloat() float64
func (*SignedFloatLiteralNode) LeadingComments ¶
func (n *SignedFloatLiteralNode) LeadingComments() []Comment
func (*SignedFloatLiteralNode) TrailingComments ¶
func (n *SignedFloatLiteralNode) TrailingComments() []Comment
func (*SignedFloatLiteralNode) Value ¶
func (n *SignedFloatLiteralNode) Value() interface{}
type SourcePos ¶
SourcePos identifies a location in a proto source file.
func UnknownPos ¶
UnknownPos is a placeholder position when only the source file name is known.
type SpecialFloatLiteralNode ¶
type SpecialFloatLiteralNode struct { *KeywordNode Val float64 }
SpecialFloatLiteralNode represents a special floating point numeric literal for "inf" and "nan" values.
func NewSpecialFloatLiteralNode ¶
func NewSpecialFloatLiteralNode(name *KeywordNode) *SpecialFloatLiteralNode
NewSpecialFloatLiteralNode returns a new *SpecialFloatLiteralNode for the given keyword, which must be "inf" or "nan".
func (*SpecialFloatLiteralNode) AsFloat ¶
func (n *SpecialFloatLiteralNode) AsFloat() float64
func (*SpecialFloatLiteralNode) Value ¶
func (n *SpecialFloatLiteralNode) Value() interface{}
type StringLiteralNode ¶
type StringLiteralNode struct { // Val is the actual string value that the literal indicates. Val string // contains filtered or unexported fields }
StringLiteralNode represents a simple string literal. Example:
"proto2"
func NewStringLiteralNode ¶
func NewStringLiteralNode(val string, info TokenInfo) *StringLiteralNode
NewStringLiteralNode creates a new *StringLiteralNode with the given val.
func (*StringLiteralNode) AsString ¶
func (n *StringLiteralNode) AsString() string
func (*StringLiteralNode) LeadingComments ¶
func (n *StringLiteralNode) LeadingComments() []Comment
func (*StringLiteralNode) LeadingWhitespace ¶
func (n *StringLiteralNode) LeadingWhitespace() string
func (*StringLiteralNode) PopLeadingComment ¶
func (n *StringLiteralNode) PopLeadingComment() Comment
func (*StringLiteralNode) PushTrailingComment ¶
func (n *StringLiteralNode) PushTrailingComment(c Comment)
func (*StringLiteralNode) TrailingComments ¶
func (n *StringLiteralNode) TrailingComments() []Comment
func (*StringLiteralNode) Value ¶
func (n *StringLiteralNode) Value() interface{}
type StringValueNode ¶
StringValueNode is an AST node that represents a string literal. Such a node can be a single literal (*StringLiteralNode) or a concatenation of multiple literals (*CompoundStringLiteralNode).
type SyntaxNode ¶
type SyntaxNode struct { Keyword *KeywordNode Equals *RuneNode Syntax StringValueNode Semicolon *RuneNode // contains filtered or unexported fields }
SyntaxNode represents a syntax declaration, which if present must be the first non-comment content. Example:
syntax = "proto2";
Files that don't have a syntax node are assumed to use proto2 syntax.
func NewSyntaxNode ¶
func NewSyntaxNode(keyword *KeywordNode, equals *RuneNode, syntax StringValueNode, semicolon *RuneNode) *SyntaxNode
NewSyntaxNode creates a new *SyntaxNode. All four arguments must be non-nil:
- keyword: The token corresponding to the "syntax" keyword.
- equals: The token corresponding to the "=" rune.
- syntax: The actual syntax value, e.g. "proto2" or "proto3".
- semicolon: The token corresponding to the ";" rune that ends the declaration.
func (*SyntaxNode) LeadingComments ¶
func (n *SyntaxNode) LeadingComments() []Comment
func (*SyntaxNode) TrailingComments ¶
func (n *SyntaxNode) TrailingComments() []Comment
type SyntheticMapField ¶
type SyntheticMapField struct { Ident IdentValueNode Tag *UintLiteralNode }
SyntheticMapField is not an actual node in the AST but a synthetic node that implements FieldDeclNode. These are used to represent the implicit field declarations of the "key" and "value" fields in a map entry.
func NewSyntheticMapField ¶
func NewSyntheticMapField(ident IdentValueNode, tagNum uint64) *SyntheticMapField
NewSyntheticMapField creates a new *SyntheticMapField for the given identifier (either a key or value type in a map declaration) and tag number (1 for key, 2 for value).
func (*SyntheticMapField) End ¶
func (n *SyntheticMapField) End() *SourcePos
func (*SyntheticMapField) FieldExtendee ¶
func (n *SyntheticMapField) FieldExtendee() Node
func (*SyntheticMapField) FieldLabel ¶
func (n *SyntheticMapField) FieldLabel() Node
func (*SyntheticMapField) FieldName ¶
func (n *SyntheticMapField) FieldName() Node
func (*SyntheticMapField) FieldTag ¶
func (n *SyntheticMapField) FieldTag() Node
func (*SyntheticMapField) FieldType ¶
func (n *SyntheticMapField) FieldType() Node
func (*SyntheticMapField) GetGroupKeyword ¶
func (n *SyntheticMapField) GetGroupKeyword() Node
func (*SyntheticMapField) GetOptions ¶
func (n *SyntheticMapField) GetOptions() *CompactOptionsNode
func (*SyntheticMapField) LeadingComments ¶
func (n *SyntheticMapField) LeadingComments() []Comment
func (*SyntheticMapField) Start ¶
func (n *SyntheticMapField) Start() *SourcePos
func (*SyntheticMapField) TrailingComments ¶
func (n *SyntheticMapField) TrailingComments() []Comment
type SyntheticOneOf ¶
type SyntheticOneOf struct {
Field *FieldNode
}
SyntheticOneOf is not an actual node in the AST but a synthetic node that implements OneOfDeclNode. These are used to represent the implicit oneof declarations that enclose "proto3 optional" fields.
func NewSyntheticOneOf ¶
func NewSyntheticOneOf(field *FieldNode) *SyntheticOneOf
NewSyntheticOneOf creates a new *SyntheticOneOf that corresponds to the given proto3 optional field.
func (*SyntheticOneOf) End ¶
func (n *SyntheticOneOf) End() *SourcePos
func (*SyntheticOneOf) LeadingComments ¶
func (n *SyntheticOneOf) LeadingComments() []Comment
func (*SyntheticOneOf) OneOfName ¶
func (n *SyntheticOneOf) OneOfName() Node
func (*SyntheticOneOf) Start ¶
func (n *SyntheticOneOf) Start() *SourcePos
func (*SyntheticOneOf) TrailingComments ¶
func (n *SyntheticOneOf) TrailingComments() []Comment
type TerminalNode ¶
type TerminalNode interface { Node // PopLeadingComment removes the first leading comment from this // token and returns it. If the node has no leading comments then // this method will panic. PopLeadingComment() Comment // PushTrailingComment appends the given comment to the token's // trailing comments. PushTrailingComment(Comment) // LeadingWhitespace returns any whitespace between the prior comment // (last leading comment), if any, or prior lexed token and this token. LeadingWhitespace() string // RawText returns the raw text of the token as read from the source. RawText() string }
TerminalNode represents a leaf in the AST. These represent the tokens/lexemes in the protobuf language. Comments and whitespace are accumulated by the lexer and associated with the following lexed token.
type TokenInfo ¶
type TokenInfo struct { // The location of the token in the source file. PosRange // The raw text of the token. RawText string // Any comments encountered preceding this token. LeadingComments []Comment // Any leading whitespace immediately preceding this token. LeadingWhitespace string // Any trailing comments following this token. This is usually // empty as tokens are created by the lexer immediately and // trailing comments are accounted for afterwards, added using // the node's PushTrailingComment method. TrailingComments []Comment }
TokenInfo represents state accumulated by the lexer to associated with a token (aka terminal node).
type UintLiteralNode ¶
type UintLiteralNode struct { // Val is the numeric value indicated by the literal Val uint64 // contains filtered or unexported fields }
UintLiteralNode represents a simple integer literal with no sign character.
func NewUintLiteralNode ¶
func NewUintLiteralNode(val uint64, info TokenInfo) *UintLiteralNode
NewUintLiteralNode creates a new *UintLiteralNode with the given val.
func (*UintLiteralNode) AsFloat ¶
func (n *UintLiteralNode) AsFloat() float64
func (*UintLiteralNode) AsInt64 ¶
func (n *UintLiteralNode) AsInt64() (int64, bool)
func (*UintLiteralNode) AsUint64 ¶
func (n *UintLiteralNode) AsUint64() (uint64, bool)
func (*UintLiteralNode) LeadingComments ¶
func (n *UintLiteralNode) LeadingComments() []Comment
func (*UintLiteralNode) LeadingWhitespace ¶
func (n *UintLiteralNode) LeadingWhitespace() string
func (*UintLiteralNode) PopLeadingComment ¶
func (n *UintLiteralNode) PopLeadingComment() Comment
func (*UintLiteralNode) PushTrailingComment ¶
func (n *UintLiteralNode) PushTrailingComment(c Comment)
func (*UintLiteralNode) TrailingComments ¶
func (n *UintLiteralNode) TrailingComments() []Comment
func (*UintLiteralNode) Value ¶
func (n *UintLiteralNode) Value() interface{}
type ValueNode ¶
type ValueNode interface { Node // Value returns a Go representation of the value. For scalars, this // will be a string, int64, uint64, float64, or bool. This could also // be an Identifier (e.g. IdentValueNodes). It can also be a composite // literal: // * For array literals, the type returned will be []ValueNode // * For message literals, the type returned will be []*MessageFieldNode Value() interface{} }
ValueNode is an AST node that represents a literal value.
It also includes references (e.g. IdentifierValueNode), which can be used as values in some contexts, such as describing the default value for a field, which can refer to an enum value.
This also allows NoSourceNode to be used in place of a real value node for some usages.
type VisitFunc ¶
VisitFunc is used to examine a node in the AST when walking the tree. It returns true or false as to whether or not the descendants of the given node should be visited. If it returns true, the node's children will be visisted; if false, they will not. When returning true, it can also return a new VisitFunc to use for the children. If it returns (true, nil), then the current function will be re-used when visiting the children.
See also the Visitor type.
type Visitor ¶
type Visitor struct { // VisitFileNode is invoked when visiting a *FileNode in the AST. VisitFileNode func(*FileNode) (bool, *Visitor) // VisitSyntaxNode is invoked when visiting a *SyntaxNode in the AST. VisitSyntaxNode func(*SyntaxNode) (bool, *Visitor) // VisitPackageNode is invoked when visiting a *PackageNode in the AST. VisitPackageNode func(*PackageNode) (bool, *Visitor) // VisitImportNode is invoked when visiting an *ImportNode in the AST. VisitImportNode func(*ImportNode) (bool, *Visitor) // VisitOptionNode is invoked when visiting an *OptionNode in the AST. VisitOptionNode func(*OptionNode) (bool, *Visitor) // VisitOptionNameNode is invoked when visiting an *OptionNameNode in the AST. VisitOptionNameNode func(*OptionNameNode) (bool, *Visitor) // VisitFieldReferenceNode is invoked when visiting a *FieldReferenceNode in the AST. VisitFieldReferenceNode func(*FieldReferenceNode) (bool, *Visitor) // VisitCompactOptionsNode is invoked when visiting a *CompactOptionsNode in the AST. VisitCompactOptionsNode func(*CompactOptionsNode) (bool, *Visitor) // VisitMessageNode is invoked when visiting a *MessageNode in the AST. VisitMessageNode func(*MessageNode) (bool, *Visitor) // VisitExtendNode is invoked when visiting an *ExtendNode in the AST. VisitExtendNode func(*ExtendNode) (bool, *Visitor) // VisitExtensionRangeNode is invoked when visiting an *ExtensionRangeNode in the AST. VisitExtensionRangeNode func(*ExtensionRangeNode) (bool, *Visitor) // VisitReservedNode is invoked when visiting a *ReservedNode in the AST. VisitReservedNode func(*ReservedNode) (bool, *Visitor) // VisitRangeNode is invoked when visiting a *RangeNode in the AST. VisitRangeNode func(*RangeNode) (bool, *Visitor) // VisitFieldNode is invoked when visiting a *FieldNode in the AST. VisitFieldNode func(*FieldNode) (bool, *Visitor) // VisitGroupNode is invoked when visiting a *GroupNode in the AST. VisitGroupNode func(*GroupNode) (bool, *Visitor) // VisitMapFieldNode is invoked when visiting a *MapFieldNode in the AST. VisitMapFieldNode func(*MapFieldNode) (bool, *Visitor) // VisitMapTypeNode is invoked when visiting a *MapTypeNode in the AST. VisitMapTypeNode func(*MapTypeNode) (bool, *Visitor) // VisitOneOfNode is invoked when visiting a *OneOfNode in the AST. VisitOneOfNode func(*OneOfNode) (bool, *Visitor) // VisitEnumNode is invoked when visiting an *EnumNode in the AST. VisitEnumNode func(*EnumNode) (bool, *Visitor) // VisitEnumValueNode is invoked when visiting an *EnumValueNode in the AST. VisitEnumValueNode func(*EnumValueNode) (bool, *Visitor) // VisitServiceNode is invoked when visiting a *ServiceNode in the AST. VisitServiceNode func(*ServiceNode) (bool, *Visitor) // VisitRPCNode is invoked when visiting an *RPCNode in the AST. VisitRPCNode func(*RPCNode) (bool, *Visitor) // VisitRPCTypeNode is invoked when visiting an *RPCTypeNode in the AST. VisitRPCTypeNode func(*RPCTypeNode) (bool, *Visitor) // VisitIdentNode is invoked when visiting an *IdentNode in the AST. VisitIdentNode func(*IdentNode) (bool, *Visitor) // VisitCompoundIdentNode is invoked when visiting a *CompoundIdentNode in the AST. VisitCompoundIdentNode func(*CompoundIdentNode) (bool, *Visitor) // VisitStringLiteralNode is invoked when visiting a *StringLiteralNode in the AST. VisitStringLiteralNode func(*StringLiteralNode) (bool, *Visitor) // VisitCompoundStringLiteralNode is invoked when visiting a *CompoundStringLiteralNode in the AST. VisitCompoundStringLiteralNode func(*CompoundStringLiteralNode) (bool, *Visitor) // VisitUintLiteralNode is invoked when visiting a *UintLiteralNode in the AST. VisitUintLiteralNode func(*UintLiteralNode) (bool, *Visitor) // VisitPositiveUintLiteralNode is invoked when visiting a *PositiveUintLiteralNode in the AST. // // Deprecated: this node type will not actually be present in an AST. VisitPositiveUintLiteralNode func(*PositiveUintLiteralNode) (bool, *Visitor) // VisitNegativeIntLiteralNode is invoked when visiting a *NegativeIntLiteralNode in the AST. VisitNegativeIntLiteralNode func(*NegativeIntLiteralNode) (bool, *Visitor) // VisitFloatLiteralNode is invoked when visiting a *FloatLiteralNode in the AST. VisitFloatLiteralNode func(*FloatLiteralNode) (bool, *Visitor) // VisitSpecialFloatLiteralNode is invoked when visiting a *SpecialFloatLiteralNode in the AST. VisitSpecialFloatLiteralNode func(*SpecialFloatLiteralNode) (bool, *Visitor) // VisitSignedFloatLiteralNode is invoked when visiting a *SignedFloatLiteralNode in the AST. VisitSignedFloatLiteralNode func(*SignedFloatLiteralNode) (bool, *Visitor) // VisitBoolLiteralNode is invoked when visiting a *BoolLiteralNode in the AST. VisitBoolLiteralNode func(*BoolLiteralNode) (bool, *Visitor) // VisitArrayLiteralNode is invoked when visiting an *ArrayLiteralNode in the AST. VisitArrayLiteralNode func(*ArrayLiteralNode) (bool, *Visitor) // VisitMessageLiteralNode is invoked when visiting a *MessageLiteralNode in the AST. VisitMessageLiteralNode func(*MessageLiteralNode) (bool, *Visitor) // VisitMessageFieldNode is invoked when visiting a *MessageFieldNode in the AST. VisitMessageFieldNode func(*MessageFieldNode) (bool, *Visitor) // VisitKeywordNode is invoked when visiting a *KeywordNode in the AST. VisitKeywordNode func(*KeywordNode) (bool, *Visitor) // VisitRuneNode is invoked when visiting a *RuneNode in the AST. VisitRuneNode func(*RuneNode) (bool, *Visitor) // VisitEmptyDeclNode is invoked when visiting a *EmptyDeclNode in the AST. VisitEmptyDeclNode func(*EmptyDeclNode) (bool, *Visitor) // VisitFieldDeclNode is invoked when visiting a FieldDeclNode in the AST. // This function is used when no concrete type function is provided. If // both this and VisitMessageDeclNode are provided, and a node implements // both (such as *GroupNode and *MapFieldNode), this function will be // invoked and not the other. VisitFieldDeclNode func(FieldDeclNode) (bool, *Visitor) // VisitMessageDeclNode is invoked when visiting a MessageDeclNode in the AST. // This function is used when no concrete type function is provided. VisitMessageDeclNode func(MessageDeclNode) (bool, *Visitor) // VisitIdentValueNode is invoked when visiting an IdentValueNode in the AST. // This function is used when no concrete type function is provided. VisitIdentValueNode func(IdentValueNode) (bool, *Visitor) // VisitStringValueNode is invoked when visiting a StringValueNode in the AST. // This function is used when no concrete type function is provided. VisitStringValueNode func(StringValueNode) (bool, *Visitor) // VisitIntValueNode is invoked when visiting an IntValueNode in the AST. // This function is used when no concrete type function is provided. If // both this and VisitFloatValueNode are provided, and a node implements // both (such as *UintLiteralNode), this function will be invoked and // not the other. VisitIntValueNode func(IntValueNode) (bool, *Visitor) // VisitFloatValueNode is invoked when visiting a FloatValueNode in the AST. // This function is used when no concrete type function is provided. VisitFloatValueNode func(FloatValueNode) (bool, *Visitor) // VisitValueNode is invoked when visiting a ValueNode in the AST. This // function is used when no concrete type function is provided and no // more specific ValueNode function is provided that matches the node. VisitValueNode func(ValueNode) (bool, *Visitor) // VisitTerminalNode is invoked when visiting a TerminalNode in the AST. // This function is used when no concrete type function is provided // no more specific interface type function is provided. VisitTerminalNode func(TerminalNode) (bool, *Visitor) // VisitCompositeNode is invoked when visiting a CompositeNode in the AST. // This function is used when no concrete type function is provided // no more specific interface type function is provided. VisitCompositeNode func(CompositeNode) (bool, *Visitor) // VisitNode is invoked when visiting a Node in the AST. This // function is only used when no other more specific function is // provided. VisitNode func(Node) (bool, *Visitor) }
Visitor provides a technique for walking the AST that allows for dynamic dispatch, where a particular function is invoked based on the runtime type of the argument.
It consists of a number of functions, each of which matches a concrete Node type. It also includes functions for sub-interfaces of Node and the Node interface itself, to be used as broader "catch all" functions.
To use a visitor, provide a function for the node types of interest and pass visitor.Visit as the function to a Walk operation. When a node is traversed, the corresponding function field of the visitor is invoked, if not nil. If the function for a node's concrete type is nil/absent but the function for an interface it implements is present, that interface visit function will be used instead. If no matching function is present, the traversal will continue. If a matching function is present, it will be invoked and its response determines how the traversal proceeds.
Every visit function returns (bool, *Visitor). If the bool returned is false, the visited node's descendants are skipped. Otherwise, traversal will continue into the node's children. If the returned visitor is nil, the current visitor will continue to be used. But if a non-nil visitor is returned, it will be used to visit the node's children.