Skip to main content

Go API overview

The public package is github.com/enolalabs/sunset/pkg/sunset. It parses one source file at a time and exposes a tree-sitter-backed wrapper for inspection. The CLI engine and Markdown renderer are internal packages; they are not required to use this API.

Parse a file

result, err := sunset.ParseFile("main.go")
if err != nil {
return err
}
defer result.Close()

root := result.Tree.RootNode()
fmt.Println(result.Language, root.Type())

ParseFile reads the file, detects a language from its extension, parses it, and returns FileResult. Close releases the underlying C resources and must be called when the result is no longer needed.

Public entry points

  • ParseFile(path string, opts ...Option) (*FileResult, error) parses one file.
  • WithLanguage(id string) Option forces a registered language ID.
  • Languages() []LanguageInfo lists language names, IDs, and extensions.
  • FileResult.HasErrors() reports syntax errors while the result is open.
  • TreeWrapper.RootNode, Walk, and Filter inspect the syntax tree.

See Node and tree operations for traversal and coordinates.