diff --git a/corpus/comments.txt b/corpus/comments.txt index 27bc42a6f..f1354d4c2 100644 --- a/corpus/comments.txt +++ b/corpus/comments.txt @@ -64,7 +64,7 @@ Using directives //> using jvm graalvm:21 //> using scala 3.3.0 //> using dep foo:bar:1,2,3,url=https://github.com -//> using exclude "examples/*" "*/resources/*" +//> using exclude "examples/*" "*/resources/*" // > just a comment -------------------------------------------------------------------------------- @@ -87,3 +87,16 @@ Using directives (using_directive_key) (using_directive_value))) (comment)) + +================================================================================ +Shebang +================================================================================ + +#!/usr/bin/env -S scala-cli shebang -S 3 + +"shebang" +-------------------------------------------------------------------------------- + +(compilation_unit + (comment) + (string)) diff --git a/grammar.js b/grammar.js index f3b9ccd45..fa31f191c 100644 --- a/grammar.js +++ b/grammar.js @@ -103,8 +103,10 @@ module.exports = grammar({ rules: { // TopStats ::= TopStat {semi TopStat} - compilation_unit: $ => + compilation_unit: $ => seq( + optional($._shebang), optional(trailingSep1($._semicolon, $._top_level_definition)), + ), _top_level_definition: $ => choice( @@ -1712,6 +1714,8 @@ module.exports = grammar({ repeat1($.guard), ), + _shebang: $ => alias(token(seq("#!", /.*/)), $.comment), + comment: $ => seq(token("//"), choice($.using_directive, $._comment_text)), _comment_text: $ => token(prec(PREC.comment, /.*/)),