Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.17', '1.16', '1.15', '1.14']
go: ['1.20', '1.17', '1.16', '1.15', '1.14']
name: Test on ${{ matrix.go }}
steps:
- uses: actions/checkout@v2
Expand Down
11 changes: 11 additions & 0 deletions _automation/grammars.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@
"reference": "v0.19.1",
"revision": "918f0fb948405181707a1772cab639f2d278d384"
},
{
"language": "sparql",
"url": "https://github.com/BonaBeavis/tree-sitter-sparql",
"files": [
"parser.c",
"grammar.json",
"node-types.json"
],
"reference": "0.1.0",
"revision": "05f949d3c1c15e3261473a244d3ce87777374dec"
},
{
"language": "svelte",
"url": "https://github.com/Himujjal/tree-sitter-svelte",
Expand Down
5 changes: 3 additions & 2 deletions _automation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func (g *Grammar) ContentURL() string {
)
}

// Try to fetch tag if reference, otherwise fetch commit
func (g *Grammar) FetchNewVersion() *GrammarVersion {
if strings.HasPrefix(g.Reference, "v") {
if g.Reference != "" {
tag, rev := fetchLastTag(g.URL)
if tag != g.Reference {
return &GrammarVersion{
Expand Down Expand Up @@ -421,7 +422,7 @@ func logAndExit(logger *Logger, msg string, args ...interface{}) {
// Git

func fetchLastTag(repository string) (string, string) {
cmd := exec.Command("git", "ls-remote", "--tags", "--refs", "--sort", "-v:refname", repository, "v*")
cmd := exec.Command("git", "ls-remote", "--tags", "--refs", "--sort", "-v:refname", repository)
b, err := cmd.Output()
if err != nil {
logAndExit(defaultLogger, err.Error())
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/smacker/go-tree-sitter

go 1.13
go 1.20

require github.com/stretchr/testify v1.7.4

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 15 additions & 0 deletions sparql/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sparql

//#include "parser.h"
//TSLanguage *tree_sitter_sparql();
import "C"
import (
"unsafe"

sitter "github.com/smacker/go-tree-sitter"
)

func GetLanguage() *sitter.Language {
ptr := unsafe.Pointer(C.tree_sitter_sparql())
return sitter.NewLanguage(ptr)
}
30 changes: 30 additions & 0 deletions sparql/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sparql_test

import (
"context"
"testing"

sitter "github.com/smacker/go-tree-sitter"
"github.com/smacker/go-tree-sitter/sparql"
"github.com/stretchr/testify/assert"
)

const code = `
SELECT * {
?s ?p ?o
FILTER (?s > 0)
}`


const expected = `(unit (select_query (select_clause) (where_clause (group_graph_pattern (triples_block (triples_same_subject subject: (var) (property_list (property (var) (object_list (var)))))) (filter (bracketted_expression (binary_expression (var) (integer))))))))`

func TestGrammar(t *testing.T) {
assert := assert.New(t)

n, err := sitter.ParseCtx(context.Background(), []byte(code), sparql.GetLanguage())
assert.NoError(err)
assert.Equal(
expected,
n.String(),
)
}
Loading