This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Prototype of imperative (Starlark-based) syntax traversal#72
Closed
Prototype of imperative (Starlark-based) syntax traversal#72
Conversation
The first part of our stack graph loader creates a stack graph node for each graph DSL node. You use attributes to specify the kind of stack graph node (defaulting to “internal”), along with any other necessary properties of the node.
If you set the `source_node` attribute for a graph DSL node, whose value must be a syntax node reference, then we will calculate the location of that syntax node in the source file and fill in the stack graph node's “source info” accordingly.
- Add `StackGraphLanguage` constructor that accepts a parse `tree_sitter_graph::ast::File` instead of a source. - Add parameter to pass `Functions` to the `StackGraphLanguage`. - Rename `load_` to `build_` where TSG is executed. - Add parameter to pass global `Variables` to `build_` method.
- Implement loading tree-sitter language and tree-sitter-graph file - Parse test files and run the given TSG file against them Co-authored-by: Douglas Creager <dcreager@dcreager.net>
Error context was lost for some errors, resulting in unhelpful error messages. This uses the same mechanism for wrapping errors everywhere, and ensures context is preserved up to the top level.
76bd8eb to
7467eba
Compare
7467eba to
2550d4d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an extremely rough proof of concept that I threw together last night of an alternative notation to TSG for expressing the syntax tree traversal. The StackGraph node and edge creation primitives are not yet implemented.
See https://github.com/github/stack-graphs/blob/adonovan/starlark-visitor/demo/demo.go for the driver program. It's in Go and uses the Go bindings for tree-sitter to parse the input file, and it uses Starlark (a simple embeddable Python dialect) to express the tree traversal.
See https://github.com/github/stack-graphs/blob/adonovan/starlark-visitor/demo/demo.star for the Starlark program. Observe that it allows, in few lines of familiar imperative code, fine control over the traversal ordering, and that it closely resembles the concepts and terminology of the Tree Sitter grammar.
This gist shows the output of the tool when run on its own Go source: https://gist.github.com/adonovan/4b477ceaa2d5016a826213697d639953