Skip to content

Commit

Permalink
Try to figure out global settings
Browse files Browse the repository at this point in the history
I think we really need some form of regex to handle this
  • Loading branch information
tgross35 committed Jan 8, 2024
1 parent 7765fb3 commit a6d75f8
Show file tree
Hide file tree
Showing 10 changed files with 3,702 additions and 4,240 deletions.
23 changes: 7 additions & 16 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function comma_sep1(item) {
}

// Create an array with the given item as contents
function array(item) {
function make_array(item) {
const array_item = field("array_item", item);
return field(
"array",
Expand Down Expand Up @@ -119,26 +119,17 @@ module.exports = grammar({
seq(
"set",
field("left", $.identifier),
field(
"right",
optional(
seq(":=", choice($.boolean, $._string, array($._string))),
),
),
$.eol,
),
seq(
"set",
"shell",
":=",
field(
"right",
array($._string),
optional(
seq(":=", field("right", choice($.boolean, $._string, $.array))),
),
$.eol,
),
),

// Our only use of arrays (setting) only accepts strings. We may want to figure
// out how to better reuse `array` while specifying a type.
array: ($) => make_array($._string),

// boolean : ':=' ('true' | 'false')
boolean: (_) => choice("true", "false"),

Expand Down
3 changes: 2 additions & 1 deletion queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
(alias left: (identifier) @variable)
(assignment
left: (identifier) @variable
[":="] @operator)
":=" @operator)

(module mod_name: (identifier) @namespace)

; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
":="? @operator
(#any-of? @keyword
"allow-duplicate-recipes"
"dotenv-filename"
Expand Down
42 changes: 25 additions & 17 deletions queries-src/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@
((comment) @injection.content
(#set! injection.language "comment"))

; NVIM-DISABLE-START
(recipe_body
(shebang) @injection.shebang
(recipe_line
(text) @injection.content))
; NVIM-DISABLE-END
(source_file
(item
(setting
left: "shell")))
right: (array
)

(recipe_line
(text) @injection.content
(#set! injection.language "bash"))
; TODO reenable
; ; NVIM-DISABLE-START
; (recipe_body
; (shebang) @injection.shebang
; (recipe_line
; (text) @injection.content))
; ; NVIM-DISABLE-END

; NVIM-ENABLE (recipe_body
; NVIM-ENABLE (shebang) @injection.language
; NVIM-ENABLE (recipe_line
; NVIM-ENABLE (text) @injection.content)
; NVIM-ENABLE (#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))
; (recipe_line
; (text) @injection.content
; (#set! injection.language "bash"))

(external_command
(command_body) @injection.content
(#set! injection.language "bash"))
; ; NVIM-ENABLE (recipe_body
; ; NVIM-ENABLE (shebang) @injection.language
; ; NVIM-ENABLE (recipe_line
; ; NVIM-ENABLE (text) @injection.content)
; ; NVIM-ENABLE (#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))

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

((regex_literal
[
Expand Down
3 changes: 2 additions & 1 deletion queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
(alias left: (identifier) @variable)
(assignment
left: (identifier) @variable
[":="] @operator)
":=" @operator)

(module mod_name: (identifier) @namespace)

; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
":="? @operator
(#any-of? @keyword
"allow-duplicate-recipes"
"dotenv-filename"
Expand Down
25 changes: 16 additions & 9 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
((comment) @injection.content
(#set! injection.language "comment"))

(source_file
(item
(setting
left: "shell")))
right: (array
)

;

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

(recipe_body
(shebang) @injection.shebang
(shebang) @injection.language
(recipe_line
(text) @injection.content
(#set! injection.language "python")))
(text) @injection.content)
(#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))

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

((regex_literal
[
Expand Down
Loading

0 comments on commit a6d75f8

Please sign in to comment.