Skip to content

Commit

Permalink
Update grammar to support modules and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 4, 2024
1 parent 9017e6e commit 59d457f
Show file tree
Hide file tree
Showing 8 changed files with 2,857 additions and 2,254 deletions.
6 changes: 6 additions & 0 deletions GRAMMAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ item : recipe
| alias
| assignment
| export
| import
| module
| setting
| eol

Expand All @@ -63,6 +65,10 @@ setting : 'set' 'dotenv-load' boolean?
| 'set' 'positional-arguments' boolean?
| 'set' 'shell' ':=' '[' string (',' string)* ','? ']'

import : 'import' '?'? string?

module : 'mod' '?'? NAME string?

boolean : ':=' ('true' | 'false')

expression : 'if' condition '{' expression '}' 'else' '{' expression '}'
Expand Down
19 changes: 18 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ module.exports = grammar({
// | alias
// | assignment
// | export
// | import
// | module
// | setting
// | eol
item: ($) =>
choice($.recipe, $.alias, $.assignment, $.export, $.setting, $.eol),
choice(
$.recipe,
$.alias,
$.assignment,
$.export,
$.import,
$.module,
$.setting,
$.eol,
),

// eol : NEWLINE
// | COMMENT NEWLINE
Expand All @@ -50,6 +61,12 @@ module.exports = grammar({
// export : 'export' assignment
export: ($) => seq("export", $.assignment),

// import : 'import' '?'? string?
import: ($) => seq("import", optional("?"), $.string),

// module : 'mod' '?'? string?
module: ($) => seq("mod", optional("?"), $.NAME, optional($.string)),

// setting : 'set' 'dotenv-load' boolean?
// | 'set' 'export' boolean?
// | 'set' 'positional-arguments' boolean?
Expand Down
12 changes: 10 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file specifies how matched syntax patterns should be highlighted

(assignment (NAME) @variable)
(alias (NAME) @variable)
(value (NAME) @variable)
Expand Down Expand Up @@ -28,9 +30,15 @@
; FIXME: interpreter
; (shebang interpreter:(TEXT) @keyword ) @comment

["export" "alias" "set"] @keyword
[
"alias"
"export"
"import"
"mod"
"set"
] @keyword

["@" "==" "!=" "+" ":=" ":"] @operator
["@" "==" "!=" "+" ":="] @operator

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

Expand Down
70 changes: 70 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
"type": "SYMBOL",
"name": "export"
},
{
"type": "SYMBOL",
"name": "import"
},
{
"type": "SYMBOL",
"name": "module"
},
{
"type": "SYMBOL",
"name": "setting"
Expand Down Expand Up @@ -130,6 +138,68 @@
}
]
},
"import": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "import"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "string"
}
]
},
"module": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "mod"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "?"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "NAME"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "BLANK"
}
]
}
]
},
"setting": {
"type": "CHOICE",
"members": [
Expand Down
54 changes: 54 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@
]
}
},
{
"type": "import",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "string",
"named": true
}
]
}
},
{
"type": "interpolation",
"named": true,
Expand Down Expand Up @@ -337,6 +352,14 @@
"type": "export",
"named": true
},
{
"type": "import",
"named": true
},
{
"type": "module",
"named": true
},
{
"type": "recipe",
"named": true
Expand Down Expand Up @@ -367,6 +390,25 @@
]
}
},
{
"type": "module",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "NAME",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "parameter",
"named": true,
Expand Down Expand Up @@ -793,6 +835,10 @@
"type": "=~",
"named": false
},
{
"type": "?",
"named": false
},
{
"type": "@",
"named": false
Expand Down Expand Up @@ -869,6 +915,14 @@
"type": "if",
"named": false
},
{
"type": "import",
"named": false
},
{
"type": "mod",
"named": false
},
{
"type": "notcomment",
"named": true
Expand Down
Loading

0 comments on commit 59d457f

Please sign in to comment.