Skip to content

Commit

Permalink
Add successful detection logic for shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 7, 2024
1 parent e4e2405 commit 4049c9a
Show file tree
Hide file tree
Showing 9 changed files with 4,181 additions and 3,977 deletions.
34 changes: 32 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ module.exports = grammar({

rules: {
// justfile : item* EOF
source_file: ($) => seq(optional($.shebang), repeat($.item)),
source_file: ($) =>
seq(
repeat(prec(2, $.eol)),
optional($.shebang),
repeat($.item),
),

// _sheb: ($) => ,

// item : recipe
// | alias
Expand Down Expand Up @@ -295,7 +302,30 @@ module.exports = grammar({

recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

shebang: ($) => seq(/\s*#!.*/, $._newline),
shebang: ($) =>
prec(
4,
seq(
// token.immediate(
// /\s*#!.*/,
// choice(
// prec(
// 2,
// token.immediate(
// $.shebang_language,
// // seq(/\S*bin\S*[/ ]/, $.shebang_language, optional(/.+/)),
// ),
// ),
// // /.*/,
// ),
// ),
/#!.*/,
$._newline,
),
),

shebang_language: ($) => /.+/,
///\S+/,

// `# ...` comment
comment: ($) => seq(/#.*/, $._newline),
Expand Down
17 changes: 5 additions & 12 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(#set! injection.language "comment"))


; FIXME: read default from shebang
(recipe_line
(text) @injection.content
(#set! injection.language "bash"))
Expand All @@ -15,16 +16,8 @@
(#set! injection.language "bash"))

((regex_literal
[(string_literal)
(raw_string_literal)] @injection.content)
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))

; ; FIXME: read default from shebang
; ([
; (recipe_body
; (recipe_line (text)))
; (external_command
; body: (_)*)
; ] @injection.content
; (#set! injection.language "bash")
; )
41 changes: 30 additions & 11 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
"source_file": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "SYMBOL",
"name": "eol"
}
}
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -1252,17 +1263,25 @@
]
},
"shebang": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "\\s*#!.*"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
"type": "PREC",
"value": 4,
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "#!.*"
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
}
},
"shebang_language": {
"type": "PATTERN",
"value": ".+"
},
"comment": {
"type": "SEQ",
Expand Down
13 changes: 9 additions & 4 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "eol",
"named": true
},
{
"type": "item",
"named": true
Expand Down Expand Up @@ -822,6 +826,11 @@
}
}
},
{
"type": "text",
"named": true,
"fields": {}
},
{
"type": "value",
"named": true,
Expand Down Expand Up @@ -1027,10 +1036,6 @@
"type": "shell",
"named": false
},
{
"type": "text",
"named": true
},
{
"type": "true",
"named": false
Expand Down
Loading

0 comments on commit 4049c9a

Please sign in to comment.