parser

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

General-purpose parser for Go source files, using the Task interface to specify behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(t Task, rootDir string, splitByDir bool, threads int) error

Runs the specified task on all Go source files in the given directory. If `splitByDir` is true, parses each top-level directory in the specified directory separately (ignoring top-level Go files). todo maybe update the Task interface to include a method for getting flags (to avoid passing so many boilerplate params)

Types

type Task

type Task interface {
	// Return the lowercase name of the task
	Name() string

	// Function called on every Go source file in the project, which may modify local state to save results
	Visit(file *ast.File, fset *token.FileSet, typeInfo *types.Info)

	// Create a new instance of the task with the same initial state and flags.
	// Used to ensure that each parsed directory can have an independent output.
	Clone() Task

	// Set the project directory for this task. Often used after Clone to set the directory for the new instance.
	SetProjectDir(dir string)

	// Function called after all files in the specified project directory have been processed
	ReportResults() error

	// Close any resources used by this task and its clones, like file handles.
	// Should only be called once after all instances of the task have finished, i.e. the parser is completely finished.
	Close()
}

The Task interface defines a task that can be performed on all the Go source files in a project. This includes a method to visit each source file, and another to report results after all files have been processed. Implementations should include fields (either public or private) to track progress, results, etc. across the entire project.

Jump to

Keyboard shortcuts

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