Skip to content

Commit

Permalink
fix: update grammar to support user defined imports
Browse files Browse the repository at this point in the history
Since 0.23.x bicep supports imports of user-defined objects.
`provider` syntax is also equivalent to previous import syntax.
  • Loading branch information
cronsorcery authored and amaanq committed Feb 1, 2024
1 parent 3604d8c commit 02f3699
Show file tree
Hide file tree
Showing 7 changed files with 14,486 additions and 13,309 deletions.
17 changes: 15 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports = grammar({
$.declaration,
$.import_statement,
$.import_with_statement,
$.import_functionality,
$.target_scope_assignment,
),

Expand All @@ -98,17 +99,28 @@ module.exports = grammar({
),

import_statement: $ => seq(
'import',
choice('import', 'provider'),
$.import_string,
optional(seq('as', $.identifier)),
),

import_with_statement: $ => seq(
'import',
choice('import', 'provider'),
$.import_string,
'with',
$.expression,
),

import_functionality: $ => seq(
'import',
choice(
seq('{', commaSep1(choice(seq($.identifier, 'as', $.identifier), $.identifier)), '}'),
seq('*', 'as', $.identifier),
),
'from',
$.string,
),

target_scope_assignment: $ => seq('targetScope', '=', $.string),

metadata_declaration: $ => seq(
Expand Down Expand Up @@ -391,6 +403,7 @@ module.exports = grammar({
choice(
'module',
'import',
'provider',
'metadata',
'output',
'param',
Expand Down
4 changes: 2 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
(_))

(call_expression
function: (_)
function: (_)
(arguments (identifier) @parameter))

(call_expression
function: (_)
function: (_)
(arguments (member_expression object: (identifier) @parameter)))

; Variables
Expand Down
176 changes: 172 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"type": "SYMBOL",
"name": "import_with_statement"
},
{
"type": "SYMBOL",
"name": "import_functionality"
},
{
"type": "SYMBOL",
"name": "target_scope_assignment"
Expand Down Expand Up @@ -109,21 +113,60 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "import"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "import"
},
{
"type": "STRING",
"value": "provider"
}
]
},
{
"type": "SYMBOL",
"name": "import_string"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "BLANK"
}
]
}
]
},
"import_with_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "import"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "import"
},
{
"type": "STRING",
"value": "provider"
}
]
},
{
"type": "SYMBOL",
Expand All @@ -139,6 +182,127 @@
}
]
},
"import_functionality": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "import"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
}
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
},
{
"type": "STRING",
"value": "from"
},
{
"type": "SYMBOL",
"name": "string"
}
]
},
"target_scope_assignment": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -2159,6 +2323,10 @@
"type": "STRING",
"value": "import"
},
{
"type": "STRING",
"value": "provider"
},
{
"type": "STRING",
"value": "metadata"
Expand Down
41 changes: 40 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
"type": "decorators",
"named": true
},
{
"type": "import_functionality",
"named": true
},
{
"type": "import_statement",
"named": true
Expand Down Expand Up @@ -521,14 +525,37 @@
]
}
},
{
"type": "import_functionality",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "import_statement",
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "import_string",
"named": true
Expand Down Expand Up @@ -1361,6 +1388,10 @@
"type": "array",
"named": false
},
{
"type": "as",
"named": false
},
{
"type": "bool",
"named": false
Expand Down Expand Up @@ -1389,6 +1420,10 @@
"type": "for",
"named": false
},
{
"type": "from",
"named": false
},
{
"type": "identifier",
"named": true
Expand Down Expand Up @@ -1465,6 +1500,10 @@
"type": "property_identifier",
"named": true
},
{
"type": "provider",
"named": false
},
{
"type": "resource",
"named": false
Expand Down
Loading

0 comments on commit 02f3699

Please sign in to comment.