Skip to content

Commit b314ade

Browse files
author
Patrick Thomson
committed
kind of get semantic-ruby working, but having trouble with stuff
1 parent 1dc1a3a commit b314ade

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

build/common.bzl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,28 @@ def tree_sitter_node_types_archive(name, version, sha256, urls = [], nodetypespa
3737
name = name,
3838
build_file_content = """
3939
exports_files(glob(["{}"]))
40+
41+
native.filegroup(
42+
name = "corpus",
43+
srcs = "test/corpus/*.txt",
44+
visibility = ["//visibility:public"],
45+
)
4046
""".format(nodetypespath),
4147
strip_prefix = "{}-{}".format(name, version),
4248
urls = ["https://github.com/tree-sitter/{}/archive/v{}.tar.gz".format(name, version)],
4349
sha256 = sha256,
4450
)
4551

46-
def semantic_language_library(language, name, srcs, nodetypes = "", **kwargs):
52+
def semantic_language_library(language, name, srcs, nodetypes = [], **kwargs):
4753
"""Create a new library target with dependencies needed for a language-AST project."""
48-
if nodetypes == "":
49-
nodetypes = "@tree-sitter-{}//:src/node-types.json".format(language)
54+
if nodetypes == []:
55+
nodetypes = [
56+
"@tree-sitter-{}//:src/node-types.json".format(language),
57+
]
58+
filegroup(
59+
name = "corpus",
60+
srcs = native.glob("@"),
61+
)
5062
haskell_library(
5163
name = name,
5264
# We can't use Template Haskell to find out the location of the
@@ -59,7 +71,7 @@ def semantic_language_library(language, name, srcs, nodetypes = "", **kwargs):
5971
'-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes),
6072
],
6173
srcs = srcs,
62-
extra_srcs = [nodetypes],
74+
extra_srcs = nodetypes,
6375
deps = [
6476
"//:base",
6577
"//semantic-analysis",

semantic-ruby/BUILD.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,35 @@ load(
55
"semantic_language_library",
66
)
77

8+
# Load rules_haskell rules.
9+
load(
10+
"@rules_haskell//haskell:defs.bzl",
11+
"haskell_test",
12+
)
13+
814
semantic_language_library(
915
name = "semantic-ruby",
1016
srcs = glob(["src/**/*.hs"]),
1117
language = "ruby",
1218
nodetypes = "@tree-sitter-ruby//:src/node-types.json",
1319
)
20+
21+
haskell_test(
22+
name = "test",
23+
srcs = glob(["test/**/*.hs"]),
24+
deps = [
25+
":semantic-ruby",
26+
"//:base",
27+
"//:bytestring",
28+
"//:text",
29+
"//semantic:fixtureshim",
30+
"//semantic-ast",
31+
"@stackage//:bazel-runfiles",
32+
"@stackage//:hedgehog",
33+
"@stackage//:pathtype",
34+
"@stackage//:tasty",
35+
"@stackage//:tasty-hedgehog",
36+
"@stackage//:tasty-hunit",
37+
"@stackage//:tree-sitter-ruby",
38+
],
39+
)

semantic-ruby/test/PreciseTest.hs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
{-# LANGUAGE DisambiguateRecordFields, OverloadedStrings, TypeApplications #-}
1+
{-# LANGUAGE DisambiguateRecordFields #-}
2+
{-# LANGUAGE ImplicitParams #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE TypeApplications #-}
25
module Main (main) where
36

4-
import TreeSitter.Ruby
57
import AST.TestHelpers
68
import AST.Unmarshal
79
import qualified Language.Ruby.AST as Rb
810
import qualified System.Path as Path
11+
import qualified System.Path.Fixture as Fixture
12+
import qualified Bazel.Runfiles as Bazel
913
import Test.Tasty
14+
import System.IO
15+
import Control.Concurrent
16+
import TreeSitter.Ruby
1017

1118
main :: IO ()
12-
main
13-
= Path.absDir <$> Rb.getTestCorpusDir
14-
>>= readCorpusFiles'
15-
>>= traverse (testCorpus parse)
16-
>>= defaultMain . tests
17-
where parse = parseByteString @Rb.Program @() tree_sitter_ruby
19+
main = do
20+
let ?project = Path.relDir "semantic-ruby"
21+
22+
rf <- Bazel.create
23+
let ?runfiles = rf
24+
25+
let parse = parseByteString @Rb.Program @() tree_sitter_ruby
26+
27+
Rb.getTestCorpusDir >>= print
28+
print (Path.toString (Fixture.bazelDir "/."))
29+
hFlush stdout
30+
threadDelay 1000000000
31+
32+
Fixture.bazelDir <$> Rb.getTestCorpusDir
33+
>>= readCorpusFiles'
34+
>>= traverse (testCorpus parse)
35+
>>= defaultMain . tests
1836

1937
tests :: [TestTree] -> TestTree
2038
tests = testGroup "tree-sitter-ruby corpus tests"

0 commit comments

Comments
 (0)