Skip to content

Commit

Permalink
Add support for injections in recipes and commands
Browse files Browse the repository at this point in the history
Use bash as a defaul
  • Loading branch information
tgross35 committed Jan 7, 2024
1 parent 064c602 commit 37ae0e3
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 336 deletions.
19 changes: 11 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,29 @@ module.exports = grammar({

string_literal: ($) =>
seq(
$._string_start,
repeat(choice($._string_body, $.escape_sequence)),
$._string_end,
field("open", alias($._string_start, '("|""")')),
field("body", repeat(choice($._string_body, $.escape_sequence))),
field("close", alias($._string_end, '("|""")')),
),

raw_string_literal: ($) =>
seq($._raw_string_start, optional($._string_body), $._raw_string_end),
seq(
field("open", alias($._raw_string_start, "('|''')")),
field("body", optional($._string_body)),
field("close", alias($._raw_string_end, "('|''')")),
),

external_command: ($) =>
seq(
$._command_start,
repeat(choice(prec(1, $.interpolation), $.command_body)),
$._command_end,
field("open", alias($._command_start, "(`|```)")),
field("body", repeat(choice(prec(1, $.interpolation), $.command_body))),
field("close", alias($._command_end, "(`|```)")),
),

command_body: ($) => $._string_body,

escape_sequence: (_) => ESCAPE_SEQUENCE,

text: (_) => /.+/, //recipe TEXT, only matches in a recipe body
// text: (_) => /\S+/, //recipe TEXT, only matches in a recipe body
},
});
14 changes: 7 additions & 7 deletions queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@

(comment) @comment.line

; (interpolation) @string

; FIXME: interpreter
; (shebang interpreter:(TEXT) @keyword ) @comment

[
"alias"
"export"
Expand All @@ -92,14 +87,19 @@
"set"
] @keyword

; exclude `=` and `&&` since they are valid in more normal scopes
; exclude `=` and `&&` since they are valid only in specific scopes
; (matching is covered in their parent nodes)
["@" "==" "!=" "+" "*" ":" "/" "?"] @operator

["(" ")" "[" "]" "{{" "}}" "{" "}"] @punctuation.bracket

["," ":"] @punctuation.delimiter

; "`" @punctuation.special

; open and close are "`" or "```"
(external_command
open: _ @punctuation.special
close: _ @punctuation.special
)

(ERROR) @error
32 changes: 20 additions & 12 deletions queries-src/injections.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
(comment) @comment
; This query specifies how nested languages are handled

; FIXME: shebang
; (shebang_recipe
; (shebang
; interpreter:(TEXT) @language)
; (shebang_body) @content
; )
((comment) @injection.content
(#set! injection.language "comment"))

(source_file
; (item (setting lang:(identifier) @language))
(item (recipe (recipe_body) @content))
)

; (interpolation (expression) @just)
(recipe_line
(text) @injection.content
(#set! injection.language "bash"))

(external_command
(command_body) @injection.content
(#set! injection.language "bash"))

; ; FIXME: read default from shebang
; ([
; (recipe_body
; (recipe_line (text)))
; (external_command
; body: (_)*)
; ] @injection.content
; (#set! injection.language "bash")
; )
14 changes: 7 additions & 7 deletions queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@

(comment) @comment

; (interpolation) @string

; FIXME: interpreter
; (shebang interpreter:(TEXT) @keyword ) @comment

[
"alias"
"export"
Expand All @@ -94,14 +89,19 @@
"set"
] @keyword

; exclude `=` and `&&` since they are valid in more normal scopes
; exclude `=` and `&&` since they are valid only in specific scopes
; (matching is covered in their parent nodes)
["@" "==" "!=" "+" "*" ":" "/" "?"] @operator

["(" ")" "[" "]" "{{" "}}" "{" "}"] @punctuation.bracket

["," ":"] @punctuation.delimiter

; "`" @punctuation.special

; open and close are "`" or "```"
(external_command
open: _ @punctuation.special
close: _ @punctuation.special
)

(ERROR) @error
32 changes: 20 additions & 12 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
; File autogenerated by build-queries-nvim.py; do not edit

(comment) @comment
; This query specifies how nested languages are handled

; FIXME: shebang
; (shebang_recipe
; (shebang
; interpreter:(TEXT) @language)
; (shebang_body) @content
; )
((comment) @injection.content
(#set! injection.language "comment"))

(source_file
; (item (setting lang:(identifier) @language))
(item (recipe (recipe_body) @content))
)

; (interpolation (expression) @just)
(recipe_line
(text) @injection.content
(#set! injection.language "bash"))

(external_command
(command_body) @injection.content
(#set! injection.language "bash"))

; ; FIXME: read default from shebang
; ([
; (recipe_body
; (recipe_line (text)))
; (external_command
; body: (_)*)
; ] @injection.content
; (#set! injection.language "bash")
; )
162 changes: 114 additions & 48 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1298,86 +1298,152 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_string_start"
"type": "FIELD",
"name": "open",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_string_start"
},
"named": false,
"value": "(\"|\"\"\")"
}
},
{
"type": "REPEAT",
"type": "FIELD",
"name": "body",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_body"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_body"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
}
},
{
"type": "SYMBOL",
"name": "_string_end"
"type": "FIELD",
"name": "close",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_string_end"
},
"named": false,
"value": "(\"|\"\"\")"
}
}
]
},
"raw_string_literal": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_raw_string_start"
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "open",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_string_body"
"name": "_raw_string_start"
},
{
"type": "BLANK"
}
]
"named": false,
"value": "('|''')"
}
},
{
"type": "SYMBOL",
"name": "_raw_string_end"
"type": "FIELD",
"name": "body",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_body"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "close",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_raw_string_end"
},
"named": false,
"value": "('|''')"
}
}
]
},
"external_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_command_start"
"type": "FIELD",
"name": "open",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_command_start"
},
"named": false,
"value": "(`|```)"
}
},
{
"type": "REPEAT",
"type": "FIELD",
"name": "body",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 1,
"content": {
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "interpolation"
}
},
{
"type": "SYMBOL",
"name": "interpolation"
"name": "command_body"
}
},
{
"type": "SYMBOL",
"name": "command_body"
}
]
]
}
}
},
{
"type": "SYMBOL",
"name": "_command_end"
"type": "FIELD",
"name": "close",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_command_end"
},
"named": false,
"value": "(`|```)"
}
}
]
},
Expand Down
Loading

0 comments on commit 37ae0e3

Please sign in to comment.