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
(first_line
(shebang_open)
(opt_ws)
(env)
(ws)
(nix_shell))
(first_line)
(next_line
(newline)
(annotation_line
(shebang_open)
(opt_ws)
(nix_shell)
(nix_shell_args)))
(next_line
(newline)))
(next_line))

View File

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

View File

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

View File

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