ast

package
v0.0.0-...-285cedf Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

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

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

func Print(w io.Writer, node Node) error

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.

func Walk

func Walk(root Node, v VisitFunc)

Walk conducts a walk of the AST rooted at the given root using the given function. It performs a "pre-order traversal", visiting a given AST node before it visits that node's descendants.

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) Children

func (n *ArrayLiteralNode) Children() []Node

func (*ArrayLiteralNode) End

func (n *ArrayLiteralNode) End() *SourcePos

func (*ArrayLiteralNode) LeadingComments

func (n *ArrayLiteralNode) LeadingComments() []Comment

func (*ArrayLiteralNode) Start

func (n *ArrayLiteralNode) Start() *SourcePos

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) Children

func (n *CompactOptionsNode) Children() []Node

func (*CompactOptionsNode) End

func (n *CompactOptionsNode) End() *SourcePos

func (*CompactOptionsNode) GetElements

func (e *CompactOptionsNode) GetElements() []*OptionNode

func (*CompactOptionsNode) LeadingComments

func (n *CompactOptionsNode) LeadingComments() []Comment

func (*CompactOptionsNode) Start

func (n *CompactOptionsNode) Start() *SourcePos

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) Children

func (n *CompoundIdentNode) Children() []Node

func (*CompoundIdentNode) End

func (n *CompoundIdentNode) End() *SourcePos

func (*CompoundIdentNode) LeadingComments

func (n *CompoundIdentNode) LeadingComments() []Comment

func (*CompoundIdentNode) Start

func (n *CompoundIdentNode) Start() *SourcePos

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) Children

func (n *CompoundStringLiteralNode) Children() []Node

func (*CompoundStringLiteralNode) End

func (n *CompoundStringLiteralNode) End() *SourcePos

func (*CompoundStringLiteralNode) LeadingComments

func (n *CompoundStringLiteralNode) LeadingComments() []Comment

func (*CompoundStringLiteralNode) Start

func (n *CompoundStringLiteralNode) Start() *SourcePos

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) Children

func (n *EmptyDeclNode) Children() []Node

func (*EmptyDeclNode) End

func (n *EmptyDeclNode) End() *SourcePos

func (*EmptyDeclNode) LeadingComments

func (n *EmptyDeclNode) LeadingComments() []Comment

func (*EmptyDeclNode) Start

func (n *EmptyDeclNode) Start() *SourcePos

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) Children

func (n *EnumNode) Children() []Node

func (*EnumNode) End

func (n *EnumNode) End() *SourcePos

func (*EnumNode) LeadingComments

func (n *EnumNode) LeadingComments() []Comment

func (*EnumNode) Start

func (n *EnumNode) Start() *SourcePos

func (*EnumNode) TrailingComments

func (n *EnumNode) TrailingComments() []Comment

type EnumValueDeclNode

type EnumValueDeclNode interface {
	Node
	GetName() Node
	GetNumber() Node
}

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) Children

func (n *EnumValueNode) Children() []Node

func (*EnumValueNode) End

func (n *EnumValueNode) End() *SourcePos

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) Start

func (n *EnumValueNode) Start() *SourcePos

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) Children

func (n *ExtendNode) Children() []Node

func (*ExtendNode) End

func (n *ExtendNode) End() *SourcePos

func (*ExtendNode) LeadingComments

func (n *ExtendNode) LeadingComments() []Comment

func (*ExtendNode) Start

func (n *ExtendNode) Start() *SourcePos

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) Children

func (n *ExtensionRangeNode) Children() []Node

func (*ExtensionRangeNode) End

func (n *ExtensionRangeNode) End() *SourcePos

func (*ExtensionRangeNode) LeadingComments

func (n *ExtensionRangeNode) LeadingComments() []Comment

func (*ExtensionRangeNode) Start

func (n *ExtensionRangeNode) Start() *SourcePos

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) Children

func (n *FieldNode) Children() []Node

func (*FieldNode) End

func (n *FieldNode) End() *SourcePos

func (*FieldNode) FieldExtendee

func (n *FieldNode) FieldExtendee() Node

func (*FieldNode) FieldLabel

func (n *FieldNode) FieldLabel() Node

func (*FieldNode) FieldName

func (n *FieldNode) FieldName() Node

func (*FieldNode) FieldTag

func (n *FieldNode) FieldTag() Node

func (*FieldNode) FieldType

func (n *FieldNode) FieldType() Node

func (*FieldNode) GetGroupKeyword

func (n *FieldNode) GetGroupKeyword() Node

func (*FieldNode) GetOptions

