tree-sitter experiment

This commit is contained in:
Felix Roos 2023-12-21 10:52:27 +01:00
parent 0a070a2084
commit 9e1ba442a9
6 changed files with 322 additions and 0 deletions

26
packages/haskell/.gitignore vendored Normal file
View file

@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
public/tree-sitter.wasm

View file

@ -0,0 +1,25 @@
# @strudel/haskell
This is an experiment in implementing tree-sitter for parsing haskell.
So far, I have just set up a vite project that imports and inits `web-tree-sitter`, which works after
- <https://github.com/tree-sitter/tree-sitter/issues/2831>
- <https://github.com/tree-sitter/tree-sitter/pull/2830>
Running:
```sh
cd haskell && pnpm i
pnpm dev
```
will start the vite dev server, loading tree sitter on `http://localhost:5174/`.
The next step is be to generate `tree-sitter-haskell.wasm` file following <https://www.npmjs.com/package/web-tree-sitter#generate-wasm-language-files>.
I've tried to generate it using <https://www.npmjs.com/package/tree-sitter-haskell> but it failed, due to some versioning conflicts involving node / v8 / node-gyp.
It seems a lot of work has gone into this package in <https://github.com/tree-sitter/tree-sitter-haskell/pull/29>, without a new npm package version being released, which is why I've written this comment: <https://github.com/tree-sitter/tree-sitter-haskell/pull/29#issuecomment-1865951565>.
So either someone authorized releases a new version of the package or we might need to pull the changes and try to build it from the tree-sitter master branch.

View file

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tree sitter test</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
</body>
</html>

7
packages/haskell/main.js Normal file
View file

@ -0,0 +1,7 @@
import Parser from 'web-tree-sitter';
console.log('Parser', Parser);
Parser.init().then(() => {
console.log('init done..');
});

View file

@ -0,0 +1,20 @@
{
"name": "haskell",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"postinstall": "cp node_modules/web-tree-sitter/tree-sitter.wasm public"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.8",
"tree-sitter-javascript": "^0.20.1",
"vite": "^5.0.8"
},
"dependencies": {
"web-tree-sitter": "^0.20.8"
}
}