-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bc4042
commit 4043417
Showing
42 changed files
with
802,759 additions
and
806,707 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tree_sitter_fsharp | ||
|
||
// #cgo CFLAGS: -I../../grammars/fsharp/src -std=c11 -fPIC | ||
// #include "../../grammars/fsharp/src/parser.c" | ||
// #include "../../grammars/fsharp/src/scanner.c" | ||
import "C" | ||
|
||
import "unsafe" | ||
|
||
// Get the tree-sitter Language for FSharp. | ||
func FSharp() unsafe.Pointer { | ||
return unsafe.Pointer(C.tree_sitter_fsharp()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tree_sitter_fsharp | ||
|
||
// #cgo CFLAGS: -I../../grammars/fsharp/src -std=c11 -fPIC | ||
// #include "../../grammars/fsharp/src/parser.c" | ||
// #include "../../grammars/fsharp/src/scanner.c" | ||
import "C" | ||
|
||
import "unsafe" | ||
|
||
// Get the tree-sitter Language for FSharp signature. | ||
func FSharpSignature() unsafe.Pointer { | ||
return unsafe.Pointer(C.tree_sitter_fsharp_signature()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
package tree_sitter_fsharp_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
tree_sitter "github.com/smacker/go-tree-sitter" | ||
"github.com/tree-sitter/tree-sitter-fsharp" | ||
tree_sitter_fsharp "github.com/ionide/tree-sitter-fsharp" | ||
) | ||
|
||
func TestCanLoadGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_fsharp.Language()) | ||
func TestFSharpGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_fsharp.FSharp()) | ||
if language == nil { | ||
t.Errorf("Error loading Fsharp grammar") | ||
t.Errorf("Error loading FSharp grammar") | ||
} | ||
|
||
sourceCode := []byte("module M = ()") | ||
|
||
node, err := tree_sitter.ParseCtx(context.Background(), sourceCode, language) | ||
if err != nil || node.HasError() { | ||
t.Errorf("Error parsing FSharp") | ||
} | ||
} | ||
|
||
func TestFSharpSignatureGrammar(t *testing.T) { | ||
language := tree_sitter.NewLanguage(tree_sitter_fsharp.FSharpSignature()) | ||
if language == nil { | ||
t.Errorf("Error loading FSharpSignature grammar") | ||
} | ||
|
||
sourceCode := []byte("val x : int -> int") | ||
|
||
node, err := tree_sitter.ParseCtx(context.Background(), sourceCode, language) | ||
if err != nil || node.HasError() { | ||
t.Errorf("Error parsing FSharpSignature") | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/tree-sitter/tree-sitter-fsharp | ||
module github.com/ionide/tree-sitter-fsharp | ||
|
||
go 1.22 | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from unittest import TestCase | ||
|
||
import tree_sitter_fsharp | ||
from tree_sitter import Language, Parser | ||
|
||
|
||
class TestLanguage(TestCase): | ||
def test_fsharp_grammar(self): | ||
language = Language(tree_sitter_fsharp.fsharp()) | ||
parser = Parser(language) | ||
tree = parser.parse( | ||
b""" | ||
module M = | ||
let x = 0 | ||
""" | ||
) | ||
self.assertFalse(tree.root_node.has_error) | ||
|
||
def test_signature_grammar(self): | ||
language = Language(tree_sitter_fsharp.signature()) | ||
parser = Parser(language) | ||
tree = parser.parse( | ||
b""" | ||
module M = | ||
val x : int -> int | ||
""" | ||
) | ||
self.assertFalse(tree.root_node.has_error) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,49 @@ | ||
"Fsharp grammar for tree-sitter" | ||
|
||
from ._binding import language | ||
from importlib.resources import files as _files | ||
|
||
__all__ = ["language"] | ||
from ._binding import fsharp, signature | ||
|
||
|
||
def _get_query(name, file): | ||
query = _files(f"{__package__}.queries") / file | ||
globals()[name] = query.read_text() | ||
return globals()[name] | ||
|
||
|
||
def __getattr__(name): | ||
if name == "HIGHLIGHTS_QUERY": | ||
return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") | ||
if name == "LOCALS_QUERY": | ||
return _get_query("LOCALS_QUERY", "locals.scm") | ||
if name == "TAGS_QUERY": | ||
return _get_query("TAGS_QUERY", "tags.scm") | ||
|
||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | ||
|
||
|
||
__all__ = [ | ||
"fsharp", | ||
"signature", | ||
"HIGHLIGHTS_QUERY", | ||
"LOCALS_QUERY", | ||
"TAGS_QUERY", | ||
] | ||
|
||
|
||
def __dir__(): | ||
return sorted( | ||
__all__ | ||
+ [ | ||
"__all__", | ||
"__builtins__", | ||
"__cached__", | ||
"__doc__", | ||
"__file__", | ||
"__loader__", | ||
"__name__", | ||
"__package__", | ||
"__path__", | ||
"__spec__", | ||
] | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
def language() -> int: ... | ||
from typing import Final | ||
|
||
|
||
HIGHLIGHTS_QUERY: Final[str] | ||
LOCALS_QUERY: Final[str] | ||
TAGS_QUERY: Final[str] | ||
|
||
|
||
def fsharp() -> int: ... | ||
def signature() -> int: ... |
Oops, something went wrong.