func (n *FieldNode) GetOptions() *CompactOptionsNode

func (*FieldNode) LeadingComments

func (n *FieldNode) LeadingComments() []Comment

func (*FieldNode) Start

func (n *FieldNode) Start() *SourcePos

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) Children

func (n *FieldReferenceNode) Children() []Node

func (*FieldReferenceNode) End

func (n *FieldReferenceNode) End() *SourcePos

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) Start

func (n *FieldReferenceNode) Start() *SourcePos

func (*FieldReferenceNode) TrailingComments

func (n *FieldReferenceNode) TrailingComments() []Comment

func (*FieldReferenceNode) Value

func (a *FieldReferenceNode) Value() string

type FileDeclNode

type FileDeclNode interface {
	Node
	GetSyntax() Node
}

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 NewEmptyFileNode(filename string) *FileNode

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) Children

func (n *FileNode) Children() []Node

func (*FileNode) End

func (n *FileNode) End() *SourcePos

func (*FileNode) GetSyntax

func (f *FileNode) GetSyntax() Node

func (*FileNode) LeadingComments

func (n *FileNode) LeadingComments() []Comment

func (*FileNode) Start

func (n *FileNode) Start() *SourcePos

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) End

func (n *FloatLiteralNode) End() *SourcePos

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) RawText

func (n *FloatLiteralNode) RawText() string

func (*FloatLiteralNode) Start

func (n *FloatLiteralNode) Start() *SourcePos

func (*FloatLiteralNode) TrailingComments

func (n *FloatLiteralNode) TrailingComments() []Comment

func (*FloatLiteralNode) Value

func (n *FloatLiteralNode) Value() interface{}

type FloatValueNode

type FloatValueNode interface {
	ValueNode
	AsFloat() float64
}

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) Children

func (n *GroupNode) Children() []Node

func (*GroupNode) End

func (n *GroupNode) End() *SourcePos

func (*GroupNode) FieldExtendee

func (n *GroupNode) FieldExtendee() Node

func (*GroupNode) FieldLabel

func (n *GroupNode) FieldLabel() Node

func (*GroupNode) FieldName

func (n *GroupNode) FieldName() Node

func (*GroupNode) FieldTag

func (n *GroupNode) FieldTag() Node

func (*GroupNode) FieldType

func (n *GroupNode) FieldType() Node

func (*GroupNode) GetGroupKeyword

func (n *GroupNode) GetGroupKeyword() Node

func (*GroupNode) GetOptions

func (n *GroupNode) GetOptions() *CompactOptionsNode

func (*GroupNode) LeadingComments

func (n *GroupNode) LeadingComments() []Comment

func (*GroupNode) MessageName

func (n *GroupNode) MessageName() Node

func (*GroupNode) Start

func (n *GroupNode) Start() *SourcePos

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

func NewIdentNode(val string, info TokenInfo) *IdentNode

NewIdentNode creates a new *IdentNode. The given val is the identifier text.

func (*IdentNode) AsIdentifier

func (n *IdentNode) AsIdentifier() Identifier

func (*IdentNode) End

func (n *IdentNode) End() *SourcePos

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) RawText

func (n *IdentNode) RawText() string

func (*IdentNode) Start

func (n *IdentNode) Start() *SourcePos

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

func (*IdentNode) Value

func (n *IdentNode) Value() interface{}

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) Children

func (n *ImportNode) Children() []Node

func (*ImportNode) End

func (n *ImportNode) End() *SourcePos

func (*ImportNode) LeadingComments

func (n *ImportNode) LeadingComments() []Comment

func (*ImportNode) Start

func (n *ImportNode) Start() *SourcePos

func (*ImportNode) TrailingComments

func (n *ImportNode) TrailingComments() []Comment

type IntValueNode

type IntValueNode interface {
	ValueNode
	AsInt64() (int64, bool)
	AsUint64() (uint64, bool)
}

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) Children

func (n *MapFieldNode) Children() []Node

func (*MapFieldNode) End

func (n *MapFieldNode) End() *SourcePos

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) Start

func (n *MapFieldNode) Start() *SourcePos

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) Children

func (n *MapTypeNode) Children() []Node

func (*MapTypeNode) End

func (n *MapTypeNode) End() *SourcePos

func (*MapTypeNode) LeadingComments

func (n *MapTypeNode) LeadingComments() []Comment

func (*MapTypeNode) Start

func (n *MapTypeNode) Start() *SourcePos

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

type MessageDeclNode interface {
	Node
	MessageName() Node
}

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) Children

