hide uninteresting nodes

This commit is contained in:
2023-07-04 09:06:08 +00:00
parent 28d79d458c
commit 9119b2ebca
4 changed files with 13 additions and 43 deletions

View File

@@ -8,18 +8,8 @@ echo "hello, world!"
--- ---
(source_file (source_file
(first_line (first_line)
(shebang_open)
(opt_ws)
(env)
(ws)
(nix_shell))
(next_line (next_line
(newline)
(annotation_line (annotation_line
(shebang_open)
(opt_ws)
(nix_shell)
(nix_shell_args))) (nix_shell_args)))
(next_line (next_line))
(newline)))

View File

@@ -6,9 +6,4 @@ nix-shell shebang without any interpreter option
--- ---
(source_file (source_file
(first_line (first_line))
(shebang_open)
(opt_ws)
(env)
(ws)
(nix_shell)))

View File

@@ -7,16 +7,7 @@ Minimal nix-shell invocation
--- ---
(source_file (source_file
(first_line (first_line)
(shebang_open)
(opt_ws)
(env)
(ws)
(nix_shell))
(next_line (next_line
(newline)
(annotation_line (annotation_line
(shebang_open)
(opt_ws)
(nix_shell)
(nix_shell_args)))) (nix_shell_args))))

View File

@@ -4,28 +4,22 @@ module.exports = grammar({
rules: { rules: {
source_file: $ => seq($.first_line, repeat($.next_line)), source_file: $ => seq($.first_line, repeat($.next_line)),
first_line: $ => seq($.shebang_open, $.opt_ws, optional(seq($.env, $.ws)), $.nix_shell), first_line: $ => seq($._shebang_open, $._opt_ws, optional(seq($._env, $._ws)), $._nix_shell),
next_line: $ => seq($.newline, choice( next_line: $ => seq($._newline, choice(
$.annotation_line, $.annotation_line,
// TODO: capture this
repeat(/./), repeat(/./),
)), )),
annotation_line: $ => seq($.shebang_open, $.opt_ws, $.nix_shell, $.nix_shell_args), annotation_line: $ => seq($._shebang_open, $._opt_ws, $._nix_shell, $.nix_shell_args),
// payload_next_line: $ => /\n.*/,
// payload_line: $ => /.*/,
// payload_line: $ => repeat(/./),
// nix_shell_directive_open: $ => '#!nix-shell',
// TODO: actually parse nix-shell arguments // TODO: actually parse nix-shell arguments
nix_shell_args: $ => ' -i bash', nix_shell_args: $ => ' -i bash',
// TODO: hide these (prefix with underscore) _shebang_open: $ => '#!',
shebang_open: $ => '#!',
// TODO: allow `usr/bin/env`, `env` // TODO: allow `usr/bin/env`, `env`
env: $ => '/usr/bin/env', _env: $ => '/usr/bin/env',
nix_shell: $ => 'nix-shell', _nix_shell: $ => 'nix-shell',
ws: $ => / +/, _ws: $ => / +/,
opt_ws: $ => / */, _opt_ws: $ => / */,
newline: $ => '\n', _newline: $ => '\n',
} }
}); });