Skip to content

Commit

Permalink
Merge pull request #160 from alanpearce/shebang-spaces
Browse files Browse the repository at this point in the history
Allow spaces after shebang
  • Loading branch information
tgross35 authored May 2, 2024
2 parents 72937dd + 2bf2bbd commit fd814fc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ module.exports = grammar({
recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

// Any shebang. Needs a named field to apply injection queries correctly.
shebang: ($) => seq("#!", choice($._shebang_with_lang, $._opaque_shebang)),
shebang: ($) =>
seq(/#![ \t]*/, choice($._shebang_with_lang, $._opaque_shebang)),

// Shebang with a nested `language` token that we can extract
_shebang_with_lang: ($) =>
Expand Down
4 changes: 2 additions & 2 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/corpus/recipes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@ foo:
(recipe_line
(text)))))

================================================================================
shebang with spaces
================================================================================

foo:
#! /bin/sh
if [ -f "foo" ]; then
echo "foo {{var}}"
fi

--------------------------------------------------------------------------------

(source_file
(recipe
(recipe_header
(identifier))
(recipe_body
(shebang
(language))
(recipe_line
(text))
(recipe_line
(text)
(interpolation
(expression
(value
(identifier))))
(text))
(recipe_line
(text)))))

================================================================================
shebang with longer body
================================================================================
Expand Down
21 changes: 21 additions & 0 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,27 @@ foo:

--------------------------------------------------------------------------------

(source_file
(shebang
(language))
(recipe
(recipe_header
(identifier))
(recipe_body
(recipe_line
(text)))))

================================================================================
shebang with space
================================================================================

#! /usr/bin/env just

foo:
body

--------------------------------------------------------------------------------

(source_file
(shebang
(language))
Expand Down

0 comments on commit fd814fc

Please sign in to comment.