### Generate godocs.io Badge (Markdown) Source: https://godocs.io/github.com/smacker/go-tree-sitter/_examples_platform=darwin%2Famd64&view=tools This snippet demonstrates how to create a Markdown-formatted badge that links to the godocs.io documentation for the go-tree-sitter examples. It's useful for README files and requires no external dependencies. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/_examples?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/_examples) ``` -------------------------------- ### Generate godocs.io Badge (HTML) Source: https://godocs.io/github.com/smacker/go-tree-sitter/_examples_platform=darwin%2Famd64&view=tools This snippet shows how to embed a badge linking to the godocs.io documentation for the go-tree-sitter examples using HTML. It requires no external dependencies and generates an image status link. ```html Go Documentation ``` -------------------------------- ### Add godocs.io Badge (HTML) Source: https://godocs.io/github.com/smacker/go-tree-sitter/_examples/predicates_platform=darwin%2Famd64&view=tools This HTML snippet allows you to embed a badge linking to the godocs.io documentation for the go-tree-sitter predicates examples. It uses an image source that dynamically displays the documentation status. ```html Go Documentation ``` -------------------------------- ### Add godocs.io Badge (Markdown) Source: https://godocs.io/github.com/smacker/go-tree-sitter/_examples/predicates_platform=darwin%2Famd64&view=tools This Markdown snippet enables you to include a badge in your README file that links to the godocs.io documentation for the go-tree-sitter predicates examples. The badge visually represents the documentation status. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/_examples/predicates?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/_examples/predicates) ``` -------------------------------- ### Query API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 Documentation for creating and managing queries, including getting capture counts, names, and closing queries. ```APIDOC ## Query API ### NewQuery **Description:** Creates a query by specifying a string containing one or more patterns. In case of error, returns `QueryError`. ### Method POST ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/NewQuery` ### Parameters #### Request Body - `pattern` ([]byte) - Required - The query pattern string. - `lang` (*Language) - Required - The language for which the query is intended. ### Request Example ```json { "pattern": "(function_declaration name: (identifier))", "language": "" } ``` ### Response #### Success Response (200) - `*Query` (Query) - A pointer to the newly created query. - `error` (error) - An error if the query creation fails. #### Response Example ```json { "query": "", "error": null } ``` ## Query CaptureCount ### Description Returns the number of captures in the query. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/CaptureCount` ### Parameters None ### Request Example ```json { "description": "Example request for CaptureCount (illustrative)" } ``` ### Response #### Success Response (200) - `uint32` - The number of captures. ## Query CaptureNameForId ### Description Returns the name of a capture for a given ID. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/CaptureNameForId` ### Parameters #### Query Parameters - `id` (uint32) - Required - The capture ID. ### Request Example ```json { "description": "Example request for CaptureNameForId (illustrative)" } ``` ### Response #### Success Response (200) - `string` - The capture name. ## Query CaptureQuantifierForId ### Description Returns the quantifier for a given capture ID and query pattern index. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/CaptureQuantifierForId` ### Parameters #### Query Parameters - `id` (uint32) - Required - The capture ID. - `captureId` (uint32) - Required - The index of the pattern. ### Request Example ```json { "description": "Example request for CaptureQuantifierForId (illustrative)" } ``` ### Response #### Success Response (200) - `Quantifier` - The quantifier for the capture. ## Query Close ### Description Closes the query, freeing associated memory. This is typically handled by Go's garbage collector via `runtime.SetFinalizer`. ### Method DELETE ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/Close` ### Parameters None ### Request Example ```json { "description": "Example request for Close (illustrative)" } ``` ### Response #### Success Response (200) None ## Query PatternCount ### Description Returns the number of patterns in the query. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/PatternCount` ### Parameters None ### Request Example ```json { "description": "Example request for PatternCount (illustrative)" } ``` ### Response #### Success Response (200) - `uint32` - The number of patterns. ## Query PredicatesForPattern ### Description Returns the predicates for a given pattern index. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/PredicatesForPattern` ### Parameters #### Query Parameters - `patternIndex` (uint32) - Required - The index of the pattern. ### Request Example ```json { "description": "Example request for PredicatesForPattern (illustrative)" } ``` ### Response #### Success Response (200) - `[][]QueryPredicateStep` - A list of predicate steps. ## Query StringCount ### Description Returns the number of strings in the query. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/StringCount` ### Parameters None ### Request Example ```json { "description": "Example request for StringCount (illustrative)" } ``` ### Response #### Success Response (200) - `uint32` - The number of strings. ## Query StringValueForId ### Description Returns the string value for a given ID. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Query/StringValueForId` ### Parameters #### Query Parameters - `id` (uint32) - Required - The string ID. ### Request Example ```json { "description": "Example request for StringValueForId (illustrative)" } ``` ### Response #### Success Response (200) - `string` - The string value. ``` -------------------------------- ### Go: Node StartPoint - Get Node Start Row and Column Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Returns the starting position of the node in terms of rows and columns (points) within the source code. This provides a human-readable location. ```go func (n Node) StartPoint() Point ``` -------------------------------- ### Go: Node StartByte - Get Node Start Byte Position Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Returns the starting byte offset of the node within the source code. This is a low-level indicator of the node's position. ```go func (n Node) StartByte() uint32 ``` -------------------------------- ### Go: NewParser - Create New Parser Instance Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Factory function to create and return a new instance of the Parser. This is the starting point for any parsing operations. ```go func NewParser() *Parser ``` -------------------------------- ### Get the Node's Start Point (Row, Column) in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the starting position of the node as a Point (row, column). This is crucial for reporting errors or highlighting code. ```go func (n Node) StartPoint() Point ``` -------------------------------- ### Add godocs.io badge (Markdown) Source: https://godocs.io/github.com/smacker/go-tree-sitter/protobuf_platform=darwin%2Famd64&view=tools This Markdown snippet allows you to include a badge in your README file that links to the godocs.io documentation for the go-tree-sitter/protobuf package. The badge indicates the documentation status. It requires no additional setup. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/protobuf?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/protobuf) ``` -------------------------------- ### Go Node Methods: Get Node Information and Relationships Source: https://godocs.io/github.com/smacker/go-tree-sitter/index This set of Go functions retrieves specific information about a syntax node, including its parent, field name for a child, byte range, start position, and symbol/type representation. Useful for detailed analysis and debugging. ```Go func (Node) FieldNameForChild(idx int) string FieldNameForChild returns the field name of the child at the given index, or "" if not named. ``` ```Go func (n Node) ID() uintptr ``` ```Go func (n Node) Parent() *Node Parent returns the node's immediate parent. ``` ```Go func (n Node) Range() Range ``` ```Go func (n Node) StartByte() uint32 StartByte returns the node's start byte. ``` ```Go func (n Node) StartPoint() Point StartPoint returns the node's start position in terms of rows and columns. ``` ```Go func (n Node) String() string String returns an S-expression representing the node as a string. ``` ```Go func (n Node) Symbol() Symbol Symbol returns the node's type as a Symbol. ``` ```Go func (n Node) Type() string Type returns the node's type as a string. ``` -------------------------------- ### Go Node StartPoint Method Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=js%2Fwasm Returns the starting position of the node as row and column. This method, part of the Node type, provides human-readable location information. ```go func (n Node) StartPoint() Point { // Implementation details would be here } ``` -------------------------------- ### Go Parser Initialization and Configuration Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 This snippet covers the initialization and basic configuration methods for the Parser type in the go-tree-sitter library. It includes functions for creating a new parser instance and retrieving its operation limit. These are fundamental steps for setting up a parser before performing any code analysis. ```Go type Parser struct { // contains filtered or unexported fields } func NewParser() *Parser func (p *Parser) Close() func (p *Parser) Debug() func (p *Parser) OperationLimit() int ``` -------------------------------- ### Get the Node's Start Byte Offset in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the starting byte offset of the node within the original source code. This is useful for pinpointing the node's location. ```go func (n Node) StartByte() uint32 ``` -------------------------------- ### Get SQL Language for Tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/sql_platform=js%2Fwasm Retrieves the tree-sitter Language object for SQL. This is essential for initializing the parser to handle SQL syntax. ```go func GetLanguage() *sitter.Language { // Implementation to return the SQL language object } ``` -------------------------------- ### Get Node Range in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the byte range (start and end offsets) of the node within the source code. This is equivalent to `StartByte()` and `EndByte()`. ```go func (n Node) Range() Range ``` -------------------------------- ### Go: Node Range - Get Node Byte Range Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Returns the byte range (start and end positions) of the node within the source code. This is useful for locating the node's exact span in the original text. ```go func (n Node) Range() Range ``` -------------------------------- ### Go Node StartByte Method Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=js%2Fwasm Returns the starting byte offset of the node in the source code. This method is part of the Node type and is useful for precise text manipulation. ```go func (n Node) StartByte() uint32 { // Implementation details would be here } ``` -------------------------------- ### Go Tree-sitter Parser Initialization and Settings Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Provides functions to initialize and configure the tree-sitter parser. Includes methods for parsing input with context, resetting the parser, setting included text ranges, assigning a language, and limiting parsing operation duration. ```go 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) ``` -------------------------------- ### Go: Parser Initialization and Control Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=darwin%2Famd64 This Go code demonstrates how to create, close, and control the behavior of a Parser. NewParser() initializes a parser, Close() frees resources, and OperationLimit() sets a time constraint for parsing operations. ```go type Parser struct { // contains filtered or unexported fields } func NewParser() *Parser func (p *Parser) Close() func (p *Parser) Debug() func (p *Parser) OperationLimit() int ``` -------------------------------- ### Add HTML Badge for go-tree-sitter/sql Documentation Source: https://godocs.io/github.com/smacker/go-tree-sitter/sql_platform=darwin%2Famd64&view=tools This HTML snippet allows you to embed a badge on your project website or README file that links directly to the godocs.io documentation page for the github.com/smacker/go-tree-sitter/sql package. It displays the documentation status. ```html Go Documentation ``` -------------------------------- ### Go Range Type Definition Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=darwin%2Famd64 Defines the `Range` struct for representing a span of text within a document. It includes start and end points (character-based) and start and end byte offsets, useful for locating specific sections of code. ```go type Range struct { StartPoint Point EndPoint Point StartByte uint32 EndByte uint32 } ``` -------------------------------- ### Parser Methods Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Details on creating and using the Parser for generating syntax trees. ```APIDOC ## Parser Methods ### Description Methods for creating and configuring a `Parser` to generate concrete syntax trees from source code. ### NewParser Creates a new `Parser` instance. * **Method**: N/A (constructor) * **Endpoint**: N/A ### Close Closes the parser and frees associated memory. This is typically handled by the Go garbage collector via `runtime.SetFinalizer`, so manual calls are often unnecessary. * **Method**: `Close` * **Endpoint**: N/A (method on `*Parser`) ### Debug Enables debug output to stderr. * **Method**: `Debug` * **Endpoint**: N/A (method on `*Parser`) ### OperationLimit Returns the duration in microseconds that parsing is allowed to take. * **Method**: `OperationLimit` * **Endpoint**: N/A (method on `*Parser`) ### Parse Produces a new `Tree` from content using an old tree. Deprecated: use `ParseCtx` instead. * **Method**: `Parse` * **Endpoint**: N/A (method on `*Parser`) * **Parameters**: * **`oldTree`** (*Tree) - The previous tree to reuse. * **`content`** ([]byte) - The source code content to parse. ### ParseCtx Produces a new `Tree` from content using an old tree with context support. * **Method**: `ParseCtx` * **Endpoint**: N/A (method on `*Parser`) * **Parameters**: * **`ctx`** (context.Context) - The context for the operation. * **`oldTree`** (*Tree) - The previous tree to reuse. * **`content`** ([]byte) - The source code content to parse. * **Returns**: * **(*Tree, error)** - The new tree and a potential error. ### ParseInput Produces a new `Tree` by reading from a callback defined in `input`. This is useful if your data is stored in a specialized data structure, as it avoids copying the data into `[]byte` and allows for faster access to edited parts of the data. * **Method**: `ParseInput` * **Endpoint**: N/A (method on `*Parser`) * **Parameters**: * **`oldTree`** (*Tree) - The previous tree to reuse. * **`input`** (Input) - The input source, likely an interface with methods to read data. ``` -------------------------------- ### Parser API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 Documentation for the Parser methods, including parsing input, resetting, setting included ranges, language, and operation limits. ```APIDOC ## Parser API ### ParseInputCtx **Description:** Produces a new Tree by reading from a callback defined in input. It's useful if your data is stored in a specialized data structure as it will avoid copying the data into `[]byte` and allows faster access to edited parts of the data. ### Method GET ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Parser/ParseInputCtx` ### Parameters #### Path Parameters - `ctx` (context.Context) - Required - The context for the operation. - `oldTree` (*Tree) - Required - The previous tree to be updated. - `input` (Input) - Required - The input source for parsing. #### Request Body None ### Request Example ```json { "description": "Example request for ParseInputCtx (illustrative)" } ``` ### Response #### Success Response (200) - `*Tree` (Tree) - The newly generated syntax tree. - `error` (error) - An error if parsing fails. #### Response Example ```json { "tree": "", "error": null } ``` ## Parser Reset ### Description 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. ### Method POST ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Parser/Reset` ### Parameters None ### Request Example ```json { "description": "Example request for Reset (illustrative)" } ``` ### Response #### Success Response (200) None ## Parser SetIncludedRanges ### Description Sets text ranges of a file. ### Method POST ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Parser/SetIncludedRanges` ### Parameters #### Request Body - `ranges` ([]Range) - Required - The ranges to include. ### Request Example ```json { "ranges": [ { "start_byte": 0, "start_point": {"row": 0, "column": 0}, "end_byte": 100, "end_point": {"row": 5, "column": 0} } ] } ``` ### Response #### Success Response (200) None ## Parser SetLanguage ### Description Assigns a Language to a parser. ### Method POST ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Parser/SetLanguage` ### Parameters #### Request Body - `lang` (*Language) - Required - The language to assign. ### Request Example ```json { "language": "" } ``` ### Response #### Success Response (200) None ## Parser SetOperationLimit ### Description Limits the maximum duration in microseconds that parsing should be allowed to take before halting. ### Method POST ### Endpoint `/websites/godocs_io_github_com_smacker_go-tree-sitter/Parser/SetOperationLimit` ### Parameters #### Request Body - `limit` (int) - Required - The maximum duration in microseconds. ### Request Example ```json { "limit": 1000000 } ``` ### Response #### Success Response (200) None ``` -------------------------------- ### Go Parser Methods: Initialization and Configuration Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Functions for creating, closing, and configuring the `Parser` in Go. `NewParser` initializes a parser, `Close` frees associated memory, and `OperationLimit` sets a time limit for parsing operations. ```Go func NewParser() *Parser NewParser creates new Parser ``` ```Go 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. ``` ```Go func (p *Parser) Debug() Debug enables debug output to stderr ``` ```Go func (p *Parser) OperationLimit() int OperationLimit returns the duration in microseconds that parsing is allowed to take ``` -------------------------------- ### Go: Get Predicates for Pattern Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Retrieves the predicate steps associated with a specific pattern index in the query. Predicates allow for conditional matching based on node properties. ```go func (q *Query) PredicatesForPattern(patternIndex uint32) [][]QueryPredicateStep ``` -------------------------------- ### Get Protobuf Language Definition (Go) Source: https://godocs.io/github.com/smacker/go-tree-sitter/protobuf_platform=js%2Fwasm Retrieves the language definition for Protobuf used by the go-tree-sitter library. This is essential for parsing and interacting with Protobuf code structures. ```Go func GetLanguage() *sitter.Language { // Implementation details would be here if provided return nil // Placeholder } ``` -------------------------------- ### Go: QueryCursor SetPointRange Method Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=darwin%2Famd64 The SetPointRange method sets the start and end points for the search range of the query cursor. This allows limiting the query execution to a specific region within the syntax tree. It takes two Point objects representing the start and end points. ```Go func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point) ``` -------------------------------- ### Query API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=js%2Fwasm This section details the methods for creating and executing queries against a syntax tree. ```APIDOC ## Query Methods ### `NewQuery(pattern []byte, lang *Language) (*Query, error)` * **Description**: Creates a new `Query` from a byte slice of query patterns for the given `Language`. * **Method**: `POST` * **Endpoint**: N/A (Constructor) * **Parameters**: * **Path Parameters**: None * **Query Parameters**: None * **Request Body**: Not applicable directly, but `pattern` is the query definition and `lang` is the `Language` object. * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `(*Query, nil)` - The created `Query` object and no error. * **Error Response**: `(nil, error)` - If the query is invalid or cannot be compiled. * **Response Example**: Not applicable. ### `Close()` * **Description**: Releases resources associated with the `Query`. * **Method**: `DELETE` (conceptually, as it cleans up resources) * **Endpoint**: N/A ### `CaptureCount() uint32` * **Description**: Returns the number of captures defined in the query. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: None * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `uint32` - The number of captures. * **Response Example**: Not applicable. ### `PatternCount() uint32` * **Description**: Returns the number of patterns in the query. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: None * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `uint32` - The number of patterns. * **Response Example**: Not applicable. ### `StringCount() uint32` * **Description**: Returns the number of string literals used in the query. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: None * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `uint32` - The number of string literals. * **Response Example**: Not applicable. ### `CaptureNameForId(id uint32) string` * **Description**: Returns the name of the capture at the given ID. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: * **Path Parameters**: None * **Query Parameters**: None * **Request Body**: Not applicable. * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `string` - The capture name. * **Response Example**: Not applicable. ### `StringValueForId(id uint32) string` * **Description**: Returns the string value associated with a string literal at the given ID. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: * **Path Parameters**: None * **Query Parameters**: None * **Request Body**: Not applicable. * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `string` - The string literal value. * **Response Example**: Not applicable. ### `CaptureQuantifierForId(id uint32, captureId uint32) Quantifier` * **Description**: Returns the quantifier associated with a capture within a specific pattern. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: * **Path Parameters**: None * **Query Parameters**: None * **Request Body**: Not applicable. * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `Quantifier` - The quantifier for the capture. * **Response Example**: Not applicable. ### `PredicatesForPattern(patternIndex uint32) [][]QueryPredicateStep` * **Description**: Retrieves the predicate steps associated with a given pattern index. * **Method**: `GET` * **Endpoint**: N/A * **Parameters**: * **Path Parameters**: None * **Query Parameters**: None * **Request Body**: Not applicable. * **Request Example**: Not applicable. * **Response**: * **Success Response (200)**: `[][]QueryPredicateStep` - A slice of slices, where each inner slice represents a sequence of predicate steps. * **Response Example**: Not applicable. ``` -------------------------------- ### Add HTML Badge for go-tree-sitter/dockerfile Documentation Source: https://godocs.io/github.com/smacker/go-tree-sitter/dockerfile_platform=darwin%2Famd64&view=tools This HTML snippet allows you to embed a badge linking to the godocs.io documentation for the go-tree-sitter/dockerfile package. Clicking the badge will direct users to the official documentation page. No specific dependencies are required to use this snippet, only an HTML-compatible environment. ```html Go Documentation ``` -------------------------------- ### Get Go Tree-sitter Markdown Language Source: https://godocs.io/github.com/smacker/go-tree-sitter/markdown/tree-sitter-markdown-inline Retrieves the tree-sitter Language object for Markdown. This is used to initialize the parser for Markdown syntax. ```go func GetLanguage() *sitter.Language { return tree_sitter_markdown_inline.GetLanguage() } ``` -------------------------------- ### Add godocs.io badge to README (Markdown) Source: https://godocs.io/github.com/smacker/go-tree-sitter/c_platform=darwin%2Famd64&view=tools This snippet enables you to include a link to the godocs.io documentation for the 'c' package within your project's README file. It utilizes Markdown syntax for an image link, showing the documentation status. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/c?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/c) ``` -------------------------------- ### Navigate Nodes in a Tree-sitter Tree in Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Provides examples of using `TreeCursor` and `Node` methods to navigate and inspect the syntax tree. This includes moving between parent, children, and siblings, as well as accessing node properties like type, range, and content. ```Go import ( "fmt" "github.com/smacker/go-tree-sitter" ) func NavigateTree(rootNode *sitter.Node) { // Using Node methods fmt.Printf("Root node type: %s\n", rootNode.Type()) childCount := rootNode.ChildCount() fmt.Printf("Root has %d children\n", childCount) if childCount > 0 { firstNode := rootNode.Child(0) fmt.Printf("First child type: %s\n", firstNode.Type()) } // Using TreeCursor for more structured traversal cursor := sitter.NewTreeCursor(rootNode) defer cursor.Close() fmt.Println("Traversing with TreeCursor:") cursor.GoToFirstChild() fmt.Printf("Current node: %s\n", cursor.CurrentNode().Type()) cursor.GoToFirstChild() fmt.Printf("First child's first child: %s\n", cursor.CurrentNode().Type()) cursor.GoToParent() cursor.GoToNextSibling() fmt.Printf("After moving to next sibling: %s\n", cursor.CurrentNode().Type()) } ``` -------------------------------- ### Markdown Badge for go-tree-sitter/yaml Documentation Source: https://godocs.io/github.com/smacker/go-tree-sitter/yaml_platform=darwin%2Famd64&view=tools This Markdown snippet enables the integration of a status badge for the github.com/smacker/go-tree-sitter/yaml package's godocs.io documentation into your project's README file. It creates a clickable image that links to the documentation. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/yaml?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/yaml) ``` -------------------------------- ### Get Node String Representation - Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=js%2Fwasm Returns a string representation of the node. This is often the source code snippet that the node represents. ```go func (n Node) String() string ``` -------------------------------- ### Get Groovy Language Instance for Tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/groovy_platform=windows%2Famd64 This function returns a pointer to the Tree-sitter Language object for Groovy. It is essential for initializing the parser for Groovy files. ```go import "github.com/smacker/go-tree-sitter/groovy" func GetLanguage() *sitter.Language { // Implementation details would be here, returning the Groovy language object panic("implement me") // Placeholder for actual implementation } ``` -------------------------------- ### Handle Query Execution with go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 Manages the execution of queries against a syntax tree. It provides methods to initialize a query cursor, execute a query on a node, and retrieve capture information from matches. ```go func NewQueryCursor() *QueryCursor func (qc *QueryCursor) Exec(q *Query, n *Node) func (qc *QueryCursor) NextCapture() (*QueryMatch, uint32, bool) func (qc *QueryCursor) NextMatch() (*QueryMatch, bool) func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point) ``` -------------------------------- ### Get Node ID in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns a unique identifier for the node. This ID can be used for comparing nodes or for internal tracking. ```go func (n Node) ID() uintptr ``` -------------------------------- ### Node Methods API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 This section details the various methods available for interacting with a syntax node. ```APIDOC ## Node Methods API ### Description This section details the various methods available for interacting with a syntax node. ### Methods - **FieldNameForChild**(idx int) string - **HasChanges**() bool - **HasError**() bool - **ID**() uintptr - **IsError**() bool - **IsExtra**() bool - **IsMissing**() bool - **IsNamed**() bool - **IsNull**() bool - **NamedChild**(idx int) *Node - **NamedChildCount**() uint32 - **NamedDescendantForPointRange**(start Point, end Point) *Node - **NextNamedSibling**() *Node - **NextSibling**() *Node - **Parent**() *Node - **PrevNamedSibling**() *Node - **PrevSibling**() *Node - **Range**() Range - **StartByte**() uint32 - **StartPoint**() Point - **String**() string - **Symbol**() Symbol - **Type**() string ``` -------------------------------- ### Get Node Type in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the type of the node as a string. The type corresponds to the grammar rule that produced this node. ```go func (n Node) Type() string ``` -------------------------------- ### Query Tree-sitter Syntax Tree in Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Demonstrates how to create a `Query` from a pattern and language, then use a `QueryCursor` to execute the query against a syntax tree node. This allows for efficient searching and matching of patterns within the code structure. ```Go import ( "github.com/smacker/go-tree-sitter" ) func QuerySyntaxTree(lang *sitter.Language, rootNode *sitter.Node, queryPattern []byte) error { query, err := sitter.NewQuery(queryPattern, lang) if err != nil { return err } defer query.Close() qc := sitter.NewQueryCursor() defer qc.Close() qc.Exec(query, rootNode) // Iterate through matches for { match, _ := qc.NextMatch() // Could check second return value for boolean indicating match if match == nil { break } // Process the match (e.g., get captures) for _, capture := range match.Captures { node := capture.Node _ = node // Use the node } } return nil } ``` -------------------------------- ### Get Python Language Definition (Go) Source: https://godocs.io/github.com/smacker/go-tree-sitter/python Retrieves the tree-sitter Language definition for Python. This is essential for initializing the parser for Python code. ```go import "github.com/smacker/go-tree-sitter/python" func GetLanguage() *sitter.Language { return python.GetLanguage() } ``` -------------------------------- ### Get Dockerfile Language for Tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/dockerfile_platform=js%2Fwasm Retrieves the Tree-sitter language object for Dockerfile syntax. This is essential for initializing a parser to analyze Dockerfile content. It requires no external input and returns a pointer to a `sitter.Language` struct. ```go func GetLanguage() *sitter.Language { return dockerfile.GetLanguage() } ``` -------------------------------- ### Add HTML Documentation Badge for go-tree-sitter/golang Source: https://godocs.io/github.com/smacker/go-tree-sitter/golang_platform=darwin%2Famd64&view=tools This HTML snippet allows you to embed a status badge directly into your project's website or README file. Clicking the badge will navigate users to the detailed documentation on godocs.io. Ensure you have the correct URL for the badge and the documentation. ```html Go Documentation ``` -------------------------------- ### Get Kotlin Language Binding - go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/kotlin_platform=windows%2Famd64 Retrieves the tree-sitter Language object for Kotlin. This is essential for initializing the parser for Kotlin code. ```go import "github.com/smacker/go-tree-sitter/kotlin" func GetLanguage() *sitter.Language { // This function is expected to return the compiled language object for Kotlin // For example purposes, a placeholder is shown. return nil // Replace with actual implementation } ``` -------------------------------- ### Get CSS Language Definition - Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/css_platform=windows%2Famd64 Retrieves the tree-sitter Language definition for CSS. This is essential for initializing the CSS parser. It requires the go-tree-sitter library to be imported. ```go import "github.com/smacker/go-tree-sitter/css" func GetLanguage() *sitter.Language { return css.GetLanguage() } ``` -------------------------------- ### Get TOML Language Grammar - Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/toml_platform=linux%2Famd64 Retrieves the tree-sitter Language object for TOML. This is essential for initializing the parser for TOML files. It does not require any input parameters. ```Go import "github.com/smacker/go-tree-sitter/toml" func GetLanguage() *sitter.Language { // Implementation details omitted for brevity } ``` -------------------------------- ### Get Groovy Language Parser (Go) Source: https://godocs.io/github.com/smacker/go-tree-sitter/groovy_platform=js%2Fwasm Retrieves the tree-sitter Language object for Groovy. This is essential for initializing the parser for Groovy code. ```go import "github.com/smacker/go-tree-sitter/groovy" func main() { language := groovy.GetLanguage() // Use the language object for parsing } ``` -------------------------------- ### Add godocs.io Badge (Markdown) Source: https://godocs.io/github.com/smacker/go-tree-sitter/csharp_platform=darwin%2Famd64&view=tools Use this Markdown snippet to include a badge linking to the godocs.io documentation for the go-tree-sitter/csharp package in your project's README file. ```markdown [![Go Documentation](https://godocs.io/github.com/smacker/go-tree-sitter/csharp?status.svg)](https://godocs.io/github.com/smacker/go-tree-sitter/csharp) ``` -------------------------------- ### Get Node's Symbol in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the Symbol associated with the node. The Symbol identifies the type of the node according to the grammar. ```go func (n Node) Symbol() Symbol ``` -------------------------------- ### Parser API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Documentation for the `Parser` type, including methods for parsing code, setting languages, and managing parser options. ```APIDOC ## Parser ### Description The `Parser` type is used to parse source code into a syntax tree. ### Methods #### `NewParser() *Parser` Creates a new `Parser`. #### `(p *Parser) Close()` Closes the parser, freeing any associated resources. #### `(p *Parser) Debug()` Prints debug information about the parser's internal state. #### `(p *Parser) OperationLimit() int` Returns the current operation limit for the parser. #### `(p *Parser) Parse(oldTree *Tree, content []byte) *Tree` Parses the given content into a new `Tree`, reusing `oldTree` if possible. #### `(p *Parser) ParseCtx(ctx context.Context, oldTree *Tree, content []byte) (*Tree, error)` Parses the given content into a new `Tree` with context support. #### `(p *Parser) ParseInput(oldTree *Tree, input Input) *Tree` Parses the given `Input` into a new `Tree`, reusing `oldTree` if possible. #### `(p *Parser) ParseInputCtx(ctx context.Context, oldTree *Tree, input Input) (*Tree, error)` Parses the given `Input` into a new `Tree` with context support. #### `(p *Parser) Reset()` Resets the parser to its initial state. #### `(p *Parser) SetIncludedRanges(ranges []Range)` Sets the ranges that should be included during parsing. #### `(p *Parser) SetLanguage(lang *Language)` Sets the language for the parser. #### `(p *Parser) SetOperationLimit(limit int)` Sets the operation limit for the parser. ``` -------------------------------- ### Get Node's Previous Sibling in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 This method returns the previous sibling of the current node. It returns nil if there is no previous sibling. ```go func (n Node) PrevSibling() *Node ``` -------------------------------- ### Parser API Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 Provides methods for creating and configuring a parser, and for parsing content into a tree. ```APIDOC ## Parser Functions ### NewParser - **Description**: Creates a new parser instance. - **Method**: `NewParser()` - **Returns**: `*Parser` - A pointer to a new Parser object. ### Parser.Parse - **Description**: Parses the given content using the parser's current language, optionally using an old tree for incremental parsing. - **Method**: `Parse(oldTree *Tree, content []byte) *Tree` - **Parameters**: - `oldTree` (*Tree) - The previous tree to reuse for incremental parsing. Can be nil. - `content` ([]byte) - The source code content to parse. - **Returns**: `*Tree` - The resulting parse tree. ### Parser.ParseCtx - **Description**: Parses the given content with context, optionally using an old tree for incremental parsing. - **Method**: `ParseCtx(ctx context.Context, oldTree *Tree, content []byte) (*Tree, error)` - **Parameters**: - `ctx` (context.Context) - The context for the operation. - `oldTree` (*Tree) - The previous tree to reuse for incremental parsing. Can be nil. - `content` ([]byte) - The source code content to parse. - **Returns**: `(*Tree, error)` - The resulting parse tree and a potential error. ### Parser.ParseInput - **Description**: Parses the given input using the parser's current language, optionally using an old tree for incremental parsing. - **Method**: `ParseInput(oldTree *Tree, input Input) *Tree` - **Parameters**: - `oldTree` (*Tree) - The previous tree to reuse for incremental parsing. Can be nil. - `input` (Input) - The input structure containing content and encoding information. - **Returns**: `*Tree` - The resulting parse tree. ### Parser.ParseInputCtx - **Description**: Parses the given input with context, optionally using an old tree for incremental parsing. - **Method**: `ParseInputCtx(ctx context.Context, oldTree *Tree, input Input) (*Tree, error)` - **Parameters**: - `ctx` (context.Context) - The context for the operation. - `oldTree` (*Tree) - The previous tree to reuse for incremental parsing. Can be nil. - `input` (Input) - The input structure containing content and encoding information. - **Returns**: `(*Tree, error)` - The resulting parse tree and a potential error. ### Parser.SetLanguage - **Description**: Sets the language for the parser. - **Method**: `SetLanguage(lang *Language)` - **Parameters**: - `lang` (*Language) - The language to set for the parser. ### Parser.SetIncludedRanges - **Description**: Sets the ranges of the input to include during parsing. - **Method**: `SetIncludedRanges(ranges []Range)` - **Parameters**: - `ranges` ([]Range) - A slice of Range objects specifying the included sections. ### Parser.SetOperationLimit - **Description**: Sets the maximum number of operations the parser can perform before stopping. - **Method**: `SetOperationLimit(limit int)` - **Parameters**: - `limit` (int) - The operation limit. ### Parser.OperationLimit - **Description**: Gets the current operation limit of the parser. - **Method**: `OperationLimit() int` - **Returns**: `int` - The current operation limit. ### Parser.Reset - **Description**: Resets the parser's internal state. - **Method**: `Reset()` ### Parser.Debug - **Description**: Enables or disables parser debugging output. (Note: actual behavior might depend on implementation details not fully described here). - **Method**: `Debug()` ### Parser.Close - **Description**: Releases any resources held by the parser. - **Method**: `Close()` ``` -------------------------------- ### Go Tree-sitter Query Creation and Management Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=linux%2Famd64 Defines functions for creating, managing, and querying syntax trees. This includes creating a new query from patterns, retrieving capture counts and names, closing queries to free resources, and accessing predicate information. ```go func NewQuery(pattern []byte, lang *Language) (*Query, error) 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 ``` -------------------------------- ### Get TSX Language for go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/typescript/tsx Retrieves the tree-sitter Language object specifically for TypeScript/TSX syntax. This is essential for initializing the parser for TSX files. ```go import "github.com/smacker/go-tree-sitter/typescript/tsx" // ... lang := tsx.GetLanguage() ``` -------------------------------- ### Get Go Tree-sitter Markdown Language Source: https://godocs.io/github.com/smacker/go-tree-sitter/markdown/tree-sitter-markdown-inline_platform=linux%2Famd64 Retrieves the `sitter.Language` object for the tree-sitter markdown parser. This is essential for initializing the parser with the correct grammar. No external dependencies are required beyond the `tree-sitter` library. ```Go func GetLanguage() *sitter.Language { return tree_sitter_markdown_inline.NewLanguage() } ``` -------------------------------- ### Manage Parser State in go-tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/index_platform=windows%2Famd64 Handles the parser configuration and operations. This includes creating a new parser, setting the language, adjusting operation limits, and parsing content. ```go func NewParser() *Parser func (p *Parser) Parse(oldTree *Tree, content []byte) *Tree func (p *Parser) ParseInput(oldTree *Tree, input Input) *Tree func (p *Parser) SetIncludedRanges(ranges []Range) func (p *Parser) SetLanguage(lang *Language) func (p *Parser) SetOperationLimit(limit int) ``` -------------------------------- ### Get TOML Language Definition (Go) Source: https://godocs.io/github.com/smacker/go-tree-sitter/toml Retrieves the tree-sitter language definition for TOML. This function is essential for initializing the parser for TOML files. ```go func GetLanguage() *sitter.Language { return toml.GetLanguage() } ``` -------------------------------- ### Add godocs.io badge (HTML) Source: https://godocs.io/github.com/smacker/go-tree-sitter/protobuf_platform=darwin%2Famd64&view=tools Use this HTML snippet to embed a badge linking to the godocs.io documentation for the go-tree-sitter/protobuf package. This badge displays the documentation status. No external dependencies are required. ```html Go Documentation ``` -------------------------------- ### Create New TreeCursor in Go Source: https://godocs.io/github.com/smacker/go-tree-sitter/index Provides the NewTreeCursor function to create a new tree cursor instance in Go. It initializes the cursor starting from a specified node, preparing it for tree traversal. ```Go func NewTreeCursor(n *Node) *TreeCursor ``` -------------------------------- ### Get Elm Language for Tree-sitter Source: https://godocs.io/github.com/smacker/go-tree-sitter/elm Retrieves the tree-sitter Language object for Elm. This is necessary to initialize the Elm parser for use with the go-tree-sitter library. ```go import "github.com/smacker/go-tree-sitter/elm" func GetElmLanguage() *sitter.Language { return elm.GetLanguage() } ```