Skip to content

Commit

Permalink
Allow parsing shebangs that do not match a language
Browse files Browse the repository at this point in the history
Add a fallback to the shebang parser using complement regex.
  • Loading branch information
tgross35 committed Mar 4, 2024
1 parent 51aa99c commit 43f2c5e
Show file tree
Hide file tree
Showing 6 changed files with 3,595 additions and 3,522 deletions.
15 changes: 9 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = grammar({
$._string,
$._string_indented,
$._raw_string_indented,
$._expression_braced,
$._expression_recurse,
],
word: ($) => $.identifier,
Expand Down Expand Up @@ -294,16 +293,20 @@ module.exports = grammar({

recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

shebang: ($) =>
shebang: ($) => seq("#!", choice($._shebang_with_lang, $._opaque_shebang)),

// Shebang with a nested `language` token that we can extract
_shebang_with_lang: ($) =>
seq(
"#!",
/.*\//,
optional(seq("env ", repeat(SHEBANG_ENV_FLAG))),
// defer dilemma: python3 => python, but json5 => json5
/\S*\//,
optional(seq("env", repeat(SHEBANG_ENV_FLAG))),
alias($.identifier, $.language),
/.*/,
),

// Fallback shebang, any string
_opaque_shebang: (_) => /[^/]+/,

// string : STRING
// | INDENTED_STRING
// | RAW_STRING
Expand Down
1 change: 0 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ errors_expected := '''
# FIXME: xfail files, these should parse correctly
repositories/just/examples/kitchen-sink.just
repositories/just/examples/powershell.just
'''

# Files used for testing that Just itself might not understand
Expand Down
26 changes: 24 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: 2 additions & 2 deletions src/node-types.json

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

Loading

0 comments on commit 43f2c5e

Please sign in to comment.