Documentation ¶
Index ¶
- type EditInput
- type IterMode
- type Iterator
- type Language
- type Node
- func (n *Node) Child(idx int) *Node
- func (n *Node) ChildByFieldName(name string) *Node
- func (n *Node) ChildCount() uint32
- func (n *Node) Content(input []byte) string
- func (n *Node) Edit(i EditInput)
- func (n *Node) EndByte() uint32
- func (n *Node) EndPoint() Point
- func (n *Node) Equal(other *Node) bool
- func (n *Node) HasChanges() bool
- func (n *Node) HasError() bool
- func (n *Node) IsMissing() bool
- func (n *Node) IsNamed() bool
- func (n *Node) IsNull() bool
- func (n *Node) NamedChild(idx int) *Node
- func (n *Node) NamedChildCount() uint32
- func (n *Node) NextNamedSibling() *Node
- func (n *Node) NextSibling() *Node
- func (n *Node) Parent() *Node
- func (n *Node) PrevNamedSibling() *Node
- func (n *Node) PrevSibling() *Node
- func (n *Node) StartByte() uint32
- func (n *Node) StartPoint() Point
- func (n *Node) String() string
- func (n *Node) Symbol() Symbol
- func (n *Node) Type() string
- type Parser
- func (p *Parser) Close()
- func (p *Parser) Debug()
- func (p *Parser) OperationLimit() int
- func (p *Parser) Parse(content []byte) *Tree
- func (p *Parser) ParseWithTree(content []byte, t *Tree) *Tree
- func (p *Parser) Reset()
- func (p *Parser) SetIncludedRanges(ranges []Range)
- func (p *Parser) SetLanguage(lang *Language)
- func (p *Parser) SetOperationLimit(limit int)
- type Point
- type Query
- type QueryCapture
- type QueryCursor
- type QueryError
- type QueryErrorType
- type QueryMatch
- type Range
- type Symbol
- type SymbolType
- type Tree
- type TreeCursor
- func (c *TreeCursor) Close()
- func (c *TreeCursor) CurrentFieldName() string
- func (c *TreeCursor) CurrentNode() *Node
- func (c *TreeCursor) GoToFirstChild() bool
- func (c *TreeCursor) GoToFirstChildForByte(b uint32) int64
- func (c *TreeCursor) GoToNextSibling() bool
- func (c *TreeCursor) GoToParent() bool
- func (c *TreeCursor) Reset(n *Node)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator for a tree of nodes
func NewIterator ¶
NewIterator takes a node and mode (DFS/BFS) and returns iterator over children of the node
func NewNamedIterator ¶
NewNamedIterator takes a node and mode (DFS/BFS) and returns iterator over named children of the node
type Language ¶
type Language struct {
// contains filtered or unexported fields
}
Language defines how to parse a particular programming language
func NewLanguage ¶
NewLanguage creates new Language from c pointer
func (*Language) SymbolCount ¶
SymbolCount returns the number of distinct field names in the language.
func (*Language) SymbolName ¶
SymbolName returns a node type string for the given Symbol.
func (*Language) SymbolType ¶
func (l *Language) SymbolType(s Symbol) SymbolType
SymbolType returns named, anonymous, or a hidden type for a Symbol.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a single node in the syntax tree It tracks its start and end positions in the source code, as well as its relation to other nodes like its parent, siblings and children.
func Parse ¶
Parse is a shortcut for parsing bytes of source code, returns root node. This should not be used outside quick prototypes or tests as it prevents closing the created Parser and Tree, it relies strictly on the Finalizer to free those resources.
func (*Node) Child ¶
Child returns the node's child at the given index, where zero represents the first child.
func (*Node) ChildByFieldName ¶
ChildByFieldName returns the node's child with the given field name.
func (*Node) ChildCount ¶
ChildCount returns the node's number of children.
func (*Node) HasChanges ¶
HasChanges checks if a syntax node has been edited.
func (*Node) IsMissing ¶
IsMissing checks if the node is *missing*. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.
func (*Node) IsNamed ¶
IsNamed checks if the node is *named*. Named nodes correspond to named rules in the grammar, whereas *anonymous* nodes correspond to string literals in the grammar.
func (*Node) NamedChild ¶
NamedChild returns the node's *named* child at the given index.
func (*Node) NamedChildCount ¶
NamedChildCount returns the node's number of *named* children.
func (*Node) NextNamedSibling ¶
NextNamedSibling returns the node's next *named* sibling.
func (*Node) NextSibling ¶
NextSibling returns the node's next sibling.
func (*Node) PrevNamedSibling ¶
PrevNamedSibling returns the node's previous *named* sibling.
func (*Node) PrevSibling ¶
PrevSibling returns the node's previous sibling.
func (*Node) StartPoint ¶
StartPoint returns the node's start position in terms of rows and columns.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser produces concrete syntax tree based on source code using Language
func (*Parser) Close ¶
func (p *Parser) Close()
Close releases the resources used by the parser. Once called, the parser shouldn't be used anymore. All trees generated by this Parser should be closed before closing the parser.
func (*Parser) OperationLimit ¶
OperationLimit returns the duration in microseconds that parsing is allowed to take
func (*Parser) ParseWithTree ¶
ParseWithTree produces new Tree from content using old tree
func (*Parser) Reset ¶
func (p *Parser) Reset()
Reset causes the parser to parse from scratch on the next call to parse, instead of resuming so that it sees the changes to the beginning of the source code.
func (*Parser) SetIncludedRanges ¶
SetIncludedRanges sets text ranges of a file
func (*Parser) SetLanguage ¶
SetLanguage assignes Language to a parser
func (*Parser) SetOperationLimit ¶
SetOperationLimit limits the maximum duration in microseconds that parsing should be allowed to take before halting
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query API
type QueryCapture ¶
QueryCapture is a captured node by a query with an index
type QueryCursor ¶
type QueryCursor struct {
// contains filtered or unexported fields
}
QueryCursor carries the state needed for processing the queries.
func (*QueryCursor) Close ¶
func (qc *QueryCursor) Close()
Close releases the resources used by the query cursor. Once called, the cursor shouldn't be used anymore.
func (*QueryCursor) Exec ¶
func (qc *QueryCursor) Exec(q *Query, n *Node)
Exec executes the query on a given syntax node.
func (*QueryCursor) NextMatch ¶
func (qc *QueryCursor) NextMatch() (*QueryMatch, bool)
NextMatch iterates over matches. This function will return (nil, false) when there are no more matches. Otherwise, it will populate the QueryMatch with data about which pattern matched and which nodes were captured.
type QueryError ¶
type QueryError struct { Offset uint32 Type QueryErrorType }
QueryError - if there is an error in the query, then the Offset argument will be set to the byte offset of the error, and the Type argument will be set to a value that indicates the type of error.
func (*QueryError) Error ¶
func (qe *QueryError) Error() string
type QueryErrorType ¶
type QueryErrorType int
QueryErrorType - value that indicates the type of QueryError.
const ( QueryErrorNone QueryErrorType = iota QueryErrorSyntax QueryErrorNodeType QueryErrorField QueryErrorCapture )
type QueryMatch ¶
type QueryMatch struct { ID uint32 PatternIndex uint16 Captures []QueryCapture }
QueryMatch - you can then iterate over the matches.
type SymbolType ¶
type SymbolType int
const ( SymbolTypeRegular SymbolType = iota SymbolTypeAnonymous SymbolTypeAuxiliary )
func (SymbolType) String ¶
func (t SymbolType) String() string
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents the syntax tree of an entire source code file Note: Tree instances are not thread safe; you must copy a tree if you want to use it on multiple threads simultaneously.
func (*Tree) Close ¶
func (t *Tree) Close()
Close releases the resources used by the tree. Once called, the tree shouldn't be used anymore.
type TreeCursor ¶
type TreeCursor struct {
// contains filtered or unexported fields
}
TreeCursor allows you to walk a syntax tree more efficiently than is possible using the `Node` functions. It is a mutable object that is always on a certain syntax node, and can be moved imperatively to different nodes.
func NewTreeCursor ¶
func NewTreeCursor(n *Node) *TreeCursor
NewTreeCursor creates a new tree cursor starting from the given node.
func (*TreeCursor) Close ¶
func (c *TreeCursor) Close()
Close releases the resources used by the tree cursor. Once called, the cursor shouldn't be used anymore.
func (*TreeCursor) CurrentFieldName ¶
func (c *TreeCursor) CurrentFieldName() string
CurrentFieldName gets the field name of the tree cursor's current node.
This returns empty string if the current node doesn't have a field.
func (*TreeCursor) CurrentNode ¶
func (c *TreeCursor) CurrentNode() *Node
CurrentNode of the tree cursor.
func (*TreeCursor) GoToFirstChild ¶
func (c *TreeCursor) GoToFirstChild() bool
GoToFirstChild moves the cursor to the first child of its current node.
This returns `true` if the cursor successfully moved, and returns `false` if there were no children.
func (*TreeCursor) GoToFirstChildForByte ¶
func (c *TreeCursor) GoToFirstChildForByte(b uint32) int64
GoToFirstChildForByte moves the cursor to the first child of its current node that extends beyond the given byte offset.
This returns the index of the child node if one was found, and returns -1 if no such child was found.
func (*TreeCursor) GoToNextSibling ¶
func (c *TreeCursor) GoToNextSibling() bool
GoToNextSibling moves the cursor to the next sibling of its current node.
This returns `true` if the cursor successfully moved, and returns `false` if there was no next sibling node.
func (*TreeCursor) GoToParent ¶
func (c *TreeCursor) GoToParent() bool
GoToParent moves the cursor to the parent of its current node.
This returns `true` if the cursor successfully moved, and returns `false` if there was no parent node (the cursor was already on the root node).
func (*TreeCursor) Reset ¶
func (c *TreeCursor) Reset(n *Node)
Reset re-initializes a tree cursor to start at a different node.