Skip to content

Commit

Permalink
Add indentation rules for strings and commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 5, 2024
1 parent 164edbe commit 6cc329c
Show file tree
Hide file tree
Showing 11 changed files with 3,839 additions and 4,385 deletions.
26 changes: 14 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = grammar({
inline: (
$,
) => [
$._string,
$._string_indented,
$._raw_string_indented,
$._expression_braced,
$._expression_recurse,
],
Expand Down Expand Up @@ -192,7 +195,7 @@ module.exports = grammar({
),

external_command: ($) =>
choice(seq($.backticked), seq($.indented_backticked)),
choice(seq($._backticked), seq($._indented_backticked)),

// sequence : expression ',' sequence
// | expression ','?
Expand Down Expand Up @@ -299,22 +302,21 @@ module.exports = grammar({
// | INDENTED_RAW_STRING
string: ($) =>
choice(
$.basic_string,
$.basic_string_indented,
$.raw_string,
$.raw_string_indented,
$._string_indented,
$._raw_string_indented,
$._string,
// _raw_string, can't be written as a separate inline for osm reason
/'[^']*'/,
),

raw_string: (_) => /'[^']*'/,
raw_string_indented: (_) => seq("'''", repeat(/./), "'''"),
basic_string: ($) =>
seq('"', repeat(choice($.string_escape, /[^\\"]+/)), '"'),
basic_string_indented: ($) =>
_raw_string_indented: (_) => seq("'''", repeat(/./), "'''"),
_string: ($) => seq('"', repeat(choice($.string_escape, /[^\\"]+/)), '"'),
_string_indented: ($) =>
seq('"""', repeat(choice($.string_escape, /[^\\"]+/)), '"""'),
string_escape: (_) => /\\[nrt"\\]/,

backticked: (_) => seq("`", repeat(/./), "`"),
indented_backticked: (_) => seq("```", repeat(/./), "```"),
_backticked: (_) => seq("`", repeat(/./), "`"),
_indented_backticked: (_) => seq("```", repeat(/./), "```"),

text: (_) => /.+/, //recipe TEXT, only matches in a recipe body
// text: (_) => /\S+/, //recipe TEXT, only matches in a recipe body
Expand Down
13 changes: 9 additions & 4 deletions queries/folds.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
; Define collapse points

(recipe) @fold
(recipe_body) @fold
(interpolation) @fold
(item (_) @fold)
(
[
(recipe)
(recipe_body)
(interpolation)
(item (_))
] @fold
(#trim! @fold)
)
8 changes: 5 additions & 3 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
(shebang) @comment

(alias left: (identifier) @variable)
(assignment left: (identifier) @variable)
(assignment
left: (identifier) @variable
[":="] @operator)

(module mod_name: (identifier) @namespace)

Expand Down Expand Up @@ -69,7 +71,7 @@
(dependency_expression recipe: (identifier) @function)

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

(comment) @comment.line
Expand All @@ -89,7 +91,7 @@

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

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

Expand Down
8 changes: 7 additions & 1 deletion queries/indents.scm
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
(recipe_body) @indent
; This query
;
; Better documentation is in https://docs.helix-editor.com/guides/indent.html

(recipe) @indent @extend
(string) @indent @extend
(external_command) @indent @extend
31 changes: 15 additions & 16 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@
"members": [
{
"type": "SYMBOL",
"name": "backticked"
"name": "_backticked"
}
]
},
Expand All @@ -801,7 +801,7 @@
"members": [
{
"type": "SYMBOL",
"name": "indented_backticked"
"name": "_indented_backticked"
}
]
}
Expand Down Expand Up @@ -1313,27 +1313,23 @@
"members": [
{
"type": "SYMBOL",
"name": "basic_string"
"name": "_string_indented"
},
{
"type": "SYMBOL",
"name": "basic_string_indented"
"name": "_raw_string_indented"
},
{
"type": "SYMBOL",
"name": "raw_string"
"name": "_string"
},
{
"type": "SYMBOL",
"name": "raw_string_indented"
"type": "PATTERN",
"value": "'[^']*'"
}
]
},
"raw_string": {
"type": "PATTERN",
"value": "'[^']*'"
},
"raw_string_indented": {
"_raw_string_indented": {
"type": "SEQ",
"members": [
{
Expand All @@ -1353,7 +1349,7 @@
}
]
},
"basic_string": {
"_string": {
"type": "SEQ",
"members": [
{
Expand Down Expand Up @@ -1382,7 +1378,7 @@
}
]
},
"basic_string_indented": {
"_string_indented": {
"type": "SEQ",
"members": [
{
Expand Down Expand Up @@ -1415,7 +1411,7 @@
"type": "PATTERN",
"value": "\\\\[nrt\"\\\\]"
},
"backticked": {
"_backticked": {
"type": "SEQ",
"members": [
{
Expand All @@ -1435,7 +1431,7 @@
}
]
},
"indented_backticked": {
"_indented_backticked": {
"type": "SEQ",
"members": [
{
Expand Down Expand Up @@ -1483,6 +1479,9 @@
}
],
"inline": [
"_string",
"_string_indented",
"_raw_string_indented",
"ReferenceError",
"_expression_recurse"
],
Expand Down
83 changes: 4 additions & 79 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,41 +101,6 @@
]
}
},
{
"type": "backticked",
"named": true,
"fields": {}
},
{
"type": "basic_string",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "string_escape",
"named": true
}
]
}
},
{
"type": "basic_string_indented",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "string_escape",
"named": true
}
]
}
},
{
"type": "boolean",
"named": true,
Expand Down Expand Up @@ -284,21 +249,7 @@
{
"type": "external_command",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "backticked",
"named": true
},
{
"type": "indented_backticked",
"named": true
}
]
}
"fields": {}
},
{
"type": "function_call",
Expand Down Expand Up @@ -367,11 +318,6 @@
]
}
},
{
"type": "indented_backticked",
"named": true,
"fields": {}
},
{
"type": "interpolation",
"named": true,
Expand Down Expand Up @@ -501,11 +447,6 @@
]
}
},
{
"type": "raw_string_indented",
"named": true,
"fields": {}
},
{
"type": "recipe",
"named": true,
Expand Down Expand Up @@ -741,23 +682,11 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"multiple": true,
"required": false,
"types": [
{
"type": "basic_string",
"named": true
},
{
"type": "basic_string_indented",
"named": true
},
{
"type": "raw_string",
"named": true
},
{
"type": "raw_string_indented",
"type": "string_escape",
"named": true
}
]
Expand Down Expand Up @@ -960,10 +889,6 @@
"type": "mod",
"named": false
},
{
"type": "raw_string",
"named": true
},
{
"type": "set",
"named": false
Expand Down
Loading

0 comments on commit 6cc329c

Please sign in to comment.