Documentation ¶
Index ¶
- Constants
- func FileNameToSitterLanguage(filename string) (*sitter.Language, error)
- func GetLanguageGlobs(lang string) ([]string, error)
- func LanguageNameToSitterLanguage(name string) (*sitter.Language, error)
- type Capture
- type Match
- type OakCommand
- func (oc *OakCommand) DumpTree(tree *sitter.Tree)
- func (oc *OakCommand) GetLanguage() (*sitter.Language, error)
- func (oc *OakCommand) Parse(ctx context.Context, oldTree *sitter.Tree, code []byte) (*sitter.Tree, error)
- func (oc *OakCommand) PrintQueries(w io.Writer) error
- func (oc *OakCommand) Render(results QueryResults) (string, error)
- func (oc *OakCommand) RenderQueries(layers *layers.ParsedLayers) error
- func (oc *OakCommand) RenderWithTemplate(results QueryResults, tmpl *template.Template) (string, error)
- func (oc *OakCommand) RenderWithTemplateFile(results QueryResults, file string) (string, error)
- func (oc *OakCommand) ResultsToJSON(results QueryResults, f io.Writer) error
- func (oc *OakCommand) ResultsToYAML(results QueryResults, f io.Writer) error
- type OakCommandDescription
- type OakCommandLoader
- func (o *OakCommandLoader) IsFileSupported(f fs.FS, fileName string) bool
- func (o *OakCommandLoader) LoadCommandAliasFromYAML(s io.Reader, options ...alias.Option) ([]*alias.CommandAlias, error)
- func (o *OakCommandLoader) LoadCommands(f fs.FS, entryName string, options []cmds.CommandDescriptionOption, ...) ([]cmds.Command, error)
- type OakCommandOption
- type OakGlazeCommand
- type OakGlazedCommandLoader
- func (o *OakGlazedCommandLoader) IsFileSupported(f fs.FS, fileName string) bool
- func (o *OakGlazedCommandLoader) LoadCommandAliasFromYAML(s io.Reader, options ...alias.Option) ([]*alias.CommandAlias, error)
- func (o *OakGlazedCommandLoader) LoadCommands(f fs.FS, entryName string, options []cmds.CommandDescriptionOption, ...) ([]cmds.Command, error)
- type OakParameterLayer
- type OakSettings
- type OakWriterCommand
- type QueryResults
- type Result
- type RunSettings
- type SitterQuery
Constants ¶
const OakSlug = "oak"
Variables ¶
This section is empty.
Functions ¶
func GetLanguageGlobs ¶ added in v0.1.1
Types ¶
type Capture ¶
type Capture struct { // Name if the capture name from the query Name string // Text is the actual text that was captured Text string // Type is the Treesitter type of the captured node Type string // TODO(manuel, 2023-04-23): Add more information about the capture // for example: offset, line number, filename, query name, ... StartByte uint32 EndByte uint32 StartPoint sitter.Point EndPoint sitter.Point }
type OakCommand ¶
type OakCommand struct { Language string `yaml:"language,omitempty"` Queries []SitterQuery `yaml:"queries"` Template string `yaml:"template"` SitterLanguage *sitter.Language *cmds.CommandDescription }
func (*OakCommand) DumpTree ¶
func (oc *OakCommand) DumpTree(tree *sitter.Tree)
DumpTree prints the tree out to the console. This is lifted straight from example_test in the smacker/sitter repo.
The output format is:
source_file [0-29]
function_declaration [0-29] func [0-4] name: identifier [5-6] parameters: parameter_list [6-29] ( [6-7] parameter_declaration [7-18] name: identifier [7-8] , [8-9] name: identifier [10-11] , [11-12] name: identifier [13-14] type: type_identifier [15-18]
The recursive cursor walker from the documentation didn't seem to work, at least on the hcl file.
func (*OakCommand) GetLanguage ¶
func (oc *OakCommand) GetLanguage() (*sitter.Language, error)
func (*OakCommand) Parse ¶
func (oc *OakCommand) Parse(ctx context.Context, oldTree *sitter.Tree, code []byte) (*sitter.Tree, error)
Parse parses the given code using the language set in the command and returns the resulting tree.
func (*OakCommand) PrintQueries ¶ added in v0.1.1
func (oc *OakCommand) PrintQueries(w io.Writer) error
func (*OakCommand) Render ¶
func (oc *OakCommand) Render(results QueryResults) (string, error)
func (*OakCommand) RenderQueries ¶ added in v0.1.1
func (oc *OakCommand) RenderQueries(layers *layers.ParsedLayers) error
RenderQueries replaces all the queries in the command with their "rendered" (using go templates) version.
WARNING: This is destructive and should only be called once. NOTE(manuel, 2023-06-19) This is not a great API, but it will do for now.
func (*OakCommand) RenderWithTemplate ¶
func (oc *OakCommand) RenderWithTemplate(results QueryResults, tmpl *template.Template) (string, error)
func (*OakCommand) RenderWithTemplateFile ¶
func (oc *OakCommand) RenderWithTemplateFile(results QueryResults, file string) (string, error)
func (*OakCommand) ResultsToJSON ¶
func (oc *OakCommand) ResultsToJSON(results QueryResults, f io.Writer) error
func (*OakCommand) ResultsToYAML ¶
func (oc *OakCommand) ResultsToYAML(results QueryResults, f io.Writer) error
type OakCommandDescription ¶
type OakCommandDescription struct { Language string `yaml:"language,omitempty"` Queries []SitterQuery `yaml:"queries"` Template string `yaml:"template,omitempty"` Name string `yaml:"name"` Short string `yaml:"short"` Long string `yaml:"long,omitempty"` Layout []*layout.Section `yaml:"layout,omitempty"` Flags []*parameters.ParameterDefinition `yaml:"flags,omitempty"` Layers []layers.ParameterLayer `yaml:"layers,omitempty"` Parents []string `yaml:",omitempty"` Source string `yaml:",omitempty"` }
type OakCommandLoader ¶
type OakCommandLoader struct { }
func (*OakCommandLoader) IsFileSupported ¶ added in v0.1.8
func (o *OakCommandLoader) IsFileSupported(f fs.FS, fileName string) bool
func (*OakCommandLoader) LoadCommandAliasFromYAML ¶
func (o *OakCommandLoader) LoadCommandAliasFromYAML( s io.Reader, options ...alias.Option, ) ([]*alias.CommandAlias, error)
func (*OakCommandLoader) LoadCommands ¶ added in v0.1.8
type OakCommandOption ¶
type OakCommandOption func(*OakCommand)
func WithLanguage ¶
func WithLanguage(lang string) OakCommandOption
func WithQueries ¶
func WithQueries(queries ...SitterQuery) OakCommandOption
func WithSitterLanguage ¶
func WithSitterLanguage(lang *sitter.Language) OakCommandOption
func WithTemplate ¶
func WithTemplate(template string) OakCommandOption
type OakGlazeCommand ¶ added in v0.2.0
type OakGlazeCommand struct {
*OakCommand
}
func NewOakGlazedCommand ¶ added in v0.1.1
func NewOakGlazedCommand(d *cmds.CommandDescription, options ...OakCommandOption) *OakGlazeCommand
func (*OakGlazeCommand) RunIntoGlazeProcessor ¶ added in v0.2.0
func (oc *OakGlazeCommand) RunIntoGlazeProcessor( ctx context.Context, parsedLayers *layers.ParsedLayers, gp middlewares.Processor, ) error
type OakGlazedCommandLoader ¶ added in v0.1.1
type OakGlazedCommandLoader struct{}
func (*OakGlazedCommandLoader) IsFileSupported ¶ added in v0.1.8
func (o *OakGlazedCommandLoader) IsFileSupported(f fs.FS, fileName string) bool
func (*OakGlazedCommandLoader) LoadCommandAliasFromYAML ¶ added in v0.1.1
func (o *OakGlazedCommandLoader) LoadCommandAliasFromYAML( s io.Reader, options ...alias.Option, ) ([]*alias.CommandAlias, error)
func (*OakGlazedCommandLoader) LoadCommands ¶ added in v0.1.8
type OakParameterLayer ¶
type OakParameterLayer struct {
layers.ParameterLayerImpl `yaml:",inline"`
}
func NewOakParameterLayer ¶
func NewOakParameterLayer( options ...layers.ParameterLayerOptions, ) (*OakParameterLayer, error)
type OakSettings ¶ added in v0.2.0
type OakWriterCommand ¶ added in v0.1.1
type OakWriterCommand struct {
*OakCommand
}
func NewOakWriterCommand ¶ added in v0.1.1
func NewOakWriterCommand(d *cmds.CommandDescription, options ...OakCommandOption) *OakWriterCommand
func (*OakWriterCommand) RunIntoWriter ¶ added in v0.1.1
func (oc *OakWriterCommand) RunIntoWriter( ctx context.Context, parsedLayers *layers.ParsedLayers, w io.Writer, ) error
type QueryResults ¶
func ExecuteQueries ¶
func ExecuteQueries( lang *sitter.Language, tree *sitter.Node, queries []SitterQuery, sourceCode []byte, ) (QueryResults, error)
ExecuteQueries runs the given queries on the given tree and returns the results. Individual names are resolved using the sourceCode string, so as to provide full identifier names when matched.
TODO(manuel, 2023-06-19) We only need the language from oc here, right?
type RunSettings ¶ added in v0.2.0
type RunSettings struct {
Sources []string `glazed.parameter:"sources"`
}