Skip to content

Commit

Permalink
Fix arrays and set strings
Browse files Browse the repository at this point in the history
Temporary break of textobjects.

Fixes #22
  • Loading branch information
tgross35 committed Jan 3, 2024
1 parent c0c31a9 commit 7145bf1
Show file tree
Hide file tree
Showing 7 changed files with 2,544 additions and 2,216 deletions.
45 changes: 27 additions & 18 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Main grammar for justfiles

// Comma separated list with at least one item
function comma_sep1(item) {
return seq(item, repeat(seq(",", item)));
}

// Create an array with the given item as contents
function array(item) {
const array_item = field("array_item", item);
return field(
"array",
seq(
"[",
optional(seq(comma_sep1(array_item), optional(array_item))),
"]",
),
);
}

module.exports = grammar({
name: "just",

Expand Down Expand Up @@ -42,37 +62,26 @@ module.exports = grammar({
seq(
"set",
field("name", $.NAME),
field("right", optional(seq(":=", choice($.boolean, $.settinglist)))),
field(
"right",
optional(
seq(":=", choice($.boolean, $.string, array($.string))),
),
),
$.eol,
),
seq(
"set",
"shell",
":=",
"[",
// field("lang", $.string),
'"',
field("lang", $.NAME),
'"',
repeat(seq(optional(","), $.string)),
"]",
array($.string),
$.eol,
),
),

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

settinglist: ($) =>
seq(
"[",
$.stringlist,
"]",
// seq("[", $.string, repeat(seq(",", $.string)), optional(","), "]")
),

stringlist: ($) => repeat1(seq($.string, optional(","))),

// expression : 'if' condition '{' expression '}' 'else' '{' expression '}'
// | value '/' expression
// | value '+' expression
Expand Down
2 changes: 1 addition & 1 deletion queries/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

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

Expand Down
18 changes: 10 additions & 8 deletions queries/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
else:(expression) @block.inner
)
(interpolation (expression) @block.inner) @block.outer
(settinglist (stringlist) @block.inner) @block.outer
; (string_array (stringlist) @block.inner) @block.outer

(call (NAME) @call.inner) @call.outer
(dependency (NAME) @call.inner) @call.outer
Expand All @@ -19,14 +19,16 @@
(depcall) @parameter.inner
(depcall (expression) @parameter.inner)

(stringlist
(string) @parameter.inner
. ","? @_end
(#make-range! "parameter.outer" @parameter.inner @_end)
)
; (stringlist
; (string) @parameter.inner
; . ","? @_end
; (#make-range! "parameter.outer" @parameter.inner @_end)
; )
(parameters
[(parameter)
(variadic_parameters)] @parameter.inner
[
(parameter)
(variadic_parameters)
] @parameter.inner
. " "? @_end
(#make-range! "parameter.outer" @parameter.inner @_end)
)
Expand Down
209 changes: 139 additions & 70 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,86 @@
},
{
"type": "SYMBOL",
"name": "settinglist"
"name": "string"
},
{
"type": "FIELD",
"name": "array",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"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": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
}
}
]
}
Expand Down Expand Up @@ -186,54 +265,85 @@
"type": "STRING",
"value": ":="
},
{
"type": "STRING",
"value": "["
},
{
"type": "STRING",
"value": "\""
},
{
"type": "FIELD",
"name": "lang",
"content": {
"type": "SYMBOL",
"name": "NAME"
}
},
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"name": "array",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
"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": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "string"
"type": "STRING",
"value": "]"
}
]
}
},
{
"type": "STRING",
"value": "]"
},
{
"type": "SYMBOL",
"name": "eol"
Expand All @@ -255,47 +365,6 @@
}
]
},
"settinglist": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "stringlist"
},
{
"type": "STRING",
"value": "]"
}
]
},
"stringlist": {
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
"expression": {
"type": "CHOICE",
"members": [
Expand Down
Loading

0 comments on commit 7145bf1

Please sign in to comment.