diff --git a/corpus/payload.txt b/corpus/payload.txt index f9031ac..4305fda 100644 --- a/corpus/payload.txt +++ b/corpus/payload.txt @@ -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)) diff --git a/corpus/shebang_only.txt b/corpus/shebang_only.txt index 2584759..0c783d0 100644 --- a/corpus/shebang_only.txt +++ b/corpus/shebang_only.txt @@ -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)) diff --git a/corpus/shebang_with_sub_interpreter.txt b/corpus/shebang_with_sub_interpreter.txt index 9c75a89..026c400 100644 --- a/corpus/shebang_with_sub_interpreter.txt +++ b/corpus/shebang_with_sub_interpreter.txt @@ -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)))) diff --git a/grammar.js b/grammar.js index ded906c..9192f83 100644 --- a/grammar.js +++ b/grammar.js @@ -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', } });