Documentation ¶
Overview ¶
Package ast provides data structure representing textproto syntax tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByFieldName ¶
ByFieldName is a NodeLess function that orders nodes by their field name.
func ByFieldValue ¶
ByFieldValue is a NodeLess function that orders adjacent scalar nodes with the same name by their scalar value.
Types ¶
type Node ¶
type Node struct { // Start describes the start position of the node. // For nodes that span entire lines, this is the first character // of the first line attributed to the node; possible a whitespace if the node is indented. // For nodes that are members of one-line message literals, // this is the first non-whitespace character encountered. Start Position // Lines of comments appearing before the field. // Each non-empty line starts with a # and does not contain the trailing newline. PreComments []string // Name of proto field (eg 'presubmit'). Will be an empty string for comment-only // nodes and unqualified messages, e.g. // { name: "first_msg" } // { name: "second_msg" } Name string // Values, for nodes that don't have children. Values []*Value // Children for nodes that have children. Children []*Node // Whether or not this node was deleted by edits. Deleted bool // Should the colon after the field name be omitted? // (e.g. "presubmit: {" vs "presubmit {") SkipColon bool // Whether or not all children are in the same line. // (eg "base { id: "id" }") ChildrenSameLine bool // Comment in the same line as the "}". ClosingBraceComment string // End holds the position suitable for inserting new items. // For multi-line nodes, this is the first character on the line with the closing brace. // For single-line nodes, this is the first character after the last item (usually a space). // For non-message nodes, this is Position zero value. End Position // Keep values in list (e.g "list: [1, 2]"). ValuesAsList bool // Keep children in list (e.g "list: [ { value: 1 }, { value: 2 } ]"). ChildrenAsList bool // Lines of comments appearing after last value inside list. // Each non-empty line starts with a # and does not contain the trailing newline. // e.g // field: [ // value // # Comment // ] PostValuesComments []string // Whether the braces used for the children of this node are curly braces or angle brackets. IsAngleBracket bool // If this is not empty, it means that formatting was disabled for this node and it contains the // raw, unformatted node string. Raw string // Used when we want to break between the field name and values when a // single-line node exceeds the requested wrap column. PutSingleValueOnNextLine bool }
Node represents a field with a value in a proto message, or a comment unattached to a field.
func GetFromPath ¶
GetFromPath returns all nodes with a given string path in the parse tree. See ast_test.go for examples.
func StringNode ¶
StringNode is a helper for constructing simple string nodes.
func (*Node) Fix ¶
func (n *Node) Fix()
Fix fixes inconsistencies that may arise after manipulation.
For example if a node is ChildrenSameLine but has non-inline children, or children with comments ChildrenSameLine will be set to false.
func (*Node) IsBlankLine ¶
IsBlankLine returns true if this is a blank line node.
func (*Node) IsCommentOnly ¶
IsCommentOnly returns true if this is a comment-only node. Even a node that only contains a blank line is considered a comment-only node in the sense that it has no proto content.
type NodeLess ¶
NodeLess is a sorting function that compares two *Nodes, possibly using the parent Node for context, returning whether a is less than b.
func ByFieldSubfield ¶
ByFieldSubfield returns a NodeLess function that orders adjacent message nodes with the given field name by the given subfield name value. If no field name is provided, it compares the subfields of any adjacent nodes with matching names.
func ChainNodeLess ¶
ChainNodeLess combines two NodeLess functions that returns the first comparison if values are not equal, else returns the second.
type Position ¶
Position describes a position of a token in the input. Both byte-based and line/column-based positions are maintained because different downstream consumers need different formats and we don't want to keep the entire input in memory to be able to convert between the two. Fields Byte, Line and Column should be interpreted as ByteRange.start_byte, TextRange.start_line, and TextRange.start_column of devtools.api.Range proto.
type Value ¶
type Value struct { // Lines of comments appearing before the value (for multi-line strings). // Each non-empty line starts with a # and does not contain the trailing newline. PreComments []string // Node value (eg 'ERROR'). Value string // Comment in the same line as the value. InlineComment string }
Value represents a field value in a proto message.