Skip to content

Commit 6fd4da1

Browse files
Golang driver written by Claude-3
1 parent 970db3a commit 6fd4da1

File tree

25 files changed

+2118
-72
lines changed

25 files changed

+2118
-72
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
.lsp
55
/prompts/stable-diffusion/*.png
66
**/.DS_Store
7+
/functions/tree-sitter/.cpcache/
8+
/functions/tree-sitter/.nrepl-port
9+
/functions/tree-sitter/hs_err_*.log
10+
/functions/tree-sitter/main
11+
/functions/tree-sitter-clj/target/
12+
/functions/tree-sitter-clj/.cpcache/

functions/tree-sitter-clj/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
# syntax = docker/dockerfile:1.4
3+
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder
4+
5+
WORKDIR /tmp/build
6+
RUN mkdir /tmp/nix-store-closure
7+
8+
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
9+
# hadolint ignore=SC2046
10+
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
11+
--mount=type=cache,target=/root/.cache \
12+
--mount=type=bind,target=/tmp/build \
13+
<<EOF
14+
nix \
15+
--extra-experimental-features "nix-command flakes" \
16+
--option filter-syscalls false \
17+
--extra-trusted-substituters "https://cache.iog.io" \
18+
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
19+
--show-trace \
20+
--log-format raw \
21+
build . --out-link /tmp/output/result
22+
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
23+
EOF
24+
25+
FROM scratch
26+
27+
WORKDIR /app
28+
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/output/ /app/
31+
32+
ENTRYPOINT ["/app/result/bin/entrypoint"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns build
2+
(:require [clojure.tools.build.api :as b]))
3+
4+
(def class-dir "target/classes")
5+
(def basis (b/create-basis {:project "deps.edn"}))
6+
7+
(defn compile-java [_]
8+
(b/delete {:path "target"})
9+
(b/javac {:src-dirs ["src/java"]
10+
:class-dir class-dir
11+
:basis basis
12+
:javac-opts ["-source" "8" "-target" "8"]}))
13+
14+
(defn uber [_]
15+
(compile-java nil) ; Compile Java first
16+
(b/copy-dir {:src-dirs ["src/clojure" "resources"]
17+
:target-dir class-dir})
18+
(b/compile-clj {:basis basis ; compile clojure code
19+
:src-dirs ["src/clojure"]
20+
:class-dir class-dir})
21+
(b/uber {:class-dir class-dir
22+
:uber-file "target/my-project.jar"
23+
:basis basis
24+
:main 'docker.ts}))
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
8+
sitter "github.com/smacker/go-tree-sitter"
9+
"github.com/smacker/go-tree-sitter/python"
10+
"github.com/smacker/go-tree-sitter/yaml"
11+
"github.com/smacker/go-tree-sitter/sql"
12+
"github.com/smacker/go-tree-sitter/bash"
13+
"github.com/smacker/go-tree-sitter/html"
14+
"github.com/smacker/go-tree-sitter/dockerfile"
15+
)
16+
17+
func main() {
18+
// Check if both language and query string are provided as arguments
19+
if len(os.Args) < 3 {
20+
fmt.Println("Usage: ./program <language> <query_string>")
21+
return
22+
}
23+
language := os.Args[1]
24+
queryString := os.Args[2]
25+
26+
// Create a parser
27+
parser := sitter.NewParser()
28+
29+
// Set the language based on the first argument
30+
switch language {
31+
case "python":
32+
parser.SetLanguage(python.GetLanguage())
33+
case "yaml":
34+
parser.SetLanguage(yaml.GetLanguage())
35+
case "sql":
36+
parser.SetLanguage(sql.GetLanguage())
37+
case "bash":
38+
parser.SetLanguage(bash.GetLanguage())
39+
case "html":
40+
parser.SetLanguage(html.GetLanguage())
41+
case "dockerfile":
42+
parser.SetLanguage(dockerfile.GetLanguage())
43+
default:
44+
fmt.Printf("Unsupported language: %s\n", language)
45+
return
46+
}
47+
48+
// Read source code from stdin
49+
sourceCode, err := ioutil.ReadAll(os.Stdin)
50+
if err != nil {
51+
fmt.Println("Error reading from stdin:", err)
52+
return
53+
}
54+
55+
// Parse the source code
56+
tree := parser.Parse(nil, sourceCode)
57+
defer tree.Close()
58+
59+
// Create a query
60+
query, err := sitter.NewQuery([]byte(queryString), python.GetLanguage())
61+
if err != nil {
62+
fmt.Println("Error creating query:", err)
63+
return
64+
}
65+
defer query.Close()
66+
67+
// Execute the query
68+
qc := sitter.NewQueryCursor()
69+
defer qc.Close()
70+
71+
qc.Exec(query, tree.RootNode())
72+
73+
// Iterate over the query results
74+
for {
75+
match, ok := qc.NextMatch()
76+
if !ok {
77+
break
78+
}
79+
80+
for _, capture := range match.Captures {
81+
captureName := query.CaptureNameForId(capture.Index)
82+
nodeText := capture.Node.Content(sourceCode)
83+
fmt.Printf("Capture: %s, Node: %s\n", captureName, nodeText)
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)