parser

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 70 Imported by: 0

Documentation

Overview

Package parser — heuristic.go: post-AST pass that injects synthetic HANDLES edges for framework routing registrations (R1).

Detects patterns such as:

  • Go: http.HandleFunc("/path", handler), r.GET("/path", handler)
  • TS: app.get('/path', handler), router.post('/path', handler)
  • Py: @app.get('/path'), path('/path', view)

For each match, a virtual NodeRoute node is created representing the route, and two synthetic edges are injected:

enclosingFn --CALLS--> routeNode
routeNode   --HANDLES--> handlerFn

Both edges are synthetic (not derived from AST call resolution) and are skipped if either endpoint cannot be resolved in the current graph. Confidence is stored in routeNode.Metadata["confidence"] (0.0–1.0 as string).

Package parser — nl_extract.go implements Tier 0 NL-to-graph entity extraction.

Tier 0 is always-on: pure Go, zero dependencies, zero cost. Given markdown body text it returns named entity candidates and relationship signals without any LLM or embedding call. Quality alone is ~50% of full NL extraction — already better than no extraction at all.

Pipeline position:

Tier 0 (this file) → Tier 1 (resolver/nl_entities.go, name-match resolution)
                   → Tier 2 (brain/client.go, P1 LLM classification)

Package parser converts source files into graph nodes and edges using Tree-sitter for accurate, incremental, multi-language AST parsing.

Index

Constants

View Source
const DefaultParseTimeout = 30 * time.Second

DefaultParseTimeout is the maximum time allowed for tree-sitter to parse a single file.

Variables

This section is empty.

Functions

func ApplyHeuristics

func ApplyHeuristics(g *graph.Graph, filePath string, src []byte)

ApplyHeuristics is the convenience entry-point called from WalkDir / ParseFile. It extracts route registrations from src and injects HANDLES edges into g.

func ApplyProvenance

func ApplyProvenance(g *graph.Graph, path string, src []byte)

ApplyProvenance sets the Provenance field on all nodes belonging to path. Called by WalkDir/IncrementalReindex/ParseFile immediately after a successful parse so that every node carries its trust tier from the moment it enters the graph. Nodes in user-authored files are left unchanged (ProvenanceUserAuthored is the zero value).

func DetectProvenance

func DetectProvenance(path string, src []byte) graph.ProvenanceType

DetectProvenance derives the provenance tier for a file from its path and the first 512 bytes of content. Runs at index time with no LLM or I/O beyond what the parser has already read.

Priority order:

  1. Vendored — path contains vendor/, node_modules/, third_party/
  2. Generated — file name matches codegen suffixes, OR file starts with a well-known codegen header comment
  3. UserAuthored — everything else (the safe default)

func InjectHandlesEdges

func InjectHandlesEdges(g *graph.Graph, registrations []RouteRegistration) int

InjectHandlesEdges resolves registrations to graph nodes and creates synthetic route nodes + HANDLES edges. Returns the number of edges injected.

func ResolveProtoTypeRefs

func ResolveProtoTypeRefs(g *graph.Graph) int

ResolveProtoTypeRefs creates DEPENDS_ON edges from fields to their message/enum types within the same proto graph. This enables impact analysis: changing a message type surfaces all messages that reference it. Must be called after all proto files in the project are parsed.

Types

type BashParser

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

BashParser parses Bash/Shell (.sh, .bash) source files.

func NewBashParser

func NewBashParser() *BashParser

NewBashParser creates a ready-to-use BashParser.

func (*BashParser) Extensions

func (p *BashParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*BashParser) Parse

