c

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package c implements a tree-sitter-based parser for C source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSignature

func BuildSignature(node *sitter.Node, src []byte, name string) string

BuildSignature extracts the function signature (name + params).

func ExtractCComment

func ExtractCComment(node *sitter.Node, src []byte) string

ExtractCComment looks for a comment node immediately before the given node.

func ExtractDeclaration

func ExtractDeclaration(node *sitter.Node, src []byte, parent string, result *ParseResult)

ExtractDeclaration checks for function prototypes inside declarations.

func ExtractDeclaratorName

func ExtractDeclaratorName(node *sitter.Node, src []byte) string

ExtractDeclaratorName walks through nested declarators to find the identifier name.

func ExtractEnum

func ExtractEnum(node *sitter.Node, src []byte, parent string, result *ParseResult)

ExtractEnum extracts an enum definition.

func ExtractFunction

func ExtractFunction(node *sitter.Node, src []byte, parent string, result *ParseResult)

ExtractFunction extracts a function definition.

func ExtractInclude

func ExtractInclude(node *sitter.Node, src []byte, result *ParseResult)

ExtractInclude handles #include directives.

func ExtractStruct

func ExtractStruct(node *sitter.Node, src []byte, parent string, result *ParseResult)

ExtractStruct extracts a struct definition and walks its body.

func ExtractTypedef

func ExtractTypedef(node *sitter.Node, src []byte, result *ParseResult)

ExtractTypedef extracts a typedef.

func WalkC

func WalkC(node *sitter.Node, src []byte, parent string, result *ParseResult)

WalkC recursively walks the tree-sitter AST extracting entities and dependencies. Exported so the C++ parser can reuse it for shared node types.

Types

type CParser

type CParser struct{}

CParser is the entry point for C source files.

func (*CParser) Parse

func (p *CParser) Parse(filePath string, content string) (*ParseResult, error)

Parse parses a C source file using tree-sitter.

type Dependency

type Dependency struct {
	Path       string
	Type       string // "include"
	LineNumber int
	IsLocal    bool
}

Dependency represents an #include directive.

type Entity

type Entity struct {
	Name      string
	Type      string // "function" | "struct" | "enum" | "union" | "type"
	Kind      string // "function" | "declaration" | "struct" | "enum" | "union" | "typedef"
	Signature string
	StartLine int
	EndLine   int
	Docs      string
	Parent    string
}

Entity represents a named code element.

type ParseResult

type ParseResult struct {
	FilePath     string
	Entities     []*Entity
	Dependencies []*Dependency
}

ParseResult is the output of Parse.

Jump to

Keyboard shortcuts

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