Skip to content

Commit

Permalink
Merge pull request smacker#74 from grouville/add/cue
Browse files Browse the repository at this point in the history
Cue binding
  • Loading branch information
smacker authored Jun 22, 2022
2 parents 2c4b54e + 4023004 commit a6260d0
Show file tree
Hide file tree
Showing 6 changed files with 27,024 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cue/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cue

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

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

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

import (
"context"
"testing"

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

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

code := `a: {
F=f: string
X="my-identifier": bool
}
`

n, err := sitter.ParseCtx(context.Background(), []byte(code), cue.GetLanguage())
assert.NoError(err)
assert.Equal(
"(source_file (field (label (identifier)) (value (struct_lit (field (label alias: (identifier) (identifier)) (value (string_type))) (field (label alias: (identifier) (simple_string_lit)) (value (bool_type)))))))",
n.String(),
)
}
Loading

0 comments on commit a6260d0

Please sign in to comment.