diff --git a/corpus/shebang.txt b/corpus/shebang.txt index ff9caa4..8791c6b 100644 --- a/corpus/shebang.txt +++ b/corpus/shebang.txt @@ -15,6 +15,26 @@ nix-shell shebang whitespace #! /usr/bin/env nix-shell --- +(source_file + (first_line)) + +================== +nix-shell shebang tab +================== + +#! /usr/bin/env nix-shell +--- + +(source_file + (first_line)) + +================== +nix-shell shebang tabs and spaces +================== + +#! /usr/bin/env nix-shell +--- + (source_file (first_line)) diff --git a/grammar.js b/grammar.js index ead1555..27ddffa 100644 --- a/grammar.js +++ b/grammar.js @@ -55,8 +55,12 @@ module.exports = grammar({ 'env', ), _nix_shell: $ => 'nix-shell', - _ws: $ => / +/, - _opt_ws: $ => / */, + // N.B.: this accepts more than it needs to: + // - shebang parser allows tab characters + // - #!nix-shell directives do not support tabs + // - wherever #!nix-shell directives allow whitespace, it's a *single* space -- never multiple + _ws: $ => /[ \t]+/, + _opt_ws: $ => /[ \t]*/, _newline: $ => '\n', } });