syntaxgo_astnode

package
v0.0.54 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 3 Imported by: 9

Documentation

Overview

Package syntaxgo_astnode provides utilities to work with AST nodes Handle node position info and extract code content from AST nodes Support operations like code extraction, modification, and deletion

syntaxgo_astnode 包提供处理 AST 节点的工具 处理节点位置信息并从 AST 节点提取代码内容 支持代码提取、修改和删除等操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeNodeCode

func ChangeNodeCode(source []byte, astNode ast.Node, newCode []byte) []byte

ChangeNodeCode replaces the code corresponding to the given AST node with new code in the source. ChangeNodeCode 用新代码替换源代码中与给定 AST 节点对应的代码。

func ChangeNodeCodeSetSomeNewLines

func ChangeNodeCodeSetSomeNewLines(source []byte, astNode ast.Node, newCode []byte, numLine int) []byte

ChangeNodeCodeSetSomeNewLines replaces the code corresponding to the given AST node with new code and adds new lines in the source. ChangeNodeCodeSetSomeNewLines 用新代码替换源代码中与给定 AST 节点对应的代码,并添加新行。

func DeleteNodeCode

func DeleteNodeCode(source []byte, astNode ast.Node) []byte

DeleteNodeCode removes the code corresponding to the given AST node from the source. DeleteNodeCode 从源代码中删除与给定 AST 节点对应的代码。

func GetCode

func GetCode(source []byte, astNode ast.Node) []byte

GetCode returns the code corresponding to the given AST node from the source. GetCode 从源代码中返回与给定 AST 节点对应的代码。

func GetText

func GetText(source []byte, astNode ast.Node) string

GetText returns the text corresponding to the given AST node from the source. GetText 从源代码中返回与给定 AST 节点对应的文本。

func SdxEdx

func SdxEdx(astNode ast.Node) (sdx, edx int)

SdxEdx returns the start and end positions of the given AST node as integers. SdxEdx 返回给定 AST 节点的起始和结束位置(整数)。

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a syntax node with position information. Node 表示一个带有位置信息的语法节点。

func NewNode

func NewNode(pos, end token.Pos) *Node

NewNode creates a new Node with the specified start and end positions. NewNode 创建一个带有指定起始和结束位置的 Node。

func NewNodeV1

func NewNodeV1(node ast.Node) *Node

NewNodeV1 creates a new Node from an existing ast.Node. NewNodeV1 从一个现有的 ast.Node 创建一个新的 Node。

func NewNodeV2

func NewNodeV2(pos, end int) *Node

NewNodeV2 creates a new Node with the specified start and end positions as integers. NewNodeV2 创建一个带有指定起始和结束位置(整数)的 Node。

func (*Node) End

func (x *Node) End() token.Pos

End returns the end position of the Node. End 返回 Node 的结束位置。

func (*Node) GetCode

func (x *Node) GetCode(source []byte) []byte

GetCode returns the code corresponding to the Node from the source. GetCode 从源代码中返回与 Node 对应的代码。

func (*Node) GetText

func (x *Node) GetText(source []byte) string

GetText returns the text corresponding to the Node from the source. GetText 从源代码中返回与 Node 对应的文本。

func (*Node) Pos

func (x *Node) Pos() token.Pos

Pos returns the start position of the Node. Pos 返回 Node 的起始位置。

func (*Node) SetEnd added in v0.0.45

func (x *Node) SetEnd(end token.Pos)

SetEnd sets the end position of the Node. SetEnd 设置 Node 的结束位置。

func (*Node) SetPos added in v0.0.45

func (x *Node) SetPos(pos token.Pos)

SetPos sets the start position of the Node. SetPos 设置 Node 的起始位置。

Jump to

Keyboard shortcuts

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