Merge pull request #363 from antosha417/shebang

Support shebang.
pull/659/head
Vasil Markoukin 2023-09-23 17:06:34 +07:00 committed by GitHub
commit 1d3a1f9f18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

@ -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))

@ -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, /.*/)),