parser

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoSpec = &LanguageSpec{
	NamedChunks: map[string]NamedChunkExtractor{
		"function_declaration": {
			NameQuery: `(function_declaration name: (identifier) @name)`,
		},
		"method_declaration": {
			NameQuery: `(method_declaration name: (field_identifier) @name)`,
			ParentNameQuery: `
				(method_declaration
					receiver: (parameter_list
						(parameter_declaration
							type: [
								(type_identifier) @name
								(pointer_type
									(type_identifier) @name)
								(generic_type
									(type_identifier) @name)
								(pointer_type
									(generic_type
										(type_identifier) @name))])))`,
		},
		"type_declaration": {
			NameQuery: `
				(type_declaration [
					(type_spec name: (type_identifier) @name)
					(type_alias name: (type_identifier) @name)])`,
		},
		"var_declaration": {
			NameQuery: `(var_declaration (var_spec name: (identifier) @name))`,
		},
		"const_declaration": {
			NameQuery: `(const_declaration (const_spec name: (identifier) @name))`,
		},
	},
	FoldIntoNextNode: []string{"comment"},
	SkipTypes: []string{

		"import_declaration",

		"package_clause",
	},
	FileTypeRules: []FileTypeRule{
		{Pattern: "**/*_test.go", Type: FileTypeTests},
		{Pattern: "vendor/**", Type: FileTypeIgnore},
		{Pattern: "third_party/**", Type: FileTypeIgnore},
	},
}
View Source
var JavaScriptSpec = &LanguageSpec{
	NamedChunks: map[string]NamedChunkExtractor{
		"function_declaration": {
			NameQuery: `(function_declaration name: (identifier) @name)`,
		},
		"generator_function_declaration": {
			NameQuery: `(generator_function_declaration name: (identifier) @name)`,
		},
		"class_declaration": {
			NameQuery: `(class_declaration name: (identifier) @name)`,
		},
		"lexical_declaration": {
			NameQuery: `(lexical_declaration (variable_declarator name: (identifier) @name))`,
		},
		"variable_declaration": {
			NameQuery: `(variable_declaration (variable_declarator name: (identifier) @name))`,
		},
		"method_definition": {
			NameQuery: `(method_definition name: (property_identifier) @name)`,
		},
		"field_definition": {
			NameQuery: `(field_definition property: (property_identifier) @name)`,
		},
	},
	ExtractChildrenIn: []string{
		"class_declaration",
		"class_body",
		"export_statement",
	},
	FoldIntoNextNode: []string{"comment", "export", "default"},
	SkipTypes: []string{

		"import_statement",

		"{", "}", ";",
		"class", "extends", "implements",

		"identifier",

		"class_heritage",

		"class_body",
		"export_statement",
	},
	FileTypeRules: []FileTypeRule{
		{Pattern: "**/*.test.js", Type: FileTypeTests},
		{Pattern: "**/*.test.jsx", Type: FileTypeTests},
		{Pattern: "**/*.spec.js", Type: FileTypeTests},
		{Pattern: "**/*.spec.jsx", Type: FileTypeTests},
		{Pattern: "**/node_modules/**", Type: FileTypeIgnore},
		{Pattern: "**/dist/**", Type: FileTypeIgnore},
		{Pattern: "**/build/**", Type: FileTypeIgnore},
	},
}
View Source
var MarkdownSpec = &LanguageSpec{
	ExtractChildrenIn: []string{"section"},
	SkipTypes: []string{

		"atx_heading", "setext_heading",

		"block_quote",
		"block_continuation",
		"fenced_code_block", "indented_code_block",
		"html_block",
		"link_reference_definition",
		"list",
		"paragraph",
		"pipe_table",
		"thematic_break",
	},
	FileTypeRules: []FileTypeRule{
		{Pattern: "**/*.md", Type: FileTypeDocs},
	},
}
View Source
var PythonSpec = &LanguageSpec{
	NamedChunks: map[string]NamedChunkExtractor{
		"function_definition": {
			NameQuery: `(function_definition name: (identifier) @name)`,
		},
		"class_definition": {
			NameQuery: `(class_definition name: (identifier) @name)`,
		},
		"decorated_definition": {
			NameQuery: `(decorated_definition definition: [
				(function_definition name: (identifier) @name)
				(class_definition name: (identifier) @name)
			])`,
			SummaryNodeQuery: `(decorated_definition definition: [
				(function_definition) @summary
				(class_definition) @summary
			])`,
		},
		"expression_statement": {
			NameQuery: `(expression_statement (assignment left: (identifier) @name))`,
		},
	},
	ExtractChildrenIn: []string{
		"class_definition",
		"block",
	},
	FoldIntoNextNode: []string{"comment"},
	SkipTypes: []string{

		"import_statement",
		"import_from_statement",

		":", "class", "def",
		"pass", "pass_statement",

		"identifier",

		"argument_list",

		"block",
	},
	FileTypeRules: []FileTypeRule{
		{Pattern: "**/test*.py", Type: FileTypeTests},
		{Pattern: "**/*_test.py", Type: FileTypeTests},
		{Pattern: "**/__pycache__/**", Type: FileTypeIgnore},
		{Pattern: "**/venv/**", Type: FileTypeIgnore},
		{Pattern: "**/.venv/**", Type: FileTypeIgnore},
		{Pattern: "**/env/**", Type: FileTypeIgnore},
		{Pattern: "**/.env/**", Type: FileTypeIgnore},
		{Pattern: "**/site-packages/**", Type: FileTypeIgnore},
	},
}
View Source
var TypeScriptSpec = &LanguageSpec{
	NamedChunks: map[string]NamedChunkExtractor{
		"function_declaration": {
			NameQuery: `(function_declaration name: (identifier) @name)`,
		},
		"function_signature": {
			NameQuery: `(function_signature name: (identifier) @name)`,
		},
		"generator_function_declaration": {
			NameQuery: `(generator_function_declaration name: (identifier) @name)`,
		},
		"class_declaration": {
			NameQuery: `(class_declaration name: (type_identifier) @name)`,
		},
		"abstract_class_declaration": {
			NameQuery: `(abstract_class_declaration name: (type_identifier) @name)`,
		},
		"interface_declaration": {
			NameQuery: `(interface_declaration name: (type_identifier) @name)`,
		},
		"type_alias_declaration": {
			NameQuery: `(type_alias_declaration name: (type_identifier) @name)`,
		},
		"lexical_declaration": {
			NameQuery: `(lexical_declaration (variable_declarator name: (identifier) @name))`,
		},
		"variable_declaration": {
			NameQuery: `(variable_declaration (variable_declarator name: (identifier) @name))`,
		},
		"ambient_declaration": {
			NameQuery: `(ambient_declaration (variable_declaration (variable_declarator name: (identifier) @name)))`,
		},
		"enum_declaration": {
			NameQuery: `(enum_declaration name: (identifier) @name)`,
		},
		"module": {
			NameQuery: `(module name: (identifier) @name)`,
		},
		"method_definition": {
			NameQuery: `(method_definition name: (property_identifier) @name)`,
		},
		"public_field_definition": {
			NameQuery: `(public_field_definition name: (property_identifier) @name)`,
		},
		"field_definition": {
			NameQuery: `(field_definition name: (property_identifier) @name)`,
		},
		"abstract_method_signature": {
			NameQuery: `(abstract_method_signature name: (property_identifier) @name)`,
		},
	},
	ExtractChildrenIn: []string{
		"class_declaration",
		"abstract_class_declaration",
		"class_body",
		"export_statement",
	},
	FoldIntoNextNode: []string{"comment", "export", "default"},
	SkipTypes: []string{

		"import_statement",
		"import_alias",

		"{", "}", ";",
		"class", "abstract", "extends", "implements",

		"type_identifier", "identifier",

		"type_parameters", "class_heritage",

		"decorator",

		"class_body",
		"export_statement",
	},
	FileTypeRules: []FileTypeRule{
		{Pattern: "**/*.test.ts", Type: FileTypeTests},
		{Pattern: "**/*.test.tsx", Type: FileTypeTests},
		{Pattern: "**/*.spec.ts", Type: FileTypeTests},
		{Pattern: "**/*.spec.tsx", Type: FileTypeTests},
		{Pattern: "**/node_modules/**", Type: FileTypeIgnore},
		{Pattern: "**/dist/**", Type: FileTypeIgnore},
		{Pattern: "**/build/**", Type: FileTypeIgnore},
	},
}

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	File        string // file path within workspace
	Type        string
	Path        string // path within file
	Summary     string
	Source      string
	StartLine   uint
	StartColumn uint
	EndLine     uint
	EndColumn   uint
	ParsedAt    int64
}