func (n *MessageFieldNode) Children() []Node

func (*MessageFieldNode) End

func (n *MessageFieldNode) End() *SourcePos

func (*MessageFieldNode) LeadingComments

func (n *MessageFieldNode) LeadingComments() []Comment

func (*MessageFieldNode) Start

func (n *MessageFieldNode) Start() *SourcePos

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) Children

func (n *MessageLiteralNode) Children() []Node

func (*MessageLiteralNode) End

func (n *MessageLiteralNode) End() *SourcePos

func (*MessageLiteralNode) LeadingComments

func (n *MessageLiteralNode) LeadingComments() []Comment

func (*MessageLiteralNode) Start

func (n *MessageLiteralNode) Start() *SourcePos

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) Children

func (n *MessageNode) Children() []Node

func (*MessageNode) End

func (n *MessageNode) End() *SourcePos

func (*MessageNode) LeadingComments

func (n *MessageNode) LeadingComments() []Comment

func (*MessageNode) MessageName

func (n *MessageNode) MessageName() Node

func (*MessageNode) Start

func (n *MessageNode) Start() *SourcePos

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) Children

func (n *NegativeIntLiteralNode) Children() []Node

func (*NegativeIntLiteralNode) End

func (n *NegativeIntLiteralNode) End() *SourcePos

func (*NegativeIntLiteralNode) LeadingComments

func (n *NegativeIntLiteralNode) LeadingComments() []Comment

func (*NegativeIntLiteralNode) Start

func (n *NegativeIntLiteralNode) Start() *SourcePos

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

type OneOfDeclNode interface {
	Node
	OneOfName() Node
}

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) Children

func (n *OneOfNode) Children() []Node

func (*OneOfNode) End

func (n *OneOfNode) End() *SourcePos

func (*OneOfNode) LeadingComments

func (n *OneOfNode) LeadingComments() []Comment

func (*OneOfNode) OneOfName

func (n *OneOfNode) OneOfName() Node

func (*OneOfNode) Start

func (n *OneOfNode) Start() *SourcePos

func (*OneOfNode) TrailingComments

func (n *OneOfNode) TrailingComments() []Comment

type OptionDeclNode

type OptionDeclNode interface {
	Node
	GetName() Node
	GetValue() ValueNode
}

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) Children

func (n *OptionNameNode) Children() []Node

func (*OptionNameNode) End

func (n *OptionNameNode) End() *SourcePos

func (*OptionNameNode) LeadingComments

func (n *OptionNameNode) LeadingComments() []Comment

func (*OptionNameNode) Start

func (n *OptionNameNode) Start() *SourcePos

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) Children

func (n *OptionNode) Children() []Node

func (*OptionNode) End

func (n *OptionNode) End() *SourcePos

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) Start

func (n *OptionNode) Start() *SourcePos

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) Children

func (n *PackageNode) Children() []Node

func (*PackageNode) End

func (n *PackageNode) End() *SourcePos

func (*PackageNode) LeadingComments

func (n *PackageNode) LeadingComments() []Comment

func (*PackageNode) Start

func (n *PackageNode) Start() *SourcePos

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) Children

func (n *PositiveUintLiteralNode) Children() []Node

func (*PositiveUintLiteralNode) End

func (n *PositiveUintLiteralNode) End() *SourcePos

func (*PositiveUintLiteralNode) LeadingComments

func (n *PositiveUintLiteralNode) LeadingComments() []Comment

func (*PositiveUintLiteralNode) Start

func (n *PositiveUintLiteralNode) Start() *SourcePos

func (*PositiveUintLiteralNode) TrailingComments

func (n *PositiveUintLiteralNode) TrailingComments() []Comment

func (*PositiveUintLiteralNode) Value

func (n *PositiveUintLiteralNode) Value() interface{}

type RPCDeclNode

type RPCDeclNode interface {
	Node
	GetInputType() Node
	GetOutputType() Node
}

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) Children

func (n *RPCNode) Children() []Node

func (*RPCNode) End

func (n *RPCNode) End() *SourcePos

func (*RPCNode) GetInputType

func (n *RPCNode) GetInputType() Node

func (*RPCNode) GetOutputType

func (n *RPCNode) GetOutputType() Node

func (*RPCNode) LeadingComments

func (n *RPCNode) LeadingComments() []Comment

func (*RPCNode) Start

func (n *RPCNode) Start() *SourcePos

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) Children

func (n *RPCTypeNode) Children() []Node

func (*RPCTypeNode) End

func (n *RPCTypeNode) End() *SourcePos

