minimal working grammar
This commit is contained in:
10
README.md
10
README.md
@@ -10,9 +10,13 @@ non-flake equivalents:
|
||||
- `nix-shell`
|
||||
|
||||
|
||||
99% of this repository is code-gen'd garbage.
|
||||
to recreate it or update it, follow this guide:
|
||||
## development workflow
|
||||
guide on using tree-sitter:
|
||||
<https://tree-sitter.github.io/tree-sitter/creating-parsers>
|
||||
|
||||
recording my steps here to maybe someday make this reproducible:
|
||||
roughly:
|
||||
1. `nix develop`
|
||||
2. `tree-sitter generate`
|
||||
3. `tree-sitter test`
|
||||
|
||||
the parser is defined in `grammar.js`, and tests live in `corpus/`.
|
||||
|
14
corpus/shebang_only.txt
Normal file
14
corpus/shebang_only.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
==================
|
||||
nix-shell shebang without any interpreter option
|
||||
==================
|
||||
|
||||
#!/usr/bin/env nix-shell
|
||||
---
|
||||
|
||||
(source_file
|
||||
(first_line
|
||||
(shebang_open)
|
||||
(opt_ws)
|
||||
(env)
|
||||
(ws)
|
||||
(nix_shell)))
|
22
corpus/shebang_with_sub_interpreter.txt
Normal file
22
corpus/shebang_with_sub_interpreter.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
==================
|
||||
Minimal nix-shell invocation
|
||||
==================
|
||||
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash
|
||||
---
|
||||
|
||||
(source_file
|
||||
(first_line
|
||||
(shebang_open)
|
||||
(opt_ws)
|
||||
(env)
|
||||
(ws)
|
||||
(nix_shell))
|
||||
(non_first_line
|
||||
(newline)
|
||||
(annotation_line
|
||||
(shebang_open)
|
||||
(opt_ws)
|
||||
(nix_shell)
|
||||
(nix_shell_args))))
|
17
grammar.js
17
grammar.js
@@ -2,7 +2,20 @@ module.exports = grammar({
|
||||
name: 'nixshell',
|
||||
|
||||
rules: {
|
||||
// TODO: add the actual grammar rules
|
||||
source_file: $ => 'hello'
|
||||
source_file: $ => seq($.first_line, repeat($.non_first_line)),
|
||||
|
||||
first_line: $ => seq($.shebang_open, $.opt_ws, optional(seq($.env, $.ws)), $.nix_shell),
|
||||
non_first_line: $ => seq($.newline, $.annotation_line),
|
||||
annotation_line: $ => seq($.shebang_open, $.opt_ws, $.nix_shell, $.nix_shell_args),
|
||||
embedded_script_line: $ => /.*/,
|
||||
|
||||
shebang_open: $ => /#!/,
|
||||
// TODO: allow `usr/bin/env`, `env`
|
||||
env: $ => '/usr/bin/env',
|
||||
nix_shell: $ => 'nix-shell',
|
||||
nix_shell_args: $ => ' -i bash',
|
||||
ws: $ => / +/,
|
||||
opt_ws: $ => / */,
|
||||
newline: $ => '\n',
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user