Chunk represents a semantic unit of code extracted from source files

func (*Chunk) ID

func (c *Chunk) ID() string

ID returns a unique identifier for this chunk in the format "file::path"

type File

type File struct {
	Path   string // path within workspace
	Chunks []*Chunk
	Source []byte
	// contains filtered or unexported fields
}

File represents a parsed source file with its extracted semantic chunks

type FileType added in v0.3.0

type FileType string

FileType represents the classification of a file within the workspace

const (
	FileTypeSrc    FileType = "src"
	FileTypeTests  FileType = "tests"
	FileTypeDocs   FileType = "docs"
	FileTypeIgnore FileType = "ignore"
)

type FileTypeRule added in v0.3.0

type FileTypeRule struct {
	Pattern string   // glob pattern to match against file paths
	Type    FileType // the file type to assign when the pattern matches
}

FileTypeRule defines a pattern-based rule for classifying file types

type LanguageSpec

type LanguageSpec struct {
	NamedChunks       map[string]NamedChunkExtractor // node types that can be extracted by name
	ExtractChildrenIn []string                       // node types whose children should be recursively processed
	FoldIntoNextNode  []string                       // node types to fold into next node, e.g., comments
	SkipTypes         []string                       // node types to completely skip
	FileTypeRules     []FileTypeRule                 // language-specific file type classification rules
}

LanguageSpec defines language-specific parsing behavior for tree-sitter

type NamedChunkExtractor

type NamedChunkExtractor struct {
	NameQuery        string // query to extract the entity name
	ParentNameQuery  string // optional query to extract parent entity name for hierarchical paths
	SummaryNodeQuery string // optional query to extract a specific node for the summary instead of the main node
}

NamedChunkExtractor defines tree-sitter queries for extracting named code entities

type Parser

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

Parser handles parsing and semantic chunk extraction from source files using tree-sitter for language-aware AST processing

func NewGoParser

func NewGoParser(workspaceRoot string) (*Parser, error)

func NewJavaScriptParser added in v0.5.0

func NewJavaScriptParser(workspaceRoot string) (*Parser, error)

func NewMarkdownParser added in v0.3.0

func NewMarkdownParser(workspaceRoot string) (*Parser, error)

func NewPythonParser added in v0.4.0

func NewPythonParser(workspaceRoot string) (*Parser, error)

func NewTypeScriptParser added in v0.5.0

func NewTypeScriptParser(workspaceRoot string) (*Parser, error)

func (*Parser) Chunk

func (p *Parser) Chunk(filePath string) (*File, error)

Chunk parses a file and extracts semantic chunks from its AST

func (*Parser) Close

func (p *Parser) Close()

Close releases resources used by the tree-sitter parser

Jump to

Keyboard shortcuts

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