func (*RPCTypeNode) LeadingComments

func (n *RPCTypeNode) LeadingComments() []Comment

func (*RPCTypeNode) Start

func (n *RPCTypeNode) Start() *SourcePos

func (*RPCTypeNode) TrailingComments

func (n *RPCTypeNode) TrailingComments() []Comment

type RangeDeclNode

type RangeDeclNode interface {
	Node
	RangeStart() Node
	RangeEnd() Node
}

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) Children

func (n *RangeNode) Children() []Node

func (*RangeNode) End

func (n *RangeNode) End() *SourcePos

func (*RangeNode) EndValue

func (n *RangeNode) EndValue() interface{}

func (*RangeNode) EndValueAsInt32

func (n *RangeNode) EndValueAsInt32(min, max int32) (int32, bool)

func (*RangeNode) LeadingComments

func (n *RangeNode) LeadingComments() []Comment

func (*RangeNode) RangeEnd

func (n *RangeNode) RangeEnd() Node

func (*RangeNode) RangeStart

func (n *RangeNode) RangeStart() Node

func (*RangeNode) Start

func (n *RangeNode) Start() *SourcePos

func (*RangeNode) StartValue

func (n *RangeNode) StartValue() interface{}

func (*RangeNode) StartValueAsInt32

func (n *RangeNode) StartValueAsInt32(min, max int32) (int32, bool)

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) Children

func (n *ReservedNode) Children() []Node

func (*ReservedNode) End

func (n *ReservedNode) End() *SourcePos

func (*ReservedNode) LeadingComments

func (n *ReservedNode) LeadingComments() []Comment

func (*ReservedNode) Start

func (n *ReservedNode) Start() *SourcePos

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

func NewRuneNode(r rune, info TokenInfo) *RuneNode

NewRuneNode creates a new *RuneNode with the given properties.

func (*RuneNode) End

func (n *RuneNode) End() *SourcePos

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) RawText

func (n *RuneNode) RawText() string

func (*RuneNode) Start

func (n *RuneNode) Start() *SourcePos

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) Children

func (n *ServiceNode) Children() []Node

func (*ServiceNode) End

func (n *ServiceNode) End() *SourcePos

func (*ServiceNode) LeadingComments

func (n *ServiceNode) LeadingComments() []Comment

func (*ServiceNode) Start

func (n *ServiceNode) Start() *SourcePos

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) Children

func (n *SignedFloatLiteralNode) Children() []Node

func (*SignedFloatLiteralNode) End

func (n *SignedFloatLiteralNode) End() *SourcePos

func (*SignedFloatLiteralNode) LeadingComments

func (n *SignedFloatLiteralNode) LeadingComments() []Comment

func (*SignedFloatLiteralNode) Start

func (n *SignedFloatLiteralNode) Start() *SourcePos

func (*SignedFloatLiteralNode) TrailingComments

func (n *SignedFloatLiteralNode) TrailingComments() []Comment

func (*SignedFloatLiteralNode) Value

func (n *SignedFloatLiteralNode) Value() interface{}

type SourcePos

type SourcePos = ast.SourcePos

SourcePos identifies a location in a proto source file.

func UnknownPos

func UnknownPos(filename string) *SourcePos

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) End

func (n *StringLiteralNode) End() *SourcePos

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) RawText

func (n *StringLiteralNode) RawText() string

func (*StringLiteralNode) Start

func (n *StringLiteralNode) Start() *SourcePos

func (*StringLiteralNode) TrailingComments

func (n *StringLiteralNode) TrailingComments() []Comment

func (*StringLiteralNode) Value

func (n *StringLiteralNode) Value() interface{}

type StringValueNode

type StringValueNode interface {
	ValueNode
	AsString() string
}

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) Children

func (n *SyntaxNode) Children() []Node

func (*SyntaxNode) End

func (n *SyntaxNode) End() *SourcePos

func (*SyntaxNode) LeadingComments

func (n *SyntaxNode) LeadingComments() []Comment

func (*SyntaxNode) Start

func (n *SyntaxNode) Start() *SourcePos

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) End

func (n *UintLiteralNode) End() *SourcePos

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) RawText

func (n *UintLiteralNode) RawText() string

func (*UintLiteralNode) Start

func (n *UintLiteralNode) Start() *SourcePos

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

type VisitFunc func(Node) (bool, 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.

func (*Visitor) Visit

func (v *Visitor) Visit(n Node) (bool, VisitFunc)

Visit provides the Visitor's implementation of VisitFunc, to be used with Walk operations.

Jump to

Keyboard shortcuts

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