Browse Source

make a SSCCE

main
Brian Hicks 6 months ago
parent
commit
fdb474022a
  1. 3
      .gitmodules
  2. 75
      Cargo.lock
  3. 4
      Cargo.toml
  4. 23
      build.rs
  5. 14
      shell.nix
  6. 14
      src/main.rs
  7. 4
      test.hs
  8. 1
      vendor/tree-sitter-haskell

3
.gitmodules

@ -0,0 +1,3 @@
[submodule "vendor/tree-sitter-haskell"]
path = vendor/tree-sitter-haskell
url = git@github.com:tree-sitter/tree-sitter-haskell

75
Cargo.lock

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
"memchr",
]
[[package]]
name = "cc"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
dependencies = [
"jobserver",
]
[[package]]
name = "jobserver"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "regex"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
[[package]]
name = "tree-sitter"
version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f41201fed3db3b520405a9c01c61773a250d4c3f43e9861c14b2bb232c981ab"
dependencies = [
"cc",
"regex",
]
[[package]]
name = "tree-sitter-haskell-sscce"
version = "0.1.0"
dependencies = [
"cc",
"tree-sitter",
]

4
Cargo.toml

@ -7,3 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tree-sitter = "0.19"
[build-dependencies]
cc = { version = "*", features = [ "parallel" ] }

23
build.rs

@ -0,0 +1,23 @@
use std::path::PathBuf;
// https://doc.rust-lang.org/cargo/reference/build-scripts.html
fn main() {
println!("cargo:rerun-if-changed=build.rs");
// haskell
let haskell_dir: PathBuf = ["vendor", "tree-sitter-haskell", "src"].iter().collect();
println!("cargo:rerun-if-changed=vendor/tree-sitter-haskell/src/parser.c");
cc::Build::new()
.include(&haskell_dir)
.file(haskell_dir.join("parser.c"))
.compile("tree-sitter-haskell");
println!("cargo:rerun-if-changed=vendor/tree-sitter-haskell/src/scanner.cc");
cc::Build::new()
.include(&haskell_dir)
.warnings(false) // lots of unused parameters
.cpp(true)
.file(haskell_dir.join("scanner.cc"))
.compile("tree_sitter_haskell_scanner");
}

14
shell.nix

@ -3,4 +3,16 @@ let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
niv = import sources.niv { };
in pkgs.mkShell { buildInputs = with pkgs; [ niv.niv git rustc cargo ]; }
in pkgs.mkShell {
buildInputs = with pkgs; [
niv.niv
git
# rust
rustc
cargo
# tree-sitter C deps
pkgs.libiconv
];
}

14
src/main.rs

@ -1,3 +1,15 @@
fn main() {
println!("Hello, world!");
let mut parser = tree_sitter::Parser::new();
parser.set_language(unsafe { tree_sitter_haskell() }).unwrap();
println!("Done making a parser");
let source = std::fs::read_to_string("test.hs").unwrap();
println!("Done reading the file");
parser.parse(&source, None);
println!("Done parsing the file");
}
extern "C" {
fn tree_sitter_haskell() -> tree_sitter::Language;
}

4
test.hs

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, World!"

1
vendor/tree-sitter-haskell

@ -0,0 +1 @@
Subproject commit 381dca04f20381ecb3f4306d727474755ad19cc4
Loading…
Cancel
Save