Skip to content

Commit

Permalink
Clean up and better comment highlighting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 4, 2024
1 parent 87f48b8 commit c5538ee
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 98 deletions.
7 changes: 5 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = grammar({
seq(
"mod",
optional("?"),
field("modname", $.identifier),
field("mod_name", $.identifier),
optional($.string),
),

Expand All @@ -114,7 +114,10 @@ module.exports = grammar({
"set",
"shell",
":=",
array($.string),
field(
"right",
array($.string),
),
$.eol,
),
),
Expand Down
12 changes: 6 additions & 6 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
left: (identifier) @variable)

(module
modname: (identifier) @namespace)
mod_name: (identifier) @namespace)

(setting "shell" @keyword)
; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
(#any-of? @keyword
Expand All @@ -40,7 +40,7 @@
(function_call
name: (identifier) @function)


; highlight known attributes (filtering does not always work)
(attribute
attr_item: ((identifier) @attribute
(#any-of? @attribute
Expand All @@ -59,12 +59,10 @@
"windows-shell"
)))

(attribute
attr_item: (identifier) @variable)

(recipe_header
recipe_name: (identifier) @function)

; recipe argument specification
; pattern includes variadic_parameter
(parameter
param: (identifier) @variable.parameter
Expand All @@ -75,6 +73,7 @@
(dependency_expression
recipe: (identifier) @function)

; handle escape sequences
(string (_ (string_escape) @constant.character.escape))
(string) @string

Expand All @@ -93,6 +92,7 @@
"set"
] @keyword

; exclude `=` since it is only an operator in parameters (matching covered there)
["@" "==" "!=" "+" ":=" "*" ":" "/" "?"] @operator

["(" ")" "[" "]" "{{" "}}" "{" "}"] @punctuation.bracket
Expand Down
154 changes: 79 additions & 75 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
},
{
"type": "FIELD",
"name": "modname",
"name": "mod_name",
"content": {
"type": "SYMBOL",
"name": "identifier"
Expand Down Expand Up @@ -371,85 +371,89 @@
},
{
"type": "FIELD",
"name": "array",
"name": "right",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "FIELD",
"name": "contents",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
"type": "FIELD",
"name": "array",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "FIELD",
"name": "contents",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
}
}
}
]
]
}
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "array_item",
"content": {
"type": "SYMBOL",
"name": "string"
}
},
{
"type": "BLANK"
}
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
]
}
]
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": "]"
}
},
{
"type": "STRING",
"value": "]"
}
]
]
}
}
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
"type": "module",
"named": true,
"fields": {
"modname": {
"mod_name": {
"multiple": false,
"required": true,
"types": [
Expand Down Expand Up @@ -663,6 +663,14 @@
"type": ":=",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "boolean",
"named": true
Expand Down
28 changes: 14 additions & 14 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ enum {
field_expression = 8,
field_kleene = 9,
field_left = 10,
field_modname = 11,
field_mod_name = 11,
field_name = 12,
field_param = 13,
field_recipe = 14,
Expand All @@ -786,7 +786,7 @@ static const char * const ts_field_names[] = {
[field_expression] = "expression",
[field_kleene] = "kleene",
[field_left] = "left",
[field_modname] = "modname",
[field_mod_name] = "mod_name",
[field_name] = "name",
[field_param] = "param",
[field_recipe] = "recipe",
Expand Down Expand Up @@ -843,13 +843,13 @@ static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {

static const TSFieldMapEntry ts_field_map_entries[] = {
[0] =
{field_modname, 1},
{field_mod_name, 1},
[1] =
{field_recipe_name, 0},
[2] =
{field_param, 0},
[3] =
{field_modname, 2},
{field_mod_name, 2},
[4] =
{field_left, 1},
[5] =
Expand Down Expand Up @@ -896,8 +896,8 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
[30] =
{field_contents, 1},
[31] =
{field_array, 3},
{field_array, 4},
{field_right, 3},
{field_right, 4},
[33] =
{field_array, 3},
{field_array, 4},
Expand All @@ -921,9 +921,9 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
[47] =
{field_array_item, 1},
[48] =
{field_array, 3},
{field_array, 5},
{field_array_item, 4},
{field_right, 3},
{field_right, 5},
[51] =
{field_array_item, 0, .inherited = true},
{field_array_item, 1, .inherited = true},
Expand All @@ -942,16 +942,16 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_braced_body, 0, .inherited = true},
{field_braced_body, 1, .inherited = true},
[63] =
{field_array, 3},
{field_array, 6},
{field_array_item, 4},
{field_array_item, 5},
{field_right, 3},
{field_right, 6},
[67] =
{field_array, 3},
{field_array, 6},
{field_array_item, 4},
{field_array_item, 5, .inherited = true},
{field_contents, 5},
{field_right, 3},
{field_right, 6},
[72] =
{field_array, 3},
{field_array, 6},
Expand All @@ -972,12 +972,12 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_braced_body, 3, .inherited = true},
{field_braced_body, 5, .inherited = true},
[88] =
{field_array, 3},
{field_array, 7},
{field_array_item, 4},
{field_array_item, 5, .inherited = true},
{field_array_item, 6},
{field_contents, 5},
{field_right, 3},
{field_right, 7},
[94] =
{field_array, 3},
{field_array, 7},
Expand Down

0 comments on commit c5538ee

Please sign in to comment.