Documentation ¶
Overview ¶
Code generated by test_grammar_generate.sh; DO NOT EDIT.
Index ¶
- Constants
- Variables
- func QueryErrorTypeToString(errorType QueryErrorType) string
- type BaseTree
- type EditInput
- type Input
- type InputEncoding
- 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) FieldNameForChild(idx int) string
- func (n Node) HasChanges() bool
- func (n Node) HasError() bool
- func (n Node) ID() uintptr
- func (n Node) IsError() bool
- func (n Node) IsExtra() 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) NamedDescendantForPointRange(start Point, end Point) *Node
- 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) Range() Range
- 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(oldTree *Tree, content []byte) *Treedeprecated
- func (p *Parser) ParseCtx(ctx context.Context, oldTree *Tree, content []byte) (*Tree, error)
- func (p *Parser) ParseInput(oldTree *Tree, input Input) *Tree
- func (p *Parser) ParseInputCtx(ctx context.Context, oldTree *Tree, input Input) (*Tree, error)
- 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 Quantifier
- type Query
- func (q *Query) CaptureCount() uint32
- func (q *Query) CaptureNameForId(id uint32) string
- func (q *Query) CaptureQuantifierForId(id uint32, captureId uint32) Quantifier
- func (q *Query) Close()
- func (q *Query) PatternCount() uint32
- func (q *Query) PredicatesForPattern(patternIndex uint32) [][]QueryPredicateStep
- func (q *Query) StringCount() uint32
- func (q *Query) StringValueForId(id uint32) string
- type QueryCapture
- type QueryCursor
- func (qc *QueryCursor) Close()
- func (qc *QueryCursor) Exec(q *Query, n *Node)
- func (qc *QueryCursor) FilterPredicates(m *QueryMatch, input []byte) *QueryMatch
- func (qc *QueryCursor) NextCapture() (*QueryMatch, uint32, bool)
- func (qc *QueryCursor) NextMatch() (*QueryMatch, bool)
- func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point)
- type QueryError
- type QueryErrorType
- type QueryMatch
- type QueryPredicateStep
- type QueryPredicateStepType
- type Range
- type ReadFunc
- 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 ¶
const ( QuantifierZero = iota QuantifierZeroOrOne QuantifierZeroOrMore QuantifierOne QuantifierOneOrMore )
Variables ¶
var ( ErrOperationLimit = errors.New("operation limit was hit") ErrNoLanguage = errors.New("cannot parse without language") )
Functions ¶
func QueryErrorTypeToString ¶
func QueryErrorTypeToString(errorType QueryErrorType) string
Types ¶
type BaseTree ¶
type BaseTree struct {
// contains filtered or unexported fields
}
we use cache for nodes on normal tree object it prevent run of SetFinalizer as it introduces cycle we can workaround it using separate object for details see: https://github.com/golang/go/issues/7358#issuecomment-66091558
func (*BaseTree) Close ¶
func (t *BaseTree) Close()
Close should be called to ensure that all the memory used by the tree is freed.
As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer, parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
type Input ¶
type Input struct { Read ReadFunc Encoding InputEncoding }
Input defines parameters for parse method
type InputEncoding ¶
type InputEncoding int
InputEncoding is a encoding of the text to parse
const ( InputEncodingUTF8 InputEncoding = iota InputEncodingUTF16 )
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 (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) FieldNameForChild ¶
FieldNameForChild returns the field name of the child at the given index, or "" if not named.
func (Node) HasChanges ¶
HasChanges checks if a syntax node has been edited.
func (Node) IsError ¶
IsError checks if the node is a syntax error. Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.
func (Node) IsExtra ¶
IsExtra checks if the node is *extra*. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.
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) NamedDescendantForPointRange ¶
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 should be called to ensure that all the memory used by the parse is freed.
As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer, parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
func (*Parser) OperationLimit ¶
OperationLimit returns the duration in microseconds that parsing is allowed to take
func (*Parser) ParseInput ¶
ParseInput produces new Tree by reading from a callback defined in input it is useful if your data is stored in specialized data structure as it will avoid copying the data into []bytes and faster access to edited part of the data
func (*Parser) ParseInputCtx ¶
ParseInputCtx produces new Tree by reading from a callback defined in input it is useful if your data is stored in specialized data structure as it will avoid copying the data into []bytes and faster access to edited part of the data
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 Quantifier ¶
type Quantifier int
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query API
func NewQuery ¶
NewQuery creates a query by specifying a string containing one or more patterns. In case of error returns QueryError.
func (*Query) CaptureCount ¶
func (*Query) CaptureNameForId ¶
func (*Query) CaptureQuantifierForId ¶
func (q *Query) CaptureQuantifierForId(id uint32, captureId uint32) Quantifier
func (*Query) Close ¶
func (q *Query) Close()
Close should be called to ensure that all the memory used by the query is freed.
As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer, parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
func (*Query) PatternCount ¶
func (*Query) PredicatesForPattern ¶
func (q *Query) PredicatesForPattern(patternIndex uint32) [][]QueryPredicateStep
func (*Query) StringCount ¶
func (*Query) StringValueForId ¶
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 should be called to ensure that all the memory used by the query cursor is freed.
As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer, parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
func (*QueryCursor) Exec ¶
func (qc *QueryCursor) Exec(q *Query, n *Node)
Exec executes the query on a given syntax node.
func (*QueryCursor) FilterPredicates ¶
func (qc *QueryCursor) FilterPredicates(m *QueryMatch, input []byte) *QueryMatch
func (*QueryCursor) NextCapture ¶
func (qc *QueryCursor) NextCapture() (*QueryMatch, uint32, bool)
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.
func (*QueryCursor) SetPointRange ¶
func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point)
type QueryError ¶
type QueryError struct { Offset uint32 Type QueryErrorType Message string }
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 QueryErrorStructure QueryErrorLanguage )
type QueryMatch ¶
type QueryMatch struct { ID uint32 PatternIndex uint16 Captures []QueryCapture }
QueryMatch - you can then iterate over the matches.
type QueryPredicateStep ¶
type QueryPredicateStep struct { Type QueryPredicateStepType ValueId uint32 }
type QueryPredicateStepType ¶
type QueryPredicateStepType int
const ( QueryPredicateStepTypeDone QueryPredicateStepType = iota QueryPredicateStepTypeCapture QueryPredicateStepTypeString )
type ReadFunc ¶
ReadFunc is a function to retrieve a chunk of text at a given byte offset and (row, column) position it should return nil to indicate the end of the document
type SymbolType ¶
type SymbolType int
const ( SymbolTypeRegular SymbolType = iota SymbolTypeAnonymous SymbolTypeAuxiliary )
func (SymbolType) String ¶
func (t SymbolType) String() string
type Tree ¶
type Tree struct { *BaseTree // 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.
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 should be called to ensure that all the memory used by the tree cursor is freed.
As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer, parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
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.