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

@ -87,3 +87,16 @@ Using directives
(using_directive_key) (using_directive_key)
(using_directive_value))) (using_directive_value)))
(comment)) (comment))
================================================================================
Shebang
================================================================================
#!/usr/bin/env -S scala-cli shebang -S 3
"shebang"
--------------------------------------------------------------------------------
(compilation_unit
(comment)
(string))

@ -103,8 +103,10 @@ module.exports = grammar({
rules: { rules: {
// TopStats ::= TopStat {semi TopStat} // TopStats ::= TopStat {semi TopStat}
compilation_unit: $ => compilation_unit: $ => seq(
optional($._shebang),
optional(trailingSep1($._semicolon, $._top_level_definition)), optional(trailingSep1($._semicolon, $._top_level_definition)),
),
_top_level_definition: $ => _top_level_definition: $ =>
choice( choice(
@ -1712,6 +1714,8 @@ module.exports = grammar({
repeat1($.guard), repeat1($.guard),
), ),
_shebang: $ => alias(token(seq("#!", /.*/)), $.comment),
comment: $ => seq(token("//"), choice($.using_directive, $._comment_text)), comment: $ => seq(token("//"), choice($.using_directive, $._comment_text)),
_comment_text: $ => token(prec(PREC.comment, /.*/)), _comment_text: $ => token(prec(PREC.comment, /.*/)),