Files
tree-sitter-nix-shell/grammar.js
2023-07-04 08:10:05 +00:00

22 lines
649 B
JavaScript

module.exports = grammar({
name: 'nixshell',
rules: {
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',
}
});