func (p *BashParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Bash/Shell file.

func (*BashParser) TSLanguageForFile

func (p *BashParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type BicepParser

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

BicepParser parses Azure Bicep (.bicep) infrastructure-as-code files. It extracts:

  • Parameters (param name type = default) → NodeVariable (kind=parameter)
  • Variables (var name = value) → NodeVariable (kind=variable)
  • Resources (resource symbolicName 'Type@api' = {...}) → NodeStruct (kind=resource)
  • Modules (module symbolicName 'path' = {...}) → NodeStruct (kind=module)
  • Outputs (output name type = value) → NodeVariable (kind=output)

Decorators (@description, @allowed) preceding declarations are collected and stored in metadata.

func NewBicepParser

func NewBicepParser() *BicepParser

NewBicepParser creates a ready-to-use BicepParser.

func (*BicepParser) Extensions

func (p *BicepParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*BicepParser) Parse

func (p *BicepParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Bicep file.

The Bicep grammar root node is "infrastructure". Its direct children are:

  • decorators: one or more @decorator nodes preceding a declaration
  • parameter_declaration, variable_declaration, resource_declaration, module_declaration, output_declaration

Decorators are collected as they appear and applied to the immediately following declaration node.

func (*BicepParser) TSLanguageForFile

func (p *BicepParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type CMakeParser

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

CMakeParser parses CMake (.cmake, CMakeLists.txt) source files. It extracts functions, macros, targets (add_executable/add_library), variables (set/option), and includes (include/find_package).

func NewCMakeParser

func NewCMakeParser() *CMakeParser

NewCMakeParser creates a ready-to-use CMakeParser.

func (*CMakeParser) Extensions

func (p *CMakeParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CMakeParser) Filenames

func (p *CMakeParser) Filenames() []string

Filenames returns the exact base filenames handled by this parser.

func (*CMakeParser) Parse

func (p *CMakeParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single CMake file and merges them into the graph.

Extracts:

  • File node (NodeFile)
  • function() definitions -> NodeFunction
  • macro() definitions -> NodeFunction with kind="macro"
  • add_executable/add_library targets -> NodeStruct with kind="target"
  • set/option variables -> NodeVariable
  • include/find_package -> EdgeImports

func (*CMakeParser) TSLanguageForFile

func (p *CMakeParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type CParser

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

CParser parses C (.c, .h) source files.

func NewCParser

func NewCParser() *CParser

NewCParser creates a ready-to-use CParser.

func (*CParser) Extensions

func (p *CParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CParser) Parse

func (p *CParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single C file and merges them into the graph.

func (*CParser) TSLanguageForFile

func (p *CParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type CSSParser

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

CSSParser parses CSS (.css) source files using tree-sitter.

func NewCSSParser

func NewCSSParser() *CSSParser

NewCSSParser creates a ready-to-use CSSParser.

func (*CSSParser) Extensions

func (p *CSSParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CSSParser) Parse

func (p *CSSParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single CSS file and merges them into the graph.

Extracts:

  • @import rules → EdgeImports to NodePackage nodes
  • Rule-set selectors (.class, #id) → NodeStruct with kind="selector"
  • @keyframes definitions → NodeFunction with kind="keyframes"
  • CSS custom property definitions (--var) → NodeVariable with kind="custom-property"
  • @font-face font-family names → NodeVariable with kind="font-face"
  • animation / animation-name references → EdgeCalls to keyframes nodes
  • var(--name) references → EdgeCalls to custom-property nodes
  • Selectors inside @media, @supports, @layer are fully handled (recursive walk)

func (*CSSParser) TSLanguageForFile

func (p *CSSParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type CSharpParser

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

CSharpParser parses C# (.cs) source files.

func NewCSharpParser

func NewCSharpParser() *CSharpParser

NewCSharpParser creates a ready-to-use CSharpParser.

func (*CSharpParser) Extensions

func (p *CSharpParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CSharpParser) Parse

func (p *CSharpParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single C# file.

func (*CSharpParser) TSLanguageForFile

func (p *CSharpParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type CUEParser

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

CUEParser parses CUE (.cue) configuration files. It extracts package declarations, imports, definitions (#Name), top-level fields, and let bindings into graph nodes with appropriate types and metadata.

func NewCUEParser

func NewCUEParser() *CUEParser

NewCUEParser creates a ready-to-use CUEParser.

func (*CUEParser) Extensions

func (p *CUEParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CUEParser) Parse

func (p *CUEParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single CUE file.

func (*CUEParser) TSLanguageForFile

func (p *CUEParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type ClojureParser

type ClojureParser struct{}

ClojureParser parses Clojure (.clj, .cljs, .cljc, .edn) source files. Used in data engineering, fintech backend systems, and JVM functional programming. Uses regex-based extraction (Clojure is not in go-tree-sitter).

Extracts:

  • (defn fn-name [args] body) → NodeFunction (Exported: true)
  • (defn- fn-name [args] body) → NodeFunction (Exported: false)
  • (defn ^:private fn-name [args]) → NodeFunction (Exported: false)
  • (defmacro name [args] body) → NodeFunction kind=macro
  • (defmulti name dispatch-fn) → NodeFunction kind=multimethod
  • (defmethod name dispatch-val [...]) → NodeFunction kind=multimethod
  • (defrecord Name [fields]) → NodeStruct kind=record
  • (defprotocol Name ...) → NodeStruct kind=protocol
  • (deftype Name [fields]) → NodeStruct kind=type
  • (ns my.namespace (:require [...])) → NodePackage + EdgeImports
  • (require '[clojure.string :as str]) → NodePackage + EdgeImports
  • (def var-name ...) → NodeVariable
  • (def ^:private var-name ...) → NodeVariable (Exported: false)

func NewClojureParser

func NewClojureParser() *ClojureParser

NewClojureParser creates a ready-to-use ClojureParser.

func (*ClojureParser) Extensions

func (p *ClojureParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ClojureParser) Parse

func (p *ClojureParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Clojure file and merges them into the graph.

type CppParser

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

CppParser parses C++ source files.

func NewCppParser

func NewCppParser() *CppParser

NewCppParser creates a ready-to-use CppParser.

func (*CppParser) Extensions

func (p *CppParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*CppParser) Parse

func (p *CppParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single C++ file and merges them into the graph.

func (*CppParser) TSLanguageForFile

func (p *CppParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type DartParser

type DartParser struct{}

DartParser parses Dart (.dart) source files. Used in Flutter mobile apps, server-side Dart, and CLI tools. Uses regex-based extraction since Dart is not in go-tree-sitter.

func NewDartParser

func NewDartParser() *DartParser

NewDartParser creates a ready-to-use DartParser.

func (*DartParser) Extensions

func (p *DartParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*DartParser) Parse

func (p *DartParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Dart file and merges them into the graph.

type DockerfileParser

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

DockerfileParser parses Dockerfile source files. It extracts build stages (FROM), COPY --from edges, ARG/ENV declarations, EXPOSE ports, LABEL metadata, and base image imports.

func NewDockerfileParser

func NewDockerfileParser() *DockerfileParser

NewDockerfileParser creates a ready-to-use DockerfileParser.

func (*DockerfileParser) Extensions

func (p *DockerfileParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*DockerfileParser) FilenamePrefixes

func (p *DockerfileParser) FilenamePrefixes() []string

FilenamePrefixes returns filename prefixes that this parser handles. Any file whose base name starts with "Dockerfile" or "Containerfile" (e.g. Dockerfile.staging, Dockerfile.ci, Containerfile.dev) is parsed.

func (*DockerfileParser) Filenames

func (p *DockerfileParser) Filenames() []string

Filenames returns the exact base filenames handled by this parser. These are files that have no extension (e.g. "Dockerfile") or use a dot-separated variant (e.g. "Dockerfile.dev"). The Walker checks this interface when no extension-based match is found.

func (*DockerfileParser) Parse

func (p *DockerfileParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Dockerfile and merges them into the graph.

Extracts:

  • FROM stages -> NodeStruct with kind="stage"
  • Base image imports -> EdgeImports to NodePackage
  • COPY --from edges -> EdgeCalls between stages
  • ARG declarations -> NodeVariable with kind="arg"
  • ENV declarations -> NodeVariable with kind="env"
  • EXPOSE ports -> metadata on file node
  • LABEL metadata -> metadata on file node

func (*DockerfileParser) TSLanguageForFile

func (p *DockerfileParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type ElixirParser

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

ElixirParser parses Elixir (.ex, .exs) source files.

func NewElixirParser

func NewElixirParser() *ElixirParser

NewElixirParser creates a ready-to-use ElixirParser.

func (*ElixirParser) Extensions

func (p *ElixirParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ElixirParser) Parse

func (p *ElixirParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Elixir file.

func (*ElixirParser) TSLanguageForFile

func (p *ElixirParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type ElmParser

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

ElmParser parses Elm (.elm) source files.

func NewElmParser

func NewElmParser() *ElmParser

NewElmParser creates a ready-to-use ElmParser.

func (*ElmParser) Extensions

func (p *ElmParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ElmParser) Parse

func (p *ElmParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Elm file.

func (*ElmParser) TSLanguageForFile

func (p *ElmParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type EntityCandidate

type EntityCandidate struct {
	Name       string  // extracted token (normalised, no backticks/quotes)
	Context    string  // surrounding sentence (≤200 chars) for Tier 2
	SourceLine int     // 1-based line in the original markdown body
	Confidence float64 // heuristic confidence: 0.6–0.95
}

EntityCandidate is a named entity extracted from natural-language text. Name is the raw extracted token; Context is the surrounding sentence for Tier 2 LLM classification. Confidence is a Tier 0 heuristic score.

func ExtractEntityCandidates

func ExtractEntityCandidates(text string) []EntityCandidate

ExtractEntityCandidates scans markdown body text and returns entity candidates. Deduplicates by name (keeps highest confidence). Filters stop words and tokens shorter than 3 characters. Safe for concurrent use (no global state).

func ExtractFrontmatterCandidates

func ExtractFrontmatterCandidates(tags []string, category string) []EntityCandidate

ExtractFrontmatterCandidates creates entity candidates from frontmatter metadata (tags and category) stored on file nodes. These have high confidence (0.95) since they are explicitly authored by the document owner.

type ErlangParser

type ErlangParser struct{}

ErlangParser parses Erlang (.erl, .hrl) source files. Used in telecom, real-time distributed systems, and high-availability platforms. Uses regex-based extraction.

func NewErlangParser

func NewErlangParser() *ErlangParser

NewErlangParser creates a ready-to-use ErlangParser.

func (*ErlangParser) Extensions

func (p *ErlangParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ErlangParser) Parse

func (p *ErlangParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Erlang file and merges them into g.

type FSharpParser

type FSharpParser struct{}

FSharpParser parses F# (.fs, .fsi, .fsx) source files. Used heavily in fintech (.NET ecosystem), financial modeling, and functional teams. Uses regex-based extraction — F# is not in go-tree-sitter.

Extracts:

  • Let bindings (functions and values) → NodeFunction
  • Type definitions (records, DUs, aliases, interfaces, classes) → NodeStruct
  • Module declarations → NodePackage
  • open statements (imports) → NodePackage + EdgeImports
  • Member methods inside types → NodeFunction (qualified)
  • Active patterns → NodeFunction with kind=active_pattern

func NewFSharpParser

func NewFSharpParser() *FSharpParser

NewFSharpParser creates a ready-to-use FSharpParser.

func (*FSharpParser) Extensions

func (p *FSharpParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*FSharpParser) Parse

func (p *FSharpParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single F# file and merges them into the graph.

type FilenameParser

type FilenameParser interface {
	Filenames() []string
}

FilenameParser is an optional interface that parsers can implement if they handle files matched by base filename rather than extension. The Walker checks this interface when no extension-based match is found.

type FilenamePatternParser

type FilenamePatternParser interface {
	FilenamePrefixes() []string
}

FilenamePatternParser is an optional interface for parsers that handle files whose base name matches a prefix (e.g. "Dockerfile" handles "Dockerfile.staging", "Dockerfile.ci", etc.).

type GoParser

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

GoParser parses Go source files into graph nodes and edges using Tree-sitter.

func NewGoParser

func NewGoParser() *GoParser

NewGoParser creates a ready-to-use GoParser.

func (*GoParser) Extensions

func (p *GoParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*GoParser) Parse

func (p *GoParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Go source file and merges them into the provided graph. The following constructs are captured:

  • Package declarations → NodePackage
  • Import declarations → NodeFile edges (IMPORTS)
  • Function declarations → NodeFunction
  • Method declarations → NodeMethod
  • Type declarations (struct) → NodeStruct
  • Type declarations (interface) → NodeInterface
  • Type aliases and named types → NodeStruct (metadata kind=type_alias)
  • Package-level const declarations → NodeVariable (metadata kind=const)
  • Package-level var declarations → NodeVariable (metadata kind=var)
  • Function/method call expressions → CALLS edges

Package-level var nodes use the line of the "var" keyword, not the line of any inferred type. For slice/map vars (var foo = []BarType{...}), the node name is "foo", the type is NodeVariable, and the element type does not affect classification (FIX-PARSER-2).

func (*GoParser) TSLanguageForFile

func (p *GoParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type GraphQLParser

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

GraphQLParser parses GraphQL (.graphql, .gql) schema and operation files using tree-sitter. Extracts type definitions, fields, enums, interfaces, unions, scalars, fragments, and directive definitions.

func NewGraphQLParser

func NewGraphQLParser() *GraphQLParser

NewGraphQLParser creates a ready-to-use GraphQLParser.

func (*GraphQLParser) Extensions

func (p *GraphQLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*GraphQLParser) Parse

func (p *GraphQLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single GraphQL file and merges them into the graph.

func (*GraphQLParser) TSLanguageForFile

func (p *GraphQLParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type GroovyParser

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

GroovyParser parses Groovy (.groovy, .gradle) source files.

func NewGroovyParser

func NewGroovyParser() *GroovyParser

NewGroovyParser creates a ready-to-use GroovyParser.

func (*GroovyParser) Extensions

func (p *GroovyParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*GroovyParser) Parse

func (p *GroovyParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Groovy file.

func (*GroovyParser) TSLanguageForFile

func (p *GroovyParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type HCLParser

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

HCLParser parses HCL/Terraform (.tf, .tfvars, .hcl) source files. It extracts resource, data, module, variable, output, locals, provider, and terraform blocks into graph nodes with appropriate types and metadata.

func NewHCLParser

func NewHCLParser() *HCLParser

NewHCLParser creates a ready-to-use HCLParser.

func (*HCLParser) Extensions

func (p *HCLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*HCLParser) Parse

func (p *HCLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single HCL/Terraform file.

func (*HCLParser) TSLanguageForFile

func (p *HCLParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type HaskellParser

type HaskellParser struct{}

HaskellParser parses Haskell (.hs, .lhs) source files. Used in fintech, compiler infrastructure, and functional programming teams. Uses regex-based extraction.

func NewHaskellParser

func NewHaskellParser() *HaskellParser

NewHaskellParser creates a ready-to-use HaskellParser.

func (*HaskellParser) Extensions

func (p *HaskellParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*HaskellParser) Parse

func (p *HaskellParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Haskell (.hs or .lhs) source file.

type JSONParser

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

JSONParser parses JSON (.json) files with filename-aware depth control. Full deep parsing is performed for known high-value filenames (package.json, tsconfig.json, jsconfig.json, *.schema.json). All other JSON files get shallow top-level-key extraction only.

func NewJSONParser

func NewJSONParser() *JSONParser

NewJSONParser creates a ready-to-use JSONParser.

func (*JSONParser) Extensions

func (p *JSONParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*JSONParser) Parse

func (p *JSONParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single JSON file and merges them into the graph.

Filename-aware strategy:

  • package.json: deep parse (name, version, dependencies, scripts)
  • tsconfig.json / jsconfig.json: compilerOptions and include/exclude
  • *.schema.json / schema.json: $defs/definitions as NodeStruct, properties as NodeField
  • all other .json: top-level keys as NodeField (1 level deep only)

func (*JSONParser) TSLanguageForFile

func (p *JSONParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type JavaParser

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

JavaParser parses Java (.java) source files.

func NewJavaParser

func NewJavaParser() *JavaParser

NewJavaParser creates a ready-to-use JavaParser.

func (*JavaParser) Extensions

func (p *JavaParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*JavaParser) Parse

func (p *JavaParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Java file and merges them into the graph.

func (*JavaParser) TSLanguageForFile

func (p *JavaParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type JavaScriptParser

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

JavaScriptParser parses JavaScript (.js, .jsx, .mjs, .cjs) source files.

func NewJavaScriptParser

func NewJavaScriptParser() *JavaScriptParser

NewJavaScriptParser creates a ready-to-use JavaScriptParser.

func (*JavaScriptParser) Extensions

func (p *JavaScriptParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*JavaScriptParser) Parse

func (p *JavaScriptParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single JavaScript file and merges them into the provided graph. The following constructs are captured:

  • Import declarations (ESM) → IMPORTS edges
  • CommonJS require() calls → IMPORTS edges
  • Function declarations → NodeFunction
  • Arrow functions (named) → NodeFunction
  • Method definitions → NodeMethod (class-qualified)
  • Class declarations → NodeStruct
  • Call expressions → call sites (resolved to CALLS edges)

func (*JavaScriptParser) TSLanguageForFile

func (p *JavaScriptParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type JsonnetParser

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

JsonnetParser parses Jsonnet (.jsonnet, .libsonnet) source files. It extracts:

  • Imports (local x = import 'path') → NodePackage + EdgeImports
  • Local variables (local x = value) at file level → NodeVariable
  • Object fields (field: value) → NodeVariable (exported)
  • Hidden fields (field:: value) → NodeVariable (unexported)
  • Function fields (field(params):: body) → NodeFunction
  • Local functions inside objects (local f(x) = body) → NodeFunction

func NewJsonnetParser

func NewJsonnetParser() *JsonnetParser

NewJsonnetParser creates a ready-to-use JsonnetParser.

func (*JsonnetParser) Extensions

func (p *JsonnetParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*JsonnetParser) Parse

func (p *JsonnetParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Jsonnet file.

The Jsonnet grammar structures files as a chain of local_bind nodes:

local_bind → local + bind + ; + (next local_bind | object | expr)

The final expression in the chain is typically an object literal containing the exported fields and functions.

func (*JsonnetParser) TSLanguageForFile

func (p *JsonnetParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type JuliaParser

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

JuliaParser parses Julia (.jl) source files.

func NewJuliaParser

func NewJuliaParser() *JuliaParser

NewJuliaParser creates a ready-to-use JuliaParser.

func (*JuliaParser) Extensions

func (p *JuliaParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*JuliaParser) Parse

func (p *JuliaParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Julia file and merges them into the graph.

func (*JuliaParser) TSLanguageForFile

func (p *JuliaParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type KotlinParser

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

KotlinParser parses Kotlin (.kt, .kts) source files.

func NewKotlinParser

func NewKotlinParser() *KotlinParser

NewKotlinParser creates a ready-to-use KotlinParser.

func (*KotlinParser) Extensions

func (p *KotlinParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*KotlinParser) Parse

func (p *KotlinParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Kotlin file.

func (*KotlinParser) TSLanguageForFile

func (p *KotlinParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type LanguageParser

type LanguageParser interface {
	// Extensions returns the file extensions this parser handles (e.g. ".go").
	Extensions() []string
	// Parse extracts code entities from src and merges them into g.
	Parse(g *graph.Graph, filePath string, src []byte) error
}

LanguageParser is implemented by each language-specific parser. Parse receives the raw source bytes and the file path; it appends discovered nodes and edges into the provided graph.

type LogicWarning

type LogicWarning struct {
	Check    string `json:"check"`    // check name, e.g. "zero_value_id"
	File     string `json:"file"`     // file path
	Line     int    `json:"line"`     // 1-based line number
	Message  string `json:"message"`  // human-readable description
	Severity string `json:"severity"` // "warning"
}

LogicWarning represents a single heuristic logic warning found by AST analysis.

func RunLogicChecks

func RunLogicChecks(filePath string, src []byte) []LogicWarning

RunLogicChecks parses the given source file and returns heuristic logic warnings. Only Go files are currently supported; other extensions return nil.

type LuaParser

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

LuaParser parses Lua (.lua) source files.

func NewLuaParser

func NewLuaParser() *LuaParser

NewLuaParser creates a ready-to-use LuaParser.

func (*LuaParser) Extensions

func (p *LuaParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*LuaParser) Parse

func (p *LuaParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Lua file.

func (*LuaParser) TSLanguageForFile

func (p *LuaParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type MATLABParser

type MATLABParser struct{}

MATLABParser parses MATLAB/Octave source files (.m).

Extracts:

  • classdef declarations → NodeStruct (with superclass edges)
  • properties blocks → NodeVariable per property
  • methods blocks → NodeFunction/NodeMethod per function_definition
  • top-level function_definition → NodeFunction

func NewMATLABParser

func NewMATLABParser() *MATLABParser

NewMATLABParser returns a new MATLAB parser.

func (*MATLABParser) Extensions

func (p *MATLABParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*MATLABParser) Language

func (p *MATLABParser) Language() string

Language returns the language name.

func (*MATLABParser) Parse

func (p *MATLABParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse parses a MATLAB file into the graph.

func (*MATLABParser) TSLanguageForFile

func (p *MATLABParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type MakefileParser

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

MakefileParser parses Makefile source files. It extracts variable assignments, build targets (rules), define directives, and include directives from GNU Make and compatible Makefiles.

func NewMakefileParser

func NewMakefileParser() *MakefileParser

NewMakefileParser creates a ready-to-use MakefileParser.

func (*MakefileParser) Extensions

func (p *MakefileParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*MakefileParser) Filenames

func (p *MakefileParser) Filenames() []string

Filenames returns the exact base filenames handled by this parser. These are files that have no extension (e.g. "Makefile") or use standard naming conventions for GNU Make.

func (*MakefileParser) Parse

func (p *MakefileParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Makefile and merges them into the graph.

Extracts:

  • File node -> NodeFile
  • Variable assignments -> NodeVariable with kind="variable"
  • Rules/targets -> NodeFunction with kind="target"
  • Define directives -> NodeFunction with kind="define"
  • Include directives -> EdgeImports to NodePackage

func (*MakefileParser) TSLanguageForFile

func (p *MakefileParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type MarkdownParser

type MarkdownParser struct{}

MarkdownParser extracts structural sections from Markdown files (.md, .markdown, .mdx). Each ATX or setext heading becomes a Section node with CONTAINS edges forming a tree. Cross-document [text](path.md) links become LINKS_TO edges. Entity linking (EXPLAINS/DOCUMENTED_BY) is deferred to resolver.ResolveDocEdges which runs after all files are parsed, ensuring code entities are available.

Handles:

  • ATX headings (# H1 through ###### H6) per CommonMark
  • Setext headings (underline-style === and ---) per CommonMark
  • YAML/TOML frontmatter (--- block at top of file) is skipped
  • Headings inside fenced code blocks (``` or ~~~) are skipped
  • Duplicate heading titles disambiguated with counter suffix

func NewMarkdownParser

func NewMarkdownParser() *MarkdownParser

NewMarkdownParser returns a parser for Markdown documentation files.

func (*MarkdownParser) Extensions

func (p *MarkdownParser) Extensions() []string

Extensions returns the file extensions handled by MarkdownParser.

func (*MarkdownParser) Parse

func (p *MarkdownParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts heading-based sections from a Markdown file. Creates: file node, Section nodes (one per heading), CONTAINS edges (hierarchy), and LINKS_TO edges for relative markdown links.

type NixParser

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

NixParser parses Nix (.nix) expression files. It extracts let bindings, attribute set keys, function parameters, and import expressions into graph nodes. Nix is a pure functional language for the Nix package manager — its main entities are bindings and derivations rather than traditional functions/classes.

func NewNixParser

func NewNixParser() *NixParser

NewNixParser creates a ready-to-use NixParser.

func (*NixParser) Extensions

func (p *NixParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*NixParser) Parse

func (p *NixParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Nix file.

func (*NixParser) TSLanguageForFile

func (p *NixParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type OCamlParser

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

OCamlParser parses OCaml (.ml, .mli) source files.

func NewOCamlParser

func NewOCamlParser() *OCamlParser

NewOCamlParser creates a ready-to-use OCamlParser.

func (*OCamlParser) Extensions

func (p *OCamlParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*OCamlParser) Parse

func (p *OCamlParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single OCaml file.

func (*OCamlParser) TSLanguageForFile

func (p *OCamlParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type ObjCParser

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

ObjCParser parses Objective-C (.m, .h) source files.

Extracted entities:

  • @interface blocks → NodeStruct (classes) with superclass and protocol metadata
  • Method declarations inside @interface → NodeMethod with selector and scope metadata
  • @property declarations inside @interface → NodeMethod (kind=property)
  • @protocol declarations → NodeInterface
  • Method declarations inside @protocol → NodeMethod
  • @implementation blocks → NodeStruct (if not already from @interface) + methods
  • #import / #include directives → NodePackage with EdgeImports

NS_ENUM / typedef enum are not extracted (complex to parse cleanly from tree-sitter).

func NewObjCParser

func NewObjCParser() *ObjCParser

NewObjCParser creates a ready-to-use ObjCParser.

func (*ObjCParser) Extensions

func (p *ObjCParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ObjCParser) Parse

func (p *ObjCParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Objective-C file and merges them into the graph.

func (*ObjCParser) TSLanguageForFile

func (p *ObjCParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type PHPParser

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

PHPParser parses PHP (.php) source files.

func NewPHPParser

func NewPHPParser() *PHPParser

NewPHPParser creates a ready-to-use PHPParser.

func (*PHPParser) Extensions

func (p *PHPParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*PHPParser) Parse

func (p *PHPParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single PHP file.

func (*PHPParser) TSLanguageForFile

func (p *PHPParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type PerlParser

type PerlParser struct{}

PerlParser parses Perl source files (.pl, .pm, .t).

Extracts:

  • package declarations → NodePackage
  • subroutine declarations → NodeFunction (exported if name doesn't start with _)
  • our/my variable declarations at file scope → NodeVariable
  • use statements (imports) → NodePackage edges

func NewPerlParser

func NewPerlParser() *PerlParser

NewPerlParser returns a new Perl parser.

func (*PerlParser) Extensions

func (p *PerlParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*PerlParser) Language

func (p *PerlParser) Language() string

Language returns the language name.

func (*PerlParser) Parse

func (p *PerlParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse parses a Perl file into the graph.

func (*PerlParser) TSLanguageForFile

func (p *PerlParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type PlaintextParser

type PlaintextParser struct{}

PlaintextParser extracts structural sections from plain text (.txt) and reStructuredText (.rst) files. Like MarkdownParser, each detected heading becomes a Section node with CONTAINS edges forming a tree.

RST heading detection follows the docutils spec: a text line followed by an underline of repeated punctuation characters (=, -, ~, ^, ", #, +, *, .) where the underline is at least as long as the text. An optional overline (same character) promotes the heading. Heading depth is assigned by the order in which underline characters first appear in the file.

TXT heading detection uses heuristics:

  • ALL-CAPS lines of 3+ characters → depth 1
  • Lines ending with ":" preceded by a blank line → depth 2
  • Fallback: double-blank-line separated paragraphs → depth 1

func NewPlaintextParser

func NewPlaintextParser() *PlaintextParser

NewPlaintextParser returns a parser for plaintext and RST documentation files.

func (*PlaintextParser) Extensions

func (p *PlaintextParser) Extensions() []string

Extensions returns the file extensions handled by PlaintextParser.

func (*PlaintextParser) Parse

func (p *PlaintextParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts heading-based sections from a plaintext or RST file.

type PluginChecker

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

PluginChecker validates whether a plugin command is allowed to execute. It reads the allowlist from the user's home directory (~/.synapses/).

func NewPluginChecker

func NewPluginChecker(synapsesDir string) *PluginChecker

NewPluginChecker creates a checker that reads allowlists from synapsesDir. synapsesDir is typically ~/.synapses.

func (*PluginChecker) ApproveCommand

func (pc *PluginChecker) ApproveCommand(command string) error

ApproveCommand adds a command to the per-machine allowlist.

func (*PluginChecker) IsAllowed

func (pc *PluginChecker) IsAllowed(command string) error

IsAllowed checks whether a plugin command is approved for execution. Returns nil if allowed, a descriptive error if not.

func (*PluginChecker) ListApproved

func (pc *PluginChecker) ListApproved() map[string]string

ListApproved returns all currently approved commands.

func (*PluginChecker) RevokeCommand

func (pc *PluginChecker) RevokeCommand(command string) error

RevokeCommand removes a command from the per-machine allowlist.

type PluginParser

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

PluginParser implements LanguageParser by spawning an external process. One process is spawned per file; the process lifetime is bounded by pluginTimeout.

func (*PluginParser) Extensions

func (p *PluginParser) Extensions() []string

Extensions implements LanguageParser.

func (*PluginParser) Parse

func (p *PluginParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse implements LanguageParser. It spawns the plugin process, writes the file path + content to stdin, reads JSON from stdout, and merges the resulting nodes and edges into g.

type PowerShellParser

type PowerShellParser struct{}

PowerShellParser parses PowerShell (.ps1, .psm1, .psd1) source files. Uses regex-based extraction since PowerShell is not in go-tree-sitter.

func NewPowerShellParser

func NewPowerShellParser() *PowerShellParser

NewPowerShellParser creates a ready-to-use PowerShellParser.

func (*PowerShellParser) Extensions

func (p *PowerShellParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*PowerShellParser) Parse

func (p *PowerShellParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single PowerShell file and merges them into the graph.

type ProtobufParser

type ProtobufParser struct{}

ProtobufParser parses Protocol Buffer (.proto) source files using github.com/emicklei/proto — a dedicated proto parser that handles oneof blocks, nested messages, and enum values correctly without producing [ERROR] nodes (the fundamental limitation of the tree-sitter proto grammar).

func NewProtobufParser

func NewProtobufParser() *ProtobufParser

NewProtobufParser creates a ready-to-use ProtobufParser.

func (*ProtobufParser) Extensions

func (p *ProtobufParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ProtobufParser) Parse

func (p *ProtobufParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single .proto file.

type PythonParser

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

PythonParser parses Python (.py, .pyi) source files.

func NewPythonParser

func NewPythonParser() *PythonParser

NewPythonParser creates a ready-to-use PythonParser.

func (*PythonParser) Extensions

func (p *PythonParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*PythonParser) Parse

func (p *PythonParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Python file and merges them into the provided graph.

func (*PythonParser) TSLanguageForFile

func (p *PythonParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type RBSParser

type RBSParser struct{}

RBSParser parses Ruby RBS type signature files (.rbs). RBS files use a dedicated syntax (not Ruby) so we parse them line-by-line rather than using the tree-sitter Ruby grammar. We emit classes, modules, interfaces, and method signatures as graph nodes.

func NewRBSParser

func NewRBSParser() *RBSParser

NewRBSParser creates a ready-to-use RBSParser.

func (*RBSParser) Extensions

func (p *RBSParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*RBSParser) Parse

func (p *RBSParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single RBS file. RBS syntax examples:

class Foo < Bar                  → NodeStruct
module Baz                       → NodeInterface
interface _Iterator[T]           → NodeInterface with kind="interface"
def initialize: (String) -> void → NodeMethod
def self.create: (Integer) -> Foo → NodeMethod with kind="singleton"
type alias_name = Integer        → NodeStruct with kind="alias"

type RParser

type RParser struct{}

RParser parses R (.r, .R) source files. Used extensively in data science, statistics, bioinformatics, finance, and pharma. Uses regex-based extraction since R is not in go-tree-sitter.

Extracts:

  • Function assignments (<-, =, <<-) → NodeFunction
  • S3 generic functions (summary.myClass) → NodeFunction with kind=s3generic
  • S4 setClass() → NodeStruct with kind=s4class
  • S4 setGeneric() → NodeFunction with kind=s4generic
  • S4 setMethod() → NodeFunction with kind=s4method
  • R5/Reference classes (setRefClass) → NodeStruct with kind=r5class
  • library()/require() imports → NodePackage + EdgeImports
  • Namespace pkg::func references → EdgeImports

func NewRParser

func NewRParser() *RParser

NewRParser creates a ready-to-use RParser.

func (*RParser) Extensions

func (p *RParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*RParser) Parse

func (p *RParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single R source file and merges them into g.

type RelationshipSignal

type RelationshipSignal struct {
	From       string
	To         string
	Signal     string // e.g. "depends on", "implements", "uses"
	SourceLine int
}

RelationshipSignal is a keyword-based relationship hint extracted from text. From and To are candidate names; Signal is the relationship keyword found. These are upgraded to typed EdgeType values by Tier 1/2 resolution.

func ExtractRelationshipSignals

func ExtractRelationshipSignals(text string, candidates []EntityCandidate) []RelationshipSignal

ExtractRelationshipSignals scans text for explicit relationship keywords and returns relationship signals between adjacent entity candidates. Best-effort: only fires when a relationship keyword appears between two recognisable entity-like tokens on the same line.

type RouteRegistration

type RouteRegistration struct {
	File        string
	Line        int    // 1-based line number of the registration call
	Method      string // HTTP method ("GET", "POST", …) or "*" for wildcard
	Path        string // URL path e.g. "/api/users"
	Handler     string // handler function name
	EnclosingFn string // function/method that contains the registration call
	Confidence  float64
}

RouteRegistration holds a single detected route registration.

func ExtractRouteRegistrations

func ExtractRouteRegistrations(filePath string, src []byte) []RouteRegistration

ExtractRouteRegistrations scans src for handler registration patterns and returns a slice of RouteRegistration describing each match. filePath is used to select the right language-specific patterns.

type RubyParser

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

RubyParser parses Ruby (.rb) source files.

func NewRubyParser

func NewRubyParser() *RubyParser

NewRubyParser creates a ready-to-use RubyParser.

func (*RubyParser) Extensions

func (p *RubyParser) Extensions() []string

Extensions returns the file extensions handled by this parser. .rbi files are Sorbet type stubs — they use Ruby syntax, so the same tree-sitter Ruby grammar handles them correctly.

func (*RubyParser) Parse

func (p *RubyParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Ruby file.

func (*RubyParser) TSLanguageForFile

func (p *RubyParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type RustParser

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

RustParser parses Rust (.rs) source files.

func NewRustParser

func NewRustParser() *RustParser

NewRustParser creates a ready-to-use RustParser.

func (*RustParser) Extensions

func (p *RustParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*RustParser) Parse

func (p *RustParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Rust file and merges them into the graph.

func (*RustParser) TSLanguageForFile

func (p *RustParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type SCSSParser

type SCSSParser struct{}

SCSSParser parses SCSS and Sass (.scss, .sass) source files using regex.

Extracts:

  • @mixin name(params) { } → NodeFunction with kind="mixin"
  • @function name(params) { } → NodeFunction with kind="function"
  • $variable: value; → NodeVariable with kind="variable"
  • %placeholder { } → NodeStruct with kind="placeholder"
  • Top-level .class, #id, and %placeholder selectors → NodeStruct with kind="selector"
  • Multiple selectors on one line (.a, .b { }) → each extracted separately
  • @use / @forward / @import → EdgeImports to NodePackage nodes
  • @include mixin-name → AddCallSite for cross-file resolution + direct EdgeCalls for same-file mixins
  • @extend .selector / %placeholder → EdgeCalls to extended node

func NewSCSSParser

func NewSCSSParser() *SCSSParser

NewSCSSParser creates a ready-to-use SCSSParser.

func (*SCSSParser) Extensions

func (p *SCSSParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*SCSSParser) Parse

func (p *SCSSParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single SCSS/Sass file and merges them into the graph.

type SQLParser

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

SQLParser parses SQL (.sql) source files, extracting CREATE TABLE, VIEW, FUNCTION, PROCEDURE, TRIGGER, and INDEX declarations as graph nodes.

func NewSQLParser

func NewSQLParser() *SQLParser

NewSQLParser creates a ready-to-use SQLParser.

func (*SQLParser) Extensions

func (p *SQLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*SQLParser) Parse

func (p *SQLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single SQL file and merges them into the graph.

Strategy: tree-sitter SQL grammars vary widely in their node types across versions. Instead of relying on specific statement types, we walk the AST recursively and inspect the source text of each node for CREATE keywords. This makes the parser resilient to grammar changes while still leveraging tree-sitter for accurate statement boundary detection.

func (*SQLParser) TSLanguageForFile

func (p *SQLParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type ScalaParser

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

ScalaParser parses Scala (.scala) source files.

func NewScalaParser

func NewScalaParser() *ScalaParser

NewScalaParser creates a ready-to-use ScalaParser.

func (*ScalaParser) Extensions

func (p *ScalaParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ScalaParser) Parse

func (p *ScalaParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Scala file.

func (*ScalaParser) TSLanguageForFile

func (p *ScalaParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type SolidityParser

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

SolidityParser parses Solidity (.sol) source files.

func NewSolidityParser

func NewSolidityParser() *SolidityParser

NewSolidityParser creates a ready-to-use SolidityParser.

func (*SolidityParser) Extensions

func (p *SolidityParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*SolidityParser) Parse

func (p *SolidityParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Solidity file and merges them into the graph.

func (*SolidityParser) TSLanguageForFile

func (p *SolidityParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type StarlarkParser

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

StarlarkParser parses Starlark/Bazel (.bzl, .star, BUILD, WORKSPACE) files. It extracts function definitions, build targets, load() imports, and top-level variable assignments.

func NewStarlarkParser

func NewStarlarkParser() *StarlarkParser

NewStarlarkParser creates a ready-to-use StarlarkParser.

func (*StarlarkParser) Extensions

func (p *StarlarkParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*StarlarkParser) Filenames

func (p *StarlarkParser) Filenames() []string

Filenames returns the exact base filenames handled by this parser.

func (*StarlarkParser) Parse

func (p *StarlarkParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Starlark/Bazel file and merges them into the graph.

Extracts:

  • File node (NodeFile)
  • function_definition -> NodeFunction
  • Top-level call to known rule function -> NodeStruct with kind="target"
  • load() calls -> EdgeImports for each loaded symbol
  • Top-level assignments -> NodeVariable

func (*StarlarkParser) TSLanguageForFile

func (p *StarlarkParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type SvelteParser

type SvelteParser struct{}

SvelteParser parses Svelte (.svelte) single-file components.

Extracts:

  • Script block imports (import X from 'module') → EdgeImports
  • Component imports (import Comp from './Comp.svelte') → EdgeImports
  • Exported variables (export let propName) → NodeVariable with kind="prop"
  • Reactive declarations ($: computed = ...) → NodeVariable with kind="reactive"
  • Function declarations (function name() {}) → NodeFunction
  • Script-level const/let variables → NodeVariable
  • Svelte component usage (<Component />) → EdgeCalls

func NewSvelteParser

func NewSvelteParser() *SvelteParser

NewSvelteParser creates a ready-to-use SvelteParser.

func (*SvelteParser) Extensions

func (p *SvelteParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*SvelteParser) Parse

func (p *SvelteParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Svelte file and merges them into the graph.

type SwiftParser

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

SwiftParser parses Swift (.swift) source files.

func NewSwiftParser

func NewSwiftParser() *SwiftParser

NewSwiftParser creates a ready-to-use SwiftParser.

func (*SwiftParser) Extensions

func (p *SwiftParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*SwiftParser) Parse

func (p *SwiftParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Swift file and merges them into the graph.

func (*SwiftParser) TSLanguageForFile

func (p *SwiftParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type TOMLParser

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

TOMLParser parses TOML (.toml) configuration files. It extracts sections (tables), array-of-tables, and key-value pairs into graph nodes. Special handling is provided for dependency sections commonly found in Cargo.toml, pyproject.toml, etc.

func NewTOMLParser

func NewTOMLParser() *TOMLParser

NewTOMLParser creates a ready-to-use TOMLParser.

func (*TOMLParser) Extensions

func (p *TOMLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*TOMLParser) Parse

func (p *TOMLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single TOML file and merges them into the graph.

Extraction rules:

  • [section] headers → NodeStruct with kind=table
  • [[array]] headers → NodeStruct with kind=array_table
  • Top-level pair nodes (before any section) → NodeField with kind=field
  • For [dependencies] / [dev-dependencies] / [build-dependencies]: each pair also emits a NodeField with kind=dependency
  • Dotted keys like [profile.release] → name = "profile.release"

func (*TOMLParser) TSLanguageForFile

func (p *TOMLParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type TerraformParser

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

TerraformParser parses HashiCorp Configuration Language (.tf) files. It extracts Terraform resources, data sources, modules, variables, outputs, locals, and providers as graph nodes, and records TerraformRefs for cross-file DEPENDS_ON resolution (resolved post-parse by ResolveTerraformRefs).

func NewTerraformParser

func NewTerraformParser() *TerraformParser

NewTerraformParser creates a ready-to-use TerraformParser.

func (*TerraformParser) Extensions

func (p *TerraformParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*TerraformParser) Parse

func (p *TerraformParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts Terraform entities from a single .tf file and merges them into g.

Node mapping:

  • resource → NodeStruct (name: "resource_type.resource_name")
  • data → NodeStruct (name: "data.resource_type.resource_name")
  • module → NodePackage (name: "module.label")
  • variable → NodeVariable (name: "var.label")
  • output → NodeVariable (name: "output.label")
  • locals → NodeVariable (name: "local.key") per key in the block
  • provider → NodeStruct (name: "provider.label")

All nodes carry Domain=DomainInfra and metadata domain="terraform", kind=<type>. Resource references found in attribute expressions are recorded as TerraformRefs for cross-file DEPENDS_ON resolution by ResolveTerraformRefs (resolver package).

func (*TerraformParser) TSLanguageForFile

func (p *TerraformParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile implements TreeSitterLanguageProvider so the watcher can pre-check .tf files for parse errors during active editing.

type ThriftParser

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

ThriftParser parses Apache Thrift IDL (.thrift) source files.

Extracted entities:

  • namespace declarations → NodePackage (kind=namespace, metadata lang=<scope>)
  • typedef definitions → NodeMethod (kind=typedef, metadata alias=<original_type>)
  • enum definitions → NodeStruct (kind=enum) + enum value identifiers → NodeMethod
  • struct definitions → NodeStruct (kind=struct) + fields → NodeMethod (kind=field)
  • exception definitions → NodeStruct (kind=exception) + fields → NodeMethod (kind=field)
  • union definitions → NodeStruct (kind=union) + fields → NodeMethod (kind=field)
  • const definitions → NodeMethod (kind=const, metadata type=<type>)
  • service definitions → NodeInterface (kind=service) + function_definition → NodeMethod

All top-level Thrift definitions are Exported=true (IDL is a public interface by definition).

AST node types verified via TestProbeThrift:

document → top-level container
namespace_declaration: [namespace][namespace_scope][namespace]
typedef_definition: [typedef][definition_type][typedef_identifier]
enum_definition: [enum][identifier]{[identifier][=][number][,]...}
struct_definition: [struct][identifier]{[field]...}
exception_definition: [exception][identifier]{[field]...}
service_definition: [service][identifier]{[function_definition]...}
union_definition: [union][identifier]{[field]...}
const_definition: [const][definition_type][identifier][=][literal]
field: [field_id][field_modifier?][type][identifier][,?]
function_definition: [type][identifier][parameters][throws?][,?]

func NewThriftParser

func NewThriftParser() *ThriftParser

NewThriftParser creates a ready-to-use ThriftParser.

func (*ThriftParser) Extensions

func (p *ThriftParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ThriftParser) Parse

func (p *ThriftParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Thrift IDL file and merges them into the graph.

func (*ThriftParser) TSLanguageForFile

func (p *ThriftParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type TreeSitterLanguageProvider

type TreeSitterLanguageProvider interface {
	TSLanguageForFile(filePath string) *sitter.Language
}

TreeSitterLanguageProvider is an optional interface for parsers that use tree-sitter internally. Returning the language enables the watcher to pre-check files for parse errors before updating the graph, preventing corrupted ASTs from half-saved files during active editing.

type TypeScriptParser

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

TypeScriptParser parses TypeScript (.ts) and TSX (.tsx) source files.

func NewTypeScriptParser

func NewTypeScriptParser() *TypeScriptParser

NewTypeScriptParser creates a ready-to-use TypeScriptParser.

func (*TypeScriptParser) Extensions

func (p *TypeScriptParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*TypeScriptParser) Parse

func (p *TypeScriptParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single TypeScript/TSX file and merges them into the provided graph.

func (*TypeScriptParser) TSLanguageForFile

func (p *TypeScriptParser) TSLanguageForFile(filePath string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

type VueParser

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

VueParser parses Vue Single-File Components (.vue files).

Extracts:

  • A component node (NodeStruct, kind=component) named after the filename
  • Script block content re-parsed via JS or TS sub-parser for functions, classes, imports, variables, etc.
  • Style block metadata (scoped flag, language)

The Vue grammar provides raw_text for script/style content rather than a parsed AST, so script content is delegated to the JS/TS sub-parsers.

func NewVueParser

func NewVueParser() *VueParser

NewVueParser creates a ready-to-use VueParser.

func (*VueParser) Extensions

func (p *VueParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*VueParser) Parse

func (p *VueParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Vue SFC file and merges them into the provided graph.

func (*VueParser) TSLanguageForFile

func (p *VueParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type Walker

type Walker struct {

	// BeginFunc is called once, on the main goroutine, after the filesystem
	// scan completes and the total file count is known, but before any parsing
	// begins. Use this to initialise progress state with the real total.
	// Set to nil to disable.
	BeginFunc func(total int)

	// ProgressFunc is called from worker goroutines after each file is parsed.
	// done is the number of files completed so far; total is the same value
	// passed to BeginFunc. byExt maps file extension (e.g. ".go") to the
	// number of files of that type parsed so far (snapshot copy — safe to read
	// without locking). Calls are throttled to at most 1 per 200ms via an
	// atomic CAS; the final call (done==total) always fires.
	// The callback is called from multiple goroutines; implementations must be
	// goroutine-safe. Set to nil to disable progress reporting.
	ProgressFunc func(done, total int, byExt map[string]int)

	// PulseClient, when non-nil, receives a ParseEvent after each file is
	// parsed during WalkDir. Fire-and-forget — never blocks parsing. (P2-2)
	PulseClient *pulse.Client
	// ProjectID is included in ParseEvent so Pulse can scope data per project.
	ProjectID string

	// Throttle reduces parsing concurrency to half the normal worker count
	// and lowers the OS scheduling priority (nice +10). Use this for the
	// initial full-index so the machine stays responsive during the first
	// impression — incremental updates are already fast and don't need this.
	Throttle bool
	// contains filtered or unexported fields
}

Walker orchestrates multi-language parsing over a directory tree.

func NewWalker

func NewWalker() *Walker

NewWalker creates a Walker pre-loaded with all built-in language parsers. Registration order matters: generic (file-only) is registered first so that dedicated AST parsers registered afterward take precedence for their extensions.

func (*Walker) HasParseErrors

func (w *Walker) HasParseErrors(path string, src []byte) bool

HasParseErrors performs a lightweight tree-sitter parse of src and returns true if the resulting AST contains syntax errors. Used by the watcher to skip reparsing files that are mid-save (half-written), preventing corrupted AST data from replacing valid graph nodes.

Returns false for parsers that don't use tree-sitter or for unknown extensions.

func (*Walker) IncrementalReindex

func (w *Walker) IncrementalReindex(g *graph.Graph, root string, known map[string]int64) (fresh map[string]int64, changed, removed int, err error)

IncrementalReindex re-parses only files whose modification time has changed since the last full index. g must be a fully-populated graph (e.g. loaded from SQLite). known maps absolute path → UnixNano mtime from the last index.

Returns: fresh mtime map (all current parseable files), # changed/new files, # removed files (deleted from disk since last index).

Note: CALLS edges from unchanged files that point INTO re-parsed files may be lost if the re-parsed file's node IDs changed. Run a full reindex if perfect edge fidelity is required.

func (*Walker) ParseFile

func (w *Walker) ParseFile(g *graph.Graph, path string) error

ParseFile parses a single file and updates g. If the file extension is not supported it returns nil without error.

func (*Walker) ParseFileSrc

func (w *Walker) ParseFileSrc(g *graph.Graph, path string, src []byte) error

ParseFileSrc parses a single file from pre-read bytes and updates g. It is identical to ParseFile but skips the os.ReadFile call, allowing callers that already hold the file bytes (e.g. for error checking or content hashing) to avoid a second disk read. If the file extension is not supported it returns nil without error.

func (*Walker) Register

func (w *Walker) Register(p LanguageParser)

Register adds a language parser. If two parsers claim the same extension the last one registered wins.

func (*Walker) RegisterPlugin

func (w *Walker) RegisterPlugin(extensions []string, command string, checker *PluginChecker)

RegisterPlugin adds an external parser plugin for the given file extensions. command is split on whitespace into binary + args (e.g. "node parsers/graphql.js"). If two parsers claim the same extension the last one registered wins, so plugins registered here override built-in parsers for their extensions.

If checker is non-nil, the command is validated against the per-machine allowlist before registration. Unapproved plugins are skipped with a stderr warning.

func (*Walker) WalkDir

func (w *Walker) WalkDir(g *graph.Graph, root string) (map[string]int64, error)

WalkDir recursively parses all supported files under root and populates g. It skips hidden directories (prefixed with ".") and common non-source dirs. Returns a map of absolute file path → modification time (UnixNano) for every file that was successfully (or non-fatally) parsed. This map can be persisted to the store and used by IncrementalReindex on subsequent runs.

Parsing is parallelised across min(runtime.NumCPU(), 8) workers. All language parsers create a fresh sitter.Parser per call so there is no shared mutable state between goroutines. Graph mutations are protected by Graph's own mutex.

type XMLParser

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

XMLParser parses XML files (.xml) using tree-sitter. It performs schema-aware extraction based on filename:

  • pom.xml (Maven): project identity, dependencies, plugins, modules
  • AndroidManifest.xml: activities, services, receivers, permissions
  • *context.xml / *config.xml (Spring): beans, imports
  • Generic XML: root element, direct children with id/name attributes

func NewXMLParser

func NewXMLParser() *XMLParser

NewXMLParser creates a ready-to-use XMLParser.

func (*XMLParser) Extensions

func (p *XMLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*XMLParser) Parse

func (p *XMLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single XML file.

func (*XMLParser) TSLanguageForFile

func (p *XMLParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for the given file.

type YAMLParser

type YAMLParser struct{}

YAMLParser parses YAML (.yaml, .yml) files. Covers Kubernetes manifests, Docker Compose, GitHub Actions, Ansible, Helm, OpenAPI, and general config. Uses gopkg.in/yaml.v3 for proper AST-level parsing (not regex).

func NewYAMLParser

func NewYAMLParser() *YAMLParser

NewYAMLParser creates a ready-to-use YAMLParser.

func (*YAMLParser) Extensions

func (p *YAMLParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*YAMLParser) Parse

func (p *YAMLParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single YAML file and merges them into the graph.

It handles multi-document YAML (--- separated) and is schema-aware for:

  • Kubernetes manifests (kind + metadata.name)
  • Docker Compose (services)
  • GitHub Actions (jobs, on triggers)
  • Ansible playbooks (top-level tasks with name field)

General extraction:

  • Top-level keys → NodeVariable with kind=key
  • YAML anchors (&name) → NodeVariable with kind=anchor
  • String values matching *.yaml or *.yml → EdgeImports

type ZigParser

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

ZigParser parses Zig (.zig) source files.

func NewZigParser

func NewZigParser() *ZigParser

NewZigParser creates a ready-to-use ZigParser.

func (*ZigParser) Extensions

func (p *ZigParser) Extensions() []string

Extensions returns the file extensions handled by this parser.

func (*ZigParser) Parse

func (p *ZigParser) Parse(g *graph.Graph, filePath string, src []byte) error

Parse extracts code entities from a single Zig file and merges them into the graph.

func (*ZigParser) TSLanguageForFile

func (p *ZigParser) TSLanguageForFile(_ string) *sitter.Language

TSLanguageForFile returns the tree-sitter language for this parser.

Jump to

Keyboard shortcuts

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