Skip to content

Commit 1d3a1f9

Browse files
authored
Merge pull request #363 from antosha417/shebang
Support shebang.
2 parents aa84398 + 526d3b1 commit 1d3a1f9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

corpus/comments.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Using directives
6464
//> using jvm graalvm:21
6565
//> using scala 3.3.0
6666
//> using dep foo:bar:1,2,3,url=https://github.com
67-
//> using exclude "examples/*" "*/resources/*"
67+
//> using exclude "examples/*" "*/resources/*"
6868
// > just a comment
6969

7070
--------------------------------------------------------------------------------
@@ -87,3 +87,16 @@ Using directives
8787
(using_directive_key)
8888
(using_directive_value)))
8989
(comment))
90+
91+
================================================================================
92+
Shebang
93+
================================================================================
94+
95+
#!/usr/bin/env -S scala-cli shebang -S 3
96+
97+
"shebang"
98+
--------------------------------------------------------------------------------
99+
100+
(compilation_unit
101+
(comment)
102+
(string))

grammar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ module.exports = grammar({
103103

104104
rules: {
105105
// TopStats ::= TopStat {semi TopStat}
106-
compilation_unit: $ =>
106+
compilation_unit: $ => seq(
107+
optional($._shebang),
107108
optional(trailingSep1($._semicolon, $._top_level_definition)),
109+
),
108110

109111
_top_level_definition: $ =>
110112
choice(
@@ -1712,6 +1714,8 @@ module.exports = grammar({
17121714
repeat1($.guard),
17131715
),
17141716

1717+
_shebang: $ => alias(token(seq("#!", /.*/)), $.comment),
1718+
17151719
comment: $ => seq(token("//"), choice($.using_directive, $._comment_text)),
17161720
_comment_text: $ => token(prec(PREC.comment, /.*/)),
17171721

0 commit comments

Comments
 (0)