Compare commits
1 Commits
master
...
wip/highli
Author | SHA1 | Date | |
---|---|---|---|
b9e6711f82 |
@@ -19,6 +19,6 @@ roughly:
|
||||
2. `tree-sitter generate`
|
||||
3. `tree-sitter test`
|
||||
|
||||
run `make clean` from within the `nix develop` shell before committing to avoid checking in build artifacts.
|
||||
run `nix run '.#clean'` before committing to avoid checking in build artifacts.
|
||||
|
||||
the parser is defined in `grammar.js`, and tests live in `corpus/`.
|
||||
|
18
default.nix
18
default.nix
@@ -2,28 +2,14 @@
|
||||
|
||||
pkgs.tree-sitter.buildGrammar {
|
||||
src = ./.;
|
||||
version = "0.2.0";
|
||||
version = "0.1.0";
|
||||
language = "nix-shell";
|
||||
generate = true;
|
||||
location = "tree-sitter-nix-shell";
|
||||
|
||||
nativeCheckInputs = with pkgs; [ htmlq ];
|
||||
checkPhase = ''
|
||||
runHook preCheck
|
||||
(cd ..; make test)
|
||||
runHook postCheck
|
||||
'';
|
||||
nativeCheckInputs = with pkgs; [ htmlq ];
|
||||
doCheck = true;
|
||||
|
||||
nativeInstallCheckInputs = with pkgs; [ tree ];
|
||||
installCheckPhase = ''
|
||||
runHook preInstallCheck
|
||||
|
||||
# make sure that all files i expect to be installed are actually installed
|
||||
(test -x $out/parser && test -f $out/queries/highlights.scm && test -f $out/queries/injections.scm) || \
|
||||
(tree $out; echo "expected output to contain /parser and /queries/"; false)
|
||||
|
||||
runHook postInstallCheck
|
||||
'';
|
||||
doInstallCheck = true;
|
||||
}
|
||||
|
12
flake.lock
generated
12
flake.lock
generated
@@ -5,11 +5,11 @@
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"lastModified": 1687709756,
|
||||
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1741851582,
|
||||
"narHash": "sha256-cPfs8qMccim2RBgtKGF+x9IBCduRvd/N5F4nYpU0TVE=",
|
||||
"lastModified": 1688590700,
|
||||
"narHash": "sha256-ZF055rIUP89cVwiLpG5xkJzx00gEuuGFF60Bs/LM3wc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6607cf789e541e7873d40d3a8f7815ea92204f32",
|
||||
"rev": "f292b4964cb71f9dfbbd30dc9f511d6165cd109b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
|
||||
# `tree-sitter test` doesn't work to validate syntax highlighting for two reasons:
|
||||
# - it identifies a file's language only by its filetype (not shebang/regex), but nix-shell has no filetype
|
||||
# - it requires the language to support comments, but nix-shell doesn't have those
|
||||
@@ -8,11 +10,11 @@
|
||||
#
|
||||
# usage: test_highlight <TEST_NAME>
|
||||
#
|
||||
# upon execution, performs this sequence:
|
||||
# 1. highlights the file at `highlight/<TEST_NAME>`.
|
||||
# 2. asserts the result's body against `hightlight/<TEST_NAME>.spec.html`
|
||||
# 2. asserts the result's body against `hightlight_spec/<TEST_NAME>.html`
|
||||
|
||||
here=$(dirname $(realpath $0))
|
||||
echo $here
|
||||
input_file="$here/highlight/$1"
|
||||
spec_file="$here/highlight/$1.spec.html"
|
||||
|
||||
|
29
tree-sitter-nix-shell/package.json
Normal file
29
tree-sitter-nix-shell/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "tree-sitter-nix-shell",
|
||||
"version": "0.0.1",
|
||||
"description": "nix-shell grammar for tree-sitter",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
"parsing",
|
||||
"incremental"
|
||||
],
|
||||
"dependencies": {
|
||||
"nan": "^2.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"first-line-regex": "^#!.*\\bnix-shell\\b.*$",
|
||||
"content-regex": "^\b$nix-shell wraps other languages so intentionally fail against (and yield to) those other language matches",
|
||||
"injection-regex": "^(nix[-_]?shell)$",
|
||||
"scope": "source.nix_shell",
|
||||
"injections": [ "queries/injections.scm" ],
|
||||
"highlights": [ "queries/highlights.scm" ]
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json",
|
||||
"grammars": [
|
||||
{
|
||||
"name": "nix_shell",
|
||||
"camelcase": "NixShell",
|
||||
"title": "NixShell",
|
||||
"scope": "source.nix_shell",
|
||||
"class-name": "TreeSitterNixShell",
|
||||
"file-types": [ ],
|
||||
"first-line-regex": "^#!.*\\bnix-shell\\b.*$",
|
||||
"content-regex": "^\b$nix-shell wraps other languages so intentionally fail against (and yield to) those other language matches",
|
||||
"injection-regex": "^(nix[-_]?shell)$",
|
||||
"injections": [ "queries/injections.scm" ],
|
||||
"highlights": [ "queries/highlights.scm" ]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"version": "0.2.0",
|
||||
"description": "understands languages encoded in #!nix-shell shebangs",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Colin",
|
||||
"email": "colin@uninsane.org",
|
||||
"url": "https://uninsane.org/"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"repository": "https://git.uninsane.org/colin/tree-sitter-nix-shell"
|
||||
}
|
||||
},
|
||||
"bindings": {
|
||||
"c": true,
|
||||
"go": true,
|
||||
"node": true,
|
||||
"python": true,
|
||||
"rust": true,
|
||||
"swift": true,
|
||||
"zig": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user