diff --git a/README.md b/README.md index e06695f..cd8285a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ this will be a tree-sitter implementation for `nix-shell` files. + +try one of the following: +- `nix build` => build the parser +- `nix develop` => manually/interactively generate the parser + - `tree-sitter generate` + +non-flake equivalents: +- `nix-build` +- `nix-shell` + + 99% of this repository is code-gen'd garbage. to recreate it or update it, follow this guide: diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..9f7aaaa --- /dev/null +++ b/default.nix @@ -0,0 +1,8 @@ +{ pkgs ? import { } }: + +pkgs.tree-sitter.buildGrammar { + src = ./.; + version = "0.1.0"; + language = "nixshell"; + generate = true; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6f0a383 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688389917, + "narHash": "sha256-RKiK1QeommEsjQ8fLgxt4831x9O6n2gD7wAhVZTrr8M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "aed4b19d312525ae7ca9bceb4e1efe3357d0e2eb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.05", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8b75377 --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "tree-sitter implementation for nix-shell scripts"; + inputs = { + nixpkgs.url = "nixpkgs/nixos-23.05"; + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = { self, nixpkgs, flake-utils }: + with flake-utils.lib; eachSystem allSystems (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in rec { + packages.tree-sitter-nixshell = pkgs.callPackage ./default.nix { }; + defaultPackage = packages.tree-sitter-nixshell; + + devShells.default = pkgs.callPackage ./shell.nix { }; + }); +} diff --git a/grammar.js b/grammar.js new file mode 100644 index 0000000..b7a98ec --- /dev/null +++ b/grammar.js @@ -0,0 +1,8 @@ +module.exports = grammar({ + name: 'nixshell', + + rules: { + // TODO: add the actual grammar rules + source_file: $ => 'hello' + } +}); diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..f3411f4 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } }: + +let + tree-sitter-nixshell = pkgs.callPackage ./. { }; +in +pkgs.mkShell { + inherit (tree-sitter-nixshell) nativeBuildInputs; + # to manually build, once in this shell, just run + # `tree-sitter generate` +} +