Skip to content

Commit

Permalink
Add support for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 3, 2024
1 parent 3bb2032 commit c0c31a9
Show file tree
Hide file tree
Showing 9 changed files with 1,971 additions and 1,740 deletions.
4 changes: 3 additions & 1 deletion GRAMMAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ string : STRING
sequence : expression ',' sequence
| expression ','?

recipe : '@'? NAME parameter* variadic? ':' dependency* body?
recipe : attribute? '@'? NAME parameter* variadic? ':' dependency* body?

attribute : '[' NAME ']' eol

parameter : '$'? NAME
| '$'? NAME '=' value
Expand Down
9 changes: 6 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ module.exports = grammar({
seq($.expression, optional(",")),
),

// recipe : '@'? NAME parameter* variadic_parameters? ':' dependency* body?
recipe: ($) => seq($.recipeheader, $.NEWLINE, optional($.body)),
attribute: ($) => seq("[", $.NAME, "]", $.eol),

recipeheader: ($) =>
// recipe : attribute? '@'? NAME parameter* variadic_parameters? ':' dependency* body?
recipe: ($) =>
seq(optional($.attribute), $.recipe_header, $.NEWLINE, optional($.body)),

recipe_header: ($) =>
seq(
optional("@"),
$.NAME,
Expand Down
2 changes: 1 addition & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(call (NAME) @function)
(dependency (NAME) @function)
(depcall (NAME) @function)
(recipeheader (NAME) @function)
(recipe_header (NAME) @function)

(depcall (expression) @parameter)
(parameter) @parameter
Expand Down
2 changes: 1 addition & 1 deletion queries/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
(call (NAME) @reference.function)
(dependency (NAME) @reference.function)
(depcall (NAME) @reference.function)
(recipeheader (NAME) @definition.function)
(recipe_header (NAME) @definition.function)

2 changes: 1 addition & 1 deletion queries/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)

(item [(alias) (assignment) (export) (setting)]) @statement.outer
(recipeheader) @statement.outer
(recipe_header) @statement.outer
(line) @statement.outer

(comment) @comment.outer
37 changes: 35 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,12 +602,45 @@
}
]
},
"attribute": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SYMBOL",
"name": "NAME"
},
{
"type": "STRING",
"value": "]"
},
{
"type": "SYMBOL",
"name": "eol"
}
]
},
"recipe": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "attribute"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "recipeheader"
"name": "recipe_header"
},
{
"type": "SYMBOL",
Expand All @@ -627,7 +660,7 @@
}
]
},
"recipeheader": {
"recipe_header": {
"type": "SEQ",
"members": [
{
Expand Down
27 changes: 25 additions & 2 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@
]
}
},
{
"type": "attribute",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "NAME",
"named": true
},
{
"type": "eol",
"named": true
}
]
}
},
{
"type": "body",
"named": true,
Expand Down Expand Up @@ -398,12 +417,16 @@
"type": "NEWLINE",
"named": true
},
{
"type": "attribute",
"named": true
},
{
"type": "body",
"named": true
},
{
"type": "recipeheader",
"type": "recipe_header",
"named": true
}
]
Expand All @@ -425,7 +448,7 @@
}
},
{
"type": "recipeheader",
"type": "recipe_header",
"named": true,
"fields": {},
"children": {
Expand Down
Loading

0 comments on commit c0c31a9

Please sign in to comment.