Skip to content

Commit

Permalink
Merge pull request smacker#36 from Himujjal/master
Browse files Browse the repository at this point in the history
svelte grammar added
  • Loading branch information
smacker committed May 19, 2021
2 parents 4a66a14 + 0e97756 commit 0ba5d9f
Show file tree
Hide file tree
Showing 7 changed files with 5,533 additions and 0 deletions.
14 changes: 14 additions & 0 deletions svelte/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package svelte

//#include "parser.h"
//TSLanguage *tree_sitter_svelte();
import "C"
import (
sitter "github.com/smacker/go-tree-sitter"
"unsafe"
)

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

import (
"testing"

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

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

n := sitter.Parse([]byte(`<script context="module">
let name = 'world';
</script>
<h1>Hello {name'<>{}"\''""{}}!</h1>
`), svelte.GetLanguage())

assert.Equal(
"(document (script_element (start_tag (tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value)))) (raw_text) (end_tag (tag_name))) (text) (element (start_tag (tag_name)) (text) (expression (raw_text_expr)) (text) (end_tag (tag_name))))",
n.String(),
)
}
Loading

0 comments on commit 0ba5d9f

Please sign in to comment.