Skip to content

Commit

Permalink
Add support for inline Python expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubro committed Aug 15, 2023
1 parent 66b97d1 commit d4e9f50
Show file tree
Hide file tree
Showing 6 changed files with 6,543 additions and 6,025 deletions.
8 changes: 8 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,14 @@ module.exports = grammar({
$.scalar_variable,
$.list_variable,
$.dictionary_variable,
$.inline_python_expression,
),
repeat(seq(
optional(" "),
choice(
$.text_chunk,
$.scalar_variable,
$.inline_python_expression,
)
))
),
Expand Down Expand Up @@ -497,6 +499,12 @@ module.exports = grammar({
"}"
),

inline_python_expression: $ => prec.left(seq(
"${{",
alias(repeat(choice("}", /[^\r\n}]+/)), $.python_expression),
"}}",
)),

variable_name: $ => /[^{}]+/,

text_chunk: $ => token(seq(
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
(argument (scalar_variable) @variable)
(argument (list_variable) @variable)
(argument (dictionary_variable) @variable)
(argument (inline_python_expression) @string.special)

(ellipses) @punctuation.delimiter

Expand Down
46 changes: 46 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,10 @@
{
"type": "SYMBOL",
"name": "dictionary_variable"
},
{
"type": "SYMBOL",
"name": "inline_python_expression"
}
]
},
Expand Down Expand Up @@ -2398,6 +2402,10 @@
{
"type": "SYMBOL",
"name": "scalar_variable"
},
{
"type": "SYMBOL",
"name": "inline_python_expression"
}
]
}
Expand Down Expand Up @@ -2529,6 +2537,44 @@
}
]
},
"inline_python_expression": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "${{"
},
{
"type": "ALIAS",
"content": {
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "}"
},
{
"type": "PATTERN",
"value": "[^\\r\\n}]+"
}
]
}
},
"named": true,
"value": "python_expression"
},
{
"type": "STRING",
"value": "}}"
}
]
}
},
"variable_name": {
"type": "PATTERN",
"value": "[^{}]+"
Expand Down
36 changes: 36 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"type": "dictionary_variable",
"named": true
},
{
"type": "inline_python_expression",
"named": true
},
{
"type": "list_variable",
"named": true
Expand Down Expand Up @@ -402,6 +406,21 @@
]
}
},
{
"type": "inline_python_expression",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "python_expression",
"named": true
}
]
}
},
{
"type": "inline_statement",
"named": true,
Expand Down Expand Up @@ -516,6 +535,11 @@
]
}
},
{
"type": "python_expression",
"named": true,
"fields": {}
},
{
"type": "return_statement",
"named": true,
Expand Down Expand Up @@ -543,6 +567,10 @@
"type": "dictionary_variable",
"named": true
},
{
"type": "inline_python_expression",
"named": true
},
{
"type": "list_variable",
"named": true
Expand Down Expand Up @@ -906,6 +934,10 @@
"type": "${",
"named": false
},
{
"type": "${{",
"named": false
},
{
"type": "&{",
"named": false
Expand Down Expand Up @@ -1017,5 +1049,9 @@
{
"type": "}",
"named": false
},
{
"type": "}}",
"named": false
}
]
Loading

0 comments on commit d4e9f50

Please sign in to comment.