Skip to content

Commit

Permalink
Merge pull request #363 from antosha417/shebang
Browse files Browse the repository at this point in the history
Support shebang.
  • Loading branch information
susliko authored Sep 23, 2023
2 parents aa84398 + 526d3b1 commit 1d3a1f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 14 additions & 1 deletion corpus/comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

--------------------------------------------------------------------------------
Expand All @@ -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))
6 changes: 5 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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, /.*/)),

Expand Down

0 comments on commit 1d3a1f9

Please sign in to comment.